From 13ab07230357e96df17fef6af3c9f792297f42f1 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 27 Oct 2021 18:24:03 +1300 Subject: [PATCH] API phpunit 9 support --- .travis.yml | 1 - composer.json | 5 ++- phpunit.xml.dist | 8 ++-- tests/php/BaseSubsiteTest.php | 2 +- tests/php/GroupSubsitesTest.php | 4 +- tests/php/InitStateMiddlewareTest.php | 4 +- tests/php/Service/ThemeResolverTest.php | 2 +- tests/php/SiteTreeSubsitesTest.php | 2 +- tests/php/SubsiteAdminFunctionalTest.php | 50 +++++++++++++++++------- tests/php/SubsiteAdminTest.php | 2 +- tests/php/SubsiteTest.php | 4 +- tests/php/SubsiteXHRControllerTest.php | 10 ++--- tests/php/SubsitesVirtualPageTest.php | 4 +- 13 files changed, 60 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5dd52b3..3e3177f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,4 @@ import: env: global: - - COMPOSER_ROOT_VERSION="2.x-dev" - BEHAT_SUITE="@subsites" diff --git a/composer.json b/composer.json index 91cda69..eeca054 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ } ], "require": { - "silverstripe/framework": "^4.4@dev", + "php": "^7.3 || ^8.0", + "silverstripe/framework": "^4.10", "silverstripe/cms": "^4.4@dev", "silverstripe/admin": "^1.4@dev", "silverstripe/asset-admin": "^1.4@dev", @@ -23,7 +24,7 @@ "silverstripe/versioned": "^1.4@dev" }, "require-dev": { - "sminnee/phpunit": "^5.7", + "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3.0" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8b43ffd..6a634a2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,9 @@ - - tests/php - + + + tests/php + + diff --git a/tests/php/BaseSubsiteTest.php b/tests/php/BaseSubsiteTest.php index 705a31f..ca29c68 100644 --- a/tests/php/BaseSubsiteTest.php +++ b/tests/php/BaseSubsiteTest.php @@ -9,7 +9,7 @@ use SilverStripe\Subsites\State\SubsiteState; class BaseSubsiteTest extends SapphireTest { - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/php/GroupSubsitesTest.php b/tests/php/GroupSubsitesTest.php index c2eaa3e..5a0b19e 100644 --- a/tests/php/GroupSubsitesTest.php +++ b/tests/php/GroupSubsitesTest.php @@ -15,8 +15,8 @@ class GroupSubsitesTest extends BaseSubsiteTest public function testTrivialFeatures() { - $this->assertInternalType('array', singleton(GroupSubsites::class)->extraStatics()); - $this->assertInternalType('array', singleton(GroupSubsites::class)->providePermissions()); + $this->assertIsArray(singleton(GroupSubsites::class)->extraStatics()); + $this->assertIsArray(singleton(GroupSubsites::class)->providePermissions()); $this->assertInstanceOf(FieldList::class, singleton(Group::class)->getCMSFields()); } diff --git a/tests/php/InitStateMiddlewareTest.php b/tests/php/InitStateMiddlewareTest.php index 5476f72..4ed6280 100644 --- a/tests/php/InitStateMiddlewareTest.php +++ b/tests/php/InitStateMiddlewareTest.php @@ -19,14 +19,14 @@ class InitStateMiddlewareTest extends BaseSubsiteTest */ protected $origServer = []; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->origServer = $_SERVER; } - protected function tearDown() + protected function tearDown(): void { $_SERVER = $this->origServer; diff --git a/tests/php/Service/ThemeResolverTest.php b/tests/php/Service/ThemeResolverTest.php index 0b98f3b..7f0fd7e 100644 --- a/tests/php/Service/ThemeResolverTest.php +++ b/tests/php/Service/ThemeResolverTest.php @@ -18,7 +18,7 @@ class ThemeResolverTest extends SapphireTest SSViewer::DEFAULT_THEME, ]; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/php/SiteTreeSubsitesTest.php b/tests/php/SiteTreeSubsitesTest.php index 9adb321..4a9c667 100644 --- a/tests/php/SiteTreeSubsitesTest.php +++ b/tests/php/SiteTreeSubsitesTest.php @@ -42,7 +42,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest ], ]; - protected function setUp() + protected function setUp(): void { // We have our own home page fixtures, prevent the default one being created in this test suite. Config::modify()->set(SiteTree::class, 'create_default_pages', false); diff --git a/tests/php/SubsiteAdminFunctionalTest.php b/tests/php/SubsiteAdminFunctionalTest.php index 029ed26..e2993b0 100644 --- a/tests/php/SubsiteAdminFunctionalTest.php +++ b/tests/php/SubsiteAdminFunctionalTest.php @@ -14,7 +14,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest protected $autoFollowRedirection = false; - protected function setUp() + protected function setUp(): void { parent::setUp(); // Ensure all pages are published @@ -48,14 +48,18 @@ class SubsiteAdminFunctionalTest extends FunctionalTest $this->logOut(); $response = $this->getAndFollowAll('admin/pages/?SubsiteID=0'); - $this->assertContains('Security/login', $this->mainSession->lastUrl(), 'Admin is disallowed'); + $this->assertStringContainsString('Security/login', $this->mainSession->lastUrl(), 'Admin is disallowed'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1'); $response = $this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}"); - $this->assertContains('Security/login', $this->mainSession->lastUrl(), 'Admin is disallowed'); + $this->assertStringContainsString('Security/login', $this->mainSession->lastUrl(), 'Admin is disallowed'); $response = $this->getAndFollowAll('admin/subsite_xhr'); - $this->assertContains('Security/login', $this->mainSession->lastUrl(), 'SubsiteXHRController is disallowed'); + $this->assertStringContainsString( + 'Security/login', + $this->mainSession->lastUrl(), + 'SubsiteXHRController is disallowed' + ); } /** @@ -67,17 +71,21 @@ class SubsiteAdminFunctionalTest extends FunctionalTest $this->getAndFollowAll('admin/pages/?SubsiteID=0'); $this->assertEquals(0, $this->session()->get('SubsiteID'), 'Can access main site.'); - $this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section'); + $this->assertStringContainsString('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1'); $this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}"); // Check the session manually, since the state is unique to the request, not this test $this->assertEquals($subsite1->ID, $this->session()->get('SubsiteID'), 'Can access other subsite.'); - $this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section'); + $this->assertStringContainsString('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section'); $response = $this->getAndFollowAll('admin/subsite_xhr'); - $this->assertNotContains('Security/login', $this->mainSession->lastUrl(), 'SubsiteXHRController is reachable'); + $this->assertStringNotContainsString( + 'Security/login', + $this->mainSession->lastUrl(), + 'SubsiteXHRController is reachable' + ); } public function testAdminIsRedirectedToObjectsSubsite() @@ -92,7 +100,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest $response = $this->get("admin/pages/edit/show/$subsite1Home->ID"); $this->assertEquals(302, $response->getStatusCode()); - $this->assertContains( + $this->assertStringContainsString( 'admin/pages/edit/show/' . $subsite1Home->ID . '?SubsiteID=' . $subsite1Home->SubsiteID, $response->getHeader('Location') ); @@ -102,7 +110,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest $response = $this->get("admin/pages/edit/show/$subsite1Home->ID"); $this->assertEquals(302, $response->getStatusCode()); - $this->assertContains( + $this->assertStringContainsString( 'admin/pages/edit/show/' . $subsite1Home->ID . '?SubsiteID=' . $subsite1Home->SubsiteID, $response->getHeader('Location') ); @@ -122,15 +130,19 @@ class SubsiteAdminFunctionalTest extends FunctionalTest $this->get('admin/pages/?SubsiteID=0'); $this->assertEquals(0, $this->session()->get('SubsiteID'), 'Can access main site.'); - $this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section'); + $this->assertStringContainsString('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1'); $this->get("admin/pages/?SubsiteID={$subsite1->ID}"); $this->assertEquals($subsite1->ID, $this->session()->get('SubsiteID'), 'Can access other subsite.'); - $this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section'); + $this->assertStringContainsString('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section'); $response = $this->get('admin/subsite_xhr'); - $this->assertNotContains('Security/login', $this->mainSession->lastUrl(), 'SubsiteXHRController is reachable'); + $this->assertStringNotContainsString( + 'Security/login', + $this->mainSession->lastUrl(), + 'SubsiteXHRController is reachable' + ); } /** @@ -146,7 +158,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest // Check allowed URL. $this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}"); $this->assertEquals($subsite1->ID, $this->session()->get('SubsiteID'), 'Can access own subsite.'); - $this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Can access permitted section.'); + $this->assertStringContainsString( + 'admin/pages', + $this->mainSession->lastUrl(), + 'Can access permitted section.' + ); // Check forbidden section in allowed subsite. $this->getAndFollowAll("admin/assets/?SubsiteID={$subsite1->ID}"); @@ -172,10 +188,14 @@ class SubsiteAdminFunctionalTest extends FunctionalTest $subsite1->ID, 'Is redirected to first permitted subsite.' ); - $this->assertNotContains('Security/login', $this->mainSession->lastUrl(), 'Is not denied access'); + $this->assertStringNotContainsString('Security/login', $this->mainSession->lastUrl(), 'Is not denied access'); // Check the standalone XHR controller. $response = $this->getAndFollowAll('admin/subsite_xhr'); - $this->assertNotContains('Security/login', $this->mainSession->lastUrl(), 'SubsiteXHRController is reachable'); + $this->assertStringNotContainsString( + 'Security/login', + $this->mainSession->lastUrl(), + 'SubsiteXHRController is reachable' + ); } } diff --git a/tests/php/SubsiteAdminTest.php b/tests/php/SubsiteAdminTest.php index 9e3a282..0fc10a8 100644 --- a/tests/php/SubsiteAdminTest.php +++ b/tests/php/SubsiteAdminTest.php @@ -11,7 +11,7 @@ class SubsiteAdminTest extends FunctionalTest { protected static $fixture_file = 'SubsiteTest.yml'; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/php/SubsiteTest.php b/tests/php/SubsiteTest.php index fdd0670..1531315 100644 --- a/tests/php/SubsiteTest.php +++ b/tests/php/SubsiteTest.php @@ -26,7 +26,7 @@ class SubsiteTest extends BaseSubsiteTest */ protected $origServer = []; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -38,7 +38,7 @@ class SubsiteTest extends BaseSubsiteTest $this->origServer = $_SERVER; } - protected function tearDown() + protected function tearDown(): void { $_SERVER = $this->origServer; diff --git a/tests/php/SubsiteXHRControllerTest.php b/tests/php/SubsiteXHRControllerTest.php index 5ec92fb..521df92 100644 --- a/tests/php/SubsiteXHRControllerTest.php +++ b/tests/php/SubsiteXHRControllerTest.php @@ -36,12 +36,12 @@ class SubsiteXHRControllerTest extends FunctionalTest $this->assertEquals(200, $result->getStatusCode()); // SilverStripe 4.0-4.2: text/json. >=4.3: application/json - $this->assertContains('json', $result->getHeader('Content-Type')); + $this->assertStringContainsString('json', $result->getHeader('Content-Type')); $body = $result->getBody(); - $this->assertContains('Main site', $body); - $this->assertContains('Test 1', $body); - $this->assertContains('Test 2', $body); - $this->assertContains('Test 3', $body); + $this->assertStringContainsString('Main site', $body); + $this->assertStringContainsString('Test 1', $body); + $this->assertStringContainsString('Test 2', $body); + $this->assertStringContainsString('Test 3', $body); } } diff --git a/tests/php/SubsitesVirtualPageTest.php b/tests/php/SubsitesVirtualPageTest.php index 527927f..af98f4b 100644 --- a/tests/php/SubsitesVirtualPageTest.php +++ b/tests/php/SubsitesVirtualPageTest.php @@ -21,7 +21,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest 'SubsitesVirtualPageTest.yml', ]; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -43,7 +43,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest $page->write(); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown();