|
14 | 14 | use PHPUnit\Framework\Attributes\DataProvider; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | 16 |
|
| 17 | +/** |
| 18 | + * @note The {@see PagerfantaHandler::PRESERVE_KEYS_KEY} constant value is inlined to avoid autoloader issues when the JMS packages are not installed |
| 19 | + */ |
17 | 20 | final class PagerfantaHandlerTest extends TestCase |
18 | 21 | { |
19 | 22 | public static function setUpBeforeClass(): void |
@@ -41,9 +44,9 @@ public static function dataSerializeWithPreserveKeysContext(): \Generator |
41 | 44 | { |
42 | 45 | yield 'Context not set' => [[0 => 'item1', 2 => 'item2', 4 => 'item3'], [], '{"items":{"0":"item1","2":"item2","4":"item3"},"pagination":{"current_page":1,"has_previous_page":false,"has_next_page":false,"per_page":10,"total_items":3,"total_pages":1}}']; |
43 | 46 |
|
44 | | - yield 'Context with preserve keys disabled' => [[0 => 'item1', 2 => 'item2', 4 => 'item3'], [PagerfantaHandler::PRESERVE_KEYS_KEY => false], '{"items":["item1","item2","item3"],"pagination":{"current_page":1,"has_previous_page":false,"has_next_page":false,"per_page":10,"total_items":3,"total_pages":1}}']; |
| 47 | + yield 'Context with preserve keys disabled' => [[0 => 'item1', 2 => 'item2', 4 => 'item3'], ['pagerfanta_preserve_keys' => false], '{"items":["item1","item2","item3"],"pagination":{"current_page":1,"has_previous_page":false,"has_next_page":false,"per_page":10,"total_items":3,"total_pages":1}}']; |
45 | 48 |
|
46 | | - yield 'Context with preserve keys enabled' => [[0 => 'item1', 2 => 'item2', 4 => 'item3'], [PagerfantaHandler::PRESERVE_KEYS_KEY => true], '{"items":{"0":"item1","2":"item2","4":"item3"},"pagination":{"current_page":1,"has_previous_page":false,"has_next_page":false,"per_page":10,"total_items":3,"total_pages":1}}']; |
| 49 | + yield 'Context with preserve keys enabled' => [[0 => 'item1', 2 => 'item2', 4 => 'item3'], ['pagerfanta_preserve_keys' => true], '{"items":{"0":"item1","2":"item2","4":"item3"},"pagination":{"current_page":1,"has_previous_page":false,"has_next_page":false,"per_page":10,"total_items":3,"total_pages":1}}']; |
47 | 50 | } |
48 | 51 |
|
49 | 52 | /** |
@@ -75,7 +78,7 @@ public function testNormalizeRejectsInvalidPreserveKeysContext(): void |
75 | 78 | $pager->setMaxPerPage(5); |
76 | 79 |
|
77 | 80 | $serializationContext = new SerializationContext(); |
78 | | - $serializationContext->setAttribute(PagerfantaHandler::PRESERVE_KEYS_KEY, 'invalid'); |
| 81 | + $serializationContext->setAttribute('pagerfanta_preserve_keys', 'invalid'); |
79 | 82 |
|
80 | 83 | $this->createSerializer()->serialize($pager, 'json', $serializationContext); |
81 | 84 | } |
|
0 commit comments