From bd0c1b281bc8bf252c46b2b67e538ec07cbfb48f Mon Sep 17 00:00:00 2001 From: Payton Swick Date: Thu, 17 Aug 2017 16:09:27 -0400 Subject: [PATCH] Add Stub match_array example to API --- API.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index e39dc9e..3fbbd10 100644 --- a/API.md +++ b/API.md @@ -78,7 +78,7 @@ expect_spy( $spy )->to_have_been_called->with( any() ); finish_spying(); ``` -- `match_array()`: Used as an argument to `Expectation->with()` to mean "any argument with these values". Shortcut for `new MatchArray()`. +- `match_array()`: Used as an argument to `Expectation->with()` or `Spy()->with()` to mean "any argument with these values". Shortcut for `new MatchArray()`. ```php $spy = get_spy_for( 'wp_update_post' ); @@ -87,6 +87,12 @@ expect_spy( $spy )->to_have_been_called->with( match_array( [ 'status' => 'publi finish_spying(); ``` +```php +mock_function( 'wp_update_post' )->when_called->with( match_array( [ 'title' => 'hello' ] ) )->will_return( 14 ); +$id = wp_update_post( [ 'title' => 'hello', 'status' => 'publish', 'post_content' => 'slartibartfast' ] ); +$this->assertEquals( 14, $id ); +``` + - `passed_arg( $index )`: Used as an argument to `Spy->and_return()` to mean "return the passed argument at $index". Shortcut for `new PassedArgument( $index )`. ```php