Skip to content

Commit fb52c9c

Browse files
committed
more tests
1 parent 4196ef8 commit fb52c9c

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

src/Command/DiffCommand.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515

1616
class DiffCommand extends BaseCommand
1717
{
18+
/**
19+
* @var PackageDiff
20+
*/
21+
protected $packageDiff;
22+
23+
public function __construct(PackageDiff $packageDiff)
24+
{
25+
$this->packageDiff = $packageDiff;
26+
27+
parent::__construct();
28+
}
29+
1830
protected function configure()
1931
{
2032
$this->setName('diff')
@@ -32,15 +44,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
3244
$base = $input->getOption('base');
3345
$target = $input->getOption('target');
3446
$withPlatform = $input->getOption('with-platform');
35-
$diff = new PackageDiff();
3647

3748
if (!$input->getOption('no-prod')) {
38-
$operations = $diff->getPackageDiff($base, $target, false, $withPlatform);
49+
$operations = $this->packageDiff->getPackageDiff($base, $target, false, $withPlatform);
3950
$this->displayTable($operations, 'Prod Packages', $output);
4051
}
4152

4253
if (!$input->getOption('no-dev')) {
43-
$operations = $diff->getPackageDiff($base, $target, true, $withPlatform);
54+
$operations = $this->packageDiff->getPackageDiff($base, $target, true, $withPlatform);
4455
$this->displayTable($operations, 'Dev Packages', $output);
4556
}
4657

src/PackageDiff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private function getFileContents($path)
9999
}
100100

101101
$output = array();
102-
exec('git show '.escapeshellarg($path), $output, $exit);
102+
@exec('git show '.escapeshellarg($path), $output, $exit);
103103

104104
if (0 !== $exit) {
105105
throw new \RuntimeException(sprintf('Could not open file %s or find it in git as %s', $originalPath, $path));

src/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function activate(Composer $composer, IOInterface $io)
2323

2424
public function getCommands()
2525
{
26-
return array(new DiffCommand());
26+
return array(new DiffCommand(new PackageDiff()));
2727
}
2828

2929
public function getCapabilities()

tests/PackageDiffTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ public function testInvalidGitRef()
6464
{
6565
$diff = new PackageDiff();
6666
$this->prepareGit();
67-
$this->expectException('RuntimeException');
67+
if (method_exists($this, 'expectException')) {
68+
$this->expectException('RuntimeException');
69+
} else {
70+
$this->setExpectedException('RuntimeException');
71+
}
6872
$diff->getPackageDiff('invalid-ref', '');
6973
}
7074

tests/PluginTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace IonBazan\ComposerDiff\Tests;
44

55
use IonBazan\ComposerDiff\Command\DiffCommand;
6+
use IonBazan\ComposerDiff\PackageDiff;
67
use IonBazan\ComposerDiff\Plugin;
78
use PHPUnit\Framework\TestCase;
89

@@ -15,11 +16,12 @@ public function testPlugin()
1516

1617
$plugin = new Plugin();
1718
$plugin->activate($composer, $io);
19+
$command = new DiffCommand(new PackageDiff());
1820

1921
$this->assertSame(
2022
array('Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Plugin'),
2123
$plugin->getCapabilities()
2224
);
23-
$this->assertEquals(array(new DiffCommand()), $plugin->getCommands());
25+
$this->assertEquals(array($command), $plugin->getCommands());
2426
}
2527
}

0 commit comments

Comments
 (0)