Skip to content

Commit

Permalink
Merge pull request #2069 from RogerRussel/assert-regex-ability
Browse files Browse the repository at this point in the history
Implemented assertRegExp and assertNotRegExp
  • Loading branch information
DavertMik committed Jun 22, 2015
2 parents 0c12ecb + 58279f0 commit a428062
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Codeception/Module/Asserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Asserts extends Module
assertLessThanOrEqual as public;
assertContains as public;
assertNotContains as public;
assertRegExp as public;
assertNotRegExp as public;
assertEmpty as public;
assertNotEmpty as public;
assertNull as public;
Expand Down
38 changes: 38 additions & 0 deletions src/Codeception/Util/Shared/Asserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@ protected function assertNotContains($needle, $haystack, $message = '')
\PHPUnit_Framework_Assert::assertNotContains($needle, $haystack, $message);
}

/**
* 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);
}

/**
* Checks that string not match with pattern
*
* @param string $pattern
* @param string $string
* @param string $message
*/
protected function assertNotRegExp($pattern, $string, $message = '')
{
\PHPUnit_Framework_Assert::assertNotRegExp($pattern, $string, $message);
}


/**
* Checks that variable is empty.
*
Expand Down Expand Up @@ -231,11 +256,24 @@ protected function assertFalse($condition, $message = '')
\PHPUnit_Framework_Assert::assertFalse($condition, $message);
}

/**
*
* @param $haystack
* @param $constraint
* @param string $message
*/
protected function assertThat($haystack, $constraint, $message)
{
\PHPUnit_Framework_Assert::assertThat($haystack, $constraint, $message);
}

/**
* Checks that haystack doesn't attend
*
* @param $haystack
* @param $constraint
* @param string $message
*/
protected function assertThatItsNot($haystack, $constraint, $message)
{
$constraint = new \PHPUnit_Framework_Constraint_Not($constraint);
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Codeception/Module/AssertsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public function testAsserts()
$module->assertContains(1,[1,2]);
$module->assertSame(1,1);
$module->assertNotSame(1,true);
$module->assertRegExp('/^[\d]$/','1');
$module->assertNotRegExp('/^[a-z]$/','1');
}

}

0 comments on commit a428062

Please sign in to comment.