Completed
Push — snake-case-tests ( 55729f )
by Kamil
87:29 queued 51:35
created

DebugResourceCommandTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 90
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A createMetadata() 0 17 1
A it_lists_all_resources_if_no_argument_is_given() 0 17 1
A it_displays_the_metadata_for_given_resource_alias() 0 22 1
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);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(\Syliu...gistryInterface::class) of type object<Prophecy\Prophecy\ObjectProphecy> is incompatible with the declared type object<Sylius\Component\...data\RegistryInterface> of property $registry.

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...
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')]);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->registry->getAll() (of type array<integer,object<Syl...ata\MetadataInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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'));
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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