diff --git a/.github/workflows/php-qa.yml b/.github/workflows/php-qa.yml new file mode 100644 index 0000000..b618a80 --- /dev/null +++ b/.github/workflows/php-qa.yml @@ -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 diff --git a/composer.json b/composer.json index 856e59f..584f21f 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -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-" + ] } } diff --git a/tests/boot.php b/tests/boot.php index 49bb30d..0310e6d 100644 --- a/tests/boot.php +++ b/tests/boot.php @@ -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); diff --git a/tests/src/Functional/CortexTest.php b/tests/src/Functional/CortexTest.php index c7791a2..0f04027 100644 --- a/tests/src/Functional/CortexTest.php +++ b/tests/src/Functional/CortexTest.php @@ -33,8 +33,8 @@ public function testBootOnce() $boot1 = Cortex::boot(); $boot2 = Cortex::boot(); - assertTrue($boot1); - assertFalse($boot2); + static::assertTrue($boot1); + static::assertFalse($boot2); } /** @@ -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() @@ -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() @@ -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() @@ -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() @@ -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])); @@ -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() @@ -214,7 +214,7 @@ public function testCortexNotMatchIfDifferentMethod() $do = $cortex->doBoot($wp, true, $request); - assertTrue($do); + static::assertTrue($do); } public function testCortexMatchStaticRouteWithUrlVars() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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', @@ -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() @@ -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() @@ -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); } } diff --git a/tests/src/Functional/RoutesTest.php b/tests/src/Functional/RoutesTest.php index 6c57b45..eccbed4 100644 --- a/tests/src/Functional/RoutesTest.php +++ b/tests/src/Functional/RoutesTest.php @@ -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; @@ -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); } } diff --git a/tests/src/Unit/Controller/QueryVarsControllerTest.php b/tests/src/Unit/Controller/QueryVarsControllerTest.php index a3abf38..0b84728 100644 --- a/tests/src/Unit/Controller/QueryVarsControllerTest.php +++ b/tests/src/Unit/Controller/QueryVarsControllerTest.php @@ -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); } } diff --git a/tests/src/Unit/Controller/RedirectControllerTest.php b/tests/src/Unit/Controller/RedirectControllerTest.php index 708442a..75a798b 100644 --- a/tests/src/Unit/Controller/RedirectControllerTest.php +++ b/tests/src/Unit/Controller/RedirectControllerTest.php @@ -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() @@ -46,7 +46,7 @@ public function testRunDefaultsToHomeUrlIfNoRedirectTo() $controller = new RedirectController(); - assertTrue($controller->run([], $wp)); + static::assertTrue($controller->run([], $wp)); } public function testRunAllStatusSettings() @@ -66,6 +66,6 @@ public function testRunAllStatusSettings() $controller = new RedirectController(); - assertTrue($controller->run($data, $wp)); + static::assertTrue($controller->run($data, $wp)); } } diff --git a/tests/src/Unit/Group/GroupCollectionTest.php b/tests/src/Unit/Group/GroupCollectionTest.php index c23d326..c56e5e2 100644 --- a/tests/src/Unit/Group/GroupCollectionTest.php +++ b/tests/src/Unit/Group/GroupCollectionTest.php @@ -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() @@ -79,7 +79,7 @@ public function testMergeGroup() ksort($actual); ksort($expected); - assertSame($expected, $actual); + static::assertSame($expected, $actual); } public function testMergeMultipleGroups() @@ -130,6 +130,6 @@ public function testMergeMultipleGroups() ksort($actual); ksort($expected); - assertSame($expected, $actual); + static::assertSame($expected, $actual); } } diff --git a/tests/src/Unit/Group/GroupTest.php b/tests/src/Unit/Group/GroupTest.php index 92ba9d0..da67d30 100644 --- a/tests/src/Unit/Group/GroupTest.php +++ b/tests/src/Unit/Group/GroupTest.php @@ -24,14 +24,14 @@ public function testIdWhenGiven() { $group = new Group(['id' => 'test_me']); - assertSame('test_me', $group->id()); + static::assertSame('test_me', $group->id()); } public function testIdWhenDefault() { $group = new Group([]); - assertStringMatchesFormat('group_%s', $group->id()); + static::assertStringMatchesFormat('group_%s', $group->id()); } public function testToArrayStripsInvalid() @@ -60,7 +60,7 @@ public function testToArrayStripsInvalid() ksort($expected); ksort($actual); - assertSame($expected, $actual); + static::assertSame($expected, $actual); } public function testArrayAccess() @@ -74,21 +74,21 @@ public function testArrayAccess() 'priority' => 0, ]); - assertFalse($group->offsetExists('foo')); - assertTrue($group->offsetExists('id')); // id is auto generated - assertTrue($group->offsetExists('vars')); - assertSame('/', $group->offsetGet('path')); - assertSame(0, $group->offsetGet('priority')); + static::assertFalse($group->offsetExists('foo')); + static::assertTrue($group->offsetExists('id')); // id is auto generated + static::assertTrue($group->offsetExists('vars')); + static::assertSame('/', $group->offsetGet('path')); + static::assertSame(0, $group->offsetGet('priority')); unset($group['path']); $group['priority'] = 1; $group->offsetUnset('id'); $group->offsetUnset('vars'); - assertNull($group->offsetGet('path')); - assertSame(1, $group->offsetGet('priority')); - assertTrue($group->offsetExists('id')); // id cannot be unset - assertFalse($group->offsetExists('vars')); - assertSame('__return_true', $group['handler']); + static::assertNull($group->offsetGet('path')); + static::assertSame(1, $group->offsetGet('priority')); + static::assertTrue($group->offsetExists('id')); // id cannot be unset + static::assertFalse($group->offsetExists('vars')); + static::assertSame('__return_true', $group['handler']); } } diff --git a/tests/src/Unit/Route/ActionRouteTest.php b/tests/src/Unit/Route/ActionRouteTest.php index 329c262..120a58a 100644 --- a/tests/src/Unit/Route/ActionRouteTest.php +++ b/tests/src/Unit/Route/ActionRouteTest.php @@ -34,21 +34,21 @@ public function testArrayAccess() 'priority' => 0 ]); - assertFalse($route->offsetExists('foo')); - assertTrue($route->offsetExists('id')); // id is auto generated - assertSame(0, $route->offsetGet('priority')); - assertSame('foo/bar', $route->offsetGet('path')); - assertSame([], $route->offsetGet('vars')); - assertInternalType('callable', $route->offsetGet('handler')); + static::assertFalse($route->offsetExists('foo')); + static::assertTrue($route->offsetExists('id')); // id is auto generated + static::assertSame(0, $route->offsetGet('priority')); + static::assertSame('foo/bar', $route->offsetGet('path')); + static::assertSame([], $route->offsetGet('vars')); + static::assertInternalType('callable', $route->offsetGet('handler')); unset($route['path']); $route['priority'] = 1; $route->offsetUnset('id'); $route->offsetUnset('vars'); - assertNull($route->offsetGet('path')); - assertSame(1, $route->offsetGet('priority')); - assertTrue($route->offsetExists('id')); // id cannot be unset - assertFalse($route->offsetExists('vars')); + static::assertNull($route->offsetGet('path')); + static::assertSame(1, $route->offsetGet('priority')); + static::assertTrue($route->offsetExists('id')); // id cannot be unset + static::assertFalse($route->offsetExists('vars')); } } diff --git a/tests/src/Unit/Route/PriorityRouteCollectionTest.php b/tests/src/Unit/Route/PriorityRouteCollectionTest.php index 375cdc2..e827467 100644 --- a/tests/src/Unit/Route/PriorityRouteCollectionTest.php +++ b/tests/src/Unit/Route/PriorityRouteCollectionTest.php @@ -40,9 +40,9 @@ public function testAddRoute() $proxy = new Proxy($collection); - assertSame(4, count($collection)); + static::assertSame(4, count($collection)); /** @noinspection PhpUndefinedFieldInspection */ - assertSame([10, 11, 5, 9], $proxy->priorities); + static::assertSame([10, 11, 5, 9], $proxy->priorities); $actual = []; /** @var Route $route */ @@ -50,7 +50,7 @@ public function testAddRoute() $actual[] = $route->id(); } - assertSame(['r_3', 'r_4', 'r_1', 'r_2'], $actual); + static::assertSame(['r_3', 'r_4', 'r_1', 'r_2'], $actual); } public function testPagedNotAddedIfNoPath() @@ -61,9 +61,9 @@ public function testPagedNotAddedIfNoPath() $collection->addRoute($route); $proxy = new Proxy($collection); - assertSame(1, count($collection)); + static::assertSame(1, count($collection)); /** @noinspection PhpUndefinedFieldInspection */ - assertSame([10], $proxy->priorities); + static::assertSame([10], $proxy->priorities); } public function testPagedSingle() @@ -78,17 +78,17 @@ public function testPagedSingle() $collection->addRoute($route); $proxy = new Proxy($collection); - assertSame(2, count($collection)); + static::assertSame(2, count($collection)); /** @noinspection PhpUndefinedFieldInspection */ - assertSame([10, 11], $proxy->priorities); + static::assertSame([10, 11], $proxy->priorities); /** @var Route $route */ $i = 0; foreach ($collection as $route) { $id = $i === 0 ? 'route_example_paged' : 'route_example'; $path = $i === 0 ? '/foo/{page:\d+}' : '/foo'; - assertSame($id, $route->id()); - assertSame($path, $route['path']); + static::assertSame($id, $route->id()); + static::assertSame($path, $route['path']); $i++; } } @@ -106,17 +106,17 @@ public function testPagedArchive() $collection->addRoute($route); $proxy = new Proxy($collection); - assertSame(2, count($collection)); + static::assertSame(2, count($collection)); /** @noinspection PhpUndefinedFieldInspection */ - assertSame([32, 33], $proxy->priorities); + static::assertSame([32, 33], $proxy->priorities); /** @var Route $route */ $i = 0; foreach ($collection as $route) { $id = $i === 0 ? 'route_example_paged' : 'route_example'; $path = $i === 0 ? '/bar/page/{paged:\d+}' : '/bar'; - assertSame($id, $route->id()); - assertSame($path, $route['path']); + static::assertSame($id, $route->id()); + static::assertSame($path, $route['path']); $i++; } } diff --git a/tests/src/Unit/Route/QueryRouteTest.php b/tests/src/Unit/Route/QueryRouteTest.php index 8896bf1..b0475b1 100644 --- a/tests/src/Unit/Route/QueryRouteTest.php +++ b/tests/src/Unit/Route/QueryRouteTest.php @@ -36,22 +36,22 @@ public function testArrayAccess() 'priority' => 0 ]); - assertFalse($route->offsetExists('foo')); - assertTrue($route->offsetExists('id')); // id is auto generated - assertSame(0, $route->offsetGet('priority')); - assertSame('foo/bar', $route->offsetGet('path')); - assertSame($vars, $route->offsetGet('vars')); - assertInstanceOf(QueryVarsController::class, $route->offsetGet('handler')); + static::assertFalse($route->offsetExists('foo')); + static::assertTrue($route->offsetExists('id')); // id is auto generated + static::assertSame(0, $route->offsetGet('priority')); + static::assertSame('foo/bar', $route->offsetGet('path')); + static::assertSame($vars, $route->offsetGet('vars')); + static::assertInstanceOf(QueryVarsController::class, $route->offsetGet('handler')); unset($route['path']); $route['priority'] = 1; $route->offsetUnset('id'); $route->offsetUnset('vars'); - assertNull($route->offsetGet('path')); - assertSame(1, $route->offsetGet('priority')); - assertTrue($route->offsetExists('id')); // id cannot be unset - assertFalse($route->offsetExists('vars')); + static::assertNull($route->offsetGet('path')); + static::assertSame(1, $route->offsetGet('priority')); + static::assertTrue($route->offsetExists('id')); // id cannot be unset + static::assertFalse($route->offsetExists('vars')); } public function testToArray() @@ -65,17 +65,17 @@ public function testToArray() $array = $route->toArray(); - assertTrue(array_key_exists('id', $array)); - assertTrue(array_key_exists('handler', $array)); - assertTrue(array_key_exists('vars', $array)); - assertTrue(array_key_exists('priority', $array)); - assertFalse(array_key_exists('foo', $array)); - assertFalse(array_key_exists(0, $array)); - assertFalse(array_key_exists(1, $array)); - assertTrue(array_key_exists('meh', $array)); - assertSame('foo/bar', $array['path']); - assertSame(['foo' => 'bar'], $array['vars']); - assertInstanceOf(QueryVarsController::class, $array['handler']); + static::assertTrue(array_key_exists('id', $array)); + static::assertTrue(array_key_exists('handler', $array)); + static::assertTrue(array_key_exists('vars', $array)); + static::assertTrue(array_key_exists('priority', $array)); + static::assertFalse(array_key_exists('foo', $array)); + static::assertFalse(array_key_exists(0, $array)); + static::assertFalse(array_key_exists(1, $array)); + static::assertTrue(array_key_exists('meh', $array)); + static::assertSame('foo/bar', $array['path']); + static::assertSame(['foo' => 'bar'], $array['vars']); + static::assertInstanceOf(QueryVarsController::class, $array['handler']); } public function testId() @@ -83,7 +83,7 @@ public function testId() $route1 = new QueryRoute('foo/bar', []); $route2 = new QueryRoute('foo/bar', [], ['id' => 'route_2']); - assertStringMatchesFormat('route_%s', $route1->id()); - assertSame('route_2', $route2->id()); + static::assertStringMatchesFormat('route_%s', $route1->id()); + static::assertSame('route_2', $route2->id()); } } diff --git a/tests/src/Unit/Route/RedirectRouteTest.php b/tests/src/Unit/Route/RedirectRouteTest.php index 8a8f571..e5b5b65 100644 --- a/tests/src/Unit/Route/RedirectRouteTest.php +++ b/tests/src/Unit/Route/RedirectRouteTest.php @@ -35,9 +35,9 @@ public function testAutoAbsoluteRedirectToFromString() 'redirect_to' => 'http://example.com/meh', ]; - assertSame('/path/from', $route['path']); - assertSame($expectedVars, $route['vars']); - assertSame(2, $route['priority']); + static::assertSame('/path/from', $route['path']); + static::assertSame($expectedVars, $route['vars']); + static::assertSame(2, $route['priority']); } public function testRedirectToInternalFromAbsoluteString() @@ -50,8 +50,8 @@ public function testRedirectToInternalFromAbsoluteString() 'redirect_to' => 'https://foo.bar/', ]; - assertSame('/path/from', $route['path']); - assertSame($expectedVars, $route['vars']); + static::assertSame('/path/from', $route['path']); + static::assertSame($expectedVars, $route['vars']); } public function testRedirectToNullIfBadStringExternal() @@ -68,8 +68,8 @@ public function testRedirectToNullIfBadStringExternal() 'redirect_to' => '', ]; - assertSame('/from', $route['path']); - assertSame($expectedVars, $route['vars']); + static::assertSame('/from', $route['path']); + static::assertSame($expectedVars, $route['vars']); } public function testRedirectToExternalFromString() @@ -82,8 +82,8 @@ public function testRedirectToExternalFromString() 'redirect_to' => 'https://foo.bar/', ]; - assertSame('/path/from', $route['path']); - assertSame($expectedVars, $route['vars']); + static::assertSame('/path/from', $route['path']); + static::assertSame($expectedVars, $route['vars']); } public function testAutoAbsoluteRedirectToFromCallback() @@ -106,10 +106,10 @@ function (array $args) { 'redirect_to' => 'http://example.com/bar', ]; - assertSame('/path/from', $route['path']); - assertSame(2, $route['priority']); - assertInstanceOf('Closure', $route['vars']); - assertSame($expectedVars, $route['vars'](['foo' => 'bar'])); + static::assertSame('/path/from', $route['path']); + static::assertSame(2, $route['priority']); + static::assertInstanceOf('Closure', $route['vars']); + static::assertSame($expectedVars, $route['vars'](['foo' => 'bar'])); } public function testRedirectToInternalEmptyIfCallbackReturnNoString() @@ -127,8 +127,8 @@ function (array $args) { 'redirect_to' => '', ]; - assertInstanceOf('Closure', $route['vars']); - assertSame($expectedVars, $route['vars'](['bar' => 111])); + static::assertInstanceOf('Closure', $route['vars']); + static::assertSame($expectedVars, $route['vars'](['bar' => 111])); } public function testRedirectToInternalEmptyString() @@ -141,7 +141,7 @@ public function testRedirectToInternalEmptyString() 'redirect_to' => '', ]; - assertSame($expectedVars, $route['vars']); + static::assertSame($expectedVars, $route['vars']); } public function testAbsoluteRedirectToFromCallback() @@ -160,10 +160,10 @@ function (array $args) { 'redirect_to' => 'http://example.com/bar', ]; - assertSame('/path/from', $route['path']); - assertSame(2, $route['priority']); - assertInstanceOf('Closure', $route['vars']); - assertSame($expectedVars, $route['vars'](['foo' => 'bar'])); + static::assertSame('/path/from', $route['path']); + static::assertSame(2, $route['priority']); + static::assertInstanceOf('Closure', $route['vars']); + static::assertSame($expectedVars, $route['vars'](['foo' => 'bar'])); } public function testRedirectToExternalFromCallback() @@ -182,9 +182,9 @@ function (array $args) { 'redirect_to' => 'https://www.bar.it/', ]; - assertSame('/path/from', $route['path']); - assertInstanceOf('Closure', $route['vars']); - assertSame($expectedVars, $route['vars'](['sub' => 'www'])); + static::assertSame('/path/from', $route['path']); + static::assertInstanceOf('Closure', $route['vars']); + static::assertSame($expectedVars, $route['vars'](['sub' => 'www'])); } public function testRedirectToExternalEmptyIfCallbackReturnNoUrl() @@ -203,9 +203,9 @@ function (array $args) { 'redirect_to' => '', ]; - assertSame('/path/from', $route['path']); - assertInstanceOf('Closure', $route['vars']); - assertSame($expectedVars, $route['vars'](['sub' => 'www'])); + static::assertSame('/path/from', $route['path']); + static::assertInstanceOf('Closure', $route['vars']); + static::assertSame($expectedVars, $route['vars'](['sub' => 'www'])); } public function testStatusTo301IfBad() @@ -218,6 +218,6 @@ public function testStatusTo301IfBad() 'redirect_to' => 'http://example.com', ]; - assertSame($expectedVars, $route['vars']); + static::assertSame($expectedVars, $route['vars']); } } diff --git a/tests/src/Unit/Route/RouteTest.php b/tests/src/Unit/Route/RouteTest.php index 8f37f8f..9baba2d 100644 --- a/tests/src/Unit/Route/RouteTest.php +++ b/tests/src/Unit/Route/RouteTest.php @@ -36,23 +36,23 @@ public function testArrayAccess() 'priority' => 0, ]); - assertFalse($route->offsetExists('foo')); - assertSame('meh', $route->offsetGet('meh')); - assertTrue($route->offsetExists('id')); // id is auto generated - assertSame(0, $route->offsetGet('priority')); - assertSame('/', $route->offsetGet('path')); - assertSame($vars, $route->offsetGet('vars')); - assertSame('__return_true', $route->offsetGet('handler')); + static::assertFalse($route->offsetExists('foo')); + static::assertSame('meh', $route->offsetGet('meh')); + static::assertTrue($route->offsetExists('id')); // id is auto generated + static::assertSame(0, $route->offsetGet('priority')); + static::assertSame('/', $route->offsetGet('path')); + static::assertSame($vars, $route->offsetGet('vars')); + static::assertSame('__return_true', $route->offsetGet('handler')); unset($route['path']); $route['priority'] = 1; $route->offsetUnset('id'); $route->offsetUnset('vars'); - assertNull($route->offsetGet('path')); - assertSame(1, $route->offsetGet('priority')); - assertTrue($route->offsetExists('id')); // id cannot be unset - assertFalse($route->offsetExists('vars')); + static::assertNull($route->offsetGet('path')); + static::assertSame(1, $route->offsetGet('priority')); + static::assertTrue($route->offsetExists('id')); // id cannot be unset + static::assertFalse($route->offsetExists('vars')); } public function testToArray() @@ -68,17 +68,17 @@ public function testToArray() $array = $route->toArray(); - assertTrue(array_key_exists('id', $array)); - assertTrue(array_key_exists('vars', $array)); - assertTrue(array_key_exists('priority', $array)); - assertFalse(array_key_exists('handler', $array)); - assertFalse(array_key_exists('foo', $array)); - assertFalse(array_key_exists(0, $array)); - assertFalse(array_key_exists(1, $array)); - assertSame(['foo' => 'bar'], $array['meh']); - assertSame('foo/bar', $array['path']); - assertSame(['foo' => 'bar'], $array['vars']); - assertStringMatchesFormat('route_%s', $array['id']); + static::assertTrue(array_key_exists('id', $array)); + static::assertTrue(array_key_exists('vars', $array)); + static::assertTrue(array_key_exists('priority', $array)); + static::assertFalse(array_key_exists('handler', $array)); + static::assertFalse(array_key_exists('foo', $array)); + static::assertFalse(array_key_exists(0, $array)); + static::assertFalse(array_key_exists(1, $array)); + static::assertSame(['foo' => 'bar'], $array['meh']); + static::assertSame('foo/bar', $array['path']); + static::assertSame(['foo' => 'bar'], $array['vars']); + static::assertStringMatchesFormat('route_%s', $array['id']); } public function testId() @@ -86,7 +86,7 @@ public function testId() $route1 = new Route([]); $route2 = new Route(['id' => 'route_2']); - assertStringMatchesFormat('route_%s', $route1->id()); - assertSame('route_2', $route2->id()); + static::assertStringMatchesFormat('route_%s', $route1->id()); + static::assertSame('route_2', $route2->id()); } } diff --git a/tests/src/Unit/Router/ResultHandlerTest.php b/tests/src/Unit/Router/ResultHandlerTest.php index 59c54ca..854bca9 100644 --- a/tests/src/Unit/Router/ResultHandlerTest.php +++ b/tests/src/Unit/Router/ResultHandlerTest.php @@ -36,8 +36,8 @@ public function testHandleDoNothingIfNotMarched() $handler = new ResultHandler(); - assertTrue($handler->handle($result, $wp, true)); - assertFalse($handler->handle($result, $wp, false)); + static::assertTrue($handler->handle($result, $wp, true)); + static::assertFalse($handler->handle($result, $wp, false)); } public function testHandleAllCallbacks() @@ -85,8 +85,8 @@ public function testHandleAllCallbacks() $handler = new ResultHandler(); - assertFalse($handler->handle($result, $wp, true)); - assertSame($expected, $accumulator); + static::assertFalse($handler->handle($result, $wp, true)); + static::assertSame($expected, $accumulator); } public function testHandleTemplate() @@ -136,7 +136,7 @@ public function testHandleTemplate() $wp = \Mockery::mock('WP'); - assertTrue($handler->handle($result, $wp, true)); + static::assertTrue($handler->handle($result, $wp, true)); } public function testHandleTemplateDoNothingIfNoTemplateFound() @@ -186,6 +186,6 @@ public function testHandleTemplateDoNothingIfNoTemplateFound() $wp = \Mockery::mock('WP'); - assertTrue($handler->handle($result, $wp, true)); + static::assertTrue($handler->handle($result, $wp, true)); } } diff --git a/tests/src/Unit/Router/RouteFilterIteratorTest.php b/tests/src/Unit/Router/RouteFilterIteratorTest.php index 01867da..fc8af77 100644 --- a/tests/src/Unit/Router/RouteFilterIteratorTest.php +++ b/tests/src/Unit/Router/RouteFilterIteratorTest.php @@ -45,7 +45,7 @@ public function testAcceptForScheme() $ok[] = $route->id(); } - assertSame(['r1', 'r3'], $ok); + static::assertSame(['r1', 'r3'], $ok); } public function testAcceptForHost() @@ -70,7 +70,7 @@ public function testAcceptForHost() $ok[] = $route->id(); } - assertSame(['r1', 'r3'], $ok); + static::assertSame(['r1', 'r3'], $ok); } public function testAcceptForHostWildcard() @@ -95,6 +95,6 @@ public function testAcceptForHostWildcard() $ok[] = $route->id(); } - assertSame(['r1', 'r2', 'r3'], $ok); + static::assertSame(['r1', 'r2', 'r3'], $ok); } } diff --git a/tests/src/Unit/Router/RouterTest.php b/tests/src/Unit/Router/RouterTest.php index c6e9b84..12a8fb3 100644 --- a/tests/src/Unit/Router/RouterTest.php +++ b/tests/src/Unit/Router/RouterTest.php @@ -44,7 +44,7 @@ public function testMatchNothingIfAlreadyMatched() /** @noinspection PhpUndefinedFieldInspection */ $proxy->results = $result; - assertSame($result, $router->match($uri, 'GET')); + static::assertSame($result, $router->match($uri, 'GET')); } public function testMatchNothingIfNoRoutes() @@ -71,8 +71,8 @@ public function testMatchNothingIfNoRoutes() /** @noinspection PhpUndefinedFieldInspection */ $data = $proxy->data; - assertFalse($result->matched()); - assertSame($expected, $data); + static::assertFalse($result->matched()); + static::assertSame($expected, $data); } public function testMatchNothingIfNoFilteredRoutes() @@ -104,8 +104,8 @@ public function testMatchNothingIfNoFilteredRoutes() /** @noinspection PhpUndefinedFieldInspection */ $data = $proxy->data; - assertFalse($result->matched()); - assertSame($expected, $data); + static::assertFalse($result->matched()); + static::assertSame($expected, $data); } public function testMatchNothingIfNoValidatingRoutes() @@ -141,8 +141,8 @@ public function testMatchNothingIfNoValidatingRoutes() /** @noinspection PhpUndefinedFieldInspection */ $data = $proxy->data; - assertFalse($result->matched()); - assertSame($expected, $data); + static::assertFalse($result->matched()); + static::assertSame($expected, $data); } public function testMatchNotMatching() @@ -176,7 +176,7 @@ public function testMatchNotMatching() $dispatcher->shouldReceive('dispatch')->with('POST', '/bar')->andReturn([0]); $factory = function (array $args) use ($dispatcher) { - assertSame($args, ['foo' => 'bar']); + static::assertSame($args, ['foo' => 'bar']); return $dispatcher; }; @@ -199,8 +199,8 @@ public function testMatchNotMatching() /** @noinspection PhpUndefinedFieldInspection */ $data = $proxy->data; - assertFalse($result->matched()); - assertSame($expected, $data); + static::assertFalse($result->matched()); + static::assertSame($expected, $data); } public function testMatchMatchingExactMatch() @@ -237,7 +237,7 @@ public function testMatchMatchingExactMatch() $dispatcher->shouldReceive('dispatch')->never(); $factory = function (array $args) use ($dispatcher) { - assertSame($args, ['foo' => 'bar']); + static::assertSame($args, ['foo' => 'bar']); return $dispatcher; }; @@ -263,8 +263,8 @@ public function testMatchMatchingExactMatch() ksort($expected); ksort($data); - assertTrue($result->matched()); - assertSame($expected, $data); + static::assertTrue($result->matched()); + static::assertSame($expected, $data); } public function testMatchDynamicMatch() @@ -309,7 +309,7 @@ public function testMatchDynamicMatch() ]); $factory = function (array $args) use ($dispatcher) { - assertSame($args, ['foo' => 'bar']); + static::assertSame($args, ['foo' => 'bar']); return $dispatcher; }; @@ -335,8 +335,8 @@ public function testMatchDynamicMatch() ksort($expected); ksort($data); - assertTrue($result->matched()); - assertSame($expected, $data); + static::assertTrue($result->matched()); + static::assertSame($expected, $data); } public function testMatchMatchingExactMatchNoQueryVars() @@ -374,7 +374,7 @@ public function testMatchMatchingExactMatchNoQueryVars() $dispatcher->shouldReceive('dispatch')->never(); $factory = function (array $args) use ($dispatcher) { - assertSame($args, ['foo' => 'bar']); + static::assertSame($args, ['foo' => 'bar']); return $dispatcher; }; @@ -397,8 +397,8 @@ public function testMatchMatchingExactMatchNoQueryVars() /** @noinspection PhpUndefinedFieldInspection */ $data = $proxy->data; - assertTrue($result->matched()); - assertSame($expected, $data); + static::assertTrue($result->matched()); + static::assertSame($expected, $data); } public function testMatchMatchingNoQueryVarsMaintainPreviewVar() @@ -443,7 +443,7 @@ public function testMatchMatchingNoQueryVarsMaintainPreviewVar() $dispatcher->shouldReceive('dispatch')->never(); $factory = function (array $args) use ($dispatcher) { - assertSame($args, ['foo' => 'bar']); + static::assertSame($args, ['foo' => 'bar']); return $dispatcher; }; @@ -474,8 +474,8 @@ public function testMatchMatchingNoQueryVarsMaintainPreviewVar() ksort($data); ksort($expected); - assertTrue($result->matched()); - assertSame($expected, $data); + static::assertTrue($result->matched()); + static::assertSame($expected, $data); } public function testMatchMatchingExactMatchCallableVars() @@ -514,7 +514,7 @@ public function testMatchMatchingExactMatchCallableVars() $dispatcher->shouldReceive('dispatch')->never(); $factory = function (array $args) use ($dispatcher) { - assertSame($args, ['foo' => 'bar']); + static::assertSame($args, ['foo' => 'bar']); return $dispatcher; }; @@ -537,7 +537,7 @@ public function testMatchMatchingExactMatchCallableVars() /** @noinspection PhpUndefinedFieldInspection */ $data = $proxy->data; - assertTrue($result->matched()); - assertSame($expected, $data); + static::assertTrue($result->matched()); + static::assertSame($expected, $data); } } diff --git a/tests/src/Unit/Uri/PsrUriTest.php b/tests/src/Unit/Uri/PsrUriTest.php index 0bf0d1b..44c819d 100644 --- a/tests/src/Unit/Uri/PsrUriTest.php +++ b/tests/src/Unit/Uri/PsrUriTest.php @@ -27,7 +27,7 @@ public function testGetSchemeSsl() $uri = new PsrUri(['HTTP_HOST' => 'example.com']); - assertSame('https', $uri->getScheme()); + static::assertSame('https', $uri->getScheme()); } public function testGetSchemeNoSsl() @@ -36,72 +36,101 @@ public function testGetSchemeNoSsl() $uri = new PsrUri(['HTTP_HOST' => 'example.com']); - assertSame('http', $uri->getScheme()); + static::assertSame('http', $uri->getScheme()); } public function testGetHostFromHttpHost() { + Functions::when('is_ssl')->justReturn(false); + $uri = new PsrUri(['HTTP_HOST' => 'example.com']); - assertSame('example.com', $uri->getHost()); + static::assertSame('example.com', $uri->getHost()); } public function testGetHostFromHttpServerName() { + Functions::when('is_ssl')->justReturn(false); + $uri = new PsrUri(['SERVER_NAME' => 'example.it']); - assertSame('example.it', $uri->getHost()); + static::assertSame('example.it', $uri->getHost()); } public function testGetHostFromHomeUrl() { + Functions::when('is_ssl')->justReturn(false); Functions::when('home_url')->justReturn('http://www.example.co.uk/wp/'); $uri = new PsrUri(['meh' => 'meh']); - assertSame('www.example.co.uk', $uri->getHost()); + static::assertSame('www.example.co.uk', $uri->getHost()); } public function testGetHostStripPort() { + Functions::when('is_ssl')->justReturn(false); + $uri = new PsrUri(['HTTP_HOST' => 'example.com:8080']); - assertSame('example.com', $uri->getHost()); + static::assertSame('example.com', $uri->getHost()); } public function testGetPath() { - $uri = new PsrUri(['REQUEST_URI' => '/foo/bar/']); + Functions::when('is_ssl')->justReturn(false); + + $uri = new PsrUri([ + 'HTTP_HOST' => 'example.com', + 'REQUEST_URI' => '/foo/bar/', + ]); - assertSame('foo/bar', $uri->getPath()); + static::assertSame('foo/bar', $uri->getPath()); } public function testGetPathStripHost() { - $uri = new PsrUri(['REQUEST_URI' => 'http://example.com/foo/bar/']); + Functions::when('is_ssl')->justReturn(false); + + $uri = new PsrUri([ + 'HTTP_HOST' => 'example.com', + 'REQUEST_URI' => 'http://example.com/foo/bar/', + ]); - assertSame('foo/bar', $uri->getPath()); + static::assertSame('foo/bar', $uri->getPath()); } public function testGetQuery() { - $uri = new PsrUri(['QUERY_STRING' => 'foo=bar']); + Functions::when('is_ssl')->justReturn(false); - assertSame('foo=bar', $uri->getQuery()); + $uri = new PsrUri([ + 'HTTP_HOST' => 'example.com', + 'QUERY_STRING' => 'foo=bar', + ]); + + static::assertSame('foo=bar', $uri->getQuery()); } public function testGetQueryStripQuestion() { - $uri = new PsrUri(['QUERY_STRING' => '?foo=bar']); + Functions::when('is_ssl')->justReturn(false); - assertSame('foo=bar', $uri->getQuery()); + $uri = new PsrUri([ + 'HTTP_HOST' => 'example.com', + 'QUERY_STRING' => '?foo=bar', + ]); + + static::assertSame('foo=bar', $uri->getQuery()); } public function testGetQueryEmpty() { + Functions::when('is_ssl')->justReturn(false); + $uri = new PsrUri(['HTTP_HOST' => 'example.com']); - assertSame('', $uri->getQuery()); + static::assertSame('', $uri->getQuery()); } public function testToString() @@ -114,7 +143,7 @@ public function testToString() 'QUERY_STRING' => '?foo=bar', ]); - assertSame('https:://example.com/foo/bar?foo=bar', (string) $uri); + static::assertSame('https:://example.com/foo/bar?foo=bar', (string) $uri); } /** diff --git a/tests/src/Unit/Uri/WordPressUriTest.php b/tests/src/Unit/Uri/WordPressUriTest.php index c3ffa2b..ccae53c 100644 --- a/tests/src/Unit/Uri/WordPressUriTest.php +++ b/tests/src/Unit/Uri/WordPressUriTest.php @@ -42,11 +42,11 @@ public function testNoHomePath() $uri = $this->psrUriFromUrl('https://www.example.com/foo/bar.php?meh=1'); $wpUri = new WordPressUri($uri); - assertSame('https', $wpUri->scheme()); - assertSame('www.example.com', $wpUri->host()); - assertSame('foo/bar.php', $wpUri->path()); - assertSame(['foo', 'bar.php'], $wpUri->chunks()); - assertSame(['meh' => '1'], $wpUri->vars()); + static::assertSame('https', $wpUri->scheme()); + static::assertSame('www.example.com', $wpUri->host()); + static::assertSame('foo/bar.php', $wpUri->path()); + static::assertSame(['foo', 'bar.php'], $wpUri->chunks()); + static::assertSame(['meh' => '1'], $wpUri->vars()); } public function testNoQueryVars() @@ -56,11 +56,11 @@ public function testNoQueryVars() $uri = $this->psrUriFromUrl('https://www.example.com/foo/bar/'); $wpUri = new WordPressUri($uri); - assertSame('https', $wpUri->scheme()); - assertSame('www.example.com', $wpUri->host()); - assertSame('foo/bar', $wpUri->path()); - assertSame(['foo', 'bar'], $wpUri->chunks()); - assertSame([], $wpUri->vars()); + static::assertSame('https', $wpUri->scheme()); + static::assertSame('www.example.com', $wpUri->host()); + static::assertSame('foo/bar', $wpUri->path()); + static::assertSame(['foo', 'bar'], $wpUri->chunks()); + static::assertSame([], $wpUri->vars()); } public function testHomeUrlHomePath() @@ -70,11 +70,11 @@ public function testHomeUrlHomePath() $uri = $this->psrUriFromUrl('https://www.example.com/foo/'); $wpUri = new WordPressUri($uri); - assertSame('https', $wpUri->scheme()); - assertSame('www.example.com', $wpUri->host()); - assertSame('/', $wpUri->path()); - assertSame([], $wpUri->chunks()); - assertSame([], $wpUri->vars()); + static::assertSame('https', $wpUri->scheme()); + static::assertSame('www.example.com', $wpUri->host()); + static::assertSame('/', $wpUri->path()); + static::assertSame([], $wpUri->chunks()); + static::assertSame([], $wpUri->vars()); } public function testHomeUrlNoHomePath() @@ -84,10 +84,10 @@ public function testHomeUrlNoHomePath() $uri = $this->psrUriFromUrl('https://www.example.com/'); $wpUri = new WordPressUri($uri); - assertSame('https', $wpUri->scheme()); - assertSame('www.example.com', $wpUri->host()); - assertSame('/', $wpUri->path()); - assertSame([], $wpUri->chunks()); - assertSame([], $wpUri->vars()); + static::assertSame('https', $wpUri->scheme()); + static::assertSame('www.example.com', $wpUri->host()); + static::assertSame('/', $wpUri->path()); + static::assertSame([], $wpUri->chunks()); + static::assertSame([], $wpUri->vars()); } }