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

CheckStyleTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testTransform() 0 42 1
1
<?php
2
3
/**
4
 * phpDocumentor
5
 *
6
 * PHP Version 5.3
7
 *
8
 * @author    Mike van Riel <[email protected]>
9
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
10
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
11
 * @link      http://phpdoc.org
12
 */
13
14
namespace phpDocumentor\Transformer\Writer;
15
16
use Mockery as m;
17
use org\bovigo\vfs\vfsStream;
18
use org\bovigo\vfs\vfsStreamDirectory;
19
20
/**
21
 * Test class for \phpDocumentor\Transformer\Writer\Checkstyle.
22
 *
23
 * @covers \phpDocumentor\Transformer\Writer\Checkstyle
24
 */
25
class CheckStyleTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
26
{
27
    /**
28
     * @var Checkstyle
29
     */
30
    protected $checkStyle;
31
32
    /** @var vfsStreamDirectory */
33
    private $fs;
34
35
    /**
36
     * Sets up the test suite
37
     */
38
    protected function setUp()
39
    {
40
        $this->checkStyle = new Checkstyle();
41
        $this->fs = vfsStream::setup('CheckStyleTest');
42
    }
43
44
    /**
45
     * @covers \phpDocumentor\Transformer\Writer\Checkstyle::transform
46
     */
47
    public function testTransform()
48
    {
49
        $transformer = m::mock('phpDocumentor\Transformer\Transformation');
50
        $transformer->shouldReceive('getTransformer->getTarget')->andReturn(vfsStream::url('CheckStyleTest'));
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

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...
51
        $transformer->shouldReceive('getArtifact')->andReturn('artifact.xml');
52
53
        $fileDescriptor = m::mock('phpDocumentor\Descriptor\FileDescriptor');
54
        $projectDescriptor = m::mock('phpDocumentor\Descriptor\ProjectDescriptor');
55
        $projectDescriptor->shouldReceive('getFiles->getAll')->andReturn([$fileDescriptor]);
56
57
        $error = m::mock('phpDocumentor\Descriptor\Validator\Error');
58
        $fileDescriptor->shouldReceive('getPath')->andReturn('/foo/bar/baz');
59
        $fileDescriptor->shouldReceive('getAllErrors->getAll')->andReturn([$error]);
60
61
        $error->shouldReceive('getLine')->andReturn(1234);
62
        $error->shouldReceive('getCode')->andReturn(5678);
63
        $error->shouldReceive('getSeverity')->andReturn('error');
64
        $error->shouldReceive('getContext')->andReturn('myContext');
65
66
        // Call the actual method
67
        $this->checkStyle->transform($projectDescriptor, $transformer);
68
69
        // Assert file exists
70
        $this->assertTrue($this->fs->hasChild('artifact.xml'));
71
72
        // Inspect XML
73
        $xml = <<<XML
74
<?xml version="1.0"?>
75
<checkstyle version="1.3.0">
76
  <file name="/foo/bar/baz">
77
    <error line="1234" severity="error" message="5678 myContext" source="phpDocumentor.file.5678"/>
78
  </file>
79
</checkstyle>
80
XML;
81
        $expectedXml = new \DOMDocument();
82
        $expectedXml->loadXML($xml);
83
84
        $actualXml = new \DOMDocument();
85
        $actualXml->load(vfsStream::url('CheckStyleTest/artifact.xml'));
86
87
        $this->assertEqualXMLStructure($expectedXml->firstChild, $actualXml->firstChild, true);
88
    }
89
}
90