Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e206b0362 |
+1
-1
@@ -1,2 +1,2 @@
|
||||
parameters:
|
||||
app.version: '0.1.94'
|
||||
app.version: '0.1.93'
|
||||
|
||||
@@ -4,8 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Module\Commercial\Api;
|
||||
|
||||
use App\Module\Commercial\Domain\Entity\Supplier;
|
||||
use App\Module\Commercial\Domain\Entity\SupplierAddress;
|
||||
use App\Module\Commercial\Domain\Entity\SupplierContact;
|
||||
use App\Module\Sites\Domain\Entity\Site;
|
||||
use DateTimeImmutable;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
/**
|
||||
@@ -20,11 +23,24 @@ use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class SupplierExportControllerTest extends AbstractSupplierApiTestCase
|
||||
final class SupplierExportControllerTest extends AbstractCommercialApiTestCase
|
||||
{
|
||||
private const string XLSX_MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
||||
private const string EXPORT_URL = '/api/suppliers/export.xlsx';
|
||||
|
||||
/**
|
||||
* Les fournisseurs doivent etre purges AVANT les categories de test (le parent
|
||||
* supprime les categories `test_cli_cat_*`) : la jointure supplier_category est
|
||||
* en ON DELETE CASCADE cote supplier mais RESTRICT cote category. Le DELETE DQL
|
||||
* sur Supplier declenche le cascade BDD sur supplier_category / _contact /
|
||||
* _address (et leurs sous-jointures), liberant les categories pour le parent.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->getEm()->createQuery('DELETE FROM '.Supplier::class)->execute();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testExportReturnsXlsxResponseWithAttachmentFilename(): void
|
||||
{
|
||||
$client = $this->createAdminClient();
|
||||
@@ -94,13 +110,9 @@ final class SupplierExportControllerTest extends AbstractSupplierApiTestCase
|
||||
$supplier = $this->seedSupplier('Contact Co');
|
||||
|
||||
// position 1 (secondaire) insere en premier...
|
||||
$this->addContact($supplier, 'Bob', 'Secondaire', '0600000001', 'bob@contact.co', 1);
|
||||
$this->addContact($supplier, 'Secondaire', 'Bob', 1, '0600000001', '0600000002', 'bob@contact.co');
|
||||
// ...position 0 (principal) insere ensuite : c'est lui qui doit gagner.
|
||||
$principal = $this->addContact($supplier, 'Alice', 'Principal', '0612345678', 'alice@contact.co', 0);
|
||||
// Le telephone secondaire n'est pas porte par le helper de base : on le pose
|
||||
// directement sur le contact principal pour alimenter la colonne dediee.
|
||||
$principal->setPhoneSecondary('0698765432');
|
||||
$this->getEm()->flush();
|
||||
$this->addContact($supplier, 'Principal', 'Alice', 0, '0612345678', '0698765432', 'alice@contact.co');
|
||||
|
||||
$row = $this->rowFor($client->request('GET', self::EXPORT_URL)->getContent(), 'CONTACT CO');
|
||||
|
||||
@@ -137,10 +149,8 @@ final class SupplierExportControllerTest extends AbstractSupplierApiTestCase
|
||||
|
||||
$flat = $this->flatten($this->gridFromResponse($client->request('GET', self::EXPORT_URL)->getContent()));
|
||||
|
||||
// Colonne « Catégories » : libelle de la categorie FOURNISSEUR du fournisseur
|
||||
// (getName()). On le derive du helper de base (idempotent) plutot que de
|
||||
// hardcoder le prefixe de nom de test.
|
||||
self::assertStringContainsString((string) $this->supplierCategory('NEGOCIANT')->getName(), $flat);
|
||||
// Colonne « Catégories » : libelle de la categorie du fournisseur (getName()).
|
||||
self::assertStringContainsString('test_cli_cat_negociant', $flat);
|
||||
// Colonne « Sites » : site agrege depuis l'adresse (RG-2.06).
|
||||
self::assertStringContainsString((string) $site->getName(), $flat);
|
||||
}
|
||||
@@ -196,6 +206,50 @@ final class SupplierExportControllerTest extends AbstractSupplierApiTestCase
|
||||
self::assertResponseStatusCodeSame(401);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seede directement un Supplier en base (sans passer par l'API), pour les
|
||||
* tests de liste / archivage. Stocke le nom en MAJUSCULES pour refleter l'etat
|
||||
* normalise (RG-2.12) qu'aurait produit le SupplierProcessor via l'API.
|
||||
*/
|
||||
private function seedSupplier(string $companyName, bool $isArchived = false, string $categoryCode = 'SECTEUR'): Supplier
|
||||
{
|
||||
$em = $this->getEm();
|
||||
$supplier = new Supplier();
|
||||
$supplier->setCompanyName(mb_strtoupper($companyName, 'UTF-8'));
|
||||
$supplier->addCategory($this->createCategory($categoryCode));
|
||||
$supplier->setIsArchived($isArchived);
|
||||
if ($isArchived) {
|
||||
$supplier->setArchivedAt(new DateTimeImmutable());
|
||||
}
|
||||
$em->persist($supplier);
|
||||
$em->flush();
|
||||
|
||||
return $supplier;
|
||||
}
|
||||
|
||||
private function addContact(
|
||||
Supplier $supplier,
|
||||
string $lastName,
|
||||
string $firstName,
|
||||
int $position,
|
||||
?string $phonePrimary = null,
|
||||
?string $phoneSecondary = null,
|
||||
?string $email = null,
|
||||
): void {
|
||||
$contact = new SupplierContact();
|
||||
$contact->setSupplier($supplier);
|
||||
$contact->setLastName($lastName);
|
||||
$contact->setFirstName($firstName);
|
||||
$contact->setPosition($position);
|
||||
$contact->setPhonePrimary($phonePrimary);
|
||||
$contact->setPhoneSecondary($phoneSecondary);
|
||||
$contact->setEmail($email);
|
||||
|
||||
$supplier->addContact($contact);
|
||||
$this->getEm()->persist($contact);
|
||||
$this->getEm()->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Relit le binaire XLSX d'une reponse et renvoie la grille de cellules.
|
||||
*
|
||||
@@ -230,7 +284,7 @@ final class SupplierExportControllerTest extends AbstractSupplierApiTestCase
|
||||
/**
|
||||
* Renvoie la ligne de donnees dont la 1re colonne (nom) vaut $companyName.
|
||||
*
|
||||
* @return null|array<int, mixed>
|
||||
* @return array<int, mixed>|null
|
||||
*/
|
||||
private function rowFor(string $binary, string $companyName): ?array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user