22
33namespace CodedMonkey \Dirigent \Tests \FunctionalTests \Controller ;
44
5+ use CodedMonkey \Dirigent \Doctrine \Entity \Package ;
6+ use CodedMonkey \Dirigent \Doctrine \Entity \Registry ;
7+ use CodedMonkey \Dirigent \Doctrine \Entity \RegistryPackageMirroring ;
58use CodedMonkey \Dirigent \Tests \FunctionalTests \PublicKernel ;
9+ use CodedMonkey \Dirigent \Tests \Helper \KernelTestCaseTrait ;
10+ use CodedMonkey \Dirigent \Tests \Helper \MockEntityFactoryTrait ;
611use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
712use Symfony \Component \HttpFoundation \Request ;
813use Symfony \Component \HttpFoundation \Response ;
914
1015class ApiControllerPublicTest extends KernelTestCase
1116{
17+ use KernelTestCaseTrait;
18+ use MockEntityFactoryTrait;
19+
1220 #[\Override]
1321 protected static function getKernelClass (): string
1422 {
@@ -28,7 +36,7 @@ public function testRoot(): void
2836 ], $ rootData );
2937 }
3038
31- public function testPackage (): void
39+ public function testPackagMetadata (): void
3240 {
3341 self ::bootKernel ();
3442
@@ -37,7 +45,7 @@ public function testPackage(): void
3745 $ this ->assertNotSame ([], $ packageData );
3846 }
3947
40- public function testPackageDev (): void
48+ public function testPackageMetadataDev (): void
4149 {
4250 self ::bootKernel ();
4351
@@ -46,6 +54,37 @@ public function testPackageDev(): void
4654 $ this ->assertNotSame ([], $ packageData );
4755 }
4856
57+ public function testPackageMetadataIsNotFound (): void
58+ {
59+ self ::bootKernel ();
60+
61+ $ request = Request::create ('/p2/psr/container.json ' , 'GET ' );
62+ $ response = self ::$ kernel ->handle ($ request );
63+
64+ $ this ->assertSame (Response::HTTP_NOT_FOUND , $ response ->getStatusCode ());
65+ }
66+
67+ public function testPackageMetadataIsMirroredOnRequest (): void
68+ {
69+ self ::bootKernel ();
70+
71+ // Verify the package doesn't already exist
72+ $ package = $ this ->findEntity (Package::class, ['name ' => 'psr/container ' ]);
73+
74+ $ this ->assertNull ($ package );
75+
76+ // Update the registry so that it allows dynamically adding packages on request from the API
77+ $ registry = $ this ->findEntity (Registry::class, ['name ' => 'Packagist ' ]);
78+ $ registry ->setPackageMirroring (RegistryPackageMirroring::Automatic);
79+
80+ $ this ->persistEntities ($ registry );
81+
82+ // Execute the API endpoint
83+ $ packageData = $ this ->requestJson ('/p2/psr/container.json ' , 'GET ' );
84+
85+ $ this ->assertNotSame ([], $ packageData );
86+ }
87+
4988 private function requestJson (...$ requestArguments )
5089 {
5190 $ request = Request::create (...$ requestArguments );
0 commit comments