test(api) : add comprehensive API test suite (161 tests)

- Add AbstractApiTestCase with auth helpers and entity factories
- Add tests for all entities: Machine, Piece, Composant, Product, Site,
  ModelType, Constructeur, CustomField, CustomFieldValue, Document,
  MachineComponentLink, MachinePieceLink, MachineProductLink, Profile
- Add controller tests: CommentController, EntityHistory
- Add HealthCheck, Filter, Pagination, Validation, Session tests
- Test auth (401), authorization (403), CRUD, and edge cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 13:42:56 +01:00
parent b342d0e50a
commit efc6ec5691
22 changed files with 2843 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace App\Tests\Api;
use App\Tests\AbstractApiTestCase;
/**
* @internal
*/
class ValidationTest extends AbstractApiTestCase
{
public function testConstructeurRequiresName(): void
{
$client = $this->createGestionnaireClient();
$client->request('POST', '/api/constructeurs', [
'headers' => ['Content-Type' => 'application/ld+json'],
'json' => ['email' => 'no-name@test.com'],
]);
$this->assertResponseStatusCodeSame(422);
}
public function testSiteRequiresName(): void
{
$client = $this->createGestionnaireClient();
$client->request('POST', '/api/sites', [
'headers' => ['Content-Type' => 'application/ld+json'],
'json' => ['contactCity' => 'Paris'],
]);
$this->assertResponseStatusCodeSame(422);
}
public function testMachineRequiresSite(): void
{
$client = $this->createGestionnaireClient();
$client->request('POST', '/api/machines', [
'headers' => ['Content-Type' => 'application/ld+json'],
'json' => ['name' => 'Machine sans site'],
]);
$this->assertResponseStatusCodeSame(422);
}
public function testProfileRequiresFirstAndLastName(): void
{
$client = $this->createAdminClient();
$client->request('POST', '/api/profiles', [
'headers' => ['Content-Type' => 'application/ld+json'],
'json' => ['email' => 'missing@names.com'],
]);
$this->assertResponseStatusCodeSame(422);
}
public function testDuplicateConstructeurName(): void
{
$this->createConstructeur('Siemens');
$client = $this->createGestionnaireClient();
$client->request('POST', '/api/constructeurs', [
'headers' => ['Content-Type' => 'application/ld+json'],
'json' => ['name' => 'Siemens'],
]);
$this->assertResponseStatusCodeSame(422);
}
}