Skip to content

Commit 323f70e

Browse files
committed
Document the PHPUnit integration
1 parent fc1618c commit 323f70e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,37 @@ Feature: Listing user toys
387387
"""
388388
```
389389

390+
## PHPUnit integration
391+
392+
The `assertMatchesPattern()` is a handy assertion that matches values in PHPUnit tests.
393+
To use it either include the `Coduo\PHPMatcher\PHPUnit\PHPMatcherAssertions` trait,
394+
or extend the `Coduo\PHPMatcher\PHPUnit\PHPMatcherTestCase`:
395+
396+
```php
397+
namespace Coduo\PHPMatcher\Tests\PHPUnit;
398+
399+
use Coduo\PHPMatcher\PHPUnit\PHPMatcherAssertions;
400+
401+
class PHPMatcherAssertionsTest extends \PHPUnit_Framework_TestCase
402+
{
403+
use PHPMatcherAssertions;
404+
405+
public function test_it_asserts_if_a_value_matches_the_pattern()
406+
{
407+
$this->assertMatchesPattern('@string@', 'foo');
408+
}
409+
}
410+
```
411+
412+
The `matchesPattern()` method can be used in PHPUnit stubs or mocks:
413+
414+
```php
415+
$mock = $this->getMock(Foo::class);
416+
$mock->method('bar')
417+
->with($this->matchesPattern('@string@'))
418+
->willReturn('foo');
419+
```
420+
390421
## License
391422

392423
This library is distributed under the MIT license. Please see the LICENSE file.

0 commit comments

Comments
 (0)