Completed
Push — master ( 3cef55...3e0b70 )
by Marco
34s queued 19s
created

dataInvalidCacheDrivers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Tools\Console\Command;
6
7
use Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand;
8
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
9
use Doctrine\Tests\OrmFunctionalTestCase;
10
use LogicException;
11
use Symfony\Component\Console\Application;
12
use Symfony\Component\Console\Helper\HelperSet;
13
use Symfony\Component\Console\Tester\CommandTester;
14
use function sprintf;
15
16
class ClearCacheMetadataCommandTest extends OrmFunctionalTestCase
17
{
18
    /** @var Application */
19
    private $application;
20
21
    /** @var MetadataCommand */
22
    private $command;
23
24
    protected function setUp() : void
25
    {
26
        parent::setUp();
27
28
        $this->command = new MetadataCommand();
29
30
        $this->application = new Application();
31
        $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->em)]));
32
        $this->application->add($this->command);
33
    }
34
35
    public function dataInvalidCacheDrivers() : array
36
    {
37
        return [
38
            'apc' => ['Doctrine\Common\Cache\ApcCache', 'APC Cache'],
39
            'apcu' => ['Doctrine\Common\Cache\ApcuCache', 'APCu Cache'],
40
            'xcache' => ['Doctrine\Common\Cache\XcacheCache', 'XCache Cache'],
41
        ];
42
    }
43
44
    /** @dataProvider dataInvalidCacheDrivers */
45
    public function testCannotClearCacheWithInvalidDriver($driver, $name) : void
46
    {
47
        $this->em->getConfiguration()->setMetadataCacheImpl(new $driver());
48
49
        $command = $this->application->find('orm:clear-cache:metadata');
50
51
        $tester = new CommandTester($command);
52
53
        $this->expectException(LogicException::class);
54
        $this->expectExceptionMessage(sprintf('Cannot clear %s from Console', $name));
55
56
        $tester->execute(
57
            [
58
                'command' => $command->getName(),
59
            ],
60
            ['decorated' => false]
61
        );
62
    }
63
}
64