@@ -47,4 +47,95 @@ public static function provideProjectionNames(): array
4747 'read_model_projection ' => ['black_hole_read_model_projection ' ],
4848 ];
4949 }
50+
51+ /**
52+ * @test
53+ * @dataProvider provideLimitOptions
54+ */
55+ public function it_lists_correct_amount_of_projections (int $ amountToGenerate , int $ limit = null ): void
56+ {
57+ $ kernel = static ::createKernel ();
58+ $ kernel ->boot ();
59+
60+ /** @var InMemoryProjectionManager $manager */
61+ $ manager = $ kernel ->getContainer ()->get ('test.prooph_event_store.projection_manager.main_projection_manager ' );
62+
63+ $ projectionNames = $ this ->projectionNameGenerator ($ amountToGenerate );
64+
65+ foreach ($ projectionNames as $ projectionName ) {
66+ $ manager ->createProjection ($ projectionName );
67+ }
68+
69+ $ app = new Application ($ kernel );
70+ $ command = $ app ->find ('event-store:projection:names ' );
71+
72+ if (null === $ limit ) {
73+ $ limit = $ command ->getDefinition ()->getOption ('limit ' )->getDefault ();
74+ }
75+
76+ $ commandTester = new CommandTester ($ command );
77+ $ commandTester ->execute (['--limit ' => $ limit ]);
78+ $ this ->assertContains ('main_projection_manager ' , $ commandTester ->getDisplay ());
79+
80+ $ expectedProjectionNames = \array_slice ($ projectionNames , 0 , $ limit );
81+ $ unexpectedProjectionNames = \array_slice ($ projectionNames , $ limit );
82+ foreach ($ expectedProjectionNames as $ projectionName ) {
83+ $ this ->assertContains ($ projectionName , $ commandTester ->getDisplay ());
84+ }
85+ foreach ($ unexpectedProjectionNames as $ projectionName ) {
86+ $ this ->assertNotContains ($ projectionName , $ commandTester ->getDisplay ());
87+ }
88+ }
89+
90+ /**
91+ * Generates an array of projection names, each suffixed with a zero-padded number
92+ *
93+ * Example:
94+ * [
95+ * 'black_hole_read_model_projection_01',
96+ * 'black_hole_read_model_projection_02',
97+ * 'black_hole_read_model_projection_03',
98+ * 'black_hole_read_model_projection_04',
99+ * 'black_hole_read_model_projection_05',
100+ * 'black_hole_read_model_projection_06',
101+ * 'black_hole_read_model_projection_07',
102+ * 'black_hole_read_model_projection_08',
103+ * 'black_hole_read_model_projection_09',
104+ * 'black_hole_read_model_projection_10',
105+ * 'black_hole_read_model_projection_11',
106+ * ...
107+ * ]
108+ *
109+ * @param int $amountToGenerate
110+ * @param string $prefix
111+ */
112+ private function projectionNameGenerator (
113+ int $ amountToGenerate ,
114+ string $ prefix = 'black_hole_read_model_projection_ '
115+ ): array {
116+ return \array_map (
117+ function ($ value ) use ($ amountToGenerate , $ prefix ) {
118+ return $ prefix . \str_pad ((string ) $ value , \strlen ((string ) $ amountToGenerate ), '0 ' , \STR_PAD_LEFT );
119+ },
120+ \range (1 , $ amountToGenerate )
121+ );
122+ }
123+
124+ public function provideLimitOptions (): array
125+ {
126+ return [
127+ [
128+ 25 ,
129+ null ,
130+ ],
131+ [
132+ 25 ,
133+ 5 ,
134+ ],
135+ [
136+ 25 ,
137+ 25 ,
138+ ],
139+ ];
140+ }
50141}
0 commit comments