diff --git a/bin/paratest b/bin/paratest
index 6cfd550..4821775 100755
--- a/bin/paratest
+++ b/bin/paratest
@@ -31,11 +31,7 @@ if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
exit(1);
}
-#use ParaTest\UI\Text\PHPUnitTextUI;
+use ParaTest\Console\Commands\ParaTestCommand;
+use ParaTest\Console\Testers\PHPUnit;
-#PHPUnitTextUI::main();
-
-use ParaTest\Console\ParaTestApplication;
-
-$app = new ParaTestApplication();
-$app->run();
+ParaTestCommand::applicationFactory(new PHPUnit())->run();
diff --git a/src/Console/Commands/ParaTestCommand.php b/src/Console/Commands/ParaTestCommand.php
index e6306bb..1a845cc 100644
--- a/src/Console/Commands/ParaTestCommand.php
+++ b/src/Console/Commands/ParaTestCommand.php
@@ -5,6 +5,7 @@
namespace ParaTest\Console\Commands;
use ParaTest\Console\Testers\Tester;
+use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -24,6 +25,17 @@ public function __construct(Tester $tester)
$this->tester->configure($this);
}
+ public static function applicationFactory(Tester $tester): Application
+ {
+ $application = new Application('ParaTest');
+ $command = new ParaTestCommand($tester);
+
+ $application->add($command);
+ $application->setDefaultCommand($command->getName(), true);
+
+ return $application;
+ }
+
/**
* Ubiquitous configuration options for ParaTest.
*/
@@ -100,12 +112,6 @@ protected function configure()
'Pass the given arguments verbatim to the underlying php process. Example: --passthru-php="\'-d\' ' .
'\'zend_extension=xdebug.so\'"'
)
- ->addOption(
- 'verbose',
- 'v',
- InputOption::VALUE_REQUIRED,
- 'If given, debug output is printed. Example: --verbose=1'
- )
->addOption('whitelist', null, InputOption::VALUE_REQUIRED, 'Directory to add to the coverage whitelist.');
}
diff --git a/src/Console/ParaTestApplication.php b/src/Console/ParaTestApplication.php
deleted file mode 100644
index 88f5aed..0000000
--- a/src/Console/ParaTestApplication.php
+++ /dev/null
@@ -1,60 +0,0 @@
-add(new ParaTestCommand(new PHPUnit()));
-
- return parent::doRun($input, $output);
- }
-
- /**
- * The default InputDefinition for the application. Leave it to specific
- * Tester objects for specifying further definitions.
- *
- * @return InputDefinition
- */
- public function getDefinition(): InputDefinition
- {
- return new InputDefinition([
- new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
- ]);
- }
-
- /**
- * @param InputInterface $input
- *
- * @return string
- */
- public function getCommandName(InputInterface $input): string
- {
- return 'paratest';
- }
-}
diff --git a/src/Console/VersionProvider.php b/src/Console/VersionProvider.php
deleted file mode 100644
index c997abf..0000000
--- a/src/Console/VersionProvider.php
+++ /dev/null
@@ -1,109 +0,0 @@
-default = $default;
- }
-
- public static function getVersion($default = null)
- {
- $provider = new self($default);
-
- return $provider->getParaTestVersion();
- }
-
- public function getParaTestVersion()
- {
- return $this->getComposerInstalledVersion(self::PACKAGE)
- ?? $this->getGitVersion()
- ?? $this->default;
- }
-
- public function getGitVersion()
- {
- $cmd = 'git describe --tags --always --first-parent';
- $process = \method_exists(Process::class, 'fromShellCommandline') ?
- Process::fromShellCommandline($cmd, __DIR__) :
- new Process($cmd, __DIR__);
-
- if ($process->run() !== 0) {
- return null;
- }
-
- return \trim($process->getOutput());
- }
-
- public function getComposerInstalledVersion($package)
- {
- if (null === $path = $this->getComposerInstalledJsonPath()) {
- return;
- }
-
- $result = \file_get_contents($path);
- if (false === $result) {
- return;
- }
-
- $struct = \json_decode($result, true, 16);
- if (!\is_array($struct)) {
- return;
- }
-
- foreach ($struct as $entry) {
- if (!\is_array($entry)) {
- continue;
- }
- $name = $entry['name'] ?? null;
- if (null === $name || $name !== $package) {
- continue;
- }
- $version = $entry['version'] ?? null;
- if (null === $version) {
- continue;
- }
-
- return $version;
- }
- }
-
- /**
- * @return string|null path to composer/installed.json
- */
- private function getComposerInstalledJsonPath()
- {
- $paths = [
- // path in the installed version
- __DIR__ . '/../../../../composer/installed.json',
- // path in the source version
- __DIR__ . '/../../vendor/composer/installed.json',
- ];
-
- // first hit makes it
- foreach ($paths as $path) {
- if (\file_exists($path) && \is_readable($path)) {
- return $path;
- }
- }
- }
-}
diff --git a/test/Unit/Console/Commands/ParaTestCommandTest.php b/test/Unit/Console/Commands/ParaTestCommandTest.php
index 8f9a00e..15a4d00 100644
--- a/test/Unit/Console/Commands/ParaTestCommandTest.php
+++ b/test/Unit/Console/Commands/ParaTestCommandTest.php
@@ -30,6 +30,15 @@ public function testConstructor()
$this->assertSame($this->tester, $this->getObjectValue($this->command, 'tester'));
}
+ public function testApplicationFactory(): void
+ {
+ $application = ParaTestCommand::applicationFactory($this->tester);
+ $commands = $application->all();
+
+ $this->assertArrayHasKey($this->command->getName(), $commands);
+ $this->assertInstanceOf(ParaTestCommand::class, $commands[$this->command->getName()]);
+ }
+
/**
* Should be configured from the ParaTest command
* as well as the Tester it is composed of.
@@ -37,6 +46,28 @@ public function testConstructor()
public function testConfiguredDefinitionWithPHPUnitTester()
{
$options = [
+ // Arguments
+ new InputArgument(
+ 'path',
+ InputArgument::OPTIONAL,
+ 'The path to a directory or file containing tests. (default: current directory)'
+ ),
+
+ // Default Symfony options
+ new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'),
+ new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
+ new InputOption(
+ '--verbose',
+ '-v|vv|vvv',
+ InputOption::VALUE_NONE,
+ 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'
+ ),
+ new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'),
+ new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output'),
+ new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output'),
+ new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'),
+
+ // Custom options
new InputOption(
'processes',
'p',
@@ -50,7 +81,6 @@ public function testConfiguredDefinitionWithPHPUnitTester()
InputOption::VALUE_NONE,
'Run test methods instead of classes in separate processes.'
),
- new InputOption('help', 'h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption(
'phpunit',
null,
@@ -95,11 +125,6 @@ public function testConfiguredDefinitionWithPHPUnitTester()
'Log test execution in JUnit XML format to file.'
),
new InputOption('colors', null, InputOption::VALUE_NONE, 'Displays a colored bar as a test result.'),
- new InputArgument(
- 'path',
- InputArgument::OPTIONAL,
- 'The path to a directory or file containing tests. (default: current directory)'
- ),
new InputOption(
'no-test-tokens',
null,
@@ -179,12 +204,6 @@ public function testConfiguredDefinitionWithPHPUnitTester()
'Pass the given arguments verbatim to the underlying php process. ' .
'Example: --passthru-php="\'-d\' \'zend_extension=xdebug.so\'"'
),
- new InputOption(
- 'verbose',
- 'v',
- InputOption::VALUE_REQUIRED,
- 'If given, debug output is printed. Example: --verbose=1'
- ),
new InputOption(
'whitelist',
null,
@@ -193,7 +212,10 @@ public function testConfiguredDefinitionWithPHPUnitTester()
),
];
$expected = new InputDefinition($options);
- $definition = $this->command->getDefinition();
+ $application = ParaTestCommand::applicationFactory($this->tester);
+ $command = $application->get($this->command->getName());
+ $command->mergeApplicationDefinition();
+ $definition = $command->getDefinition();
$this->assertEquals($expected, $definition);
}
diff --git a/test/Unit/Console/VersionProviderTest.php b/test/Unit/Console/VersionProviderTest.php
deleted file mode 100644
index bd513ff..0000000
--- a/test/Unit/Console/VersionProviderTest.php
+++ /dev/null
@@ -1,49 +0,0 @@
-assertInstanceOf(VersionProvider::class, $provider);
- }
-
- public function testStaticCall()
- {
- $provider = new VersionProvider();
- $this->assertSame($provider::getVersion(), $provider->getParaTestVersion());
- }
-
- public function testComposerInstalledVersion()
- {
- $provider = new VersionProvider();
- $actual = $provider->getComposerInstalledVersion('phpunit/phpunit');
- $this->assertIsString($actual, 'Version of phpunit package was found installed');
-
- // dev-master is included here as the phpunit package is checked and there is a dev-master used on travis
- $this->assertRegExp("~^dev-master|\d.\d.(.)+$~", $actual, 'Actual version number');
-
- $actual = $provider->getComposerInstalledVersion('foooo/barazzoraz');
- $this->assertNull($actual, 'No version for non-existent package');
- }
-
- public function testGitVersion()
- {
- $provider = new VersionProvider();
- $actual = $provider->getGitVersion();
- $this->assertIsString($actual, 'Git is enabled and works');
- $this->assertRegExp("~^\d.\d(?:.\d+)?(?:-\d+-g[\da-f]+)?$~", $actual, 'Git gives a version');
- }
-}