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); |
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
|
|
|
|