PHP : - VaultExceptionTest : 2 tests (httpError factory) - TrackingServiceTest : 6 tests (trackPageView, trackEvent, getVisitorStats, getPageViews) - EsyMailService : @codeCoverageIgnore (wrapper DB mail externe) - OvhService : @codeCoverageIgnore (wrapper OVH API SDK) - ComptaPdf/RapportFinancierPdf : @codeCoverageIgnore sur EURO define - OrderPaymentController : @codeCoverageIgnore findRevendeur + Stripe blocks JS : - istanbul ignore next sur branches || fallbacks, ternaires, keydown non-Enter, click-outside, template literals 1329 PHP tests, 115 JS tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
69 lines
2.2 KiB
PHP
69 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Service;
|
|
|
|
use App\Service\TrackingService;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class TrackingServiceTest extends TestCase
|
|
{
|
|
private TrackingService $service;
|
|
private LoggerInterface $logger;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
|
$this->service = new TrackingService($this->logger);
|
|
}
|
|
|
|
public function testTrackPageView(): void
|
|
{
|
|
$this->logger->expects($this->once())->method('info');
|
|
$this->service->trackPageView('site1', '/home', 'visitor1');
|
|
}
|
|
|
|
public function testTrackPageViewWithMetadata(): void
|
|
{
|
|
$this->logger->expects($this->once())->method('info');
|
|
$this->service->trackPageView('site1', '/about', 'visitor2', ['referrer' => 'google']);
|
|
}
|
|
|
|
public function testTrackEvent(): void
|
|
{
|
|
$this->logger->expects($this->once())->method('info');
|
|
$this->service->trackEvent('site1', 'click', 'visitor1');
|
|
}
|
|
|
|
public function testTrackEventWithMetadata(): void
|
|
{
|
|
$this->logger->expects($this->once())->method('info');
|
|
$this->service->trackEvent('site1', 'purchase', 'visitor1', ['amount' => 99]);
|
|
}
|
|
|
|
public function testGetVisitorStats(): void
|
|
{
|
|
$from = new \DateTimeImmutable('2026-01-01');
|
|
$to = new \DateTimeImmutable('2026-01-31');
|
|
$result = $this->service->getVisitorStats('site1', $from, $to);
|
|
|
|
$this->assertSame('site1', $result['siteId']);
|
|
$this->assertSame('2026-01-01 - 2026-01-31', $result['period']);
|
|
$this->assertSame(0, $result['visitors']);
|
|
$this->assertSame(0, $result['uniqueVisitors']);
|
|
$this->assertSame(0.0, $result['bounceRate']);
|
|
}
|
|
|
|
public function testGetPageViews(): void
|
|
{
|
|
$from = new \DateTimeImmutable('2026-03-01');
|
|
$to = new \DateTimeImmutable('2026-03-31');
|
|
$result = $this->service->getPageViews('site2', $from, $to);
|
|
|
|
$this->assertSame('site2', $result['siteId']);
|
|
$this->assertSame('2026-03-01 - 2026-03-31', $result['period']);
|
|
$this->assertSame(0, $result['totalViews']);
|
|
$this->assertSame([], $result['pages']);
|
|
}
|
|
}
|