BinCommandTest.php
3.49 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
<?php
namespace Bamarni\Composer\Bin\Tests;
use Composer\Console\Application;
use Bamarni\Composer\Bin\BinCommand;
use Bamarni\Composer\Bin\Tests\Fixtures\MyTestCommand;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\NullOutput;
class BinCommandTest extends \PHPUnit_Framework_TestCase
{
private $application;
private $myTestCommand;
private $rootDir;
protected function setUp()
{
$this->rootDir = sys_get_temp_dir().'/'.uniqid('composer_bin_plugin_tests_');
mkdir($this->rootDir);
chdir($this->rootDir);
file_put_contents($this->rootDir.'/composer.json', '{}');
$this->application = new Application();
$this->application->addCommands(array(
new BinCommand(),
$this->myTestCommand = new MyTestCommand($this),
));
}
public function tearDown()
{
putenv('COMPOSER_BIN_DIR');
$this->myTestCommand->data = array();
}
/**
* @dataProvider namespaceProvider
*/
public function testNamespaceCommand($input)
{
$input = new StringInput($input);
$output = new NullOutput();
$this->application->doRun($input, $output);
$this->assertCount(1, $this->myTestCommand->data);
$dataSet = array_shift($this->myTestCommand->data);
$this->assertEquals($dataSet['bin-dir'], $this->rootDir.'/vendor/bin');
$this->assertEquals($dataSet['cwd'], $this->rootDir.'/vendor-bin/mynamespace');
$this->assertEquals($dataSet['vendor-dir'], $this->rootDir.'/vendor-bin/mynamespace/vendor');
}
public static function namespaceProvider()
{
return array(
array('bin mynamespace mytest'),
array('bin mynamespace mytest --myoption'),
);
}
public function testAllNamespaceWithoutAnyNamespace()
{
$input = new StringInput('bin all mytest');
$output = new NullOutput();
$this->application->doRun($input, $output);
$this->assertEmpty($this->myTestCommand->data);
}
public function testAllNamespaceCommand()
{
$namespaces = array('mynamespace', 'yournamespace');
foreach ($namespaces as $ns) {
mkdir($this->rootDir.'/vendor-bin/'.$ns, 0777, true);
}
$input = new StringInput('bin all mytest');
$output = new NullOutput();
$this->application->doRun($input, $output);
$this->assertCount(count($namespaces), $this->myTestCommand->data);
foreach ($namespaces as $ns) {
$dataSet = array_shift($this->myTestCommand->data);
$this->assertEquals($dataSet['bin-dir'], $this->rootDir . '/vendor/bin');
$this->assertEquals($dataSet['cwd'], $this->rootDir . '/vendor-bin/'.$ns);
$this->assertEquals($dataSet['vendor-dir'], $this->rootDir . '/vendor-bin/'.$ns.'/vendor');
}
}
public function testBinDirFromLocalConfig()
{
$binDir = 'bin';
$composer = array(
'config' => array(
'bin-dir' => $binDir
)
);
file_put_contents($this->rootDir.'/composer.json', json_encode($composer));
$input = new StringInput('bin theirspace mytest');
$output = new NullOutput();
$this->application->doRun($input, $output);
$this->assertCount(1, $this->myTestCommand->data);
$dataSet = array_shift($this->myTestCommand->data);
$this->assertEquals($dataSet['bin-dir'], $this->rootDir.'/'.$binDir);
}
}