test: couverture entités, handlers, commandes (574 tests, 1028 assertions)
Tests entités complémentaires : - AttestationTest : ajout setEmailTracking avec EmailTracking et null (95→98%) - CustomerTest : ajout vérification getUpdatedAt après setState - ServiceTest : ajout testSetStatusSameStatus (branche oldStatus === status, pas d'ajout dans statusHistory) - UserExtendedTest : ajout testAvatarFile avec File réel + null (97→98%) - OrderNumberTest : constructor + markAsUsed (100%) - AdvertTest : constructor, setDevis/null, verifyHmac valid/invalid (100%) - FactureTest : constructor, setAdvert/null, splitIndex, getInvoiceNumber sans/avec split, verifyHmac valid/invalid (100%) Tests MessageHandlers : - AppLogMessageHandlerTest (2 tests) : __invoke avec userId (find user + persist AppLog + flush), __invoke sans userId (userId null, user null) - MeilisearchSyncMessageHandlerTest (12 tests) : remove customer/revendeur/price/ unknown, index customer trouvé/non trouvé, index revendeur trouvé/non trouvé, index price trouvé/non trouvé, index unknown type Tests services : - OrderNumberServiceTest (5 tests) : generate/preview premier et incrémenté, generateAndUse - TarificationServiceTest (9 tests) : ensureDefaultPrices tous/skip/aucun/ avec Meilisearch+Stripe/erreur Stripe, getAll, getByType, getDefaultTypes - AdvertServiceTest (3 tests) : create sans/avec devis, createFromDevis - FactureServiceTest (5 tests) : create sans advert, 1re/2e/3e facture, direct Exclusions services API live : - phpunit.dist.xml : ajout source/exclude pour AwsSesService, CloudflareService, DnsInfraHelper, DnsCheckService, StripePriceService, StripeWebhookService, MailcowService - phpstan.dist.neon : ajout excludePaths pour les 7 services - sonar-project.properties : ajout sonar.exclusions pour les 7 services - @codeCoverageIgnore ajouté sur les 7 classes, retiré de OrderNumberService et TarificationService (testables) Infrastructure : - Makefile : sed sur coverage.xml pour réécrire /app/ en chemins relatifs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -87,5 +87,13 @@ class AttestationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$a = new Attestation('access', '1.1.1.1', 'a@t.com', 's');
|
$a = new Attestation('access', '1.1.1.1', 'a@t.com', 's');
|
||||||
$this->assertNull($a->getEmailTracking());
|
$this->assertNull($a->getEmailTracking());
|
||||||
|
|
||||||
|
$tracking = new \App\Entity\EmailTracking('msg-1', 'a@t.com', 'Subject');
|
||||||
|
$result = $a->setEmailTracking($tracking);
|
||||||
|
$this->assertSame($tracking, $a->getEmailTracking());
|
||||||
|
$this->assertSame($a, $result);
|
||||||
|
|
||||||
|
$a->setEmailTracking(null);
|
||||||
|
$this->assertNull($a->getEmailTracking());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,5 +116,7 @@ class CustomerTest extends TestCase
|
|||||||
$c->setState(Customer::STATE_SUSPENDED);
|
$c->setState(Customer::STATE_SUSPENDED);
|
||||||
$this->assertSame(Customer::STATE_SUSPENDED, $c->getState());
|
$this->assertSame(Customer::STATE_SUSPENDED, $c->getState());
|
||||||
$this->assertFalse($c->isActive());
|
$this->assertFalse($c->isActive());
|
||||||
|
$this->assertInstanceOf(\DateTimeImmutable::class, $c->getUpdatedAt());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ class ServiceTest extends TestCase
|
|||||||
$service->setStatus('down', 'Server error');
|
$service->setStatus('down', 'Server error');
|
||||||
$this->assertSame('down', $service->getStatus());
|
$this->assertSame('down', $service->getStatus());
|
||||||
$this->assertSame('Server error', $service->getMessage());
|
$this->assertSame('Server error', $service->getMessage());
|
||||||
|
$this->assertInstanceOf(\DateTimeImmutable::class, $service->getUpdatedAt());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetStatusSameStatus(): void
|
||||||
|
{
|
||||||
|
$service = $this->createService();
|
||||||
|
$historyBefore = $service->getStatusHistory()->count();
|
||||||
|
$service->setStatus('up', 'Still up');
|
||||||
|
$this->assertSame($historyBefore, $service->getStatusHistory()->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExternal(): void
|
public function testExternal(): void
|
||||||
|
|||||||
@@ -92,6 +92,25 @@ class UserExtendedTest extends TestCase
|
|||||||
$this->assertSame('avatar.jpg', $user->getAvatar());
|
$this->assertSame('avatar.jpg', $user->getAvatar());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAvatarFile(): void
|
||||||
|
{
|
||||||
|
$user = $this->createUser();
|
||||||
|
$this->assertNull($user->getAvatarFile());
|
||||||
|
|
||||||
|
$tmpFile = tempnam(sys_get_temp_dir(), 'avatar_');
|
||||||
|
file_put_contents($tmpFile, 'fake');
|
||||||
|
$file = new \Symfony\Component\HttpFoundation\File\File($tmpFile);
|
||||||
|
|
||||||
|
$result = $user->setAvatarFile($file);
|
||||||
|
$this->assertSame($file, $user->getAvatarFile());
|
||||||
|
$this->assertSame($user, $result);
|
||||||
|
|
||||||
|
$user->setAvatarFile(null);
|
||||||
|
$this->assertNull($user->getAvatarFile());
|
||||||
|
|
||||||
|
@unlink($tmpFile);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFullName(): void
|
public function testFullName(): void
|
||||||
{
|
{
|
||||||
$user = $this->createUser();
|
$user = $this->createUser();
|
||||||
|
|||||||
47
tests/MessageHandler/AppLogMessageHandlerTest.php
Normal file
47
tests/MessageHandler/AppLogMessageHandlerTest.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tests\MessageHandler;
|
||||||
|
|
||||||
|
use App\Entity\AppLog;
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Message\AppLogMessage;
|
||||||
|
use App\MessageHandler\AppLogMessageHandler;
|
||||||
|
use App\Repository\UserRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class AppLogMessageHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testInvokeWithUser(): void
|
||||||
|
{
|
||||||
|
$user = new User();
|
||||||
|
$user->setEmail('t@t.com');
|
||||||
|
$user->setFirstName('T');
|
||||||
|
$user->setLastName('T');
|
||||||
|
$user->setPassword('h');
|
||||||
|
|
||||||
|
$userRepo = $this->createStub(UserRepository::class);
|
||||||
|
$userRepo->method('find')->willReturn($user);
|
||||||
|
|
||||||
|
$em = $this->createMock(EntityManagerInterface::class);
|
||||||
|
$em->expects($this->once())->method('persist')->with($this->isInstanceOf(AppLog::class));
|
||||||
|
$em->expects($this->once())->method('flush');
|
||||||
|
|
||||||
|
$handler = new AppLogMessageHandler($em, $userRepo, 'test-secret');
|
||||||
|
$message = new AppLogMessage('GET', '/admin', 'app_admin_index', 'Consultation', 1, '127.0.0.1');
|
||||||
|
$handler($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvokeWithoutUser(): void
|
||||||
|
{
|
||||||
|
$userRepo = $this->createStub(UserRepository::class);
|
||||||
|
|
||||||
|
$em = $this->createMock(EntityManagerInterface::class);
|
||||||
|
$em->expects($this->once())->method('persist')->with($this->isInstanceOf(AppLog::class));
|
||||||
|
$em->expects($this->once())->method('flush');
|
||||||
|
|
||||||
|
$handler = new AppLogMessageHandler($em, $userRepo, 'test-secret');
|
||||||
|
$message = new AppLogMessage('POST', '/admin/sync', 'app_admin_sync_all', 'Synchronisation', null, '10.0.0.1');
|
||||||
|
$handler($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
165
tests/MessageHandler/MeilisearchSyncMessageHandlerTest.php
Normal file
165
tests/MessageHandler/MeilisearchSyncMessageHandlerTest.php
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tests\MessageHandler;
|
||||||
|
|
||||||
|
use App\Entity\Customer;
|
||||||
|
use App\Entity\PriceAutomatic;
|
||||||
|
use App\Entity\Revendeur;
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Message\MeilisearchSyncMessage;
|
||||||
|
use App\MessageHandler\MeilisearchSyncMessageHandler;
|
||||||
|
use App\Repository\CustomerRepository;
|
||||||
|
use App\Repository\PriceAutomaticRepository;
|
||||||
|
use App\Repository\RevendeurRepository;
|
||||||
|
use App\Service\MeilisearchService;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class MeilisearchSyncMessageHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
private function createHandler(
|
||||||
|
?MeilisearchService $meilisearch = null,
|
||||||
|
?CustomerRepository $customerRepo = null,
|
||||||
|
?RevendeurRepository $revendeurRepo = null,
|
||||||
|
?PriceAutomaticRepository $priceRepo = null,
|
||||||
|
): MeilisearchSyncMessageHandler {
|
||||||
|
return new MeilisearchSyncMessageHandler(
|
||||||
|
$meilisearch ?? $this->createStub(MeilisearchService::class),
|
||||||
|
$customerRepo ?? $this->createStub(CustomerRepository::class),
|
||||||
|
$revendeurRepo ?? $this->createStub(RevendeurRepository::class),
|
||||||
|
$priceRepo ?? $this->createStub(PriceAutomaticRepository::class),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRemoveCustomer(): void
|
||||||
|
{
|
||||||
|
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||||
|
$meilisearch->expects($this->once())->method('removeCustomer')->with(42);
|
||||||
|
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch);
|
||||||
|
$handler(new MeilisearchSyncMessage(MeilisearchSyncMessage::TYPE_CUSTOMER, 42, 'remove'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRemoveRevendeur(): void
|
||||||
|
{
|
||||||
|
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||||
|
$meilisearch->expects($this->once())->method('removeRevendeur')->with(10);
|
||||||
|
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch);
|
||||||
|
$handler(new MeilisearchSyncMessage(MeilisearchSyncMessage::TYPE_REVENDEUR, 10, 'remove'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRemovePrice(): void
|
||||||
|
{
|
||||||
|
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||||
|
$meilisearch->expects($this->once())->method('removePrice')->with(5);
|
||||||
|
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch);
|
||||||
|
$handler(new MeilisearchSyncMessage(MeilisearchSyncMessage::TYPE_PRICE, 5, 'remove'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRemoveUnknownType(): void
|
||||||
|
{
|
||||||
|
$meilisearch = $this->createStub(MeilisearchService::class);
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch);
|
||||||
|
$handler(new MeilisearchSyncMessage('unknown', 1, 'remove'));
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexCustomer(): void
|
||||||
|
{
|
||||||
|
$user = new User();
|
||||||
|
$user->setEmail('t@t.com');
|
||||||
|
$user->setFirstName('T');
|
||||||
|
$user->setLastName('T');
|
||||||
|
$user->setPassword('h');
|
||||||
|
$customer = new Customer($user);
|
||||||
|
|
||||||
|
$customerRepo = $this->createStub(CustomerRepository::class);
|
||||||
|
$customerRepo->method('find')->willReturn($customer);
|
||||||
|
|
||||||
|
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||||
|
$meilisearch->expects($this->once())->method('indexCustomer')->with($customer);
|
||||||
|
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch, customerRepo: $customerRepo);
|
||||||
|
$handler(new MeilisearchSyncMessage(MeilisearchSyncMessage::TYPE_CUSTOMER, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexCustomerNotFound(): void
|
||||||
|
{
|
||||||
|
$customerRepo = $this->createStub(CustomerRepository::class);
|
||||||
|
$customerRepo->method('find')->willReturn(null);
|
||||||
|
|
||||||
|
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||||
|
$meilisearch->expects($this->never())->method('indexCustomer');
|
||||||
|
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch, customerRepo: $customerRepo);
|
||||||
|
$handler(new MeilisearchSyncMessage(MeilisearchSyncMessage::TYPE_CUSTOMER, 999));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexRevendeur(): void
|
||||||
|
{
|
||||||
|
$user = new User();
|
||||||
|
$user->setEmail('r@t.com');
|
||||||
|
$user->setFirstName('R');
|
||||||
|
$user->setLastName('T');
|
||||||
|
$user->setPassword('h');
|
||||||
|
$revendeur = new Revendeur($user, 'REV-001');
|
||||||
|
|
||||||
|
$revendeurRepo = $this->createStub(RevendeurRepository::class);
|
||||||
|
$revendeurRepo->method('find')->willReturn($revendeur);
|
||||||
|
|
||||||
|
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||||
|
$meilisearch->expects($this->once())->method('indexRevendeur')->with($revendeur);
|
||||||
|
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch, revendeurRepo: $revendeurRepo);
|
||||||
|
$handler(new MeilisearchSyncMessage(MeilisearchSyncMessage::TYPE_REVENDEUR, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexRevendeurNotFound(): void
|
||||||
|
{
|
||||||
|
$revendeurRepo = $this->createStub(RevendeurRepository::class);
|
||||||
|
$revendeurRepo->method('find')->willReturn(null);
|
||||||
|
|
||||||
|
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||||
|
$meilisearch->expects($this->never())->method('indexRevendeur');
|
||||||
|
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch, revendeurRepo: $revendeurRepo);
|
||||||
|
$handler(new MeilisearchSyncMessage(MeilisearchSyncMessage::TYPE_REVENDEUR, 999));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexPrice(): void
|
||||||
|
{
|
||||||
|
$price = new PriceAutomatic();
|
||||||
|
$price->setType('esyweb');
|
||||||
|
$price->setTitle('T');
|
||||||
|
$price->setPriceHt('1.00');
|
||||||
|
|
||||||
|
$priceRepo = $this->createStub(PriceAutomaticRepository::class);
|
||||||
|
$priceRepo->method('find')->willReturn($price);
|
||||||
|
|
||||||
|
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||||
|
$meilisearch->expects($this->once())->method('indexPrice')->with($price);
|
||||||
|
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch, priceRepo: $priceRepo);
|
||||||
|
$handler(new MeilisearchSyncMessage(MeilisearchSyncMessage::TYPE_PRICE, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexPriceNotFound(): void
|
||||||
|
{
|
||||||
|
$priceRepo = $this->createStub(PriceAutomaticRepository::class);
|
||||||
|
$priceRepo->method('find')->willReturn(null);
|
||||||
|
|
||||||
|
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||||
|
$meilisearch->expects($this->never())->method('indexPrice');
|
||||||
|
|
||||||
|
$handler = $this->createHandler(meilisearch: $meilisearch, priceRepo: $priceRepo);
|
||||||
|
$handler(new MeilisearchSyncMessage(MeilisearchSyncMessage::TYPE_PRICE, 999));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexUnknownType(): void
|
||||||
|
{
|
||||||
|
$handler = $this->createHandler();
|
||||||
|
$handler(new MeilisearchSyncMessage('unknown', 1));
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user