1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hgraca\Phorensic\Test\Miner\Code\PDepend; |
4
|
|
|
|
5
|
|
|
use Hgraca\Helper\InstanceHelper; |
6
|
|
|
use Hgraca\Phorensic\Miner\Code\PDepend\PDependAdapter; |
7
|
|
|
use Hgraca\Phorensic\SharedKernel\Port\FileSystem\FileSystemInterface; |
8
|
|
|
use Mockery; |
9
|
|
|
use Mockery\MockInterface; |
10
|
|
|
use PDepend\Engine; |
11
|
|
|
use PHPUnit_Framework_TestCase; |
12
|
|
|
|
13
|
|
|
final class PDependAdapterUnitTest extends PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
/** @var PDependAdapter */ |
16
|
|
|
private $adapter; |
17
|
|
|
|
18
|
|
|
/** @var MockInterface|FileSystemInterface */ |
19
|
|
|
private $fileSystem; |
20
|
|
|
|
21
|
|
|
/** @var MockInterface|Engine */ |
22
|
|
|
private $pdepend; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @before |
26
|
|
|
*/ |
27
|
|
|
public function setUpAdapter() |
28
|
|
|
{ |
29
|
|
|
$this->fileSystem = Mockery::mock(FileSystemInterface::class); |
30
|
|
|
$this->pdepend = Mockery::mock(Engine::class); |
31
|
|
|
$this->adapter = new PDependAdapter($this->pdepend, $this->fileSystem); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
* |
37
|
|
|
* @small |
38
|
|
|
*/ |
39
|
|
|
public function mine() |
40
|
|
|
{ |
41
|
|
|
$fileA = 'Y/Z/a.php'; |
42
|
|
|
$fileB = 'Y/b.php'; |
43
|
|
|
$fileC = 'Y/Z/c.php'; |
44
|
|
|
$fileD = 'Y/Z/d.php'; |
45
|
|
|
|
46
|
|
|
$this->fileSystem->shouldReceive('readFile')->once()->with('/X/' . $fileA)->andReturn('file that can be handled'); |
|
|
|
|
47
|
|
|
$this->fileSystem->shouldReceive('readFile')->once()->with('/X/' . $fileB)->andReturn('file that can NOT be handled class('); |
48
|
|
|
$this->fileSystem->shouldReceive('readFile')->once()->with('/X/' . $fileC)->andReturn('file that can be handled'); |
49
|
|
|
$this->fileSystem->shouldReceive('readFile')->once()->with('/X/' . $fileD)->andReturn('file that can be handled'); |
50
|
|
|
|
51
|
|
|
$this->pdepend->shouldReceive('addFile')->once()->with('/X/' . $fileA); |
|
|
|
|
52
|
|
|
$this->pdepend->shouldNotReceive('addFile')->with('/X/' . $fileB); |
|
|
|
|
53
|
|
|
$this->pdepend->shouldReceive('addFile')->once()->with('/X/' . $fileC); |
54
|
|
|
$this->pdepend->shouldReceive('addFile')->once()->with('/X/' . $fileD); |
55
|
|
|
|
56
|
|
|
$this->pdepend->shouldReceive('addReportGenerator')->once()->with($this->adapter); |
57
|
|
|
$adapter = $this->adapter; |
58
|
|
|
$expectedMetrics = [ |
59
|
|
|
$fileA => ['metricA' => 1, 'metricB' => 2], |
60
|
|
|
$fileC => ['metricA' => 3, 'metricB' => 4], |
61
|
|
|
$fileD => ['metricA' => 5, 'metricB' => 6], |
62
|
|
|
]; |
63
|
|
|
$this->pdepend->shouldReceive('analyze')->once()->andReturnUsing( |
64
|
|
|
function() use ($adapter, $expectedMetrics) { |
65
|
|
|
InstanceHelper::setProtectedProperty($adapter, 'sourceFileMetricsList', $expectedMetrics); |
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
$actualMetrics = $this->adapter->mine( |
69
|
|
|
[ |
70
|
|
|
$fileA, |
71
|
|
|
$fileB, |
72
|
|
|
$fileC, |
73
|
|
|
$fileD, |
74
|
|
|
], |
75
|
|
|
'/X' |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
self::assertEquals($expectedMetrics, $actualMetrics); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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: