Failed Conditions
Pull Request — master (#7494)
by Woody
06:31
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
0 ignored issues
show
introduced by
Missing declare(strict_types = 1).
Loading history...
2
3
namespace Doctrine\Tests\ORM\Tools\Console\Command;
4
5
use Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand;
6
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
7
use Doctrine\Tests\OrmFunctionalTestCase;
8
use Symfony\Component\Console\Application;
9
use Symfony\Component\Console\Helper\HelperSet;
10
use Symfony\Component\Console\Tester\CommandTester;
11
12
class ClearCacheResultCommandTest extends OrmFunctionalTestCase
13
{
14
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Tools\Console\Command\ClearCacheResultCommandTest::$application with single line content, use one-line comment instead.
Loading history...
15
     * @var \Symfony\Component\Console\Application
0 ignored issues
show
introduced by
Class \Symfony\Component\Console\Application should not be referenced via a fully qualified name, but via a use statement.
Loading history...
16
     */
17
    private $application;
18
19
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Tools\Console\Command\ClearCacheResultCommandTest::$command with single line content, use one-line comment instead.
Loading history...
20
     * @var \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand
0 ignored issues
show
introduced by
Class \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand should not be referenced via a fully qualified name, but via a use statement.
Loading history...
21
     */
22
    private $command;
23
24
    protected function setUp()
25
    {
26
        parent::setUp();
27
28
        $this->command = new ResultCommand();
29
30
        $this->application = new Application();
31
        $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Tools...rCacheResultCommandTest. Did you maybe forget to declare it?
Loading history...
32
        $this->application->add($this->command);
33
    }
34
35
    public function dataInvalidCacheDrivers()
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
    /**
45
     * @dataProvider dataInvalidCacheDrivers
46
     */
47
    public function testCannotClearCacheWithInvalidDriver($driver, $name)
48
    {
49
        $this->_em->getConfiguration()->setResultCacheImpl(new $driver());
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Tools...rCacheResultCommandTest. Did you maybe forget to declare it?
Loading history...
50
51
        $command = $this->application->find('orm:clear-cache:result');
52
        $tester = new CommandTester($command);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
53
54
        $this->expectException(\LogicException::class);
0 ignored issues
show
introduced by
Class \LogicException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
55
        $this->expectExceptionMessage("Cannot clear $name from Console");
0 ignored issues
show
Coding Style Best Practice introduced by
Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
56
57
        $tester->execute(
58
            [
59
                'command' => $command->getName(),
60
            ],
61
            ['decorated' => false]
62
        );
63
    }
64
}
65