createSite(); $this->createMachine('Machine A', $site); $this->createMachine('Machine B', $site); $client = $this->createViewerClient(); $client->request('GET', '/api/machines'); $this->assertResponseIsSuccessful(); $this->assertJsonContainsHydraCollection(); $this->assertJsonContains(['totalItems' => 2]); } public function testGetItem(): void { $m = $this->createMachine('Machine A', reference: 'REF-001'); $client = $this->createViewerClient(); $client->request('GET', self::iri('machines', $m->getId())); $this->assertResponseIsSuccessful(); $this->assertJsonContains([ 'name' => 'Machine A', 'reference' => 'REF-001', ]); } public function testPost(): void { $site = $this->createSite('Usine'); $client = $this->createGestionnaireClient(); $client->request('POST', '/api/machines', [ 'headers' => ['Content-Type' => 'application/ld+json'], 'json' => [ 'name' => 'Nouvelle Machine', 'reference' => 'REF-NEW', 'site' => self::iri('sites', $site->getId()), ], ]); $this->assertResponseStatusCodeSame(201); $this->assertJsonContains(['name' => 'Nouvelle Machine']); } public function testPut(): void { $m = $this->createMachine('Machine A'); $client = $this->createGestionnaireClient(); $client->request('PUT', self::iri('machines', $m->getId()), [ 'headers' => ['Content-Type' => 'application/ld+json'], 'json' => [ 'name' => 'Machine A Renommée', 'site' => self::iri('sites', $m->getSite()->getId()), ], ]); $this->assertResponseIsSuccessful(); $this->assertJsonContains(['name' => 'Machine A Renommée']); } public function testPatch(): void { $m = $this->createMachine('Machine A'); $client = $this->createGestionnaireClient(); $client->request('PATCH', self::iri('machines', $m->getId()), [ 'headers' => ['Content-Type' => 'application/merge-patch+json'], 'json' => ['prix' => '1500.00'], ]); $this->assertResponseIsSuccessful(); $this->assertJsonContains(['prix' => '1500.00']); } public function testDelete(): void { $m = $this->createMachine('ToDelete'); $client = $this->createGestionnaireClient(); $client->request('DELETE', self::iri('machines', $m->getId())); $this->assertResponseStatusCodeSame(204); } public function testUnauthenticatedAccess(): void { $client = $this->createUnauthenticatedClient(); $client->request('GET', '/api/machines'); $this->assertResponseStatusCodeSame(401); } public function testViewerCannotWrite(): void { $site = $this->createSite(); $client = $this->createViewerClient(); $client->request('POST', '/api/machines', [ 'headers' => ['Content-Type' => 'application/ld+json'], 'json' => [ 'name' => 'Blocked', 'site' => self::iri('sites', $site->getId()), ], ]); $this->assertResponseStatusCodeSame(403); } public function testPostWithoutSiteFails(): void { $client = $this->createGestionnaireClient(); $client->request('POST', '/api/machines', [ 'headers' => ['Content-Type' => 'application/ld+json'], 'json' => ['name' => 'No site'], ]); $this->assertResponseStatusCodeSame(422); } }