Skip to content

Commit

Permalink
Add Stub match_array example to API
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig committed Aug 17, 2017
1 parent 6d90a3a commit bd0c1b2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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
Expand Down

0 comments on commit bd0c1b2

Please sign in to comment.