2
2
3
3
namespace Test \Pager ;
4
4
5
+ use Knp \Component \Pager \Event \BeforeEvent ;
6
+ use Knp \Component \Pager \Event \ItemsEvent ;
5
7
use Knp \Component \Pager \Event \Subscriber \Paginate \PaginationSubscriber ;
8
+ use Knp \Component \Pager \Pagination \SlidingPagination ;
6
9
use PHPUnit \Framework \Attributes \Test ;
7
10
use Symfony \Component \EventDispatcher \EventDispatcher ;
11
+ use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
8
12
use Test \Tool \BaseTestCase ;
9
13
10
14
final class PaginatorTest extends BaseTestCase
@@ -29,4 +33,45 @@ public function shouldFailToPaginateUnsupportedValue(): void
29
33
$ paginator = $ this ->getPaginatorInstance (null , $ dispatcher );
30
34
$ paginator ->paginate (null , 1 , 10 );
31
35
}
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
+ }
32
77
}
0 commit comments