-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathManager.run.phpt
141 lines (116 loc) · 4.16 KB
/
Manager.run.phpt
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @testCase
*/
require __DIR__ . '/../vendor/autoload.php';
Tester\Environment::setup();
use JakubOnderka\PhpParallelLint\Manager;
use JakubOnderka\PhpParallelLint\NullWriter;
use JakubOnderka\PhpParallelLint\Settings;
use JakubOnderka\PhpParallelLint\TextOutput;
use Tester\Assert;
class ManagerRunTest extends Tester\TestCase
{
public function testBadPath()
{
$settings = $this->prepareSettings();
$settings->paths = array('path/for-not-found/');
$manager = $this->getManager($settings);
Assert::exception(function () use ($manager, $settings) {
$manager->run($settings);
}, 'JakubOnderka\PhpParallelLint\NotExistsPathException');
}
public function testFilesNotFound()
{
$settings = $this->prepareSettings();
$settings->paths = array('examples/example-01/');
$manager = $this->getManager($settings);
Assert::exception(function () use ($manager, $settings) {
$manager->run($settings);
}, 'JakubOnderka\PhpParallelLint\Exception', 'No file found to check.');
}
public function testSuccess()
{
$settings = $this->prepareSettings();
$settings->paths = array('examples/example-02/');
$manager = $this->getManager($settings);
$result = $manager->run($settings);
Assert::false($result->hasError());
}
public function testError()
{
$settings = $this->prepareSettings();
$settings->paths = array('examples/example-03/');
$manager = $this->getManager($settings);
$result = $manager->run($settings);
Assert::true($result->hasError());
}
public function testExcludeRelativeSubdirectory()
{
$settings = $this->prepareSettings();
$settings->paths = array('examples/example-04/');
$manager = $this->getManager($settings);
$result = $manager->run($settings);
Assert::true($result->hasError());
$settings->excluded = array('examples/example-04/dir1/dir2');
$manager = $this->getManager($settings);
$result = $manager->run($settings);
Assert::false($result->hasError());
}
public function testExcludeAbsoluteSubdirectory()
{
$settings = $this->prepareSettings();
$cwd = getcwd();
$settings->paths = array($cwd . '/examples/example-04/');
$settings->excluded = array();
$manager = $this->getManager($settings);
$result = $manager->run($settings);
Assert::true($result->hasError());
$settings->excluded = array($cwd . '/examples/example-04/dir1/dir2');
$manager = $this->getManager($settings);
$result = $manager->run($settings);
Assert::false($result->hasError());
}
/**
* Note: the `example.php-dist` file contains a parse error.
* With multi-part extensions being escaped before being used in the RegexIterator,
* this file will not be included in the scan and the test will pass.
*/
public function testMultiPartExtensions()
{
$settings = $this->prepareSettings();
$settings->paths = array('examples/example-06/');
$settings->extensions = array('php', 'php.dist');
$manager = $this->getManager($settings);
$result = $manager->run($settings);
Assert::false($result->hasError());
}
/**
* @param Settings $settings
* @return Manager
*/
private function getManager(Settings $settings)
{
$manager = new Manager($settings);
$manager->setOutput(new TextOutput(new NullWriter()));
return $manager;
}
/**
* @return JakubOnderka\PhpParallelLint\Settings
*/
private function prepareSettings()
{
$settings = new Settings();
$settings->phpExecutable = 'php';
$settings->shortTag = false;
$settings->aspTags = false;
$settings->parallelJobs = 10;
$settings->extensions = array('php', 'phtml', 'php3', 'php4', 'php5');
$settings->paths = array('FOR-SET');
$settings->excluded = array();
$settings->colors = false;
return $settings;
}
}
$testCase = new ManagerRunTest;
$testCase->run();