Skip to content

Commit c268382

Browse files
committed
add regex context
1 parent 961cba0 commit c268382

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

features/bootstrap/support.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
// Utility functions used by Behat steps
44

5+
function assertRegExp( $regex, $actual ) {
6+
if ( ! preg_match( $regex, $actual ) ) {
7+
throw new Exception( "Actual value: " . var_export( $actual, true ) );
8+
}
9+
}
10+
511
function assertEquals( $expected, $actual ) {
612
if ( $expected != $actual ) {
713
throw new Exception( "Actual value: " . var_export( $actual, true ) );

features/steps/then.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function ( $world, $stream, $operator, $goal_ver ) {
152152
throw new Exception( $world->result );
153153
}
154154
}
155-
);
155+
);
156156

157157
$steps->Then( '/^the (.+) (file|directory) should (exist|not exist|be:|contain:|not contain:)$/',
158158
function ( $world, $path, $type, $action, $expected = null ) {
@@ -199,6 +199,20 @@ function ( $world, $path, $type, $action, $expected = null ) {
199199
}
200200
);
201201

202+
$steps->Then( '/^the (.+) file should match (((\/.+\/)|(#.+#))([a-z]+)?)$/',
203+
function ( $world, $path, $expected = null ) {
204+
$path = $world->replace_variables( $path );
205+
206+
// If it's a relative path, make it relative to the current test dir
207+
if ( '/' !== $path[0] ) {
208+
$path = $world->variables['RUN_DIR'] . "/$path";
209+
}
210+
211+
$contents = file_get_contents( $path );
212+
assertRegExp( $expected, $contents );
213+
}
214+
);
215+
202216
$steps->Then( '/^an email should (be sent|not be sent)$/', function( $world, $expected ) {
203217
if ( 'be sent' === $expected ) {
204218
assertNotEquals( 0, $world->email_sends );

0 commit comments

Comments
 (0)