Skip to content

Commit c9b8485

Browse files
committed
README: clarify code examples
To use the functionality from the library, users can choose one of two methods to use it. The existing code example in the readme was confusing as it used both methods in the same example, while at any time, only one method should be used. This splits out the example into the two distinct usages. Includes: * Update namespace in code samples to make it clear that the user namespace is expected. * Update test class name in code samples to make it clear this is an example. * Remove `strict_types` declaration. While this may just be my opinion, `strict_types` should not be used in test files as it can block the testing of unhappy paths.
1 parent 89f08a4 commit c9b8485

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,47 @@ composer require --dev dms/phpunit-arraysubset-asserts
1717

1818
You have two options to use this in your classes: either directly as a static call or as a trait if you wish to keep existing references working.
1919

20+
### Trait use example
21+
2022
```php
2123
<?php
22-
declare(strict_types=1);
2324

24-
namespace DMS\Tests;
25+
namespace Your\Package\Tests;
2526

26-
use DMS\PHPUnitExtensions\ArraySubset\Assert;
2727
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
2828
use PHPUnit\Framework\TestCase;
2929

30-
31-
final class AssertTest extends TestCase
30+
final class ExampleTest extends TestCase
3231
{
3332
use ArraySubsetAsserts;
34-
33+
3534
public function testWithTrait(): void
3635
{
3736
$expectedSubset = ['bar' => 0];
3837

3938
$content = ['bar' => '0'];
4039

4140
self::assertArraySubset($expectedSubset, $content, true);
41+
42+
$content = ['foo' => '1'];
43+
44+
$this->assertArraySubset($expectedSubset, $content, true);
4245
}
46+
}
47+
```
48+
49+
### Static class method example
4350

51+
```php
52+
<?php
53+
54+
namespace Your\Package\Tests;
55+
56+
use DMS\PHPUnitExtensions\ArraySubset\Assert;
57+
use PHPUnit\Framework\TestCase;
58+
59+
final class ExampleTest extends TestCase
60+
{
4461
public function testWithDirectCall(): void
4562
{
4663
$expectedSubset = ['bar' => 0];
@@ -50,5 +67,4 @@ final class AssertTest extends TestCase
5067
Assert::assertArraySubset($expectedSubset, $content, true);
5168
}
5269
}
53-
5470
```

0 commit comments

Comments
 (0)