Compare commits
10 Commits
817ba4501d
...
0511638d1a
Author | SHA1 | Date | |
---|---|---|---|
|
0511638d1a | ||
|
adc22cdee6 | ||
|
00a9c6d298 | ||
|
1935601cc7 | ||
|
f576ad2bcb | ||
|
42526c39b0 | ||
|
379c9ba842 | ||
|
2dd0f53c44 | ||
|
bb11cec5c7 | ||
|
eb547ef962 |
@ -37,8 +37,15 @@
|
|||||||
"plugin-modifies-downloads": true
|
"plugin-modifies-downloads": true
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
"platform": {
|
||||||
|
"php": "7.2.5"
|
||||||
|
},
|
||||||
|
"platform-check": true,
|
||||||
"allow-plugins": {
|
"allow-plugins": {
|
||||||
"topfloor/composer-cleanup-vcs-dirs": false
|
"topfloor/composer-cleanup-vcs-dirs": false
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^8.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,16 @@
|
|||||||
|
|
||||||
namespace Seacms\Command;
|
namespace Seacms\Command;
|
||||||
|
|
||||||
|
use Composer\Console\Application;
|
||||||
use Composer\Command\BaseCommand;
|
use Composer\Command\BaseCommand;
|
||||||
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command to lauch tests from command line accross all seacms dependencies
|
* Command to lauch tests from command line accross all seacms dependencies
|
||||||
@ -17,7 +24,6 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
|
|
||||||
class Command extends BaseCommand
|
class Command extends BaseCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set name
|
* set name
|
||||||
*/
|
*/
|
||||||
@ -30,11 +36,22 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
|
|
||||||
// the full command description shown when running the command with
|
// the full command description shown when running the command with
|
||||||
// the "--help" option
|
// the "--help" option
|
||||||
->setHelp("Test seacms via command line.\n".
|
->setHelp(
|
||||||
"(Only if phpunit available)\n")
|
<<<STR
|
||||||
|
Test seacms via command line.
|
||||||
|
(Only if phpunit available)
|
||||||
|
|
||||||
|
Examples :
|
||||||
|
composer seacms-test phpunit -- -h : display phpunit help (do not forget --)
|
||||||
|
composer seacms-test phpunit -- --pversion : display phpunit version
|
||||||
|
composer seacms-test help : show this help
|
||||||
|
composer seacms-test : show this help
|
||||||
|
composer seacms-test test : run tests
|
||||||
|
composer seacms-test test -- --filter AppTest::testInit : run tests with phpunit parameters
|
||||||
|
STR)
|
||||||
|
|
||||||
->addOption('toto', '', InputOption::VALUE_NONE, 'Display toto text')
|
->addArgument('type', InputArgument::OPTIONAL, 'phpunit|test')
|
||||||
->addOption('text', 't', InputOption::VALUE_REQUIRED, 'Display the text')
|
->addArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'phpunit command line params|other test params')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,14 +66,116 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
{
|
{
|
||||||
$output->writeln('<info>Testing seacms</info>');
|
$output->writeln('<info>Testing seacms</info>');
|
||||||
|
|
||||||
$totoOption = $input->getOption('toto');
|
$args = $input->getArgument('args');
|
||||||
$textOption = $input->getOption('test');
|
|
||||||
|
|
||||||
if ($totoOption){
|
switch ($input->getArgument('type')) {
|
||||||
$output->writeln('toto');
|
case 'test':
|
||||||
|
$empty = true;
|
||||||
|
foreach([
|
||||||
|
'vendor/seacms/app/tests/',
|
||||||
|
'vendor/seacms/composer-plugin/tests/',
|
||||||
|
'vendor/picocms/plugins/PicoContentEditor/tests',
|
||||||
|
'vendor/picocms/plugins/SeacmsApi/tests',
|
||||||
|
'vendor/picocms/plugins/SeacmsAuth/tests',
|
||||||
|
] as $path){
|
||||||
|
if (is_dir($path)){
|
||||||
|
$empty = false;
|
||||||
|
$newargs = array_merge([
|
||||||
|
'--bootstrap',
|
||||||
|
'vendor/autoload.php',
|
||||||
|
$path
|
||||||
|
],$args);
|
||||||
|
$code = $this->runPhpUnitIfAvailable($newargs,$output);
|
||||||
|
if ($code != Command::SUCCESS){
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($empty){
|
||||||
|
$output->writeln('<info>Nothing to test</info>');
|
||||||
|
}
|
||||||
|
return Command::SUCCESS;
|
||||||
|
case 'phpunit':
|
||||||
|
return $this->runPhpUnitIfAvailable($args,$output);
|
||||||
|
|
||||||
|
default:
|
||||||
|
// default display help
|
||||||
|
return $this->runApplicationSafe([
|
||||||
|
'command' => 'help',
|
||||||
|
'command_name' => 'seacms-test'
|
||||||
|
],$output);
|
||||||
}
|
}
|
||||||
if ($textOption){
|
}
|
||||||
$output->writeln($textOption);
|
|
||||||
|
/**
|
||||||
|
* run safe new Application
|
||||||
|
* @param array $def
|
||||||
|
* @param OutputInterface $output
|
||||||
|
* @return int errorCode
|
||||||
|
*/
|
||||||
|
protected function runApplicationSafe(array $def, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$app = new Application();
|
||||||
|
$app->setCatchExceptions(false); // force not catching exceptions
|
||||||
|
$app->setAutoExit(false); // force not exiting
|
||||||
|
try {
|
||||||
|
// if ($output instanceof ConsoleOutputInterface){
|
||||||
|
// $errBuffer = new BufferedOutput();
|
||||||
|
// $output->setErrorOutput($errBuffer);
|
||||||
|
// }
|
||||||
|
$code = $app->run(new ArrayInput($def),$output);
|
||||||
|
if ($code != 0){
|
||||||
|
$output->writeln("<info>Commands {$def['command']} return code $code</info>");
|
||||||
|
// if ($errBuffer){
|
||||||
|
// $errorOutput = $errBuffer->fetch();
|
||||||
|
// $output->writeln("<warning>Error</warning>");
|
||||||
|
// $output->writeln($errorOutput);
|
||||||
|
// }
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
} catch (Throwable $th){
|
||||||
|
$output->writeln("<info>Something went wrong ({$th->getMessage()} - code :{$th->getCode()} )</info>");
|
||||||
|
$output->writeln("<info>In file {$th->getFile()}(line {$th->getLine()})</infos>");
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if phpunit available
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function canRunPhpunit(): bool
|
||||||
|
{
|
||||||
|
return is_file('vendor/bin/phpunit');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* run php unit if available otherwise output a message
|
||||||
|
* @param array $args
|
||||||
|
* @param OutputInterface $output
|
||||||
|
* @return int $code
|
||||||
|
*/
|
||||||
|
protected function runPhpUnitIfAvailable(array $args, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
if ($this->canRunPhpunit()){
|
||||||
|
$def = [
|
||||||
|
'command' => 'exec',
|
||||||
|
'binary' => 'phpunit',
|
||||||
|
// '-v' => '-v', // only for debug command exec
|
||||||
|
];
|
||||||
|
$args = array_merge([
|
||||||
|
// '-v' => '--verbose', // verbse phpunit
|
||||||
|
// '--debug' => '--debug', // debug phpunit
|
||||||
|
],$args);
|
||||||
|
if (!empty($args)){
|
||||||
|
$def['args'] = array_map(function($v){
|
||||||
|
return ($v == '--pversion') ? '--version' : $v; // hack to prevent bad caught
|
||||||
|
},$args);
|
||||||
|
}
|
||||||
|
return $this->runApplicationSafe($def,$output);
|
||||||
|
} else {
|
||||||
|
$output->writeln('<info>phpunit not installed !</info>');
|
||||||
}
|
}
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
25
src/commands/CommandProvider.php
Normal file
25
src/commands/CommandProvider.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SPDX-License-Identifier: EUPL-1.2
|
||||||
|
* Authors: see /README.md
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Seacms\Command;
|
||||||
|
|
||||||
|
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
|
||||||
|
use Seacms\Command\Command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide list of commands
|
||||||
|
*/
|
||||||
|
|
||||||
|
class CommandProvider implements CommandProviderCapability
|
||||||
|
{
|
||||||
|
public function getCommands()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new Command()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -233,7 +233,7 @@ class Plugin extends ParentPlugin
|
|||||||
public function getCapabilities()
|
public function getCapabilities()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'Composer\Plugin\Capability\CommandProvider' => 'Seacms\\Command\\Command',
|
'Composer\Plugin\Capability\CommandProvider' => 'Seacms\\Command\\CommandProvider',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
/* === implements EventsSubscriberInterface === */
|
/* === implements EventsSubscriberInterface === */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user