```
✨ feat(ReserverController): Ajoute vérification de disponibilité produit. 🛠️ refactor(BackupCommand): Utilise DatabaseDumper et ZipArchiver. ✨ feat(GitSyncLogCommand): Utilise Gemini pour messages plus clairs. ✨ feat(GenerateVideoThumbsCommand): Utilise VideoThumbnailer service. ✨ feat(AppWarmupImagesCommand): Utilise StorageInterface pour warmup. 🔒️ security(nelmio_security): Renforce la sécurité avec des en-têtes. 🔧 chore(caddy): Améliore la configuration de Caddy pour la performance. 🐛 fix(makefile): Corrige les commandes de test. 🧪 chore(.env.test): Supprime la ligne vide à la fin du fichier. 🔧 chore(doctrine): Active native_lazy_objects. 🔧 chore(cache): Ajoute un cache system. ```
This commit is contained in:
75
tests/Command/SitemapCommandTest.php
Normal file
75
tests/Command/SitemapCommandTest.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Command;
|
||||
|
||||
use App\Command\SitemapCommand;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Presta\SitemapBundle\Service\DumperInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
class SitemapCommandTest extends TestCase
|
||||
{
|
||||
private MockObject&KernelInterface $kernel;
|
||||
private MockObject&DumperInterface $dumper;
|
||||
private string $tempDir;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->kernel = $this->createMock(KernelInterface::class);
|
||||
$this->dumper = $this->createMock(DumperInterface::class);
|
||||
|
||||
$this->tempDir = sys_get_temp_dir() . '/sitemap_test_' . uniqid();
|
||||
mkdir($this->tempDir . '/public/seo', 0777, true);
|
||||
$_ENV['DEFAULT_URI'] = 'https://test.com';
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->removeDirectory($this->tempDir);
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
// 1. Setup Files (Old sitemap to delete)
|
||||
touch($this->tempDir . '/public/seo/old.xml');
|
||||
|
||||
$this->kernel->method('getProjectDir')->willReturn($this->tempDir);
|
||||
|
||||
// 2. Expect Dumper call
|
||||
$this->dumper->expects($this->once())
|
||||
->method('dump')
|
||||
->with(
|
||||
$this->stringEndsWith('/public/seo'),
|
||||
'https://test.com/seo',
|
||||
'',
|
||||
[]
|
||||
);
|
||||
|
||||
// 3. Execute
|
||||
$command = new SitemapCommand($this->kernel, $this->dumper);
|
||||
$application = new Application();
|
||||
$application->add($command);
|
||||
$commandTester = new CommandTester($application->find('app:sitemap'));
|
||||
|
||||
$commandTester->execute([]);
|
||||
|
||||
// 4. Assertions
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('Anciens fichiers sitemap supprimés', $output);
|
||||
$this->assertStringContainsString('Sitemap généré avec succès', $output);
|
||||
|
||||
$this->assertFileDoesNotExist($this->tempDir . '/public/seo/old.xml');
|
||||
}
|
||||
|
||||
private function removeDirectory($dir) {
|
||||
if (!is_dir($dir)) return;
|
||||
$files = array_diff(scandir($dir), array('.','..'));
|
||||
foreach ($files as $file) {
|
||||
(is_dir("$dir/$file")) ? $this->removeDirectory("$dir/$file") : unlink("$dir/$file");
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user