These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Maker; |
||
15 | |||
16 | use PHPUnit\Framework\TestCase; |
||
17 | use Prophecy\Argument; |
||
18 | use Sonata\AdminBundle\Maker\AdminMaker; |
||
19 | use Sonata\AdminBundle\Model\ModelManagerInterface; |
||
20 | use Symfony\Bundle\MakerBundle\ConsoleStyle; |
||
21 | use Symfony\Bundle\MakerBundle\FileManager; |
||
22 | use Symfony\Bundle\MakerBundle\Generator; |
||
23 | use Symfony\Component\Console\Input\ArrayInput; |
||
24 | use Symfony\Component\Console\Input\InputArgument; |
||
25 | use Symfony\Component\Console\Input\InputDefinition; |
||
26 | use Symfony\Component\Console\Input\InputInterface; |
||
27 | use Symfony\Component\Console\Input\InputOption; |
||
28 | use Symfony\Component\Console\Output\OutputInterface; |
||
29 | use Symfony\Component\Console\Output\StreamOutput; |
||
30 | use Symfony\Component\Filesystem\Filesystem; |
||
31 | |||
32 | /** |
||
33 | * @author Gaurav Singh Faujdar <[email protected]> |
||
34 | */ |
||
35 | class AdminMakerTest extends TestCase |
||
36 | { |
||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $projectDirectory; |
||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | private $modelManagers = []; |
||
45 | /** |
||
46 | * @var InputInterface |
||
47 | */ |
||
48 | private $input; |
||
49 | /** |
||
50 | * @var OutputInterface |
||
51 | */ |
||
52 | private $output; |
||
0 ignored issues
–
show
Comprehensibility
introduced
by
Loading history...
|
|||
53 | /** |
||
54 | * @var ConsoleStyle |
||
55 | */ |
||
56 | private $io; |
||
57 | /** |
||
58 | * @var Generator |
||
59 | */ |
||
60 | private $generator; |
||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | private $servicesFile; |
||
65 | |||
66 | protected function setup(): void |
||
67 | { |
||
68 | if (!class_exists('Symfony\Component\Console\CommandLoader\CommandLoaderInterface')) { |
||
69 | $this->markTestSkipped('Test only available for SF 3.4'); |
||
70 | } |
||
71 | |||
72 | $managerOrmProxy = $this->prophesize(ModelManagerInterface::class); |
||
73 | $managerOrmProxy->getExportFields(Argument::exact('Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Foo')) |
||
74 | ->willReturn(['bar', 'baz']); |
||
75 | |||
76 | $this->modelManagers = ['sonata.admin.manager.orm' => $managerOrmProxy->reveal()]; |
||
77 | $this->servicesFile = sprintf('%s.yml', lcg_value()); |
||
78 | $this->projectDirectory = sys_get_temp_dir(); |
||
79 | } |
||
80 | |||
81 | protected function tearDown(): void |
||
82 | { |
||
83 | @unlink($this->projectDirectory.'/config/'.$this->servicesFile); |
||
84 | } |
||
85 | |||
86 | public function testExecute(): void |
||
87 | { |
||
88 | $maker = new AdminMaker($this->projectDirectory, $this->modelManagers); |
||
89 | |||
90 | $in = [ |
||
91 | 'model' => \Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Foo::class, |
||
92 | '--admin' => 'FooAdmin', |
||
93 | '--controller' => 'FooAdminController', |
||
94 | '--services' => $this->servicesFile, |
||
95 | '--id' => 'acme_demo_admin.admin.foo', |
||
96 | ]; |
||
97 | |||
98 | $definition = new InputDefinition([ |
||
99 | new InputArgument('model', InputArgument::REQUIRED), |
||
100 | new InputOption('admin', 'a', InputOption::VALUE_REQUIRED), |
||
101 | new InputOption('controller', 'c', InputOption::VALUE_REQUIRED), |
||
102 | new InputOption('manager', 'm', InputOption::VALUE_REQUIRED), |
||
103 | new InputOption('services', 'y', InputOption::VALUE_REQUIRED), |
||
104 | new InputOption('id', 'i', InputOption::VALUE_REQUIRED), |
||
105 | ]); |
||
106 | |||
107 | $this->input = new ArrayInput($in, $definition); |
||
108 | |||
109 | $this->output = new StreamOutput(fopen('php://memory', 'w', false)); |
||
110 | |||
111 | $this->io = new ConsoleStyle($this->input, $this->output); |
||
112 | $fileManager = new FileManager(new Filesystem(), '.'); |
||
113 | $fileManager->setIO($this->io); |
||
114 | $this->generator = new Generator($fileManager, 'Sonata\AdminBundle\Tests'); |
||
115 | |||
116 | $maker->generate($this->input, $this->io, $this->generator); |
||
117 | } |
||
118 | } |
||
119 |