diff --git a/composer.json b/composer.json index e358e68d..435d8ab0 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ } ], "require": { - "php": ">=5.6", - "sminnee/phpunit": "^5.7", + "php": ">=7.3", + "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3", "behat/behat": "^3.2", "behat/mink": "^1.7", @@ -30,7 +30,7 @@ "silverstripe/mink-facebook-web-driver": "^1", "symfony/dom-crawler": "^3 || ^4", "silverstripe/testsession": "^2.2", - "silverstripe/framework": "^4", + "silverstripe/framework": "^4.10", "symfony/finder": "^3.2 || ^4" }, "autoload": { diff --git a/docs/tutorial.md b/docs/tutorial.md index 6bebc76c..fee890d4 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -246,7 +246,7 @@ not exactly one record found in the relation, and hence fail that step for Behat public function thereShouldBeAnAbuseReportForWithReason($id, $reason) { $page = $this->fixtureFactory->get('Page', $id); - assertEquals(1, $page->PageAbuseReports()->filter('Reason', $reason)->Count()); + Assert::assertEquals(1, $page->PageAbuseReports()->filter('Reason', $reason)->Count()); } ``` diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b00a4eac..a313a562 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,8 @@ - - tests/php - + + + tests/php + + diff --git a/src/Context/BasicContext.php b/src/Context/BasicContext.php index 640f99ec..df671ac6 100644 --- a/src/Context/BasicContext.php +++ b/src/Context/BasicContext.php @@ -17,6 +17,7 @@ use Facebook\WebDriver\WebDriverAlert; use Facebook\WebDriver\WebDriverExpectedCondition; use InvalidArgumentException; +use PHPUnit\Framework\Assert; use SilverStripe\Assets\File; use SilverStripe\Assets\Filesystem; use SilverStripe\BehatExtension\Utility\StepHelper; @@ -366,7 +367,7 @@ public function takeScreenshot(StepScope $event) public function stepPageCantBeFound() { $page = $this->getSession()->getPage(); - assertTrue( + Assert::assertTrue( // Content from ErrorPage default record $page->hasContent('Page not found') // Generic ModelAsController message @@ -425,9 +426,9 @@ public function iShouldSeeAButton($negative, $text) { $button = $this->findNamedButton($text); if (trim($negative)) { - assertNull($button, sprintf('%s button found', $text)); + Assert::assertNull($button, sprintf('%s button found', $text)); } else { - assertNotNull($button, sprintf('%s button not found', $text)); + Assert::assertNotNull($button, sprintf('%s button not found', $text)); } } @@ -438,7 +439,7 @@ public function iShouldSeeAButton($negative, $text) public function stepIPressTheButton($text) { $button = $this->findNamedButton($text); - assertNotNull($button, "{$text} button not found"); + Assert::assertNotNull($button, "{$text} button not found"); $button->click(); } @@ -456,7 +457,7 @@ public function stepIPressTheButtons($text) } } - assertNotNull($button, "{$text} button not found"); + Assert::assertNotNull($button, "{$text} button not found"); $button->click(); } @@ -495,7 +496,7 @@ public function iClickOnTheElement($selector) { $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)); $element->click(); } @@ -525,9 +526,9 @@ public function iClickInTheElement($clickType, $text, $selector) ); $page = $this->getSession()->getPage(); $parentElement = $page->find('css', $selector); - assertNotNull($parentElement, sprintf('"%s" element not found', $selector)); + Assert::assertNotNull($parentElement, sprintf('"%s" element not found', $selector)); $element = $parentElement->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text)); - assertNotNull($element, sprintf('"%s" not found', $text)); + Assert::assertNotNull($element, sprintf('"%s" not found', $text)); $clickTypeFn = $clickTypeMap[$clickType]; $element->$clickTypeFn(); } @@ -569,7 +570,7 @@ public function iClickInTheElementDismissingTheDialog($clickType, $text, $select public function iSeeTheDialogText($expected) { $text = $this->getExpectedAlert()->getText(); - assertContains($expected, $text); + Assert::assertStringContainsString($expected, $text); } /** @@ -841,13 +842,13 @@ public function stepFieldShouldBeDisabled($name, $type, $negate) )); } - assertNotNull($element, sprintf("Element '%s' not found", $name)); + Assert::assertNotNull($element, sprintf("Element '%s' not found", $name)); $disabledAttribute = $element->getAttribute('disabled'); if (trim($negate)) { - assertNull($disabledAttribute, sprintf("Failed asserting element '%s' is not disabled", $name)); + Assert::assertNull($disabledAttribute, sprintf("Failed asserting element '%s' is not disabled", $name)); } else { - assertNotNull($disabledAttribute, sprintf("Failed asserting element '%s' is disabled", $name)); + Assert::assertNotNull($disabledAttribute, sprintf("Failed asserting element '%s' is disabled", $name)); } } @@ -864,11 +865,11 @@ public function stepFieldShouldBeEnabled($field) { $page = $this->getSession()->getPage(); $fieldElement = $page->findField($field); - assertNotNull($fieldElement, sprintf("Field '%s' not found", $field)); + Assert::assertNotNull($fieldElement, sprintf("Field '%s' not found", $field)); $disabledAttribute = $fieldElement->getAttribute('disabled'); - assertNull($disabledAttribute, sprintf("Failed asserting field '%s' is enabled", $field)); + Assert::assertNull($disabledAttribute, sprintf("Failed asserting field '%s' is enabled", $field)); } /** @@ -887,7 +888,7 @@ public function iFollowInTheRegion($link, $region) { $context = $this->getMainContext(); $regionObj = $context->getRegionObj($region); - assertNotNull($regionObj); + Assert::assertNotNull($regionObj); $linkObj = $regionObj->findLink($link); if (empty($linkObj)) { @@ -913,7 +914,7 @@ public function iFillinTheRegion($field, $value, $region) { $context = $this->getMainContext(); $regionObj = $context->getRegionObj($region); - assertNotNull($regionObj, "Region Object is null"); + Assert::assertNotNull($regionObj, "Region Object is null"); $fieldObj = $regionObj->findField($field); if (empty($fieldObj)) { @@ -943,7 +944,7 @@ public function iSeeTextInRegion($negate, $text, $region) { $context = $this->getMainContext(); $regionObj = $context->getRegionObj($region); - assertNotNull($regionObj); + Assert::assertNotNull($regionObj); $actual = $regionObj->getText(); $actual = preg_replace('/\s+/u', ' ', $actual); @@ -987,7 +988,7 @@ public function iSelectTheRadioButton($radioLabel) 'radio', $this->getMainContext()->getXpathEscaper()->escapeLiteral($radioLabel) ]); - assertNotNull($radioButton); + Assert::assertNotNull($radioButton); $session->getDriver()->click($radioButton->getXPath()); } @@ -1001,7 +1002,7 @@ public function theTableShouldContain($selector, $text) $table = $this->getTable($selector); $element = $table->find('named', array('content', "'$text'")); - assertNotNull($element, sprintf('Element containing `%s` not found in `%s` table', $text, $selector)); + Assert::assertNotNull($element, sprintf('Element containing `%s` not found in `%s` table', $text, $selector)); } /** @@ -1014,7 +1015,7 @@ public function theTableShouldNotContain($selector, $text) $table = $this->getTable($selector); $element = $table->find('named', array('content', "'$text'")); - assertNull($element, sprintf('Element containing `%s` not found in `%s` table', $text, $selector)); + Assert::assertNull($element, sprintf('Element containing `%s` not found in `%s` table', $text, $selector)); } /** @@ -1027,7 +1028,7 @@ public function iClickOnInTheTable($text, $selector) $table = $this->getTable($selector); $element = $table->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text)); - assertNotNull($element, sprintf('Element containing `%s` not found', $text)); + Assert::assertNotNull($element, sprintf('Element containing `%s` not found', $text)); $element->click(); } @@ -1065,7 +1066,7 @@ protected function getTable($selector) // Some tables don't have a visible title, so look for a fieldset with data-name instead $candidates += $page->findAll('xpath', "//fieldset[@data-name=$selector]//table"); - assertTrue((bool)$candidates, 'Could not find any table elements'); + Assert::assertTrue((bool)$candidates, 'Could not find any table elements'); $table = null; /** @var NodeElement $candidate */ @@ -1075,7 +1076,7 @@ protected function getTable($selector) } } - assertTrue((bool)$table, 'Found table elements, but none are visible'); + Assert::assertTrue((bool)$table, 'Found table elements, but none are visible'); return $table; } @@ -1092,19 +1093,19 @@ protected function getTable($selector) public function theTextBeforeAfter($textBefore, $order, $textAfter, $element) { $ele = $this->getSession()->getPage()->find('css', $element); - assertNotNull($ele, sprintf('%s not found', $element)); + Assert::assertNotNull($ele, sprintf('%s not found', $element)); // Check both of the texts exist in the element $text = $ele->getText(); - assertTrue(strpos($text, $textBefore) !== 'FALSE', sprintf('%s not found in the element %s', $textBefore, $element)); - assertTrue(strpos($text, $textAfter) !== 'FALSE', sprintf('%s not found in the element %s', $textAfter, $element)); + Assert::assertTrue(strpos($text, $textBefore) !== 'FALSE', sprintf('%s not found in the element %s', $textBefore, $element)); + Assert::assertTrue(strpos($text, $textAfter) !== 'FALSE', sprintf('%s not found in the element %s', $textAfter, $element)); /// Use strpos to get the position of the first occurrence of the two texts (case-sensitive) // and compare them with the given order (before or after) if ($order === 'before') { - assertTrue(strpos($text, $textBefore) < strpos($text, $textAfter)); + Assert::assertTrue(strpos($text, $textBefore) < strpos($text, $textAfter)); } else { - assertTrue(strpos($text, $textBefore) > strpos($text, $textAfter)); + Assert::assertTrue(strpos($text, $textBefore) > strpos($text, $textAfter)); } } @@ -1213,7 +1214,7 @@ public function iScrollToField($locator, $type) { $page = $this->getSession()->getPage(); $el = $page->find('named', array($type, "'$locator'")); - assertNotNull($el, sprintf('%s element not found', $locator)); + Assert::assertNotNull($el, sprintf('%s element not found', $locator)); $id = $el->getAttribute('id'); if (empty($id)) { @@ -1236,7 +1237,7 @@ public function iScrollToField($locator, $type) public function iScrollToElement($locator) { $el = $this->getSession()->getPage()->find('css', $locator); - assertNotNull($el, sprintf('The element "%s" is not found', $locator)); + Assert::assertNotNull($el, sprintf('The element "%s" is not found', $locator)); $id = $el->getAttribute('id'); if (empty($id)) { @@ -1305,7 +1306,7 @@ public function iShouldSeeTheElement($selector) return document.querySelector("$sel"); JS; $element = $this->getSession()->evaluateScript($js); - assertNotNull($element, sprintf('Element %s not found', $selector)); + Assert::assertNotNull($element, sprintf('Element %s not found', $selector)); } /** diff --git a/src/Context/EmailContext.php b/src/Context/EmailContext.php index d3e73c51..b30180bf 100644 --- a/src/Context/EmailContext.php +++ b/src/Context/EmailContext.php @@ -6,6 +6,7 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Session; +use PHPUnit\Framework\Assert; use SilverStripe\BehatExtension\Utility\TestMailer; use SilverStripe\Control\Email\Email; use SilverStripe\Control\Email\Mailer; @@ -65,9 +66,9 @@ public function thereIsAnEmailFromTo($negate, $direction, $email) $from = ($direction == 'from') ? $email : null; $match = $this->mailer->findEmail($to, $from); if (trim($negate)) { - assertNull($match); + Assert::assertNull($match); } else { - assertNotNull($match); + Assert::assertNotNull($match); } $this->lastMatchedEmail = $match; } @@ -89,7 +90,7 @@ public function thereIsAnEmailFromToTitled($negate, $direction, $email, $subject return $email->Subject; }, $allMails)) . '"' : null; if (trim($negate)) { - assertNull($match); + Assert::assertNull($match); } else { $msg = sprintf( 'Could not find email %s "%s" titled "%s".', @@ -100,7 +101,7 @@ public function thereIsAnEmailFromToTitled($negate, $direction, $email, $subject if ($allTitles) { $msg .= ' Existing emails: ' . $allTitles; } - assertNotNull($match, $msg); + Assert::assertNotNull($match, $msg); } $this->lastMatchedEmail = $match; } @@ -129,9 +130,9 @@ public function thereTheEmailContains($negate, $content) } if (trim($negate)) { - assertNotContains($content, $emailContent); + Assert::assertNotContains($content, $emailContent); } else { - assertContains($content, $emailContent); + Assert::assertContains($content, $emailContent); } } @@ -155,7 +156,7 @@ public function thereTheEmailContainsPlainText($content) $emailPlainText = strip_tags($emailContent); $emailPlainText = preg_replace("/\h+/", " ", $emailPlainText); - assertContains($content, $emailPlainText); + Assert::assertContains($content, $emailPlainText); } /** @@ -169,13 +170,13 @@ public function iGoToInTheEmailTo($linkSelector, $direction, $email) $to = ($direction == 'to') ? $email : null; $from = ($direction == 'from') ? $email : null; $match = $this->mailer->findEmail($to, $from); - assertNotNull($match); + Assert::assertNotNull($match); $crawler = new Crawler($match->Content); $linkEl = $crawler->selectLink($linkSelector); - assertNotNull($linkEl); + Assert::assertNotNull($linkEl); $link = $linkEl->attr('href'); - assertNotNull($link); + Assert::assertNotNull($link); $this->getMainContext()->visit($link); } @@ -192,13 +193,13 @@ public function iGoToInTheEmailToTitled($linkSelector, $direction, $email, $titl $to = ($direction == 'to') ? $email : null; $from = ($direction == 'from') ? $email : null; $match = $this->mailer->findEmail($to, $from, $title); - assertNotNull($match); + Assert::assertNotNull($match); $crawler = new Crawler($match->Content); $linkEl = $crawler->selectLink($linkSelector); - assertNotNull($linkEl); + Assert::assertNotNull($linkEl); $link = $linkEl->attr('href'); - assertNotNull($link); + Assert::assertNotNull($link); $this->getMainContext()->visit($link); } @@ -218,9 +219,9 @@ public function iGoToInTheEmail($linkSelector) $match = $this->lastMatchedEmail; $crawler = new Crawler($match->Content); $linkEl = $crawler->selectLink($linkSelector); - assertNotNull($linkEl); + Assert::assertNotNull($linkEl); $link = $linkEl->attr('href'); - assertNotNull($link); + Assert::assertNotNull($link); $this->getMainContext()->visit($link); } @@ -264,11 +265,11 @@ public function theEmailContainFollowingData($negate, TableNode $table) // For "should not contain" if (trim($negate)) { foreach ($rows as $row) { - assertNotContains($row[0], $emailContent); + Assert::assertNotContains($row[0], $emailContent); } } else { foreach ($rows as $row) { - assertContains($row[0], $emailContent); + Assert::assertContains($row[0], $emailContent); } } } @@ -282,13 +283,13 @@ public function thereIsAnEmailTitled($negate, $subject) { $match = $this->mailer->findEmail(null, null, $subject); if (trim($negate)) { - assertNull($match); + Assert::assertNull($match); } else { $msg = sprintf( 'Could not find email titled "%s".', $subject ); - assertNotNull($match, $msg); + Assert::assertNotNull($match, $msg); } $this->lastMatchedEmail = $match; } @@ -306,9 +307,9 @@ public function theEmailSentFrom($negate, $from) $match = $this->lastMatchedEmail; if (trim($negate)) { - assertNotContains($from, $match->From); + Assert::assertNotContains($from, $match->From); } else { - assertContains($from, $match->From); + Assert::assertContains($from, $match->From); } } @@ -325,9 +326,9 @@ public function theEmailSentTo($negate, $to) $match = $this->lastMatchedEmail; if (trim($negate)) { - assertNotContains($to, $match->To); + Assert::assertNotContains($to, $match->To); } else { - assertContains($to, $match->To); + Assert::assertContains($to, $match->To); } } @@ -358,7 +359,7 @@ public function iClickOnHttpLinkInEmail($httpText) break; } } - assertNotNull($href); + Assert::assertNotNull($href); $this->getMainContext()->visit($href); } diff --git a/src/Context/FixtureContext.php b/src/Context/FixtureContext.php index 007c344e..209c7c5d 100644 --- a/src/Context/FixtureContext.php +++ b/src/Context/FixtureContext.php @@ -9,6 +9,7 @@ use Behat\Gherkin\Node\TableNode; use Exception; use InvalidArgumentException; +use PHPUnit\Framework\Assert; use SilverStripe\Assets\Folder; use SilverStripe\Assets\Storage\AssetStore; use SilverStripe\Core\ClassInfo; @@ -650,7 +651,7 @@ public function stepGoToNamedRecord($type, $id) public function iAddAnExtensionToTheClass($extension, $class) { // Validate the extension - assertTrue( + Assert::assertTrue( class_exists($extension) && is_subclass_of($extension, Extension::class), 'Given extension does not extend Extension' ); @@ -696,9 +697,9 @@ protected function getDestinationConfigFolder($filename) { $project = ModuleManifest::config()->get('project') ?: 'mysite'; $mysite = ModuleLoader::getModule($project); - assertNotNull($mysite, 'Project exists'); + Assert::assertNotNull($mysite, 'Project exists'); $destPath = $mysite->getResource("_config/{$filename}")->getPath(); - assertFileNotExists($destPath, "Config file {$filename} hasn't aleady been loaded"); + Assert::assertFileDoesNotExist($destPath, "Config file {$filename} hasn't aleady been loaded"); return $destPath; } @@ -712,7 +713,7 @@ protected function getDestinationConfigFolder($filename) */ public function stepThereShouldBeAFileOrFolder($type, $path) { - assertFileExists($this->joinPaths(BASE_PATH, $path)); + Assert::assertFileExists($this->joinPaths(BASE_PATH, $path)); } /** @@ -727,7 +728,7 @@ public function stepThereShouldBeAFileOrFolder($type, $path) public function stepThereShouldBeAFileWithTuple($filename, $hash) { $exists = $this->getAssetStore()->exists($filename, $hash); - assertTrue((bool)$exists, "A file exists with filename $filename and hash $hash"); + Assert::assertTrue((bool)$exists, "A file exists with filename $filename and hash $hash"); } /** diff --git a/src/Context/LoginContext.php b/src/Context/LoginContext.php index a7007ea0..54255d20 100644 --- a/src/Context/LoginContext.php +++ b/src/Context/LoginContext.php @@ -4,6 +4,7 @@ use Behat\Behat\Context\Context; use Behat\Mink\Element\NodeElement; +use PHPUnit\Framework\Assert; use SilverStripe\Security\Authenticator; use SilverStripe\Security\Group; use SilverStripe\Security\Member; @@ -32,7 +33,7 @@ public function stepIAmLoggedIn() if (0 == strpos($this->getMainContext()->getSession()->getCurrentUrl(), $loginUrl)) { $this->stepILogInWith('admin', 'password'); - assertStringStartsWith($adminUrl, $this->getMainContext()->getSession()->getCurrentUrl()); + Assert::assertStringStartsWith($adminUrl, $this->getMainContext()->getSession()->getCurrentUrl()); } } @@ -63,13 +64,13 @@ public function stepIAmNotLoggedIn() $page = $this->getMainContext()->getSession()->getPage(); $form = $page->findById('LogoutForm_Form'); - assertNotNull($form, 'Logout form not found'); + Assert::assertNotNull($form, 'Logout form not found'); $submitButton = $form->find('css', '[type=submit]'); $securityID = $form->find('css', '[name=SecurityID]'); - assertNotNull($submitButton, 'Submit button on logout form not found'); - assertNotNull($securityID, 'CSRF token not found'); + Assert::assertNotNull($submitButton, 'Submit button on logout form not found'); + Assert::assertNotNull($securityID, 'CSRF token not found'); $submitButton->press(); } @@ -86,7 +87,7 @@ public function stepILogInWith($email, $password) $this->getMainContext()->getSession()->visit($loginUrl); $page = $this->getMainContext()->getSession()->getPage(); $form = $page->findById('MemberLoginForm_LoginForm'); - assertNotNull($form, 'Login form not found'); + Assert::assertNotNull($form, 'Login form not found'); // Try to find visible forms again on login page. $visibleForm = null; @@ -94,17 +95,17 @@ public function stepILogInWith($email, $password) if ($form->isVisible() && $form->find('css', '[name=Email]')) { $visibleForm = $form; } - assertNotNull($visibleForm, 'Could not find login email field'); + Assert::assertNotNull($visibleForm, 'Could not find login email field'); $emailField = $visibleForm->find('css', '[name=Email]'); $passwordField = $visibleForm->find('css', '[name=Password]'); $submitButton = $visibleForm->find('css', '[type=submit]'); $securityID = $visibleForm->find('css', '[name=SecurityID]'); - assertNotNull($emailField, 'Email field on login form not found'); - assertNotNull($passwordField, 'Password field on login form not found'); - assertNotNull($submitButton, 'Submit button on login form not found'); - assertNotNull($securityID, 'CSRF token not found'); + Assert::assertNotNull($emailField, 'Email field on login form not found'); + Assert::assertNotNull($passwordField, 'Password field on login form not found'); + Assert::assertNotNull($submitButton, 'Submit button on login form not found'); + Assert::assertNotNull($securityID, 'CSRF token not found'); $emailField->setValue($email); $passwordField->setValue($password); @@ -119,7 +120,7 @@ public function stepILogInWith($email, $password) $page = $this->getMainContext()->getSession()->getPage(); $message = $page->find('css', '.message.error'); $error = $message ? $message->getText() : null; - assertNull($message, 'Could not log in with user ' . $email . '. Error: "' . $error. '""'); + Assert::assertNull($message, 'Could not log in with user ' . $email . '. Error: "' . $error. '""'); } /** @@ -129,7 +130,7 @@ public function stepIShouldSeeALogInForm() { $page = $this->getMainContext()->getSession()->getPage(); $loginForm = $page->find('css', '#MemberLoginForm_LoginForm'); - assertNotNull($loginForm, 'I should see a log-in form'); + Assert::assertNotNull($loginForm, 'I should see a log-in form'); } /** @@ -139,7 +140,7 @@ public function stepIShouldSeeALogOutForm() { $page = $this->getMainContext()->getSession()->getPage(); $logoutForm = $page->find('css', '#LogoutForm_Form'); - assertNotNull($logoutForm, 'I should see a log-out form'); + Assert::assertNotNull($logoutForm, 'I should see a log-out form'); } /** @@ -150,7 +151,7 @@ public function stepIWillSeeALogInMessage($type) { $page = $this->getMainContext()->getSession()->getPage(); $message = $page->find('css', sprintf('.message.%s', $type)); - assertNotNull($message, sprintf('%s message not found.', $type)); + Assert::assertNotNull($message, sprintf('%s message not found.', $type)); } /** @@ -163,10 +164,10 @@ public function stepPasswordForEmailShouldBe($id, $password) { /** @var Member $member */ $member = Member::get()->filter('Email', $id)->First(); - assertNotNull($member); + Assert::assertNotNull($member); $authenticators = Security::singleton()->getApplicableAuthenticators(Authenticator::CHECK_PASSWORD); foreach ($authenticators as $authenticator) { - assertTrue($authenticator->checkPassword($member, $password)->isValid()); + Assert::assertTrue($authenticator->checkPassword($member, $password)->isValid()); } } diff --git a/tests/php/SilverStripeContextTest.php b/tests/php/SilverStripeContextTest.php index e9b8c1a2..78058992 100644 --- a/tests/php/SilverStripeContextTest.php +++ b/tests/php/SilverStripeContextTest.php @@ -8,6 +8,7 @@ use Behat\Mink\Mink; use Behat\Mink\Driver\DriverInterface; use Behat\Mink\Element\Element; +use PHPUnit\Framework\MockObject\MockObject; use SilverStripe\BehatExtension\Tests\SilverStripeContextTest\FeatureContext; use SilverStripe\Dev\SapphireTest; @@ -16,22 +17,18 @@ class SilverStripeContextTest extends SapphireTest protected $backupGlobals = false; - /** - * @expectedException \LogicException - * @expectedExceptionMessage Cannot find 'region_map' in the behat.yml - */ public function testGetRegionObjThrowsExceptionOnUnknownSelector() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage("Cannot find 'region_map' in the behat.yml"); $context = $this->getContextMock(); $context->getRegionObj('.unknown'); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Cannot find the specified region in the behat.yml - */ public function testGetRegionObjThrowsExceptionOnUnknownRegion() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage("Cannot find the specified region in the behat.yml"); $context = $this->getContextMock(); $context->setRegionMap(array('MyRegion' => '.my-region')); $context->getRegionObj('.unknown'); @@ -92,7 +89,7 @@ protected function getContextMock() } /** - * @return Element|\PHPUnit_Framework_MockObject_MockObject + * @return Element|MockObject */ protected function getElementMock() {