-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathCronMonitorPassTest.php
More file actions
61 lines (47 loc) · 2.19 KB
/
Copy pathCronMonitorPassTest.php
File metadata and controls
61 lines (47 loc) · 2.19 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
<?php
declare(strict_types=1);
namespace Sentry\SentryBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase;
use Sentry\SentryBundle\Command\SentryTestCommand;
use Sentry\SentryBundle\DependencyInjection\Compiler\CronMonitorPass;
use Sentry\SentryBundle\EventListener\CronMonitorListener;
use Sentry\State\HubInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
class CronMonitorPassTest extends TestCase
{
public function testProcess(): void
{
$container = $this->createContainerBuilder(true);
$container->setDefinition(
SentryTestCommand::class,
(new Definition(SentryTestCommand::class))
->setPublic(false)
->addTag('console.command')
->addTag('sentry.monitor_command', ['slug' => 'test-command'])
);
$container->compile();
$insertedCronMonitorListenerArgument = $container->getDefinition(CronMonitorListener::class)->getArgument(1);
$this->assertIsArray($insertedCronMonitorListenerArgument);
$this->assertArrayHasKey(SentryTestCommand::class, $insertedCronMonitorListenerArgument);
$this->assertEquals('test-command', $insertedCronMonitorListenerArgument[SentryTestCommand::class]);
}
public function testProcessDoesNothingIfConditionsForEnablingCronIsFalse(): void
{
$container = $this->createContainerBuilder(false);
$container->compile();
$this->assertFalse($container->getDefinition(CronMonitorListener::class)->getArgument(1));
}
private function createContainerBuilder(bool $isCronActive): ContainerBuilder
{
$container = new ContainerBuilder();
$container->addCompilerPass(new CronMonitorPass());
$container->setParameter('sentry.cron.enabled', $isCronActive);
$cronMonitorListenerMock = $this->createMock(CronMonitorListener::class);
$container->setDefinition(CronMonitorListener::class, (new Definition(\get_class($cronMonitorListenerMock)))
->setPublic(true))
->setArgument(0, HubInterface::class)
->setArgument(1, false);
return $container;
}
}