@@ -42,43 +42,13 @@ public static function discoverDataProvider(): Iterator
4242 ];
4343 }
4444
45- public function testCanDiscoverPackagesByType (): void
46- {
47- $ basePath = __DIR__ .'/Resources/test_one ' ;
48- $ finder = new Finder ($ basePath );
49-
50- $ plugins = $ finder ->discoverByType ('composer-plugin ' , 'myerscode ' );
51- $ this ->assertArrayHasKey ('myerscode/test-package ' , $ plugins );
52-
53- $ libraries = $ finder ->discoverByType ('library ' , 'myerscode ' );
54- $ this ->assertSame ([], $ libraries );
55- }
56-
57- public function testDiscoverByTypeReturnsEmptyForUnknownType (): void
58- {
59- $ basePath = __DIR__ .'/Resources/test_one ' ;
60- $ finder = new Finder ($ basePath );
61-
62- $ this ->assertSame ([], $ finder ->discoverByType ('unknown-type ' , 'myerscode ' ));
63- }
64-
65- public function testCanDiscoverMultipleNamespacesAtOnce (): void
66- {
67- $ basePath = __DIR__ .'/Resources/test_locate ' ;
68- $ finder = new Finder ($ basePath );
69-
70- $ discovered = $ finder ->discover (['myerscode ' , 'corgi ' ]);
71-
72- $ this ->assertArrayHasKey ('myerscode/test-package ' , $ discovered );
73- $ this ->assertCount (1 , $ discovered );
74- }
75-
76- public function testDiscoverWithArrayReturnsEmptyForUnknownNamespaces (): void
45+ public function testCanCheckIfPackageIsInstalled (): void
7746 {
7847 $ basePath = __DIR__ .'/Resources/test_locate ' ;
7948 $ finder = new Finder ($ basePath );
8049
81- $ this ->assertSame ([], $ finder ->discover (['unknown-ns ' ]));
50+ $ this ->assertTrue ($ finder ->has ('myerscode/test-package ' ));
51+ $ this ->assertFalse ($ finder ->has ('myerscode/not-a-package ' ));
8252 }
8353
8454 public function testCanDiscoverAllPackagesWithExtras (): void
@@ -93,33 +63,27 @@ public function testCanDiscoverAllPackagesWithExtras(): void
9363 $ this ->assertArrayNotHasKey ('myerscode/utilities-bags ' , $ all );
9464 }
9565
96- public function testDiscoverAllReturnsEmptyWhenNoPackagesHaveExtras (): void
97- {
98- $ basePath = __DIR__ .'/Resources ' ;
99- $ finder = new Finder ($ basePath );
100-
101- $ this ->assertSame ([], $ finder ->discoverAll ());
102- }
103-
104- public function testCanGetInstalledPackageNames (): void
66+ public function testCanDiscoverMultipleNamespacesAtOnce (): void
10567 {
10668 $ basePath = __DIR__ .'/Resources/test_locate ' ;
10769 $ finder = new Finder ($ basePath );
10870
109- $ names = $ finder ->installedPackageNames ( );
71+ $ discovered = $ finder ->discover ([ ' myerscode ' , ' corgi ' ] );
11072
111- $ this ->assertIsArray ($ names );
112- $ this ->assertContains ('myerscode/test-package ' , $ names );
113- $ this ->assertContains ('myerscode/utilities-bags ' , $ names );
73+ $ this ->assertArrayHasKey ('myerscode/test-package ' , $ discovered );
74+ $ this ->assertCount (1 , $ discovered );
11475 }
11576
116- public function testCanCheckIfPackageIsInstalled (): void
77+ public function testCanDiscoverPackagesByType (): void
11778 {
118- $ basePath = __DIR__ .'/Resources/test_locate ' ;
79+ $ basePath = __DIR__ .'/Resources/test_one ' ;
11980 $ finder = new Finder ($ basePath );
12081
121- $ this ->assertTrue ($ finder ->has ('myerscode/test-package ' ));
122- $ this ->assertFalse ($ finder ->has ('myerscode/not-a-package ' ));
82+ $ plugins = $ finder ->discoverByType ('composer-plugin ' , 'myerscode ' );
83+ $ this ->assertArrayHasKey ('myerscode/test-package ' , $ plugins );
84+
85+ $ libraries = $ finder ->discoverByType ('library ' , 'myerscode ' );
86+ $ this ->assertSame ([], $ libraries );
12387 }
12488
12589 public function testCanGePackageExtras (): void
@@ -142,6 +106,18 @@ public function testCanGePackageExtras(): void
142106 ], $ meta );
143107 }
144108
109+ public function testCanGetInstalledPackageNames (): void
110+ {
111+ $ basePath = __DIR__ .'/Resources/test_locate ' ;
112+ $ finder = new Finder ($ basePath );
113+
114+ $ names = $ finder ->installedPackageNames ();
115+
116+ $ this ->assertIsArray ($ names );
117+ $ this ->assertContains ('myerscode/test-package ' , $ names );
118+ $ this ->assertContains ('myerscode/utilities-bags ' , $ names );
119+ }
120+
145121 public function testCanGetMetaForPackageUsingMetaNamespace (): void
146122 {
147123 $ basePath = __DIR__ .'/Resources/test_locate ' ;
@@ -180,15 +156,28 @@ public function testCanSeeInstalledPackages(): void
180156 $ this ->assertGreaterThan (0 , count ($ installed ));
181157 }
182158
183- public function testInstalledPackagesAreCached (): void
159+ public function testDiscoverAllReturnsEmptyWhenNoPackagesHaveExtras (): void
184160 {
185- $ basePath = __DIR__ .'/../ ' ;
161+ $ basePath = __DIR__ .'/Resources ' ;
186162 $ finder = new Finder ($ basePath );
187163
188- $ first = $ finder ->installedPackages ( );
189- $ second = $ finder -> installedPackages ();
164+ $ this -> assertSame ([], $ finder ->discoverAll () );
165+ }
190166
191- $ this ->assertSame ($ first , $ second );
167+ public function testDiscoverByTypeReturnsEmptyForUnknownType (): void
168+ {
169+ $ basePath = __DIR__ .'/Resources/test_one ' ;
170+ $ finder = new Finder ($ basePath );
171+
172+ $ this ->assertSame ([], $ finder ->discoverByType ('unknown-type ' , 'myerscode ' ));
173+ }
174+
175+ public function testDiscoverWithArrayReturnsEmptyForUnknownNamespaces (): void
176+ {
177+ $ basePath = __DIR__ .'/Resources/test_locate ' ;
178+ $ finder = new Finder ($ basePath );
179+
180+ $ this ->assertSame ([], $ finder ->discover (['unknown-ns ' ]));
192181 }
193182
194183
@@ -213,15 +202,15 @@ public function testHandlesMissingInstallFile(): void
213202 $ this ->assertCount (0 , $ installed );
214203 }
215204
216- public function testThrowsExceptionWhenCannotLocatePackage (): void
205+ public function testInstalledPackagesAreCached (): void
217206 {
218- $ basePath = __DIR__ .'/Resources/test_locate ' ;
207+ $ basePath = __DIR__ .'/../ ' ;
219208 $ finder = new Finder ($ basePath );
220- $ packageName = 'myerscode/does-not-exists-package ' ;
221209
222- $ this ->expectException (PackageNotFoundException::class);
223- $ this ->expectExceptionMessage ($ packageName . ' is not a known package ' );
224- $ finder ->locate ($ packageName );
210+ $ first = $ finder ->installedPackages ();
211+ $ second = $ finder ->installedPackages ();
212+
213+ $ this ->assertSame ($ first , $ second );
225214 }
226215
227216 public function testPackageNotFoundExceptionExtendsInvalidArgumentException (): void
@@ -237,6 +226,17 @@ public function testPackageNotFoundExceptionExtendsInvalidArgumentException(): v
237226 }
238227 }
239228
229+ public function testThrowsExceptionWhenCannotLocatePackage (): void
230+ {
231+ $ basePath = __DIR__ .'/Resources/test_locate ' ;
232+ $ finder = new Finder ($ basePath );
233+ $ packageName = 'myerscode/does-not-exists-package ' ;
234+
235+ $ this ->expectException (PackageNotFoundException::class);
236+ $ this ->expectExceptionMessage ($ packageName . ' is not a known package ' );
237+ $ finder ->locate ($ packageName );
238+ }
239+
240240 public function testThrowsExceptionWhenPackagePathCannotBeResolved (): void
241241 {
242242 $ basePath = __DIR__ .'/Resources/test_locate ' ;
0 commit comments