From 66ad92e5f6e8947d90f0d8c8b7bc58850fdbaf64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andor=20D=C3=A1vid?= Date: Sun, 30 Jul 2017 12:29:26 +0200 Subject: [PATCH] Remove AssetJar --- codeception.yml | 2 + composer.json | 2 +- composer.lock | 37 +------ src/Task/{Run.php => TsLintRunTask.php} | 72 +++++++++---- src/TsLintTaskLoader.php | 12 +-- tests/_data/RoboFile.php | 13 +-- tests/_support/AcceptanceTester.php | 12 ++- tests/_support/Helper/Acceptance.php | 7 +- .../Dummy/{Output.php => DummyOutput.php} | 9 +- .../Dummy/{Process.php => DummyProcess.php} | 11 +- tests/_support/Helper/Module/Cli.php | 2 +- tests/_support/Helper/Unit.php | 7 +- tests/_support/UnitTester.php | 5 +- tests/acceptance.suite.yml | 6 +- tests/acceptance/RunRoboTaskCest.php | 2 +- tests/unit.suite.yml | 6 +- .../{RunTest.php => TsLintRunTaskTest.php} | 100 ++++++++---------- 17 files changed, 127 insertions(+), 178 deletions(-) rename src/Task/{Run.php => TsLintRunTask.php} (94%) rename tests/_support/Helper/Dummy/{Output.php => DummyOutput.php} (62%) rename tests/_support/Helper/Dummy/{Process.php => DummyProcess.php} (89%) rename tests/unit/Task/{RunTest.php => TsLintRunTaskTest.php} (86%) diff --git a/codeception.yml b/codeception.yml index d6d6e0e..3661505 100644 --- a/codeception.yml +++ b/codeception.yml @@ -1,4 +1,6 @@ +namespace: 'Sweetchuck\Robo\TsLint\Test' + actor: Tester paths: diff --git a/composer.json b/composer.json index 8c2ffdd..2fd9f8a 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,6 @@ "prefer-stable": true, "require": { "php": ">=7.1", - "sweetchuck/asset-jar": "^0.0", "consolidation/robo": "^1.0" }, "require-dev": { @@ -29,6 +28,7 @@ "autoload-dev": { "psr-4": { "Sweetchuck\\Robo\\TsLint\\Composer\\": "src-dev/Composer/", + "Sweetchuck\\Robo\\TsLint\\Test\\": "tests/_support/", "Sweetchuck\\Robo\\TsLint\\Tests\\Unit\\": "tests/unit/", "Sweetchuck\\Robo\\TsLint\\Tests\\Acceptance\\": "tests/acceptance/" } diff --git a/composer.lock b/composer.lock index 4c924a2..2575d6f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "31a1aa971a36e18c064c83bf35943dd1", + "content-hash": "60ee00ba5282101895981682fd1e2c85", "packages": [ { "name": "consolidation/annotated-command", @@ -727,41 +727,6 @@ ], "time": "2016-10-10T12:19:37+00:00" }, - { - "name": "sweetchuck/asset-jar", - "version": "v0.0.2", - "source": { - "type": "git", - "url": "https://github.com/Sweetchuck/asset-jar.git", - "reference": "a6d4d67db8eef018aa10779b3906fb109bcb6508" - }, - "dist": { - "type": "zip", - "url": "https://github.com/gitapi/repos/Sweetchuck/asset-jar/zipball/a6d4d67db8eef018aa10779b3906fb109bcb6508", - "reference": "a6d4d67db8eef018aa10779b3906fb109bcb6508", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "require-dev": { - "phpunit/php-code-coverage": "^4.0", - "phpunit/phpunit": "^5.4", - "squizlabs/php_codesniffer": "^2.6" - }, - "type": "library", - "autoload": { - "psr-4": { - "Sweetchuck\\AssetJar\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0+" - ], - "description": "Provides a very simple, shared, in-memory data storage.", - "time": "2017-07-29T07:37:14+00:00" - }, { "name": "symfony/console", "version": "v3.3.5", diff --git a/src/Task/Run.php b/src/Task/TsLintRunTask.php similarity index 94% rename from src/Task/Run.php rename to src/Task/TsLintRunTask.php index bc3c6f5..e3c70f2 100644 --- a/src/Task/Run.php +++ b/src/Task/TsLintRunTask.php @@ -2,8 +2,6 @@ namespace Sweetchuck\Robo\TsLint\Task; -use Sweetchuck\AssetJar\AssetJarAware; -use Sweetchuck\AssetJar\AssetJarAwareInterface; use Sweetchuck\LintReport\ReporterInterface; use Sweetchuck\LintReport\ReportWrapperInterface; use Sweetchuck\Robo\TsLint\LintReportWrapper\ReportWrapper; @@ -28,15 +26,13 @@ * * @package Sweetchuck\Robo\TsLint\Task */ -class Run extends BaseTask implements - AssetJarAwareInterface, +class TsLintRunTask extends BaseTask implements CommandInterface, ContainerAwareInterface, BuilderAwareInterface, OutputAwareInterface { - use AssetJarAware; use ContainerAwareTrait; use FsLoadTasks; use FsShortCuts; @@ -71,6 +67,29 @@ class Run extends BaseTask implements protected $processClass = Process::class; //region Options. + + // region Option - assetNamePrefix. + /** + * @var string + */ + protected $assetNamePrefix = ''; + + public function getAssetNamePrefix(): string + { + return $this->assetNamePrefix; + } + + /** + * @return $this + */ + public function setAssetNamePrefix(string $value) + { + $this->assetNamePrefix = $value; + + return $this; + } + // endregion + //region Option - workingDirectory. /** * @var string @@ -456,6 +475,13 @@ public function removeLintReporter(string $id) //endregion //endregion + /** + * @var array + */ + protected $assets = [ + 'report' => [], + ]; + protected $options = [ 'config' => 'value', 'exclude' => 'multi-value', @@ -510,8 +536,8 @@ public function options(array $options) { foreach ($options as $name => $value) { switch ($name) { - case 'assetJarMapping': - $this->setAssetJarMapping($value); + case 'assetNamePrefix': + $this->setAssetNamePrefix($value); break; case 'workingDirectory': @@ -645,8 +671,8 @@ public function run() $numOfErrors = $reportWrapper->numOfErrors(); $numOfWarnings = $reportWrapper->numOfWarnings(); - if ($this->isReportHasToBePutBackIntoJar()) { - $this->setAssetJarValue('report', $reportWrapper); + if ($this->isLintSuccess()) { + $this->assets['report'] = $reportWrapper; } foreach ($lintReporters as $lintReporter) { @@ -667,9 +693,7 @@ public function run() $this, $exitCode, $this->getExitMessage($exitCode) ?: $process->getErrorOutput(), - [ - 'time' => $this->getExecutionTime(), - ] + $this->getAssetsWithPrefixedNames() ); } @@ -743,15 +767,6 @@ protected function buildCommandOptions(): array ]; } - protected function isReportHasToBePutBackIntoJar(): bool - { - return ( - $this->hasAssetJar() - && $this->getAssetJarMap('report') - && $this->isLintSuccess() - ); - } - protected function isOutputFormatMachineReadable(): bool { return ($this->getFormat() === 'json'); @@ -871,4 +886,19 @@ protected function prepareOutputDirectory(): Result return $result; } + + protected function getAssetsWithPrefixedNames(): array + { + $prefix = $this->getAssetNamePrefix(); + if (!$prefix) { + return $this->assets; + } + + $data = []; + foreach ($this->assets as $key => $value) { + $data["{$prefix}{$key}"] = $value; + } + + return $data; + } } diff --git a/src/TsLintTaskLoader.php b/src/TsLintTaskLoader.php index 5598071..4ca857e 100644 --- a/src/TsLintTaskLoader.php +++ b/src/TsLintTaskLoader.php @@ -5,11 +5,6 @@ use League\Container\ContainerAwareInterface; use Robo\Contract\OutputAwareInterface; -/** - * Class LoadTasks. - * - * @package Sweetchuck\Robo\TsLint\Task - */ trait TsLintTaskLoader { /** @@ -20,13 +15,12 @@ trait TsLintTaskLoader * @param string[] $paths * File paths. * - * @return \Sweetchuck\Robo\TsLint\Task\Run - * A lint runner task instance. + * @return \Sweetchuck\Robo\TsLint\Task\TsLintRunTask|\Robo\Collection\CollectionBuilder */ protected function taskTsLintRun(array $options = [], array $paths = []) { - /** @var \Sweetchuck\Robo\TSLint\Task\Run $task */ - $task = $this->task(Task\Run::class, $options, $paths); + /** @var \Sweetchuck\Robo\TSLint\Task\TsLintRunTask $task */ + $task = $this->task(Task\TsLintRunTask::class, $options, $paths); if ($this instanceof ContainerAwareInterface) { $task->setContainer($this->getContainer()); } diff --git a/tests/_data/RoboFile.php b/tests/_data/RoboFile.php index c713784..7dc2e12 100644 --- a/tests/_data/RoboFile.php +++ b/tests/_data/RoboFile.php @@ -3,13 +3,8 @@ use Sweetchuck\LintReport\Reporter\BaseReporter; use Sweetchuck\LintReport\Reporter\SummaryReporter; use Sweetchuck\LintReport\Reporter\VerboseReporter; -use League\Container\ContainerAwareInterface; use League\Container\ContainerInterface; -use Robo\Contract\ConfigAwareInterface; -/** - * Class RoboFile. - */ // @codingStandardsIgnoreStart class RoboFile extends \Robo\Tasks { @@ -22,8 +17,6 @@ class RoboFile extends \Robo\Tasks protected $reportsDir = 'actual'; /** - * @param \League\Container\ContainerInterface $container - * * @return $this */ public function setContainer(ContainerInterface $container) @@ -36,7 +29,7 @@ public function setContainer(ContainerInterface $container) } /** - * @return \Sweetchuck\Robo\TsLint\Task\Run + * @return \Sweetchuck\Robo\TsLint\Task\TsLintRunTask|\Robo\Collection\CollectionBuilder */ public function lintStylishStdOutput() { @@ -47,7 +40,7 @@ public function lintStylishStdOutput() } /** - * @return \Sweetchuck\Robo\TsLint\Task\Run + * @return \Sweetchuck\Robo\TsLint\Task\TsLintRunTask|\Robo\Collection\CollectionBuilder */ public function lintStylishFile() { @@ -59,7 +52,7 @@ public function lintStylishFile() } /** - * @return \Sweetchuck\Robo\TsLint\Task\Run + * @return \Sweetchuck\Robo\TsLint\Task\TsLintRunTask|\Robo\Collection\CollectionBuilder */ public function lintAllInOne() { diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index d57e77b..357d677 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -1,6 +1,8 @@ in($reportsDir); - foreach ($finder->files() as $file) { + $finder = (new \Symfony\Component\Finder\Finder()) + ->in($reportsDir) + ->files(); + /** @var \Symfony\Component\Finder\SplFileInfo $file */ + foreach ($finder as $file) { unlink($file->getPathname()); } } diff --git a/tests/_support/Helper/Acceptance.php b/tests/_support/Helper/Acceptance.php index 0b2c81a..251968e 100644 --- a/tests/_support/Helper/Acceptance.php +++ b/tests/_support/Helper/Acceptance.php @@ -1,14 +1,9 @@ $c['f'], - ], - $withJar, - json_encode($report) - ]; + foreach ($combinations as $c) { + $i++; + $report = $reportBase; + + if ($c['e']) { + $report[] = $failureError; + } + + if ($c['w']) { + $report[] = $failureWarning; } + + $label = sprintf($labelPattern, $i, $c['f'], $c['e'], $c['w'], $c['c']); + $cases[$label] = [ + $c['c'], + [ + 'failOn' => $c['f'], + ], + json_encode($report) + ]; } return $cases; @@ -411,7 +406,6 @@ public function casesRun(): array public function testRun( int $exitCode, array $options, - bool $withJar, string $expectedStdOutput ): void { $container = Robo::createDefaultContainer(); @@ -421,11 +415,10 @@ public function testRun( $options += [ 'workingDirectory' => 'my-working-dir', - 'assetJarMapping' => ['report' => ['tsLintRun', 'report']], 'format' => 'json', ]; - /** @var \Sweetchuck\Robo\TsLint\Task\Run $task */ + /** @var \Sweetchuck\Robo\TsLint\Task\TsLintRunTask $task */ $task = Stub::construct( RunTask::class, [$options, []], @@ -444,12 +437,6 @@ public function testRun( $task->setLogger($container->get('logger')); $task->setOutput($mainStdOutput); - $assetJar = null; - if ($withJar) { - $assetJar = new AssetJar(); - $task->setAssetJar($assetJar); - } - $result = $task->run(); $this->tester->assertEquals( @@ -458,21 +445,20 @@ public function testRun( 'Exit code' ); - if ($withJar) { - /** @var \Sweetchuck\LintReport\ReportWrapperInterface $reportWrapper */ - $reportWrapper = $assetJar->getValue(['tsLintRun', 'report']); - $this->tester->assertEquals( - json_decode($expectedStdOutput, true), - $reportWrapper->getReport(), - 'Output equals with jar' - ); - } else { - $this->tester->assertContains( - $expectedStdOutput, - $mainStdOutput->output, - 'Output equals without jar' - ); - } + $assetNamePrefix = $options['assetNamePrefix'] ?? ''; + /** @var \Sweetchuck\LintReport\ReportWrapperInterface $reportWrapper */ + $reportWrapper = $result["{$assetNamePrefix}report"]; + $this->tester->assertEquals( + json_decode($expectedStdOutput, true), + $reportWrapper->getReport(), + 'Output equals with jar' + ); + + $this->tester->assertContains( + $expectedStdOutput, + $mainStdOutput->output, + 'Output equals without jar' + ); } public function testRunFailed(): void @@ -490,7 +476,6 @@ public function testRunFailed(): void $expectedReportJson = json_encode($expectedReport); $options = [ 'workingDirectory' => 'my-working-dir', - 'assetJarMapping' => ['report' => ['tsLintRun', 'report']], 'failOn' => 'warning', 'format' => 'json', ]; @@ -513,8 +498,6 @@ public function testRunFailed(): void $task->setConfig(Robo::config()); $task->setLogger($container->get('logger')); - $assetJar = new AssetJar(); - $task->setAssetJar($assetJar); $result = $task->run(); @@ -524,8 +507,9 @@ public function testRunFailed(): void 'Exit code' ); + $assetNamePrefix = $options['assetNamePrefix'] ?? ''; /** @var \Sweetchuck\LintReport\ReportWrapperInterface $reportWrapper */ - $reportWrapper = $assetJar->getValue(['tsLintRun', 'report']); + $reportWrapper = $result["{$assetNamePrefix}report"]; $this->tester->assertEquals($expectedReport, $reportWrapper->getReport()); } }