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')); |
|
|
|
|
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
|
|
|
|
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: