Created
February 1, 2013 01:54
-
-
Save tikitikipoo/4688544 to your computer and use it in GitHub Desktop.
CakePHP Behat 表示されるべき個数をテストしたいとき
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$steps->Given('/^"([^"]*)" が (\d+) 個表示されていること$/', function($world, $text, $num) { | |
$actual = $world->getSession()->getPage()->getContent(); | |
$regex = '/'.preg_quote($text, '/').'/u'; | |
$result = preg_match_all($regex, $actual, $matches); | |
if (!$result) { | |
$message = sprintf('The text "%s" was not found anywhere in the text of the current page.', $text); | |
throw new \Exception($message, E_USER_ERROR); | |
} | |
if (count($matches[0]) != $num) { | |
$message = sprintf('The text "%s" was not found "%d" times. actualy %d times.', $text, $num, count($matches[0])); | |
throw new \Exception($message, E_USER_ERROR); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment