Passed
Pull Request — master (#7494)
by Woody
16: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
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Tools\Console\Command;
6
7
use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand;
8
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
9
use Doctrine\Tests\OrmFunctionalTestCase;
10
use Symfony\Component\Console\Application;
11
use Symfony\Component\Console\Helper\HelperSet;
12
use Symfony\Component\Console\Tester\CommandTester;
13
14
class ClearCacheQueryCommandTest extends OrmFunctionalTestCase
15
{
16
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Tools\Console\Command\ClearCacheQueryCommandTest::$application with single line content, use one-line comment instead.
Loading history...
17
     * @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...
18
     */
19
    private $application;
20
21
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Tools\Console\Command\ClearCacheQueryCommandTest::$command with single line content, use one-line comment instead.
Loading history...
22
     * @var \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand
0 ignored issues
show
introduced by
Class \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand should not be referenced via a fully qualified name, but via a use statement.
Loading history...
23
     */
24
    private $command;
25
26
    protected function setUp(): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
27
    {
28
        parent::setUp();
29
30
        $this->command = new QueryCommand();
31
32
        $this->application = new Application();
33
        $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->em)]));
34
        $this->application->add($this->command);
35
    }
36
37
    public function dataInvalidCacheDrivers(): array
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
38
    {
39
        return [
40
            'apc' => ['Doctrine\Common\Cache\ApcCache', 'APC Cache'],
41
            'apcu' => ['Doctrine\Common\Cache\ApcuCache', 'APCu Cache'],
42
            'xcache' => ['Doctrine\Common\Cache\XcacheCache', 'XCache Cache'],
43
        ];
44
    }
45
46
    /**
47
     * @dataProvider dataInvalidCacheDrivers
48
     */
49
    public function testCannotClearCacheWithInvalidDriver($driver, $name): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
50
    {
51
        $this->em->getConfiguration()->setQueryCacheImpl(new $driver());
52
53
        $command = $this->application->find('orm:clear-cache:query');
54
        $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...
55
56
        $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...
57
        $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...
58
59
        $tester->execute(
60
            [
61
                'command' => $command->getName(),
62
            ],
63
            ['decorated' => false]
64
        );
65
    }
66
}
67