1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Grafizzi\Graph\Tests\AbstractCommandFilterTest: a component of the Grafizzi library. |
6
|
|
|
* |
7
|
|
|
* (c) 2016 Frédéric G. MARAND <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Grafizzi is free software: you can redistribute it and/or modify it under the |
10
|
|
|
* terms of the GNU Lesser General Public License as published by the Free |
11
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
12
|
|
|
* later version. |
13
|
|
|
* |
14
|
|
|
* Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY |
15
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
16
|
|
|
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
17
|
|
|
* details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
20
|
|
|
* along with Grafizzi, in the COPYING.LESSER.txt file. If not, see |
21
|
|
|
* <http://www.gnu.org/licenses/> |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Grafizzi\Graph\Tests; |
25
|
|
|
|
26
|
|
|
use Grafizzi\Graph\Filter\AbstractCommandFilter; |
27
|
|
|
|
28
|
|
|
require 'vendor/autoload.php'; |
29
|
|
|
|
30
|
|
|
class PseudoCommandFilter extends AbstractCommandFilter {} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class AbstractCommandFilterTest |
34
|
|
|
*/ |
35
|
|
|
class AbstractCommandFilterTest extends \PHPUnit_Framework_TestCase { |
36
|
|
|
|
37
|
|
|
public function testFilterArguments() { |
38
|
|
|
// echo is both a Linux, MacOS, and Windows command. |
39
|
|
|
PseudoCommandFilter::$commandName = 'echo'; |
40
|
|
|
$args = array('-' => 'n', 'foo' => '=bar'); |
41
|
|
|
$filter = new PseudoCommandFilter($args); |
42
|
|
|
$output_lines = $filter->filter(""); |
43
|
|
|
$output = implode("\n", $output_lines); |
44
|
|
|
$this->assertEquals("foo=bar\n", $output); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testUnavailableCommand() { |
48
|
|
|
// Since this is the name of this package, it is unlikely to exist. |
49
|
|
|
PseudoCommandFilter::$commandName = 'grafizzi'; |
50
|
|
|
$filter = new PseudoCommandFilter(); |
51
|
|
|
try { |
52
|
|
|
$filter->filter(""); |
53
|
|
|
$this->fail("Nonexistent command did not trigger an exception."); |
54
|
|
|
} |
55
|
|
|
catch (\ErrorException $e) { |
56
|
|
|
// 'Caught expected exception for nonexistent command. |
57
|
|
|
} |
58
|
|
|
catch (\Exception $e) { |
59
|
|
|
$this->fail('Caught unexpected exception for nonexistent command.'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|