|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\CronBundle\Tests\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Alpixel\Bundle\CronBundle\Command\CronRunCommand; |
|
6
|
|
|
use Alpixel\Bundle\CronBundle\Tests\Fixtures\CronTestCommand; |
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
8
|
|
|
use Symfony\Component\Console\Application; |
|
9
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
11
|
|
|
|
|
12
|
|
|
class CronRunCommandTest extends KernelTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $container; |
|
15
|
|
|
|
|
16
|
|
|
public function setUp() |
|
17
|
|
|
{ |
|
18
|
|
|
self::bootKernel(); |
|
19
|
|
|
$this->container = static::$kernel->getContainer(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testExecute() |
|
23
|
|
|
{ |
|
24
|
|
|
$commandTester = $this->createCommandTester($this->container); |
|
25
|
|
|
|
|
26
|
|
|
$exitCode = $commandTester->execute([ |
|
27
|
|
|
'command' => 'cron:run', |
|
28
|
|
|
], [ |
|
29
|
|
|
'decorated' => false, |
|
30
|
|
|
'interactive' => false, |
|
31
|
|
|
]); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertEquals(0, $exitCode, 'Returns 0 in case of success'); |
|
34
|
|
|
$this->assertRegExp('/Running 1 jobs/', $commandTester->getDisplay()); |
|
35
|
|
|
$this->assertRegExp('/Cron run completed in/', $commandTester->getDisplay()); |
|
36
|
|
|
$this->assertEquals('ok', file_get_contents(__DIR__.'/../Fixtures/app/cache/cron_result.log')); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
private function createCommandTester(ContainerInterface $container, Application $application = null) |
|
40
|
|
|
{ |
|
41
|
|
|
if (null === $application) { |
|
42
|
|
|
$application = new Application(); |
|
43
|
|
|
} |
|
44
|
|
|
$application->setAutoExit(false); |
|
45
|
|
|
|
|
46
|
|
|
$command = new CronRunCommand(); |
|
47
|
|
|
$command->setContainer($container); |
|
48
|
|
|
|
|
49
|
|
|
$testCommand = new CronTestCommand(); |
|
50
|
|
|
$testCommand->setContainer($container); |
|
51
|
|
|
|
|
52
|
|
|
$application->add($testCommand); |
|
53
|
|
|
$application->add($command); |
|
54
|
|
|
|
|
55
|
|
|
return new CommandTester($application->find('cron:run')); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|