| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
trait TestAllServiceOptionsUsed { |
| 18 |
|
| 19 |
private static $serviceOptionsAccessLog = []; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public function assertAllServiceOptionsUsed( array $expectedUnused = [] ) { |
| 25 |
$this->assertNotEmpty( self::$serviceOptionsAccessLog, |
| 26 |
'You need to pass LoggedServiceOptions to your class instead of ServiceOptions ' . |
| 27 |
'for TestAllServiceOptionsUsed to work.' |
| 28 |
); |
| 29 |
|
| 30 |
[ $expected, $actual ] = self::$serviceOptionsAccessLog; |
| 31 |
|
| 32 |
$expected = array_diff( $expected, $expectedUnused ); |
| 33 |
|
| 34 |
$this->assertSame( |
| 35 |
[], |
| 36 |
array_diff( $expected, array_keys( $actual ) ), |
| 37 |
"Some ServiceOptions keys were not accessed in tests. If they really aren't used, " . |
| 38 |
"remove them from the class' option list. If they are used, add tests to cover them, " . |
| 39 |
"or ignore the problem for now by passing them to assertAllServiceOptionsUsed() in " . |
| 40 |
"its \$expectedUnused argument." |
| 41 |
); |
| 42 |
|
| 43 |
if ( $expectedUnused ) { |
| 44 |
$this->markTestIncomplete( 'Some ServiceOptions keys are not yet accessed by tests: ' . |
| 45 |
implode( ', ', $expectedUnused ) ); |
| 46 |
} |
| 47 |
} |
| 48 |
} |