Completed
Push — develop ( 80740b...61b5c3 )
by Mike
10:20
created

Transformer/Writer/CollectionTest.php (3 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @author    Mike van Riel <[email protected]>
8
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Transformer\Writer;
14
15
use Mockery as m;
16
use Mockery\MockInterface;
17
use phpDocumentor\Plugin\Core\Transformer\Writer\Xsl;
18
use phpDocumentor\Transformer\Router\Queue;
19
20
/**
21
 * Test class for phpDocumentor\Transformer\Writer\Collection
22
 */
23
class CollectionTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
24
{
25
    /** @var MockInterface|Queue */
26
    protected $routers;
27
28
    /** @var MockInterface|Xsl */
29
    protected $writer;
30
31
    /** @var Collection */
32
    protected $fixture;
33
34
    /**
35
     * Initializes the fixture and dependencies for this testcase.
36
     */
37
    protected function setUp()
38
    {
39
        $this->routers = m::mock('phpDocumentor\Transformer\Router\Queue');
40
        $this->writer = m::mock('phpDocumentor\Plugin\Core\Transformer\Writer\Xsl');
41
        $this->fixture = new Collection($this->routers);
42
    }
43
44
    /**
45
     * @covers phpDocumentor\Transformer\Writer\Collection::__construct
46
     */
47
    public function testIfDependenciesAreCorrectlyRegisteredOnInitialization()
48
    {
49
        $this->assertAttributeSame($this->routers, 'routers', $this->fixture);
50
    }
51
52
    /**
53
     * @expectedException \InvalidArgumentException
54
     * @covers phpDocumentor\Transformer\Writer\Collection::offsetSet
55
     */
56
    public function testOffsetSetWithWriterNotDescendingFromWriterAbstract()
57
    {
58
        $this->fixture->offsetSet('index', new \stdClass());
59
    }
60
61
    /**
62
     * @expectedException \InvalidArgumentException
63
     * @covers phpDocumentor\Transformer\Writer\Collection::offsetSet
64
     */
65
    public function testOffsetSetWithInvalidIndexName()
66
    {
67
        $this->fixture->offsetSet('i', $this->writer);
68
    }
69
70
    /**
71
     * @covers phpDocumentor\Transformer\Writer\Collection::offsetSet
72
     */
73
    public function testOffsetSetWriterReceivesRouterQueue()
74
    {
75
        $this->writer->shouldReceive('setRouters')->once()->with($this->routers);
0 ignored issues
show
The method shouldReceive does only exist in Mockery\MockInterface, but not in phpDocumentor\Plugin\Core\Transformer\Writer\Xsl.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
76
        $this->fixture->offsetSet('index', $this->writer);
77
78
        $this->assertTrue(true);
79
    }
80
81
    /**
82
     * @expectedException \InvalidArgumentException
83
     * @covers phpDocumentor\Transformer\Writer\Collection::offsetGet
84
     */
85
    public function testOffsetGetWithNonExistingIndex()
86
    {
87
        $this->fixture->offsetGet('nonExistingIndex');
88
    }
89
90
    /**
91
     * @covers phpDocumentor\Transformer\Writer\Collection::offsetGet
92
     */
93
    public function testOffsetGetWithExistingIndex()
94
    {
95
        $this->registerWriter();
96
97
        $this->assertSame($this->writer, $this->fixture->offsetGet('index'));
98
    }
99
100
    /**
101
     * @covers phpDocumentor\Transformer\Writer\Collection::checkRequirements
102
     */
103
    public function testCheckRequirements()
104
    {
105
        $this->registerWriter();
106
107
        $this->writer->shouldReceive('checkRequirements')->once();
0 ignored issues
show
The method shouldReceive does only exist in Mockery\MockInterface, but not in phpDocumentor\Plugin\Core\Transformer\Writer\Xsl.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
108
        $this->fixture->checkRequirements();
109
110
        $this->assertTrue(true);
111
    }
112
113
    /**
114
     * Registers a writer for tests that need a collection item
115
     */
116
    private function registerWriter()
117
    {
118
        $this->writer->shouldReceive('setRouters')->with($this->routers);
0 ignored issues
show
The method shouldReceive does only exist in Mockery\MockInterface, but not in phpDocumentor\Plugin\Core\Transformer\Writer\Xsl.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
119
        $this->fixture->offsetSet('index', $this->writer);
120
    }
121
}
122