1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\ResourceBundle\Tests\Command; |
13
|
|
|
|
14
|
|
|
use Sylius\Bundle\ResourceBundle\Command\DebugResourceCommand; |
15
|
|
|
use Sylius\Component\Resource\Metadata\Metadata; |
16
|
|
|
use Sylius\Component\Resource\Metadata\RegistryInterface; |
17
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Daniel Leech <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class DebugResourceCommandTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var RegistryInterface |
26
|
|
|
*/ |
27
|
|
|
private $registry; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var CommandTester |
31
|
|
|
*/ |
32
|
|
|
private $tester; |
33
|
|
|
|
34
|
|
|
public function setUp() |
35
|
|
|
{ |
36
|
|
|
$this->registry = $this->prophesize(RegistryInterface::class); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$command = new DebugResourceCommand($this->registry->reveal()); |
39
|
|
|
$this->tester = new CommandTester($command); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @test |
44
|
|
|
*/ |
45
|
|
|
public function it_lists_all_resources_if_no_argument_is_given() |
46
|
|
|
{ |
47
|
|
|
$this->registry->getAll()->willReturn([$this->createMetadata('one'), $this->createMetadata('two')]); |
|
|
|
|
48
|
|
|
$this->tester->execute([]); |
49
|
|
|
$display = $this->tester->getDisplay(); |
50
|
|
|
|
51
|
|
|
$this->assertEquals(<<<'EOT' |
52
|
|
|
+------------+ |
53
|
|
|
| Alias | |
54
|
|
|
+------------+ |
55
|
|
|
| sylius.one | |
56
|
|
|
| sylius.two | |
57
|
|
|
+------------+ |
58
|
|
|
|
59
|
|
|
EOT |
60
|
|
|
, $display); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @test |
65
|
|
|
*/ |
66
|
|
|
public function it_displays_the_metadata_for_given_resource_alias() |
67
|
|
|
{ |
68
|
|
|
$this->registry->get('metadata.one')->willReturn($this->createMetadata('one')); |
|
|
|
|
69
|
|
|
$this->tester->execute([ |
70
|
|
|
'resource' => 'metadata.one', |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
$display = $this->tester->getDisplay(); |
74
|
|
|
|
75
|
|
|
$this->assertEquals(<<<'EOT' |
76
|
|
|
+------------------------------+-----------------+ |
77
|
|
|
| name | one | |
78
|
|
|
| application | sylius | |
79
|
|
|
| driver | doctrine/foobar | |
80
|
|
|
| classes.foo | bar | |
81
|
|
|
| classes.bar | foo | |
82
|
|
|
| whatever.something.elephants | camels | |
83
|
|
|
+------------------------------+-----------------+ |
84
|
|
|
|
85
|
|
|
EOT |
86
|
|
|
, $display); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $suffix |
91
|
|
|
* |
92
|
|
|
* @return Metadata |
93
|
|
|
*/ |
94
|
|
|
private function createMetadata($suffix) |
95
|
|
|
{ |
96
|
|
|
$metadata = Metadata::fromAliasAndConfiguration(sprintf('sylius.%s', $suffix), [ |
97
|
|
|
'driver' => 'doctrine/foobar', |
98
|
|
|
'classes' => [ |
99
|
|
|
'foo' => 'bar', |
100
|
|
|
'bar' => 'foo', |
101
|
|
|
], |
102
|
|
|
'whatever' => [ |
103
|
|
|
'something' => [ |
104
|
|
|
'elephants' => 'camels', |
105
|
|
|
], |
106
|
|
|
], |
107
|
|
|
]); |
108
|
|
|
|
109
|
|
|
return $metadata; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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..