From 360fbcd878c31625be57a8593943ac62556a5232 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 28 Oct 2021 10:40:52 +1300 Subject: [PATCH] API phpunit9 support --- composer.json | 6 ++-- phpunit.xml.dist | 10 +++---- tests/behat/src/FixtureContext.php | 7 +++-- tests/behat/src/LoginContext.php | 7 +++-- tests/php/Controllers/CMSBatchActionsTest.php | 2 +- tests/php/Controllers/CMSMainTest.php | 8 ++--- .../CMSPageHistoryControllerTest.php | 18 +++++------ .../ContentControllerPermissionsTest.php | 2 +- .../ContentControllerSearchExtensionTest.php | 4 +-- .../php/Controllers/ContentControllerTest.php | 4 +-- .../LeftAndMainPageIconsExtensionTest.php | 6 ++-- .../php/Controllers/ModelAsControllerTest.php | 2 +- tests/php/GraphQL/LinkablePluginTest.php | 2 +- tests/php/Model/RedirectorPageTest.php | 8 ++--- tests/php/Model/SiteTreeBacklinksTest.php | 4 +-- tests/php/Model/SiteTreeBrokenLinksTest.php | 4 +-- .../php/Model/SiteTreeHTMLEditorFieldTest.php | 4 +-- tests/php/Model/SiteTreeLinkTrackingTest.php | 2 +- tests/php/Model/SiteTreePermissionsTest.php | 4 +-- tests/php/Model/SiteTreeTest.php | 30 +++++++++---------- tests/php/Model/VirtualPageTest.php | 12 ++++---- tests/php/Reports/CmsReportsTest.php | 2 +- tests/php/Search/CMSMainSearchFormTest.php | 2 +- tests/php/Search/DatabaseSearchEngineTest.php | 2 +- tests/php/Search/SearchFormTest.php | 6 ++-- .../Tasks/MigrateSiteTreeLinkingTaskTest.php | 6 ++-- .../php/Tasks/RemoveOrphanedPagesTaskTest.php | 2 +- 27 files changed, 84 insertions(+), 82 deletions(-) diff --git a/composer.json b/composer.json index 0171a2a4..567d1d3c 100644 --- a/composer.json +++ b/composer.json @@ -21,15 +21,15 @@ "require": { "silverstripe/admin": "^1.9@dev", "silverstripe/campaign-admin": "^1.7@dev", - "silverstripe/framework": "^4.7@dev", + "silverstripe/framework": "^4.10", "silverstripe/reports": "^4.7@dev", "silverstripe/siteconfig": "^4.7@dev", "silverstripe/versioned": "^1.7@dev", "silverstripe/vendor-plugin": "^1.0", - "php": "^7.1 || ^8" + "php": "^7.3 || ^8.0" }, "require-dev": { - "sminnee/phpunit": "^5.7", + "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3" }, "extra": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ca5ce765..82808aba 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,9 +1,9 @@ - - - tests - - + + + tests + + . diff --git a/tests/behat/src/FixtureContext.php b/tests/behat/src/FixtureContext.php index 60f14317..93aa0476 100644 --- a/tests/behat/src/FixtureContext.php +++ b/tests/behat/src/FixtureContext.php @@ -5,6 +5,7 @@ namespace SilverStripe\CMS\Tests\Behaviour; use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Mink\Element\DocumentElement; use Behat\Mink\Element\NodeElement; +use PHPUnit\Framework\Assert; use SilverStripe\BehatExtension\Context\BasicContext; use SilverStripe\BehatExtension\Context\FixtureContext as BehatFixtureContext; use SilverStripe\CMS\Model\RedirectorPage; @@ -90,7 +91,7 @@ class FixtureContext extends BehatFixtureContext $page = $this->getMainContext()->getSession()->getPage(); $element = $page->find('css', $selector); - assertNotNull($element, sprintf('Element %s not found', $selector)); + Assert::assertNotNull($element, sprintf('Element %s not found', $selector)); } /** @@ -109,7 +110,7 @@ class FixtureContext extends BehatFixtureContext 'radio', $this->getMainContext()->getXpathEscaper()->escapeLiteral($radioLabel) ]); - assertNotNull($radioButton); - assertEquals($value, $radioButton->getAttribute($attribute)); + Assert::assertNotNull($radioButton); + Assert::assertEquals($value, $radioButton->getAttribute($attribute)); } } diff --git a/tests/behat/src/LoginContext.php b/tests/behat/src/LoginContext.php index ec20d1fb..93d982a8 100644 --- a/tests/behat/src/LoginContext.php +++ b/tests/behat/src/LoginContext.php @@ -3,6 +3,7 @@ namespace SilverStripe\CMS\Tests\Behaviour; use Page; +use PHPUnit\Framework\Assert; use SilverStripe\BehatExtension\Context\LoginContext as BehatLoginContext; class LoginContext extends BehatLoginContext @@ -20,16 +21,16 @@ class LoginContext extends BehatLoginContext { // Reset permission cache $page = Page::get()->First(); - assertNotNull($page, 'A page exists'); + Assert::assertNotNull($page, 'A page exists'); $email = "{$permCode}@example.org"; $password = 'Password!456'; $member = $this->generateMemberWithPermission($email, $password, $permCode); $canEdit = strstr($negative, 'not') ? false : true; if ($canEdit) { - assertTrue($page->canEdit($member), 'The member can edit this page'); + Assert::assertTrue($page->canEdit($member), 'The member can edit this page'); } else { - assertFalse($page->canEdit($member), 'The member cannot edit this page'); + Assert::assertFalse($page->canEdit($member), 'The member cannot edit this page'); } } } diff --git a/tests/php/Controllers/CMSBatchActionsTest.php b/tests/php/Controllers/CMSBatchActionsTest.php index eb8911fc..441e18b2 100644 --- a/tests/php/Controllers/CMSBatchActionsTest.php +++ b/tests/php/Controllers/CMSBatchActionsTest.php @@ -19,7 +19,7 @@ class CMSBatchActionsTest extends SapphireTest protected static $fixture_file = 'CMSBatchActionsTest.yml'; - public function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/php/Controllers/CMSMainTest.php b/tests/php/Controllers/CMSMainTest.php index 4a0e71a3..6584f0b8 100644 --- a/tests/php/Controllers/CMSMainTest.php +++ b/tests/php/Controllers/CMSMainTest.php @@ -32,7 +32,7 @@ class CMSMainTest extends FunctionalTest protected static $orig = []; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -128,7 +128,7 @@ class CMSMainTest extends FunctionalTest $this->logInAs('admin'); $response = $this->get('admin/pages/publishall?confirm=1'); - $this->assertContains( + $this->assertStringContainsString( 'Done: Published 30 pages', $response->getBody() ); @@ -218,7 +218,7 @@ class CMSMainTest extends FunctionalTest $this->assertTrue($livePage->canDelete()); // Check that the 'restore' button exists as a simple way of checking that the correct page is returned. - $this->assertRegExp('/