createComposant('Pompe A'); $this->createComposant('Pompe B'); $client = $this->createViewerClient(); $client->request('GET', '/api/composants'); $this->assertResponseIsSuccessful(); $this->assertJsonContainsHydraCollection(); $this->assertJsonContains(['totalItems' => 2]); } public function testGetItem(): void { $c = $this->createComposant('Pompe A'); $client = $this->createViewerClient(); $client->request('GET', self::iri('composants', $c->getId())); $this->assertResponseIsSuccessful(); $this->assertJsonContains(['name' => 'Pompe A']); } public function testPost(): void { $client = $this->createGestionnaireClient(); $client->request('POST', '/api/composants', [ 'headers' => ['Content-Type' => 'application/ld+json'], 'json' => [ 'name' => 'Nouveau composant', 'reference' => 'REF-COMP-001', ], ]); $this->assertResponseStatusCodeSame(201); $this->assertJsonContains(['name' => 'Nouveau composant']); } public function testPostWithType(): void { $mt = $this->createModelType('Pompe', 'POMPE-001', ModelCategory::COMPONENT); $client = $this->createGestionnaireClient(); $client->request('POST', '/api/composants', [ 'headers' => ['Content-Type' => 'application/ld+json'], 'json' => [ 'name' => 'Composant typé', 'typeComposant' => self::iri('model_types', $mt->getId()), ], ]); $this->assertResponseStatusCodeSame(201); } public function testPut(): void { $c = $this->createComposant('Pompe A'); $client = $this->createGestionnaireClient(); $client->request('PUT', self::iri('composants', $c->getId()), [ 'headers' => ['Content-Type' => 'application/ld+json'], 'json' => ['name' => 'Pompe A Renommée'], ]); $this->assertResponseIsSuccessful(); $this->assertJsonContains(['name' => 'Pompe A Renommée']); } public function testPatch(): void { $c = $this->createComposant('Pompe A'); $client = $this->createGestionnaireClient(); $client->request('PATCH', self::iri('composants', $c->getId()), [ 'headers' => ['Content-Type' => 'application/merge-patch+json'], 'json' => ['prix' => '250.00'], ]); $this->assertResponseIsSuccessful(); $this->assertJsonContains(['prix' => '250.00']); } public function testDelete(): void { $c = $this->createComposant('ToDelete'); $client = $this->createGestionnaireClient(); $client->request('DELETE', self::iri('composants', $c->getId())); $this->assertResponseStatusCodeSame(204); } public function testUnauthenticatedAccess(): void { $client = $this->createUnauthenticatedClient(); $client->request('GET', '/api/composants'); $this->assertResponseStatusCodeSame(401); } public function testViewerCannotWrite(): void { $client = $this->createViewerClient(); $client->request('POST', '/api/composants', [ 'headers' => ['Content-Type' => 'application/ld+json'], 'json' => ['name' => 'Blocked'], ]); $this->assertResponseStatusCodeSame(403); } public function testSearchFilter(): void { $this->createComposant('Pompe hydraulique'); $this->createComposant('Vanne de contrôle'); $client = $this->createViewerClient(); $client->request('GET', '/api/composants?name=pompe'); $this->assertResponseIsSuccessful(); $this->assertJsonContains(['totalItems' => 1]); } }