Skip to content

#207 - Adding log-junuit example for v1 #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"symfony/dependency-injection": "^4.4||^5.0||^6.0",
"symfony/event-dispatcher": "^4.4||^5.0||^6.0",
"symfony/process": "^4.4||^5.0||^6.0",
"symfony/stopwatch": "^4.4||^5.0||^6.0"
"symfony/stopwatch": "^4.4||^5.0||^6.0",
"ext-simplexml": "*"
},
"require-dev": {
"facile-it/facile-coding-standard": "^0.5.1",
Expand Down
1 change: 1 addition & 0 deletions src/Command/ParallelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function __construct(ParallelConfiguration $configuration)
new PHPUnitOption('static-backup', false),

new PHPUnitOption('loader'),
new PHPUnitOption('log-junit'),
new PHPUnitOption('repeat'),
new PHPUnitOption('printer'),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Paraunit\Runner\PipelineFactory;
use Paraunit\Runner\Runner;
use Paraunit\TestResult\TestResultList;
use Paraunit\Util\Log\JUnit\JUnit;
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
use SebastianBergmann\FileIterator\Facade;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -74,6 +75,8 @@ private function configureConfiguration(ContainerBuilder $container): void
'%paraunit.phpunit_config_filename%',
]))
->setPublic(true);
$container->setDefinition(JUnit::class, new Definition(JUnit::class));

$container->setDefinition(TempFilenameFactory::class, new Definition(TempFilenameFactory::class, [
new Reference(TempDirectory::class),
]));
Expand Down Expand Up @@ -117,6 +120,7 @@ private function configurePrinter(ContainerBuilder $container): void
new Reference(TestResultList::class),
$output,
new Reference(ChunkSize::class),
new Reference(JUnit::class),
];
$container->setDefinition(FinalPrinter::class, new Definition(FinalPrinter::class, $finalPrinterArguments));
$container->setDefinition(FailuresPrinter::class, new Definition(FailuresPrinter::class, $finalPrinterArguments));
Expand All @@ -133,6 +137,7 @@ private function configureProcess(ContainerBuilder $container): void
$container->setDefinition(CommandLine::class, new Definition(CommandLine::class, [
new Reference(PHPUnitBinFile::class),
new Reference(ChunkSize::class),
new Reference(JUnit::class)
]));

$container->setDefinition(ProcessFactoryInterface::class, new Definition(ProcessFactory::class, [
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration/EnvVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ class EnvVariables
public const PIPELINE_NUMBER = 'PARAUNIT_PIPELINE_NUMBER';

public const PROCESS_UNIQUE_ID = 'PARAUNIT_PROCESS_UNIQUE_ID';

public const LOG_JUNIT_DIR = 'PARAUNIT_LOG_JUNIT_DIR';
}
2 changes: 2 additions & 0 deletions src/Configuration/ParallelConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ protected function loadCommandLineOptions(ContainerBuilder $containerBuilder, In
$containerBuilder->setParameter('paraunit.testsuite', $input->getOption('testsuite'));
$containerBuilder->setParameter('paraunit.string_filter', $input->getArgument('stringFilter'));
$containerBuilder->setParameter('paraunit.show_logo', $input->getOption('logo'));
$containerBuilder->setParameter('paraunit.log_junit', $input->getOption('log-junit')
);

if ($input->getOption('debug')) {
$this->enableDebugMode($containerBuilder);
Expand Down
9 changes: 8 additions & 1 deletion src/Printer/AbstractFinalPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Paraunit\Configuration\ChunkSize;
use Paraunit\TestResult\TestResultList;
use Paraunit\Util\Log\JUnit\JUnit;
use Symfony\Component\Console\Output\OutputInterface;

abstract class AbstractFinalPrinter extends AbstractPrinter
Expand All @@ -16,14 +17,20 @@ abstract class AbstractFinalPrinter extends AbstractPrinter
/** @var ChunkSize */
protected $chunkSize;

/** @var JUnit */
protected $log;


public function __construct(
TestResultList $testResultList,
OutputInterface $output,
ChunkSize $chunkSize
ChunkSize $chunkSize,
JUnit $log
) {
parent::__construct($output);
$this->testResultList = $testResultList;
$this->chunkSize = $chunkSize;
$this->log = $log;
}

abstract public function onEngineEnd(): void;
Expand Down
6 changes: 4 additions & 2 deletions src/Printer/FinalPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Paraunit\Lifecycle\ProcessToBeRetried;
use Paraunit\TestResult\Interfaces\TestResultContainerInterface;
use Paraunit\TestResult\TestResultList;
use Paraunit\Util\Log\JUnit\JUnit;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Stopwatch\Stopwatch;
Expand All @@ -33,9 +34,10 @@ class FinalPrinter extends AbstractFinalPrinter implements EventSubscriberInterf
public function __construct(
TestResultList $testResultList,
OutputInterface $output,
ChunkSize $chunkSize
ChunkSize $chunkSize,
JUnit $log
) {
parent::__construct($testResultList, $output, $chunkSize);
parent::__construct($testResultList, $output, $chunkSize, $log);

$this->stopWatch = new Stopwatch();
$this->processCompleted = 0;
Expand Down
26 changes: 24 additions & 2 deletions src/Process/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Paraunit\Configuration\PHPUnitConfig;
use Paraunit\Configuration\PHPUnitOption;
use Paraunit\Parser\JSON\TestHook as Hooks;
use Paraunit\Util\Log\JUnit\JUnit;

class CommandLine
{
Expand All @@ -18,12 +19,20 @@ class CommandLine
/** @var ChunkSize */
protected $chunkSize;

/** @var JUnit */
private $log;

/** @var bool */
private $generateJunitLog = false;

public function __construct(
PHPUnitBinFile $phpUnitBin,
ChunkSize $chunkSize
ChunkSize $chunkSize,
JUnit $log
) {
$this->phpUnitBin = $phpUnitBin;
$this->chunkSize = $chunkSize;
$this->log = $log;
}

/**
Expand Down Expand Up @@ -68,6 +77,13 @@ public function getOptions(PHPUnitConfig $config): array
private function buildPhpunitOptionString(PHPUnitOption $option): string
{
$optionString = '--' . $option->getName();

// This is creating log-junit output -> merges multiple log-junit files into one report
if ($option->getName() === 'log-junit' && $option->getValue() !== null) {
$this->generateJunitLog = true;
$this->log->setInputFileName($option->getValue());
}

if ($option->hasValue()) {
$optionString .= '=' . $option->getValue();
}
Expand All @@ -80,6 +96,12 @@ private function buildPhpunitOptionString(PHPUnitOption $option): string
*/
public function getSpecificOptions(string $testFilename): array
{
return [];
$options = array();

if ($this->generateJunitLog) {
$options[] = $this->log->generateLogForTest($testFilename);
}

return $options;
}
}
23 changes: 23 additions & 0 deletions src/Util/Log/Helpers/DOMDocumentAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Paraunit\Util\Log\Helpers;

class DOMDocumentAttributes
{
public const BASE_SUITE_ATTRIBUTES = [
'name' => 'All Suites',
'tests' => '0',
'assertions' => '0',
'errors' => '0',
'failures' => '0',
'skipped' => '0',
'time' => '0',
];

public function getBaseSuiteAttributes(): array
{
return self::BASE_SUITE_ATTRIBUTES;
}
}
32 changes: 32 additions & 0 deletions src/Util/Log/Interfaces/LogInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Paraunit\Util\Log\Interfaces;

interface LogInterface
{
public function setInputFileName(string $inputFileName): void;

public function checkIfInitialized(): bool;

public function generateLogForTest(string $testFilename): string;

public function getExtension(): string;

public function setExtension(string $inputFileName): void;

public function getDirname(): string;

public function setDirname(string $inputFileName): void;

public function getBasename(): string;

public function setBasename(string $inputFileName): void;

public function generate(): int|string;

public function getFiles(): array;

public function getInputFileName(): ?string;

public function getTempDirectory(): array|string;
}
Loading