assertRegExp() public static method

Asserts that a string matches a given regular expression.
public static assertRegExp ( string $pattern, string $string, string $message = '' )
$pattern string
$string string
$message string
 /**
  * @Then /^the latest email to ([^ ]+@[^ ]+) should contain "([^"]*)"$/
  */
 public function assertFakeEmailReceipt($emailAddress, $pattern)
 {
     $regex = $this->fixStepArgument($pattern);
     $inbox = $this->inboxFactory->getInbox($emailAddress);
     $email = $inbox->getLatestEmail();
     $body = $email->getBody();
     \PHPUnit_Framework_Assert::assertRegExp("/{$regex}/", $body, sprintf('Did not find an email to %s which matched "%s". Found instead: %s – ', $emailAddress, $regex, $body));
 }
 /**
  * Assert that readiness check items are passed.
  *
  * @param SetupWizard $setupWizard
  * @return void
  */
 public function processAssert(SetupWizard $setupWizard)
 {
     \PHPUnit_Framework_Assert::assertContains(self::UPDATER_APPLICATION_MESSAGE, $setupWizard->getReadiness()->getUpdaterApplicationCheck(), 'Updater application check is incorrect.');
     \PHPUnit_Framework_Assert::assertContains(self::CRON_SCRIPT_MESSAGE, $setupWizard->getReadiness()->getCronScriptCheck(), 'Cron scripts are incorrect.');
     \PHPUnit_Framework_Assert::assertContains(self::DEPENDENCY_CHECK_MESSAGE, $setupWizard->getReadiness()->getDependencyCheck(), 'Dependency check is incorrect.');
     \PHPUnit_Framework_Assert::assertContains(self::PHP_VERSION_MESSAGE, $setupWizard->getReadiness()->getPhpVersionCheck(), 'PHP version is incorrect.');
     \PHPUnit_Framework_Assert::assertContains(self::PHP_SETTING_REGEXP, $setupWizard->getReadiness()->getSettingsCheck(), 'PHP settings check failed.');
     \PHPUnit_Framework_Assert::assertRegExp(self::PHP_EXTENSIONS_REGEXP, $setupWizard->getReadiness()->getPhpExtensionsCheck(), 'PHP extensions missed.');
 }
Example #3
0
 public function seeInLogs(array $patterns)
 {
     foreach ($patterns as $pattern) {
         $line = stream_get_line($this->logFile, 1024, "\n");
         \PHPUnit_Framework_Assert::assertRegExp($pattern, $line);
     }
     $rest = stream_get_line($this->logFile, 1024, "\n");
     $this->assertFalse($rest);
 }
Example #4
0
File: Demo.php Project: ataxel/tp
    /**
     * @Then I (should) see :total search result(s)
     */
    public function iSeeSearchResults( $total )
    {
        $resultCountElement = $this->getXpath()->findXpath( "//div[@class = 'feedback']" );

        EzAssertion::assertSingleElement( 'search feedback', $resultCountElement );

        Assertion::assertRegExp(
            "/Search for \"(.*)\" returned {$total} matches/",
            $resultCountElement[0]->getText()
        );
    }
 /**
  * @Then the response data :field contains :value
  */
 public function responseDataFieldContains($field, $value)
 {
     Assert::assertRegExp('/' . preg_quote($value) . '/i', $this->getResponseDataField($field));
 }
Example #6
0
/**
 * Asserts that a string matches a given regular expression.
 *
 * @param  string $pattern
 * @param  string $string
 * @param  string $message
 */
function assertRegExp($pattern, $string, $message = '')
{
    return PHPUnit_Framework_Assert::assertRegExp($pattern, $string, $message);
}
 protected function assertCommand($command, $arguments, $info)
 {
     $method = $info['originalMethod'];
     $result = $this->__call($method, $arguments);
     if ($info['isBoolean']) {
         if (!isset($info['negative']) || !$info['negative']) {
             PHPUnit_Framework_Assert::assertTrue($result);
         } else {
             PHPUnit_Framework_Assert::assertFalse($result);
         }
     } else {
         $expected = array_pop($arguments);
         if (strpos($expected, 'exact:') === 0) {
             $expected = substr($expected, strlen('exact:'));
             if (!isset($info['negative']) || !$info['negative']) {
                 PHPUnit_Framework_Assert::assertEquals($expected, $result);
             } else {
                 PHPUnit_Framework_Assert::assertNotEquals($expected, $result);
             }
         } else {
             if (strpos($expected, 'regexp:') === 0) {
                 $expected = substr($expected, strlen('regexp:'));
             } else {
                 if (strpos($expected, 'glob:') === 0) {
                     $expected = substr($expected, strlen('glob:'));
                 }
                 $expected = str_replace(array('*', '?'), array('.*', '.?'), $expected);
             }
             $expected = str_replace('/', '\\/', $expected);
             if (!isset($info['negative']) || !$info['negative']) {
                 PHPUnit_Framework_Assert::assertRegExp('/' . $expected . '/', $result);
             } else {
                 PHPUnit_Framework_Assert::assertNotRegExp('/' . $expected . '/', $result);
             }
         }
     }
 }
 /**
  * Checks that response body contains specific text.
  *
  * @param string $text
  *
  * @Then /^(?:the )?response should contain "([^"]*)"$/
  */
 public function theResponseShouldContain($text)
 {
     $expectedRegexp = '/' . preg_quote($text) . '/i';
     $actual = (string) $this->response->getBody();
     Assertions::assertRegExp($expectedRegexp, $actual);
 }
Example #9
0
 public function seeShellOutputMatches($regex)
 {
     \PHPUnit_Framework_Assert::assertRegExp($regex, $this->output);
 }
Example #10
0
 public function toMatchPattern($pattern)
 {
     if ($this->negate) {
         a::assertNotRegExp($pattern, $this->actual);
     } else {
         a::assertRegExp($pattern, $this->actual);
     }
 }
Example #11
0
 public function matchesRegExp($expression)
 {
     Assert::assertRegExp($expression, $this->actual, $this->description);
     return $this;
 }
 public function toMatch($regex)
 {
     \PHPUnit_Framework_Assert::assertRegExp($regex, $this->actual);
 }
Example #13
0
 /**
  * Checks that response body contains specific text.
  *
  * @param string $text
  *
  * @Then /^(?:the )?response should contain "([^"]*)"$/
  */
 public function theResponseShouldContain($text)
 {
     \PHPUnit_Framework_Assert::assertRegExp('/' . preg_quote($text) . '/', $this->browser->getLastResponse()->getContent());
 }
 /**
  * Asserts that the revision with the given ID has a summary matching $regex
  *
  * @param string|string[] $regex The regex to match, or an array to build a regex from
  * @param int $revid
  * @param string $message
  */
 public function assertRevisionSummary($regex, $revid, $message = '')
 {
     if (is_array($regex)) {
         $r = '';
         foreach ($regex as $s) {
             if (strlen($r) > 0) {
                 $r .= '.*';
             }
             $r .= preg_quote($s, '!');
         }
         $regex = "!{$r}!";
     }
     $entry = $this->mockRepository->getLogEntry($revid);
     Assert::assertNotNull($entry, "revision not found: {$revid}");
     Assert::assertRegExp($regex, $entry['summary'], $message);
 }
Example #15
0
 public function testGetAccessToken()
 {
     $response = $this->getMockBuilder('Widop\\HttpAdapter\\HttpResponse')->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('getBody')->will($this->returnValue('oauth_token=token_key&oauth_token_secret=token_secret'));
     $this->httpAdapter->expects($this->once())->method('postContent')->with($this->equalTo('https://api.twitter.com/oauth/access_token'), $this->callback(function ($headers) {
         try {
             \PHPUnit_Framework_Assert::assertArrayHasKey('Authorization', $headers);
             \PHPUnit_Framework_Assert::assertRegExp('#OAuth oauth_verifier="oauth_verifier", oauth_version="1.0", oauth_consumer_key="consumer_key", oauth_signature_method="signature-name", oauth_token="token_key", oauth_signature="signature", oauth_nonce="(.*)", oauth_timestamp="(.*)"#', $headers['Authorization']);
             return true;
         } catch (\Exception $e) {
             return false;
         }
     }))->will($this->returnValue($response));
     $accessToken = $this->oauth->getAccessToken(new OAuthToken('token_key', 'token_secret'), 'oauth_verifier');
     $this->assertInstanceOf('Widop\\Twitter\\OAuth\\Token\\OAuthToken', $accessToken);
     $this->assertSame('token_key', $accessToken->getKey());
     $this->assertSame('token_secret', $accessToken->getSecret());
 }
Example #16
0
 public function regExp($expression)
 {
     a::assertRegExp($expression, $this->actual, $this->description);
 }
 /**
  * Assert that PHP Version, PHP Extensions and File Permission are ok.
  *
  * @param Install $installPage
  * @return void
  */
 public function processAssert(Install $installPage)
 {
     \PHPUnit_Framework_Assert::assertContains(self::PHP_VERSION_MESSAGE, $installPage->getReadinessBlock()->getPhpVersionCheck(), 'PHP version is incorrect.');
     \PHPUnit_Framework_Assert::assertRegExp(self::PHP_EXTENSIONS_REGEXP, $installPage->getReadinessBlock()->getPhpExtensionsCheck(), 'PHP extensions missed.');
     \PHPUnit_Framework_Assert::assertRegExp(self::FILE_PERMISSION_REGEXP, $installPage->getReadinessBlock()->getFilePermissionCheck(), 'File permissions does not meet requirements.');
 }
Example #18
0
 /**
  * @Then there should be a meta-tag with property :propertyValue and content matching :contentValueRegex
  */
 public function thereShouldBeAMetaTagWithPropertyAndContentMatching($propertyValue, $contentValueRegex)
 {
     $tag = $this->getMetaTagByProperty($propertyValue);
     Assert::assertRegExp($contentValueRegex, $tag->getAttribute('content'));
 }
 /**
  * @param $pattern
  * @return $this
  * @throws \PHPUnit_Framework_AssertionFailedError
  */
 public function isRedirectToRegExp($pattern)
 {
     $location = $this->getRedirectLocation();
     Assert::assertRegExp($pattern, $location);
     return $this;
 }
Example #20
0
 /**
  * @Then I should retrieve a valid download url
  */
 public function isValidDownloadUrl()
 {
     $regex = "/---PACKAGE_URL:(.*)---/";
     \PHPUnit_Framework_Assert::assertRegExp($regex, $this->lastOutput);
     preg_match($regex, $this->lastOutput, $matches);
     $url = $matches[1];
     \PHPUnit_Framework_Assert::assertNotEquals('${package.url}', $url, $this->lastOutput);
 }
Example #21
0
 /**
  * Depends on session:info command
  *
  * @Then /^I should not be logged into the session$/
  */
 public function iShouldNotBeLoggedIntoTheSession()
 {
     $this->executeCommand('session:info');
     $output = $this->getOutput();
     \PHPUnit_Framework_Assert::assertRegExp('/live .*no/', $output);
 }
Example #22
0
 protected function assertCommand($command, $arguments, $info)
 {
     $method = $info['originalMethod'];
     $requiresTarget = $info['requiresTarget'];
     $result = $this->__call($method, $arguments);
     if ($info['isBoolean']) {
         if (!isset($info['negative']) || !$info['negative']) {
             PHPUnit_Framework_Assert::assertTrue($result, $arguments[count($arguments) - 1]);
         } else {
             PHPUnit_Framework_Assert::assertFalse($result, $arguments[count($arguments) - 1]);
         }
     } else {
         if ($requiresTarget === TRUE) {
             $expected = $arguments[1];
         } else {
             $expected = $arguments[0];
         }
         if (strpos($expected, 'exact:') === 0) {
             $expected = substr($expected, strlen('exact:'));
             if (!isset($info['negative']) || !$info['negative']) {
                 PHPUnit_Framework_Assert::assertEquals($expected, $result);
             } else {
                 PHPUnit_Framework_Assert::assertNotEquals($expected, $result);
             }
         } else {
             $caseInsensitive = FALSE;
             if (strpos($expected, 'regexp:') === 0) {
                 $expected = substr($expected, strlen('regexp:'));
             } else {
                 if (strpos($expected, 'regexpi:') === 0) {
                     $expected = substr($expected, strlen('regexpi:'));
                     $caseInsensitive = TRUE;
                 } else {
                     if (strpos($expected, 'glob:') === 0) {
                         $expected = substr($expected, strlen('glob:'));
                     }
                     $expected = str_replace(array('*', '?'), array('.*', '.?'), $expected);
                 }
             }
             $expected = '/' . str_replace('/', '\\/', $expected) . '/';
             if ($caseInsensitive) {
                 $expected .= 'i';
             }
             if (!isset($info['negative']) || !$info['negative']) {
                 PHPUnit_Framework_Assert::assertRegExp($expected, $result);
             } else {
                 PHPUnit_Framework_Assert::assertNotRegExp($expected, $result);
             }
         }
     }
 }
 /**
  * @param mixed $expected
  * @param mixed $actual
  */
 protected function assertContains($expected, $actual)
 {
     if (is_array($expected)) {
         foreach ($expected as $key => $needle) {
             $actualValue = isset($actual[$key]) ? $actual[$key] : null;
             $this->assertContains($needle, $actualValue);
         }
         return;
     }
     if ($expected === '*') {
         return;
     }
     if (preg_match('/^\\%.+\\%$/', $expected, $result)) {
         $pattern = sprintf('/%s/', trim($result[0], '%'));
         Assertions::assertRegExp($pattern, $actual);
         return;
     }
     Assertions::assertEquals($expected, $actual, 'JSON equality');
 }
Example #24
0
 public function seeCurrentUrlMatches($uri)
 {
     \PHPUnit_Framework_Assert::assertRegExp($uri, $this->_getCurrentUri());
 }
 /**
  * Assert that default Admin URI is generated according to the pattern.
  *
  * @param Install $installPage
  * @return void
  */
 public function processAssert(Install $installPage)
 {
     \PHPUnit_Framework_Assert::assertRegExp(self::ADMIN_URI_PATTERN, $installPage->getWebConfigBlock()->getAdminUriCheck(), 'Unexpected Backend Frontname pattern.');
 }
Example #26
0
 /**
  * Checks that string match with pattern
  *
  * @param string $pattern
  * @param string $string
  * @param string $message
  */
 protected function assertRegExp($pattern, $string, $message = '')
 {
     \PHPUnit_Framework_Assert::assertRegExp($pattern, $string, $message);
 }
Example #27
0
 /**
  * Expect that a string matches a given regular expression.
  *
  * @param string $pattern
  * @param string $message
  *
  * @return Expect
  */
 public function toMatchRegExp($pattern, $message = '')
 {
     Assert::assertRegExp($pattern, $this->value, $message);
     return $this;
 }
 /**
  * @Then /^(\d+) tests? and (\d+) assertions? should be executed$/
  */
 public function testShouldBeExecuted($tests, $assertions)
 {
     PHPUnit_Framework_Assert::assertRegExp("/OK \\({$tests} tests?, {$assertions} assertions?\\)/", $this->output);
 }
Example #29
0
 public function testSimpleFormPostMailSendWithCallbacks()
 {
     $app = $this->getApp(false);
     $extension = $this->getExtension($app);
     $app['extensions.SimpleForms']->config['test_simple_form']['fields']['ip']['type'] = 'ip';
     $app['extensions.SimpleForms']->config['test_simple_form']['fields']['host']['type'] = 'remotehost';
     $app['extensions.SimpleForms']->config['test_simple_form']['fields']['ua']['type'] = 'useragent';
     $app['extensions.SimpleForms']->config['test_simple_form']['fields']['now']['type'] = 'timestamp';
     $parameters = $this->getPostParameters();
     $mailer = $this->getMock('\\Swift_Mailer', array('send'), array($app['swiftmailer.transport']));
     $mailer->expects($this->any())->method('send')->will($this->returnCallback(function ($message) {
         $message = $message->toString();
         \PHPUnit_Framework_Assert::assertRegExp('#ip: 8.8.8.8#', $message);
         \PHPUnit_Framework_Assert::assertRegExp('#host: simpleforms.bolt.cm#', $message);
         \PHPUnit_Framework_Assert::assertRegExp('#ua: SimpleForms/2.X#', $message);
         \PHPUnit_Framework_Assert::assertRegExp('#now: [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}#', $message);
     }));
     $app['mailer'] = $mailer;
     $server = array('SERVER_NAME' => 'localhost', 'SERVER_PORT' => 80, 'HTTP_HOST' => 'unittest.bolt.cm', 'HTTP_USER_AGENT' => 'SimpleForms/2.X', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'REMOTE_ADDR' => '8.8.8.8', 'REMOTE_HOST' => 'simpleforms.bolt.cm', 'SCRIPT_NAME' => 'SimpleForms.php', 'SCRIPT_FILENAME' => __FILE__, 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_TIME' => 42);
     $app['request'] = Request::create('/', 'POST', $parameters, array(), array(), $server);
     $app->boot();
     $extension->simpleForm('test_simple_form');
 }