diff --git a/composer.json b/composer.json index a2501247..94b29fdb 100644 --- a/composer.json +++ b/composer.json @@ -20,15 +20,15 @@ } ], "require": { + "php": "^7.3 || ^8.0", "silverstripe/admin": "^1.6", - "silverstripe/framework": "^4.6", + "silverstripe/framework": "^4.10", "silverstripe/versioned": "^1.6", "silverstripe/graphql": "^3.5 || ^4", "silverstripe/vendor-plugin": "^1" }, "require-dev": { - "sminnee/phpunit": "^5", - "sminnee/phpunit-mock-objects": "^3.4.5", + "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3", "silverstripe/cms": "^4.6" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d9c630eb..82bd3199 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,9 @@ - - tests - - + + + tests + + src/ diff --git a/tests/ArchiveAdminTest.php b/tests/ArchiveAdminTest.php index 650820fd..7fdacf1f 100644 --- a/tests/ArchiveAdminTest.php +++ b/tests/ArchiveAdminTest.php @@ -23,7 +23,7 @@ class ArchiveAdminTest extends SapphireTest ViewProviderVersionedObject::class, ]; - protected function setUp() + protected function setUp(): void { parent::setUp(); } diff --git a/tests/Behat/Context/FeatureContext.php b/tests/Behat/Context/FeatureContext.php index 1f8f8745..7425f03d 100644 --- a/tests/Behat/Context/FeatureContext.php +++ b/tests/Behat/Context/FeatureContext.php @@ -3,6 +3,7 @@ namespace SilverStripe\VersionedAdmin\Tests\Behat\Context; use Behat\Mink\Element\NodeElement; +use PHPUnit\Framework\Assert; use SilverStripe\BehatExtension\Context\SilverStripeContext; if (!class_exists(SilverStripeContext::class)) { @@ -25,7 +26,7 @@ public function iShouldSeeAListOfVersions() public function iShouldSeeAListOfVersionsInDescendingOrder() { $versions = $this->getVersions(); - assertNotEmpty($versions, 'I see a list of versions'); + Assert::assertNotEmpty($versions, 'I see a list of versions'); $previous = null; @@ -43,7 +44,7 @@ public function iShouldSeeAListOfVersionsInDescendingOrder() */ public function iClickOnTheFirstVersion() { - assertNotNull($this->getLatestVersion(), 'I should see a list of versions'); + Assert::assertNotNull($this->getLatestVersion(), 'I should see a list of versions'); $this->getLatestVersion()->click(); } @@ -61,7 +62,7 @@ public function iClickOnVersion($versionNo) break; } } - assertNotNull($desiredVersion, 'Desired version ' . $versionNo . ' was not found in the page.'); + Assert::assertNotNull($desiredVersion, 'Desired version ' . $versionNo . ' was not found in the page.'); $this->clickVersion($desiredVersion); } @@ -71,7 +72,7 @@ public function iClickOnVersion($versionNo) public function iOpenTheHistoryViewerActionsMenu() { $button = $this->getSession()->getPage()->find('css', '.history-viewer__heading .history-viewer__actions .btn'); - assertNotNull($button, 'History viewer actions menu not found in the page.'); + Assert::assertNotNull($button, 'History viewer actions menu not found in the page.'); $button->click(); } @@ -85,7 +86,7 @@ public function theTextShouldBeDeleted($text) 'xpath', sprintf('//del[contains(normalize-space(string(.)), \'%s\')]', $text) ); - assertNotNull($result, $text . ' was not shown as deleted'); + Assert::assertNotNull($result, $text . ' was not shown as deleted'); } /** @@ -97,7 +98,7 @@ public function theTextShouldBeAdded($text) 'xpath', sprintf('//ins[contains(normalize-space(string(.)), \'%s\')]', $text) ); - assertNotNull($result, $text . ' was not shown as added'); + Assert::assertNotNull($result, $text . ' was not shown as added'); } /** @@ -158,7 +159,7 @@ public function iShouldSeeInTheAuthorColumn($text, $versionNumber) $authorColumn = $version->find('css', '.history-viewer__author'); $exists = strpos($authorColumn->getText(), $text) !== false; - assertTrue($exists, 'Author column contains ' . $text); + Assert::assertTrue($exists, 'Author column contains ' . $text); } /** @@ -172,7 +173,7 @@ public function iShouldSeeInTheRecordColumn($text, $versionNumber) $recordColumn = $version->find('css', '.history-viewer__version-state'); $exists = strpos($recordColumn->getText(), $text) !== false; - assertTrue($exists, 'Record column contains ' . $text); + Assert::assertTrue($exists, 'Record column contains ' . $text); } /** @@ -184,7 +185,7 @@ public function iShouldSeeInTheVersionColumn($text, $versionNumber) $versionColumn = $version->find('css', '.history-viewer__version-no'); $exists = strpos($versionColumn->getText(), $text) !== false; - assertTrue($exists, 'Version column contains ' . $text); + Assert::assertTrue($exists, 'Version column contains ' . $text); } /** diff --git a/tests/Controllers/HistoryViewerControllerTest.php b/tests/Controllers/HistoryViewerControllerTest.php index 4edfe0c6..1de2234b 100644 --- a/tests/Controllers/HistoryViewerControllerTest.php +++ b/tests/Controllers/HistoryViewerControllerTest.php @@ -85,22 +85,18 @@ public function testSchema() $this->assertSame('application/json', $result->getHeader('Content-Type')); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessageRegExp /Missing required field/ - */ public function testGetVersionFormThrowsExceptionWhenArgsAreMissing() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/Missing required field/'); $controller = new HistoryViewerController(); $controller->getVersionForm([]); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessageRegExp /Missing required field/ - */ public function testGetVersionFormThrowsExceptionWhenArgsAreFalsy() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/Missing required field/'); $controller = new HistoryViewerController(); $controller->getVersionForm([ 'RecordClass' => 'Page', @@ -109,12 +105,10 @@ public function testGetVersionFormThrowsExceptionWhenArgsAreFalsy() ]); } - /** - * @expectedException \SilverStripe\Control\HTTPResponse_Exception - * @expectedExceptionCode 404 - */ public function testGetVersionFormThrowsExceptionWhenRecordVersionDoesntExist() { + $this->expectException(\SilverStripe\Control\HTTPResponse_Exception::class); + $this->expectExceptionCode(404); $controller = new HistoryViewerController(); $controller->getVersionForm([ 'RecordClass' => UnviewableVersionedObject::class, @@ -123,13 +117,11 @@ public function testGetVersionFormThrowsExceptionWhenRecordVersionDoesntExist() ]); } - /** - * @expectedException \SilverStripe\Control\HTTPResponse_Exception - * @expectedExceptionCode 403 - * @expectedExceptionMessage You don't have the necessary permissions to view Unviewable Versioned Object - */ public function testGetVersionFormThrowsExceptionWhenCanViewIsFalse() { + $this->expectException(\SilverStripe\Control\HTTPResponse_Exception::class); + $this->expectExceptionCode(403); + $this->expectExceptionMessage("You don't have the necessary permissions to view Unviewable Versioned Object"); $controller = new HistoryViewerController(); $controller->getVersionForm([ 'RecordClass' => UnviewableVersionedObject::class, @@ -151,32 +143,26 @@ public function testGetVersionFormReturnsForm() $this->assertInstanceOf(LeftAndMainFormRequestHandler::class, $result->getRequestHandler()); } - /** - * @expectedException \SilverStripe\Control\HTTPResponse_Exception - * @expectedExceptionCode 400 - */ public function testVersionFormThrowsExceptionWithoutRequest() { + $this->expectException(\SilverStripe\Control\HTTPResponse_Exception::class); + $this->expectExceptionCode(400); $controller = new HistoryViewerController(); $controller->versionForm(null); } - /** - * @expectedException \SilverStripe\Control\HTTPResponse_Exception - * @expectedExceptionCode 400 - */ public function testCompareFormThrowsExceptionWithoutRequest() { + $this->expectException(\SilverStripe\Control\HTTPResponse_Exception::class); + $this->expectExceptionMessage(400); $controller = new HistoryViewerController(); $controller->compareForm(null); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessageRegExp /Missing required field/ - */ public function testVersionFormThrowsExceptionWhenArgsAreFalsy() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/Missing required field/'); $controller = new HistoryViewerController(); $controller->getVersionForm([ 'RecordClass' => 'Page', diff --git a/tests/Forms/DataObjectVersionFormFactoryTest.php b/tests/Forms/DataObjectVersionFormFactoryTest.php index 9dfc6696..0dd00ad3 100644 --- a/tests/Forms/DataObjectVersionFormFactoryTest.php +++ b/tests/Forms/DataObjectVersionFormFactoryTest.php @@ -29,7 +29,7 @@ class DataObjectVersionFormFactoryTest extends SapphireTest */ protected $controller; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -56,12 +56,10 @@ public function testIsReadonlyFormType() ); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Missing required context Record - */ public function testGetFormThrowsExceptionOnMissingRequiredContext() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Missing required context Record'); $this->factory->getForm(); } diff --git a/tests/Forms/DiffFieldTest.php b/tests/Forms/DiffFieldTest.php index 796d187c..08ed3183 100644 --- a/tests/Forms/DiffFieldTest.php +++ b/tests/Forms/DiffFieldTest.php @@ -19,7 +19,7 @@ public function testScalarValuesAreDiffed() $diffField->setComparisonField($newField); $diffField->setValue('old'); - $this->assertRegExp('/^new<\/ins> *old<\/del>$/', $diffField->Value()); + $this->assertMatchesRegularExpression('/^new<\/ins> *old<\/del>$/', $diffField->Value()); } /** diff --git a/tests/Forms/DiffTransformationTest.php b/tests/Forms/DiffTransformationTest.php index 7741a72a..1158d849 100644 --- a/tests/Forms/DiffTransformationTest.php +++ b/tests/Forms/DiffTransformationTest.php @@ -27,7 +27,7 @@ class DiffTransformationTest extends SapphireTest */ private $testForm; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -62,8 +62,8 @@ public function testTransform() $form->loadDataFrom($oldData); foreach ($form->Fields() as $index => $field) { - $this->assertContains($expected[$index]['before'], $field->Value(), 'Value before is shown'); - $this->assertContains($expected[$index]['after'], $field->Value(), 'Value after is shown'); + $this->assertStringContainsString($expected[$index]['before'], $field->Value(), 'Value before is shown'); + $this->assertStringContainsString($expected[$index]['after'], $field->Value(), 'Value after is shown'); } } @@ -87,8 +87,8 @@ public function testTransformWithCompositeFields() $form->loadDataFrom($oldData); foreach (array_values($form->Fields()->dataFields()) as $index => $field) { - $this->assertContains($expected[$index]['before'], $field->Value(), 'Value before is shown'); - $this->assertContains($expected[$index]['after'], $field->Value(), 'Value after is shown'); + $this->assertStringContainsString($expected[$index]['before'], $field->Value(), 'Value before is shown'); + $this->assertStringContainsString($expected[$index]['after'], $field->Value(), 'Value after is shown'); } }