Skip to content

Commit 4196ef8

Browse files
committed
add prefer lowest
1 parent 6c6ccfa commit 4196ef8

File tree

7 files changed

+66
-27
lines changed

7 files changed

+66
-27
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ jobs:
88
fail-fast: false
99
matrix:
1010
php-versions:
11-
- '5.4'
12-
- '5.5'
13-
- '5.6'
14-
- '7.0'
15-
- '7.1'
16-
- '7.2'
17-
- '7.3'
11+
# - '5.4'
12+
# - '5.5'
13+
# - '5.6'
14+
# - '7.0'
15+
# - '7.1'
16+
# - '7.2'
17+
# - '7.3'
1818
- '7.4'
1919
include:
2020
- php-versions: '5.3'
21-
composer-flags: '--prefer-lowest'
21+
composer-flags: '--prefer-lowest'
2222
- php-versions: '8.0'
2323
composer-flags: '--ignore-platform-reqs'
2424
steps:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/.php_cs
55
/tests/fixtures/**/vendor/
66
/tests/test-git/
7+
/coverage/

src/Command/DiffCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
4949

5050
protected function displayTable(array $operations, $header, OutputInterface $output)
5151
{
52+
if (!\count($operations)) {
53+
return;
54+
}
55+
5256
$table = new MarkdownTable($output);
57+
$table->setHeaders(array($header, 'Base', 'Target'));
5358

5459
foreach ($operations as $operation) {
5560
$table->addRow($this->getTableRow($operation));
5661
}
5762

58-
$table->setHeaders(array($header, 'Base', 'Target'))->render();
63+
$table->render();
5964
$output->writeln('');
6065
}
6166

src/MarkdownTable.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace IonBazan\ComposerDiff;
44

5-
use Symfony\Component\Console\Helper\TableSeparator;
65
use Symfony\Component\Console\Output\OutputInterface;
76

87
class MarkdownTable
@@ -106,11 +105,7 @@ private function getColumnWidth($column)
106105
return $this->columnWidths[$column];
107106
}
108107

109-
foreach (array_merge($this->headers, $this->rows) as $row) {
110-
if ($row instanceof TableSeparator) {
111-
continue;
112-
}
113-
108+
foreach (array_merge(array($this->headers), $this->rows) as $row) {
114109
$lengths[] = strlen($row[$column]);
115110
}
116111

src/Plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public function activate(Composer $composer, IOInterface $io)
2323

2424
public function getCommands()
2525
{
26-
return array(new DiffCommand($this->composer));
26+
return array(new DiffCommand());
2727
}
2828

2929
public function getCapabilities()
3030
{
3131
return array(
32-
CommandProvider::class => static::class,
32+
'Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Plugin',
3333
);
3434
}
3535
}

tests/PackageDiffTest.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,21 @@ public function testSameBaseAndTarget()
5353
*/
5454
public function testGitUsage(array $expected, $dev, $withPlatform)
5555
{
56-
$gitDir = __DIR__.'/test-git';
5756
$diff = new PackageDiff();
58-
@mkdir($gitDir);
59-
chdir($gitDir);
60-
exec('git init');
61-
exec('git config user.name test');
62-
exec('git config user.email test@example.com');
63-
file_put_contents($gitDir.'/composer.lock', file_get_contents(__DIR__.'/fixtures/base/composer.lock'));
64-
exec('git add composer.lock && git commit -m "init"');
65-
file_put_contents($gitDir.'/composer.lock', file_get_contents(__DIR__.'/fixtures/target/composer.lock'));
66-
$operations = $diff->getPackageDiff('HEAD:composer.lock', 'composer.lock', $dev, $withPlatform);
57+
$this->prepareGit();
58+
$operations = $diff->getPackageDiff('HEAD', '', $dev, $withPlatform);
6759

6860
$this->assertSame($expected, array_map(array($this, 'operationToString'), $operations));
6961
}
7062

63+
public function testInvalidGitRef()
64+
{
65+
$diff = new PackageDiff();
66+
$this->prepareGit();
67+
$this->expectException('RuntimeException');
68+
$diff->getPackageDiff('invalid-ref', '');
69+
}
70+
7171
public function operationsProvider()
7272
{
7373
return array(
@@ -123,6 +123,19 @@ public function operationsProvider()
123123
);
124124
}
125125

126+
private function prepareGit()
127+
{
128+
$gitDir = __DIR__.'/test-git';
129+
@mkdir($gitDir);
130+
chdir($gitDir);
131+
exec('git init');
132+
exec('git config user.name test');
133+
exec('git config user.email test@example.com');
134+
file_put_contents($gitDir.'/composer.lock', file_get_contents(__DIR__.'/fixtures/base/composer.lock'));
135+
exec('git add composer.lock && git commit -m "init"');
136+
file_put_contents($gitDir.'/composer.lock', file_get_contents(__DIR__.'/fixtures/target/composer.lock'));
137+
}
138+
126139
private function operationToString(OperationInterface $operation)
127140
{
128141
if ($operation instanceof InstallOperation) {

tests/PluginTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace IonBazan\ComposerDiff\Tests;
4+
5+
use IonBazan\ComposerDiff\Command\DiffCommand;
6+
use IonBazan\ComposerDiff\Plugin;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class PluginTest extends TestCase
10+
{
11+
public function testPlugin()
12+
{
13+
$composer = $this->createMock('Composer\Composer');
14+
$io = $this->createMock('Composer\IO\IOInterface');
15+
16+
$plugin = new Plugin();
17+
$plugin->activate($composer, $io);
18+
19+
$this->assertSame(
20+
array('Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Plugin'),
21+
$plugin->getCapabilities()
22+
);
23+
$this->assertEquals(array(new DiffCommand()), $plugin->getCommands());
24+
}
25+
}

0 commit comments

Comments
 (0)