-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleanupCommandTest.php
More file actions
81 lines (66 loc) · 2.27 KB
/
Copy pathCleanupCommandTest.php
File metadata and controls
81 lines (66 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace App\Tests\Command\Validations;
use App\DataFixtures\ValidationsFixtures;
use App\Entity\Validation;
use App\Tests\WebTestCase;
use Doctrine\ORM\EntityManagerInterface;
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Filesystem;
/**
* Tests for ProcessOneCommand class.
*/
class CleanupCommandTest extends WebTestCase
{
/**
* @var AbstractDatabaseTool
*/
private $databaseTool;
/**
* @var EntityManagerInterface
*/
private $em;
public function setUp(): void
{
parent::setUp();
$this->databaseTool = static::getContainer()->get(DatabaseToolCollection::class)->get();
$this->databaseTool->loadFixtures([
ValidationsFixtures::class,
]);
$this->em = static::getContainer()->get('doctrine')->getManager();
}
public function tearDown(): void
{
parent::tearDown();
$fs = new Filesystem();
$fs->remove($this->getValidationsStorage()->getPath());
$this->em->getConnection()->close();
}
/**
* Testing execution of the command.
*/
public function testCleanupOneSecond()
{
static::ensureKernelShutdown();
// wait for 2 seconds
sleep(2);
// archive all older than 1 second
$kernel = static::createKernel();
$application = new Application($kernel);
$command = $application->find('ign-validator:validations:cleanup');
$commandTester = new CommandTester($command);
$statusCode = $commandTester->execute([
'--max-age' => 'PT1S',
]);
$this->assertEquals(0, $statusCode);
/** @var array<Validation> $validations */
$validations = $this->em->getRepository(Validation::class)->findAll();
foreach ($validations as $validation) {
$this->assertEquals(Validation::STATUS_ARCHIVED, $validation->getStatus());
$validationDirectory = $this->getValidationsStorage()->getDirectory($validation);
$this->assertFalse(file_exists($validationDirectory));
}
}
}