diff --git a/composer.json b/composer.json index 9a682f60c..d3ce3935a 100644 --- a/composer.json +++ b/composer.json @@ -19,13 +19,13 @@ } ], "require": { - "silverstripe/framework": "^4.5", + "silverstripe/framework": "^4.10", "silverstripe/versioned": "^1@dev", "silverstripe/vendor-plugin": "^1.0", "php": "^7.1 || ^8" }, "require-dev": { - "sminnee/phpunit": "^5.7", + "phpunit/phpunit": "^9", "squizlabs/php_codesniffer": "^3", "nikic/php-parser": "^3 || ^4", "monolog/monolog": "~1.16" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1d2d96658..618dcb550 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,7 +4,9 @@ Standard module phpunit configuration. Requires PHPUnit ^5.7 --> - - tests/php - + + + tests/php + + diff --git a/tests/behat/src/AdminContext.php b/tests/behat/src/AdminContext.php index 69f8b53d3..206b39f3a 100644 --- a/tests/behat/src/AdminContext.php +++ b/tests/behat/src/AdminContext.php @@ -3,6 +3,7 @@ namespace SilverStripe\Admin\Tests\Behat\Context; use Behat\Behat\Context\Context; +use PHPUnit\Framework\Assert; use SilverStripe\BehatExtension\Context\MainContextAwareTrait; class AdminContext implements Context @@ -29,10 +30,10 @@ public function iShouldSeeAnInvalidTabIcon(string $not, string $tabLabel) $element = $page->find('css', $selector); $hiddenElement = $page->find('css', $hiddenSelector); $message = "Tab validation icon for $id is visible when it should not be"; - assertTrue(is_null($element) || $hiddenElement, $message); + Assert::assertTrue(is_null($element) || $hiddenElement, $message); } else { $element = $page->find('css', $selector); - assertNotNull($element, "Tab validation icon for $id was not found"); + Assert::assertNotNull($element, "Tab validation icon for $id was not found"); } } @@ -48,15 +49,15 @@ public function iCanSeeTheFormValidationErrorMessage($not) $element = $page->find('css', $selector); if ($not) { if (is_null($element)) { - assertTrue(true); + Assert::assertTrue(true); } else { $message = 'Form validation error message is present when it should not be'; - assertFalse(strpos($element->getText(), $text), $message); + Assert::assertFalse(strpos($element->getText(), $text), $message); } } else { $message = sprintf('Element %s not found', $selector); - assertNotNull($element, $message); - assertTrue(strpos($element->getText(), $text) !== false, $message); + Assert::assertNotNull($element, $message); + Assert::assertTrue(strpos($element->getText(), $text) !== false, $message); } } } diff --git a/tests/php/CMSMenuItemTest.php b/tests/php/CMSMenuItemTest.php index 7db9f964e..33e4352df 100644 --- a/tests/php/CMSMenuItemTest.php +++ b/tests/php/CMSMenuItemTest.php @@ -45,6 +45,6 @@ public function testAttributes() ); $menuItem->setAttributes(['' => '']); - $this->assertNotContains('', $menuItem->getAttributesHTML(), 'Html is escaped for both name and value'); + $this->assertStringNotContainsString('', $menuItem->getAttributesHTML(), 'Html is escaped for both name and value'); } } diff --git a/tests/php/CMSMenuTest.php b/tests/php/CMSMenuTest.php index 77e1f6578..ba7ec0fd1 100644 --- a/tests/php/CMSMenuTest.php +++ b/tests/php/CMSMenuTest.php @@ -25,7 +25,7 @@ public function testBasicMenuHandling() $menuItems = CMSMenu::get_menu_items(); $menuItem = $menuItems['SilverStripe-Admin-Tests-CMSMenuTest-LeftAndMainController']; $this->assertInstanceOf(CMSMenuItem::class, $menuItem, 'Controller menu item is of class CMSMenuItem'); - $this->assertContains( + $this->assertStringContainsString( $menuItem->url, CMSMenuTest\LeftAndMainController::singleton()->Link(), 'Controller menu item has the correct link' @@ -112,7 +112,7 @@ public function testAdvancedMenuHandling() CMSMenu::populate_menu(); $menuItem = CMSMenu::get_menu_item('SilverStripe-Admin-SecurityAdmin'); $this->assertInstanceOf(CMSMenuItem::class, $menuItem, 'SecurityAdmin menu item exists'); - $this->assertContains($menuItem->url, SecurityAdmin::singleton()->Link(), 'Menu item has the correct link'); + $this->assertStringContainsString($menuItem->url, SecurityAdmin::singleton()->Link(), 'Menu item has the correct link'); $this->assertEquals( SecurityAdmin::class, $menuItem->controller, diff --git a/tests/php/LeftAndMainTest.php b/tests/php/LeftAndMainTest.php index ce4762228..d5797ea63 100644 --- a/tests/php/LeftAndMainTest.php +++ b/tests/php/LeftAndMainTest.php @@ -19,7 +19,7 @@ class LeftAndMainTest extends FunctionalTest protected $backupCombined; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -50,7 +50,7 @@ protected function resetMenu() CMSMenu::populate_menu(); } - public function tearDown() + protected function tearDown(): void { parent::tearDown(); Requirements::set_combined_files_enabled($this->backupCombined); @@ -62,12 +62,12 @@ public function testExtraCssAndJavascript() $this->logInAs($admin); $response = $this->get('admin/security'); - $this->assertRegExp( + $this->assertMatchesRegularExpression( '/tests\/php\/assets\/LeftAndMainTest.css/i', $response->getBody(), "body should contain custom css" ); - $this->assertRegExp( + $this->assertMatchesRegularExpression( '/tests\/php\/assets\/LeftAndMainTest.js/i', $response->getBody(), "body should contain custom js" @@ -95,9 +95,9 @@ public function testLeftAndMainSubclasses() $this->assertInstanceOf(HTTPResponse::class, $response, "$link should return a response object"); $this->assertEquals(200, $response->getStatusCode(), "$link should return 200 status code"); // Check that a HTML page has been returned - $this->assertRegExp('/]*>/i', $response->getBody(), "$link should contain tag"); - $this->assertRegExp('/]*>/i', $response->getBody(), "$link should contain tag"); - $this->assertRegExp('/]*>/i', $response->getBody(), "$link should contain tag"); + $this->assertMatchesRegularExpression('/]*>/i', $response->getBody(), "$link should contain tag"); + $this->assertMatchesRegularExpression('/]*>/i', $response->getBody(), "$link should contain tag"); + $this->assertMatchesRegularExpression('/]*>/i', $response->getBody(), "$link should contain tag"); } public function testCanView() diff --git a/tests/php/ModelAdminTest.php b/tests/php/ModelAdminTest.php index a2a35947b..b75888bf7 100644 --- a/tests/php/ModelAdminTest.php +++ b/tests/php/ModelAdminTest.php @@ -134,12 +134,12 @@ public function testGetGridField() $field = $form->Fields()->fieldByName('SilverStripe-Admin-Tests-ModelAdminTest-Player'); $this->assertNotNull($field, 'A GridField has been found on the form.'); - $this->assertContains( + $this->assertStringContainsString( 'OverridenModelAdmin', $field->extraClass(), 'OverridenModelAdmin has added an extra class to the grid field' ); - $this->assertContains( + $this->assertStringContainsString( 'called', $field->getAttribute('ModelAdminExtension'), 'ModelAdminExtension has added an attribute to the GridField' diff --git a/tests/php/SecurityAdminTest.php b/tests/php/SecurityAdminTest.php index bea2751b1..d2a9f0ae7 100644 --- a/tests/php/SecurityAdminTest.php +++ b/tests/php/SecurityAdminTest.php @@ -27,7 +27,7 @@ class SecurityAdminTest extends FunctionalTest // $lines = preg_split('/\n/', $this->content()); // $this->assertEquals(count($lines), 3, "Export with members has one content row"); - // $this->assertRegExp('/"","","admin@example.com"/', $lines[1], "Member values are correctly exported"); + // $this->assertMatchesRegularExpression('/"","","admin@example.com"/', $lines[1], "Member values are correctly exported"); // } // TODO Fix export feature (moved from MemberTableField to GridFieldExportButton) @@ -57,11 +57,11 @@ public function testPermissionFieldRespectsHiddenPermissions() Config::modify()->merge(Permission::class, 'hidden_permissions', array('CMS_ACCESS_ReportAdmin')); $response = $this->get(sprintf('admin/security/EditForm/field/Groups/item/%d/edit', $group->ID)); - $this->assertContains( + $this->assertStringContainsString( 'CMS_ACCESS_SecurityAdmin', $response->getBody() ); - $this->assertNotContains( + $this->assertStringNotContainsString( 'CMS_ACCESS_ReportAdmin', $response->getBody() );