PHPUnit_Framework_Assert::assertRegExp PHP Method

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
    public static function assertRegExp($pattern, $string, $message = '')
    {
        if (!is_string($pattern)) {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
        }
        if (!is_string($string)) {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
        }
        $constraint = new PHPUnit_Framework_Constraint_PCREMatch($pattern);
        static::assertThat($string, $constraint, $message);
    }

Usage Example

 /**
  * @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));
 }
All Usage Examples Of PHPUnit_Framework_Assert::assertRegExp
PHPUnit_Framework_Assert