Completed
Push — 3.x ( 1cd1d0...b03505 )
by Grégoire
16:27 queued 03:11
created

testExecuteWithoutDoctrineService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Command;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\AdminBundle\Admin\Pool;
18
use Sonata\AdminBundle\Command\GenerateObjectAclCommand;
19
use Symfony\Component\Console\Application;
20
use Symfony\Component\Console\Tester\CommandTester;
21
use Symfony\Component\DependencyInjection\ContainerInterface;
22
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
23
24
/**
25
 * @author Javier Spagnoletti <[email protected]>
26
 */
27
class GenerateObjectAclCommandTest extends TestCase
28
{
29
    /**
30
     * @var ContainerInterface
31
     */
32
    private $container;
33
34
    protected function setUp(): void
35
    {
36
        parent::setUp();
37
38
        $this->container = $this->createMock(ContainerInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Symfo...tainerInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component...ion\ContainerInterface> of property $container.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39
40
        $this->container->expects($this->any())
41
            ->method('has')
42
            ->willReturnCallback(static function (string $id): bool {
43
                switch ($id) {
44
                    case 'doctrine':
45
                        return false;
46
                }
47
            });
48
    }
49
50
    public function testExecuteWithoutDoctrineService(): void
51
    {
52
        $generateObjectAclCommand = new GenerateObjectAclCommand(new Pool($this->container, '', ''), []);
53
54
        $application = new Application();
55
        $application->add($generateObjectAclCommand);
56
57
        $command = $application->find(GenerateObjectAclCommand::getDefaultName());
58
        $commandTester = new CommandTester($command);
59
60
        $this->assertFalse($this->container->has('doctrine'));
61
62
        $this->expectException(ServiceNotFoundException::class);
63
        $this->expectExceptionMessage(sprintf('The command "%s" has a dependency on a non-existent service "doctrine".', GenerateObjectAclCommand::getDefaultName()));
64
65
        $commandTester->execute(['command' => GenerateObjectAclCommand::getDefaultName()]);
66
    }
67
}
68