forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpUnitTest.php
More file actions
118 lines (94 loc) · 3.38 KB
/
Copy pathPhpUnitTest.php
File metadata and controls
118 lines (94 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace Tests\PHPCensor\Plugin;
/**
* Unit test for the PHPUnit plugin.
*
* @author Pablo Tejada <pablo@ptejada.com>
*/
class PhpUnitTest extends \PHPUnit\Framework\TestCase
{
public function testSingleConfigFile()
{
$options = [
'config' => ROOT_DIR . 'phpunit.xml'
];
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfig'])->getMock();
$mockPlugin->expects($this->once())->method('runConfig')->with(null, ROOT_DIR . 'phpunit.xml');
$mockPlugin->execute();
}
public function testMultiConfigFile()
{
$options = [
'config' => [
ROOT_DIR . 'phpunit1.xml',
ROOT_DIR . 'phpunit2.xml',
]
];
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfig'])->getMock();
$mockPlugin->expects($this->exactly(2))->method('runConfig')->withConsecutive(
[null, ROOT_DIR . 'phpunit1.xml'],
[null, ROOT_DIR . 'phpunit2.xml']
);
$mockPlugin->execute();
}
/**
* @param array $options
*
* @return \PHPUnit_Framework_MockObject_MockBuilder
*/
protected function getPluginBuilder($options = [])
{
$loggerMock = $this->getMockBuilder('\Monolog\Logger')
->setConstructorArgs(['Test'])
->setMethods(['addRecord'])
->getMock();
$mockBuild = $this->getMockBuilder('\PHPCensor\Model\Build')->getMock();
$mockBuilder = $this->getMockBuilder('\PHPCensor\Builder')
->setConstructorArgs([$mockBuild, $loggerMock])
->setMethods(['executeCommand'])->getMock();
return $this->getMockBuilder('PHPCensor\Plugin\PhpUnit')->setConstructorArgs(
[$mockBuilder, $mockBuild, $options]
);
}
public function testSingleDir()
{
$options = [
'directory' => '/test/directory/one'
];
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfig'])->getMock();
$mockPlugin->expects($this->once())->method('runConfig')->with('/test/directory/one', null);
$mockPlugin->execute();
}
public function testMultiDir()
{
$options = [
'directory' => [
'/test/directory/one',
'/test/directory/two',
]
];
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfig'])->getMock();
$mockPlugin->expects($this->exactly(2))->method('runConfig')->withConsecutive(
['/test/directory/one'], ['/test/directory/two']
);
$mockPlugin->execute();
}
public function testProcessResultsFromConfig()
{
$options = [
'config' => ROOT_DIR . 'phpunit.xml'
];
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['processResults'])->getMock();
$mockPlugin->expects($this->once())->method('processResults')->with($this->isType('string'));
$mockPlugin->execute();
}
public function testProcessResultsFromDir()
{
$options = [
'directory' => ROOT_DIR . 'Tests'
];
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['processResults'])->getMock();
$mockPlugin->expects($this->once())->method('processResults')->with($this->isType('string'));
$mockPlugin->execute();
}
}