Skip to content

Commit

Permalink
Merge pull request #41 from tfrommen/php81-qa
Browse files Browse the repository at this point in the history
PHP 8.1 QA (Follow-Up)
  • Loading branch information
gmazzap authored Sep 18, 2023
2 parents 3907a50 + 5d3fe41 commit 86bec05
Show file tree
Hide file tree
Showing 19 changed files with 323 additions and 233 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/php-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: PHP Quality Assurance
on:
push:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
qa:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip')"
strategy:
fail-fast: true
matrix:
php-versions: ['5.5', '5.6']

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none
tools: parallel-lint
env:
fail-fast: true

- name: Check syntax error in sources
run: parallel-lint ./src/ ./tests/

- name: Install dependencies
uses: "ramsey/composer-install@v2"
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Check cross-version PHP compatibility
if: ${{ matrix.php-versions == '5.6' }}
run: composer phpcompat

- name: Run unit tests
run: ./vendor/bin/phpunit
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"phpunit/phpunit": "4.8.*",
"mockery/mockery": "0.9.3",
"brain/monkey": "~1.2.0",
"gmazzap/andrew": "~1.0.0"
"gmazzap/andrew": "~1.0.0",
"squizlabs/php_codesniffer": "^3.7",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"phpcompatibility/php-compatibility": "^9.3"
},
"autoload": {
"psr-4": {
Expand All @@ -46,6 +49,14 @@
},
"minimum-stability": "stable",
"config": {
"optimize-autoloader": true
"optimize-autoloader": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts" : {
"phpcompat": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs -ps . --standard=PHPCompatibility --exclude=PHPCompatibility.Attributes.NewAttributes --ignore=*/vendor/* --extensions=php --runtime-set testVersion 7.0-"
]
}
}
1 change: 0 additions & 1 deletion tests/boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@

@require_once $vendor.'antecedent/patchwork/Patchwork.php';
require_once $vendor.'autoload.php';
require_once $vendor.'phpunit/phpunit/src/Framework/Assert/Functions.php';

unset($vendor);
76 changes: 38 additions & 38 deletions tests/src/Functional/CortexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function testBootOnce()
$boot1 = Cortex::boot();
$boot2 = Cortex::boot();

assertTrue($boot1);
assertFalse($boot2);
static::assertTrue($boot1);
static::assertFalse($boot2);
}

/**
Expand Down Expand Up @@ -75,14 +75,14 @@ public function testCortexDoNothingIfNoRoutes()

$do = $cortex->doBoot($wp, true, $request);

assertTrue($do);
static::assertTrue($do);
}

public function testCortexBuildUriWithNoRequest()
{
$cortex = new Proxy(new Cortex());

assertInstanceOf(WordPressUri::class, $cortex->factoryUri());
static::assertInstanceOf(WordPressUri::class, $cortex->factoryUri());
}

public function testRouterReturnRouteResultsWhenGiven()
Expand All @@ -107,8 +107,8 @@ public function testRouterReturnRouteResultsWhenGiven()

$do = $cortex->doBoot($wp, true, $request);

assertTrue($do);
assertFalse(isset($wp->query_vars));
static::assertTrue($do);
static::assertFalse(isset($wp->query_vars));
}

public function testCortexMatchStaticRoute()
Expand All @@ -133,8 +133,8 @@ public function testCortexMatchStaticRoute()

$do = $cortex->doBoot($wp, true, $request);

assertSame(['post_type' => 'products'], $wp->query_vars);
assertFalse($do);
static::assertSame(['post_type' => 'products'], $wp->query_vars);
static::assertFalse($do);
}

public function testCortexMatchPagedRoute()
Expand All @@ -159,8 +159,8 @@ public function testCortexMatchPagedRoute()

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['paged' => 3], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['paged' => 3], $wp->query_vars);
}

public function testCortexAddPagedArgToMatchedPagedRoute()
Expand All @@ -173,7 +173,7 @@ public function testCortexAddPagedArgToMatchedPagedRoute()
->whenHappen(function (RouteCollectionInterface $routes) {
$routes->addRoute(new QueryRoute('/bar', function ($vars) {

assertSame(3, $vars['paged']);
static::assertSame(3, $vars['paged']);

return ['category' => 'bar'];
}, ['paged' => QueryRoute::PAGED_ARCHIVE]));
Expand All @@ -188,8 +188,8 @@ public function testCortexAddPagedArgToMatchedPagedRoute()

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['category' => 'bar', 'paged' => 3], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['category' => 'bar', 'paged' => 3], $wp->query_vars);
}

public function testCortexNotMatchIfDifferentMethod()
Expand All @@ -214,7 +214,7 @@ public function testCortexNotMatchIfDifferentMethod()

$do = $cortex->doBoot($wp, true, $request);

assertTrue($do);
static::assertTrue($do);
}

public function testCortexMatchStaticRouteWithUrlVars()
Expand Down Expand Up @@ -245,8 +245,8 @@ function (array $vars = []) {

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['post_type' => 'products', 'posts_per_page' => '12'], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['post_type' => 'products', 'posts_per_page' => '12'], $wp->query_vars);
}

public function testDefaultQueryVarsAreMerged()
Expand Down Expand Up @@ -277,8 +277,8 @@ function () {

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['posts_per_page' => 12, 'post_type' => 'products'], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['posts_per_page' => 12, 'post_type' => 'products'], $wp->query_vars);
}

public function testDefaultQueryVarsAreOverwrittenByRouteVars()
Expand Down Expand Up @@ -309,8 +309,8 @@ function (array $vars) {

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['posts_per_page' => '24', 'post_type' => 'products'], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['posts_per_page' => '24', 'post_type' => 'products'], $wp->query_vars);
}

public function testCortexMatchDynamicRouteWithUrlVars()
Expand Down Expand Up @@ -344,8 +344,8 @@ function (array $vars = []) {

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['post_type' => 'products', 'posts_per_page' => '12'], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['post_type' => 'products', 'posts_per_page' => '12'], $wp->query_vars);
}

public function testCortexNotMatchDynamicRouteBadRequirements()
Expand All @@ -372,8 +372,8 @@ public function testCortexNotMatchDynamicRouteBadRequirements()

$do = $cortex->doBoot($wp, true, $request);

assertTrue($do);
assertFalse(isset($wp->query_vars));
static::assertTrue($do);
static::assertFalse(isset($wp->query_vars));
}

public function testCortexMatchDynamicRouteOptionRequirements()
Expand All @@ -400,8 +400,8 @@ public function testCortexMatchDynamicRouteOptionRequirements()

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['greeting' => 'ciao'], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['greeting' => 'ciao'], $wp->query_vars);
}

public function testCortexNotMatchDynamicRouteBadOptionRequirements()
Expand All @@ -428,8 +428,8 @@ public function testCortexNotMatchDynamicRouteBadOptionRequirements()

$do = $cortex->doBoot($wp, true, $request);

assertTrue($do);
assertFalse(isset($wp->query_vars));
static::assertTrue($do);
static::assertFalse(isset($wp->query_vars));
}

public function testCortexMatchFirstRoute()
Expand Down Expand Up @@ -461,8 +461,8 @@ public function testCortexMatchFirstRoute()

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['first' => 'bar', 'second' => 'baz'], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['first' => 'bar', 'second' => 'baz'], $wp->query_vars);
}

public function testPreviewQueryArgsArePreserved()
Expand Down Expand Up @@ -492,8 +492,8 @@ public function testPreviewQueryArgsArePreserved()

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(
static::assertFalse($do);
static::assertSame(
[
'pagename' => 'bar',
'preview' => 'true',
Expand Down Expand Up @@ -532,8 +532,8 @@ public function testPreviewQueryArgsAreNotPreservedIfNotLogged()

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['pagename' => 'bar'], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['pagename' => 'bar'], $wp->query_vars);
}

public function testCortexNotMatchBecauseUrlChangedViaFilter()
Expand Down Expand Up @@ -569,8 +569,8 @@ public function testCortexNotMatchBecauseUrlChangedViaFilter()

$do = $cortex->doBoot($wp, true, $request);

assertTrue($do);
assertFalse(isset($wp->query_vars));
static::assertTrue($do);
static::assertFalse(isset($wp->query_vars));
}

public function testCortexMatchWhenUrlChangedViaFilterIsInvalid()
Expand Down Expand Up @@ -599,7 +599,7 @@ public function testCortexMatchWhenUrlChangedViaFilterIsInvalid()

$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['post_type' => 'products'], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['post_type' => 'products'], $wp->query_vars);
}
}
8 changes: 5 additions & 3 deletions tests/src/Functional/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ public function testAddRoutesAndGroups()
$wp = \Mockery::mock('WP');
$do = $cortex->doBoot($wp, true, $request);

assertFalse($do);
assertSame(['name' => 'baz'], $wp->query_vars);
static::assertFalse($do);
static::assertSame(['name' => 'baz'], $wp->query_vars);
}

public function testMatchRedirectRoute()
{
Functions::when('home_url')->justReturn('http://example.com/');

/** @var callable|null $factory */
$factory = null;

Expand All @@ -123,6 +125,6 @@ public function testMatchRedirectRoute()
$cortex = new Proxy(new Cortex());
$do = $cortex->doBoot(\Mockery::mock('WP'), true, $request);

assertTrue($do);
static::assertTrue($do);
}
}
4 changes: 2 additions & 2 deletions tests/src/Unit/Controller/QueryVarsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testRun()

$result = $controller->run(['foo' => 'bar'], $wp);

assertFalse($result);
assertSame(['foo' => 'bar'], $wp->query_vars);
static::assertFalse($result);
static::assertSame(['foo' => 'bar'], $wp->query_vars);
}
}
6 changes: 3 additions & 3 deletions tests/src/Unit/Controller/RedirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testRunDoNothingIfRedirectToIsInvalid()

$controller = new RedirectController();

assertTrue($controller->run(['redirect_to' => 'meh'], $wp));
static::assertTrue($controller->run(['redirect_to' => 'meh'], $wp));
}

public function testRunDefaultsToHomeUrlIfNoRedirectTo()
Expand All @@ -46,7 +46,7 @@ public function testRunDefaultsToHomeUrlIfNoRedirectTo()

$controller = new RedirectController();

assertTrue($controller->run([], $wp));
static::assertTrue($controller->run([], $wp));
}

public function testRunAllStatusSettings()
Expand All @@ -66,6 +66,6 @@ public function testRunAllStatusSettings()

$controller = new RedirectController();

assertTrue($controller->run($data, $wp));
static::assertTrue($controller->run($data, $wp));
}
}
8 changes: 4 additions & 4 deletions tests/src/Unit/Group/GroupCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function testAddGroup()
$proxy = new Proxy($collection);

/** @noinspection PhpUndefinedFieldInspection */
assertSame($proxy->groups, ['foo' => $group]);
assertSame($return, $collection);
static::assertSame($proxy->groups, ['foo' => $group]);
static::assertSame($return, $collection);
}

public function testMergeGroup()
Expand Down Expand Up @@ -79,7 +79,7 @@ public function testMergeGroup()
ksort($actual);
ksort($expected);

assertSame($expected, $actual);
static::assertSame($expected, $actual);
}

public function testMergeMultipleGroups()
Expand Down Expand Up @@ -130,6 +130,6 @@ public function testMergeMultipleGroups()
ksort($actual);
ksort($expected);

assertSame($expected, $actual);
static::assertSame($expected, $actual);
}
}
Loading

0 comments on commit 86bec05

Please sign in to comment.