From 11c7f68a8ffb11bd16484b750a09f6e8d3a92f17 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 21 Oct 2021 17:20:13 +1300 Subject: [PATCH] API phpunit 9 support --- .travis.yml | 1 - composer.json | 4 +- 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, 59 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5dd52b3f..3e3177f3 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 91cda69d..5a03a01c 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "silverstripe/framework": "^4.4@dev", + "silverstripe/framework": "^4.10", "silverstripe/cms": "^4.4@dev", "silverstripe/admin": "^1.4@dev", "silverstripe/asset-admin": "^1.4@dev", @@ -23,7 +23,7 @@ "silverstripe/versioned": "^1.4@dev" }, "require-dev": { - "sminnee/phpunit": "^5.7", + "phpunit/phpunit": "^9", "squizlabs/php_codesniffer": "^3.0" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8b43ffd7..6a634a2e 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 705a31fb..ca29c685 100644 --- a/tests/php/BaseSubsiteTest.php +++ b/tests/php/BaseSubsiteTest.php @@ -9,7 +9,7 @@ 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 c2eaa3e4..5a0b19ea 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 5476f720..4ed62804 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 0b98f3bb..7f0fd7e0 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 9adb3211..4a9c667c 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 029ed263..e2993b0d 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 @@ public function testAnonymousIsForbiddenAdminAccess() $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 @@ public function testAdminCanAccessAllSubsites() $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 @@ public function testAdminIsRedirectedToObjectsSubsite() $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 @@ public function testAdminIsRedirectedToObjectsSubsite() $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 @@ public function testEditorCanAccessAllSubsites() $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 @@ public function testSubsiteAdmin() // 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 @@ public function testSubsiteAdmin() $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 9e3a2825..0fc10a89 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 fdd06707..1531315b 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 @@ protected function setUp() $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 5ec92fb2..521df920 100644 --- a/tests/php/SubsiteXHRControllerTest.php +++ b/tests/php/SubsiteXHRControllerTest.php @@ -36,12 +36,12 @@ public function testCanView() $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 527927f3..af98f4b6 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 @@ protected function setUp() $page->write(); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown();