Checks a given value using the Perl Compatible Regular Expression extension
in PHP. The pattern is matched by executing preg_match().
The pattern string passed in the constructor.
public function testConstraintPCREMatch2() { $constraint = new PHPUnit_Framework_Constraint_PCREMatch('/foo/'); try { $constraint->fail('barbazbar', 'custom message'); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals("custom message\nFailed asserting that <string:barbazbar> matches PCRE pattern \"/foo/\".", $e->getDescription()); return; } $this->fail(); }
/** * @param string $string */ public function __construct($string) { parent::__construct($string); $this->pattern = $this->createPatternFromFormat(preg_replace('/\\r\\n/', "\n", $string)); $this->string = $string; }
public function testConstraintPCREMatch() { $constraint = new PHPUnit_Framework_Constraint_PCREMatch('/foo/'); $this->assertFalse($constraint->evaluate('barbazbar')); $this->assertTrue($constraint->evaluate('barfoobar')); $this->assertEquals('matches PCRE pattern "/foo/"', $constraint->toString()); try { $constraint->fail('barbazbar', ''); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals('Failed asserting that <string:barbazbar> matches PCRE pattern "/foo/".', $e->getDescription()); return; } $this->fail(); }