Skip to content

Commit 7f58bff

Browse files
committed
bug #4262 FixCommand - fix help (keradus)
This PR was squashed before being merged into the 2.12 branch (closes #4262). Discussion ---------- FixCommand - fix help ![screenshot from 2019-01-14 09-28-43](https://user-images.githubusercontent.com/2716794/51103387-d2e85500-17e2-11e9-958f-104928106800.png) Commits ------- 612ca78 FixCommand - fix help
2 parents 2693fb4 + 612ca78 commit 7f58bff

File tree

8 files changed

+161
-24
lines changed

8 files changed

+161
-24
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ tests/Test/AbstractTransformerTestCase.php export-ignore
1919
benchmark.sh export-ignore
2020
box.json export-ignore
2121
check_trailing_spaces.sh export-ignore
22-
dev-tools/ export-ignore
2322
phpmd.xml export-ignore
2423
phpunit.xml.dist export-ignore
2524

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
php: 7.1
135135
install: ./dev-tools/build.sh
136136
script:
137-
- PHP_CS_FIXER_TEST_ALLOW_SKIPPING_PHAR_TESTS=0 vendor/bin/phpunit tests/Smoke/
137+
- PHP_CS_FIXER_TEST_ALLOW_SKIPPING_SMOKE_TESTS=0 vendor/bin/phpunit tests/Smoke/
138138

139139
before_deploy:
140140
# ensure that deployment is happening only if tag matches version of PHP CS Fixer

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<ini name="zend.enable_gc" value="0"/>
5555
<ini name="memory_limit" value="1G"/>
5656
<env name="SKIP_LINT_TEST_CASES" value="0"/>
57-
<env name="PHP_CS_FIXER_TEST_ALLOW_SKIPPING_PHAR_TESTS" value="1"/>
57+
<env name="PHP_CS_FIXER_TEST_ALLOW_SKIPPING_SMOKE_TESTS" value="1"/>
5858
<env name="PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER" value="0"/>
5959
</php>
6060
</phpunit>

tests/Smoke/AbstractSmokeTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP CS Fixer.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
8+
*
9+
* This source file is subject to the MIT license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace PhpCsFixer\Tests\Smoke;
14+
15+
use PhpCsFixer\Tests\TestCase;
16+
17+
/**
18+
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
19+
*
20+
* @internal
21+
*
22+
* @requires OS Linux|Darwin
23+
* @coversNothing
24+
* @group covers-nothing
25+
* @large
26+
*/
27+
abstract class AbstractSmokeTest extends TestCase
28+
{
29+
protected static function markTestSkippedOrFail($message)
30+
{
31+
if (getenv('PHP_CS_FIXER_TEST_ALLOW_SKIPPING_SMOKE_TESTS')) {
32+
self::markTestSkipped($message);
33+
}
34+
35+
self::fail($message.' Failing as test is obligatory because of `PHP_CS_FIXER_TEST_ALLOW_SKIPPING_SMOKE_TESTS=0`.');
36+
}
37+
}

tests/Smoke/CiIntegrationTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use Keradus\CliExecutor\CommandExecutor;
1616
use Keradus\CliExecutor\ScriptExecutor;
17-
use PhpCsFixer\Tests\TestCase;
1817

1918
/**
2019
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
@@ -26,7 +25,7 @@
2625
* @group covers-nothing
2726
* @large
2827
*/
29-
final class CiIntegrationTest extends TestCase
28+
final class CiIntegrationTest extends AbstractSmokeTest
3029
{
3130
public static $fixtureDir;
3231

@@ -36,6 +35,18 @@ public static function setUpBeforeClass()
3635

3736
self::$fixtureDir = __DIR__.'/../Fixtures/ci-integration';
3837

38+
try {
39+
CommandExecutor::create('composer --version', __DIR__)->getResult();
40+
} catch (\RuntimeException $e) {
41+
self::markTestSkippedOrFail('Missing `composer` env script. Details:'."\n".$e->getMessage());
42+
}
43+
44+
try {
45+
CommandExecutor::create('composer check', __DIR__.'/../..')->getResult();
46+
} catch (\RuntimeException $e) {
47+
self::markTestSkippedOrFail('Composer check failed. Details:'."\n".$e->getMessage());
48+
}
49+
3950
try {
4051
self::executeScript([
4152
'rm -rf .git',
@@ -46,7 +57,7 @@ public static function setUpBeforeClass()
4657
'git commit -m "init" -q',
4758
]);
4859
} catch (\RuntimeException $e) {
49-
self::markTestSkipped($e->getMessage());
60+
self::markTestSkippedOrFail($e->getMessage());
5061
}
5162
}
5263

tests/Smoke/InstallViaComposerTest.php

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
namespace PhpCsFixer\Tests\Smoke;
1414

1515
use Keradus\CliExecutor\CommandExecutor;
16+
use PhpCsFixer\Console\Application;
1617
use PhpCsFixer\Utils;
17-
use PHPUnit\Framework\TestCase;
1818
use Symfony\Component\Filesystem\Filesystem;
1919

2020
/**
@@ -26,24 +26,43 @@
2626
* @group covers-nothing
2727
* @large
2828
*/
29-
final class InstallViaComposerTest extends TestCase
29+
final class InstallViaComposerTest extends AbstractSmokeTest
3030
{
31+
private $stepsToVerifyInstallation = [
32+
// Confirm we can install.
33+
'composer install -q',
34+
// Ensure that autoloader works.
35+
'composer dump-autoload --optimize',
36+
'php vendor/autoload.php',
37+
// Ensure basic commands work.
38+
'vendor/bin/php-cs-fixer --version',
39+
'vendor/bin/php-cs-fixer fix --help',
40+
];
41+
3142
public static function setUpBeforeClass()
3243
{
44+
parent::setUpBeforeClass();
45+
3346
try {
3447
CommandExecutor::create('php --version', __DIR__)->getResult();
3548
} catch (\RuntimeException $e) {
36-
self::markTestSkipped('Missing `php` env script. Details:'."\n".$e->getMessage());
49+
self::markTestSkippedOrFail('Missing `php` env script. Details:'."\n".$e->getMessage());
3750
}
3851

3952
try {
4053
CommandExecutor::create('composer --version', __DIR__)->getResult();
4154
} catch (\RuntimeException $e) {
42-
self::markTestSkipped('Missing `composer` env script. Details:'."\n".$e->getMessage());
55+
self::markTestSkippedOrFail('Missing `composer` env script. Details:'."\n".$e->getMessage());
56+
}
57+
58+
try {
59+
CommandExecutor::create('composer check', __DIR__.'/../..')->getResult();
60+
} catch (\RuntimeException $e) {
61+
self::markTestSkippedOrFail('Composer check failed. Details:'."\n".$e->getMessage());
4362
}
4463
}
4564

46-
public function testInstallationIsPossible()
65+
public function testInstallationViaPathIsPossible()
4766
{
4867
$fs = new Filesystem();
4968

@@ -68,11 +87,80 @@ public function testInstallationIsPossible()
6887
json_encode($initialComposerFileState, Utils::calculateBitmask(['JSON_PRETTY_PRINT']))
6988
);
7089

71-
$this->assertSame(0, CommandExecutor::create('composer install -q', $tmpPath)->getResult()->getCode());
72-
$this->assertSame(0, CommandExecutor::create('composer dump-autoload --optimize', $tmpPath)->getResult()->getCode());
73-
$this->assertSame(0, CommandExecutor::create('php vendor/autoload.php', $tmpPath)->getResult()->getCode());
74-
$this->assertSame(0, CommandExecutor::create('vendor/bin/php-cs-fixer --version', $tmpPath)->getResult()->getCode());
90+
self::assertCommandsWork($this->stepsToVerifyInstallation, $tmpPath);
7591

7692
$fs->remove($tmpPath);
7793
}
94+
95+
// test that respects `export-ignore` from `.gitattributes` file
96+
public function testInstallationViaArtifactIsPossible()
97+
{
98+
// Composer Artifact Repository requires `zip` extension
99+
if (!\extension_loaded('zip')) {
100+
$this->markTestSkippedOrFail('No zip extension available.');
101+
}
102+
103+
$fs = new Filesystem();
104+
105+
$tmpPath = tempnam(sys_get_temp_dir(), 'cs_fixer_tmp_');
106+
unlink($tmpPath);
107+
$fs->mkdir($tmpPath);
108+
109+
$tmpArtifactPath = tempnam(sys_get_temp_dir(), 'cs_fixer_tmp_');
110+
unlink($tmpArtifactPath);
111+
$fs->mkdir($tmpArtifactPath);
112+
113+
$fakeVersion = preg_replace('/\\-.+/', '', Application::VERSION, 1).'-alpha987654321';
114+
115+
$initialComposerFileState = [
116+
'repositories' => [
117+
[
118+
'type' => 'artifact',
119+
'url' => $tmpArtifactPath,
120+
],
121+
],
122+
'require' => [
123+
'friendsofphp/php-cs-fixer' => $fakeVersion,
124+
],
125+
];
126+
127+
file_put_contents(
128+
$tmpPath.'/composer.json',
129+
json_encode($initialComposerFileState, Utils::calculateBitmask(['JSON_PRETTY_PRINT']))
130+
);
131+
132+
$cwd = __DIR__.'/../..';
133+
134+
$stepsToInitializeArtifact = [
135+
// Clone current version of project to new location, as we gonna modify it.
136+
// Warning! Only already committed changes will be cloned!
137+
"git clone . ${tmpArtifactPath}",
138+
];
139+
$stepsToPrepareArtifact = [
140+
// Configure git user for new repo to not use global git user.
141+
// We need this, as global git user may not be set!
142+
'git config user.name test && git config user.email test',
143+
// Adjust cloned project to expose version in `composer.json`.
144+
// Without that, it would not be possible to use it as Composer Artifact.
145+
"composer config version ${fakeVersion} && git add . && git commit -m 'provide version'",
146+
// Create repo archive that will serve as Composer Artifact.
147+
'git archive HEAD --format=zip -o archive.zip',
148+
// Drop the repo, keep the archive
149+
'git rm -r . && rm -rf .git',
150+
];
151+
152+
self::assertCommandsWork($stepsToInitializeArtifact, $cwd);
153+
self::assertCommandsWork($stepsToPrepareArtifact, $tmpArtifactPath);
154+
self::assertCommandsWork($this->stepsToVerifyInstallation, $tmpPath);
155+
156+
$fs->remove($tmpPath);
157+
$fs->remove($tmpArtifactPath);
158+
}
159+
160+
private static function assertCommandsWork(array $commands, $cwd)
161+
{
162+
foreach ($commands as $command) {
163+
self::assertSame(0, CommandExecutor::create($command, $cwd)->getResult()->getCode());
164+
}
165+
}
78166
}

tests/Smoke/PharTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PhpCsFixer\Console\Application;
1717
use PhpCsFixer\Console\Command\DescribeCommand;
1818
use PhpCsFixer\Console\Command\HelpCommand;
19-
use PHPUnit\Framework\TestCase;
2019
use Symfony\Component\Console\Tester\CommandTester;
2120

2221
/**
@@ -28,7 +27,7 @@
2827
* @group covers-nothing
2928
* @large
3029
*/
31-
final class PharTest extends TestCase
30+
final class PharTest extends AbstractSmokeTest
3231
{
3332
private static $pharCwd;
3433
private static $pharName;
@@ -41,11 +40,7 @@ public static function setUpBeforeClass()
4140
self::$pharName = 'php-cs-fixer.phar';
4241

4342
if (!file_exists(self::$pharCwd.'/'.self::$pharName)) {
44-
if (getenv('PHP_CS_FIXER_TEST_ALLOW_SKIPPING_PHAR_TESTS')) {
45-
self::markTestSkipped('No phar file available.');
46-
}
47-
48-
self::fail('No phar file available. Failing as test is obligatory because of `PHP_CS_FIXER_TEST_ALLOW_SKIPPING_PHAR_TESTS=0`.');
43+
self::markTestSkippedOrFail('No phar file available.');
4944
}
5045
}
5146

@@ -96,6 +91,14 @@ public function testFix()
9691
);
9792
}
9893

94+
public function testFixHelp()
95+
{
96+
$this->assertSame(
97+
0,
98+
self::executePharCommand('fix --help')->getCode()
99+
);
100+
}
101+
99102
/**
100103
* @param string $params
101104
*

tests/Smoke/StdinTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace PhpCsFixer\Tests\Smoke;
1414

1515
use Keradus\CliExecutor\CommandExecutor;
16-
use PHPUnit\Framework\TestCase;
1716

1817
/**
1918
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
@@ -24,7 +23,7 @@
2423
* @coversNothing
2524
* @group covers-nothing
2625
*/
27-
final class StdinTest extends TestCase
26+
final class StdinTest extends AbstractSmokeTest
2827
{
2928
public function testFixingStdin()
3029
{

0 commit comments

Comments
 (0)