|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace PHPUnit\Framework; |
| 4 | + |
| 5 | +use PHPUnit\Framework\Attributes\CoversMethod; |
| 6 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 7 | +use PHPUnit\Framework\Attributes\Small; |
| 8 | +use PHPUnit\Framework\Attributes\TestDox; |
| 9 | +use stdClass; |
| 10 | + |
| 11 | +#[CoversMethod(Assert::class, 'assertSameDictionaryKeysValuesTest')] |
| 12 | +#[TestDox('assertSameDictionaryKeysValuesTest()')] |
| 13 | +#[Small] |
| 14 | +final class assertSameDictionaryKeysValuesTest extends TestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @return non-empty-list<array{0: mixed, 1: mixed}> |
| 18 | + */ |
| 19 | + public static function successProvider(): array |
| 20 | + { |
| 21 | + return [ |
| 22 | + [ |
| 23 | + [ |
| 24 | + 'string' => 'string', |
| 25 | + true => true, |
| 26 | + 1 => 1, |
| 27 | + 2 => 2.5, |
| 28 | + 'object' => new stdClass(), |
| 29 | + 'array' => [1, 2, 3], |
| 30 | + 'dictionary' => [ |
| 31 | + 'string' => 'string', |
| 32 | + true => true, |
| 33 | + 1 => 1, |
| 34 | + 2 => 2.5, |
| 35 | + 'object' => new stdClass(), |
| 36 | + 'array' => [1, 2, 3], |
| 37 | + ], |
| 38 | + ], |
| 39 | + [ |
| 40 | + 'dictionary' => [ |
| 41 | + 'object' => new stdClass(), |
| 42 | + 'array' => [1, 2, 3], |
| 43 | + 'string' => 'string', |
| 44 | + true => true, |
| 45 | + 1 => 1, |
| 46 | + 2 => 2.5, |
| 47 | + ], |
| 48 | + 'string' => 'string', |
| 49 | + true => true, |
| 50 | + 1 => 1, |
| 51 | + 2 => 2.5, |
| 52 | + 'object' => new stdClass(), |
| 53 | + 'array' => [1, 2, 3], |
| 54 | + ], |
| 55 | + ], |
| 56 | + ]; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @return non-empty-list<array{0: mixed, 1: mixed}> |
| 61 | + */ |
| 62 | + public static function failureProvider(): array |
| 63 | + { |
| 64 | + return [ |
| 65 | + [ |
| 66 | + [ |
| 67 | + 'string' => 'string', |
| 68 | + true => true, |
| 69 | + 1 => 1, |
| 70 | + 2 => 2.5, |
| 71 | + 'object' => new stdClass(), |
| 72 | + 'array' => [1, 2, 3], |
| 73 | + 'dictionary' => [ |
| 74 | + 'string' => 'string', |
| 75 | + true => true, |
| 76 | + 1 => 1, |
| 77 | + 2 => 2.5, |
| 78 | + 'object' => new stdClass(), |
| 79 | + 'array' => [1, 2, 3], |
| 80 | + ], |
| 81 | + ], |
| 82 | + [ |
| 83 | + 'string' => 'string', |
| 84 | + true => true, |
| 85 | + 1 => 1, |
| 86 | + ], |
| 87 | + ], |
| 88 | + ]; |
| 89 | + } |
| 90 | + |
| 91 | + #[DataProvider('successProvider')] |
| 92 | + public function testSucceedsWhenConstraintEvaluatesToTrue(mixed $expected, mixed $actual): void |
| 93 | + { |
| 94 | + $this->assertSameDictionaryKeysValues($expected, $actual); |
| 95 | + } |
| 96 | + |
| 97 | + #[DataProvider('failureProvider')] |
| 98 | + public function testFailsWhenConstraintEvaluatesToFalse(mixed $expected, mixed $actual): void |
| 99 | + { |
| 100 | + $this->expectException(AssertionFailedError::class); |
| 101 | + |
| 102 | + $this->assertSameDictionaryKeysValues($expected, $actual); |
| 103 | + } |
| 104 | +} |
0 commit comments