22
33namespace Test \Pager ;
44
5+ use Knp \Component \Pager \Event \BeforeEvent ;
6+ use Knp \Component \Pager \Event \ItemsEvent ;
57use Knp \Component \Pager \Event \Subscriber \Paginate \PaginationSubscriber ;
8+ use Knp \Component \Pager \Pagination \SlidingPagination ;
69use PHPUnit \Framework \Attributes \Test ;
710use Symfony \Component \EventDispatcher \EventDispatcher ;
11+ use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
812use Test \Tool \BaseTestCase ;
913
1014final class PaginatorTest extends BaseTestCase
@@ -29,4 +33,45 @@ public function shouldFailToPaginateUnsupportedValue(): void
2933 $ paginator = $ this ->getPaginatorInstance (null , $ dispatcher );
3034 $ paginator ->paginate (null , 1 , 10 );
3135 }
36+
37+ #[Test]
38+ public function shouldPassOptionsToBeforeEventSubscriber (): void
39+ {
40+ $ dispatcher = new EventDispatcher ();
41+ $ dispatcher ->addSubscriber (new class implements EventSubscriberInterface {
42+ public static function getSubscribedEvents (): array
43+ {
44+ return [
45+ 'knp_pager.before ' => ['before ' , 1 ],
46+ ];
47+ }
48+ public function before (BeforeEvent $ event ): void
49+ {
50+ BaseTestCase::assertArrayHasKey ('some_option ' , $ event ->options );
51+ BaseTestCase::assertEquals ('value ' , $ event ->options ['some_option ' ]);
52+
53+ $ event ->options ['some_option ' ] = 'changed ' ;
54+ $ event ->options ['extra_option ' ] = 'added ' ;
55+ }
56+ });
57+ $ dispatcher ->addSubscriber (new class implements EventSubscriberInterface {
58+ public static function getSubscribedEvents (): array
59+ {
60+ return [
61+ 'knp_pager.items ' => ['items ' , 1 ],
62+ ];
63+ }
64+ public function items (ItemsEvent $ event ): void
65+ {
66+ BaseTestCase::assertArrayHasKey ('some_option ' , $ event ->options );
67+ BaseTestCase::assertEquals ('changed ' , $ event ->options ['some_option ' ]);
68+ BaseTestCase::assertArrayHasKey ('extra_option ' , $ event ->options );
69+ BaseTestCase::assertEquals ('added ' , $ event ->options ['extra_option ' ]);
70+ }
71+ });
72+ $ dispatcher ->addSubscriber (new PaginationSubscriber ());
73+ $ paginator = $ this ->getPaginatorInstance (null , $ dispatcher );
74+
75+ $ paginator ->paginate ([], 1 , 10 , ['some_option ' => 'value ' ]);
76+ }
3277}
0 commit comments