MyTestCommand.php
1.41 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
<?php
namespace Bamarni\Composer\Bin\Tests\Fixtures;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Composer\Command\BaseCommand;
use Composer\Factory;
use Composer\IO\NullIO;
class MyTestCommand extends BaseCommand
{
public $data = array();
private $assert;
public function __construct(\PHPUnit_Framework_Assert $assert)
{
$this->assert = $assert;
parent::__construct('mytest');
$this->setDefinition(array(
new InputOption('myoption', null, InputOption::VALUE_NONE),
));
}
public function execute(InputInterface $input, OutputInterface $output)
{
// make sure the proxy command didn't instantiate Composer
$this->assert->assertNull($this->getComposer(false));
$this->assert->assertNull($this->getApplication()->getComposer(false));
// put a dummy composer.json to be able to create Composer
file_put_contents(getcwd().'/composer.json', '{}');
$factory = Factory::create(new NullIO());
$config = $factory->getConfig();
$this->data[] = array(
'bin-dir' => $config->get('bin-dir'),
'cwd' => getcwd(),
'vendor-dir' => $config->get('vendor-dir'),
);
$this->resetComposer();
$this->getApplication()->resetComposer();
}
}