Skip to content
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

Refactor log parser, adapt to new events #172

Merged
merged 34 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bd44b22
Move TestHook namespace one level higher
Jean85 Jun 17, 2022
9980d17
Use a backed enum as test status
Jean85 Jun 17, 2022
4f7037a
Add Finished event hook
Jean85 Jun 17, 2022
4045471
Rename Successful to Passed, fix CS
Jean85 Jun 17, 2022
fda6096
Refactor log DTO leveraging public readonly
Jean85 Jun 17, 2022
8ae994d
Simplify log writing method; move Enum into DTO namespace
Jean85 Jun 17, 2022
9a0f1fa
Create Test DTO
Jean85 Jun 17, 2022
f344112
Refactor LogFetcher
Jean85 Jun 17, 2022
9b7fd0c
Rename DTO namespace to ValueObject
Jean85 Jun 17, 2022
1283e39
--wip-- [skip ci]
Jean85 Dec 21, 2022
d9b05db
Fix Dockerfile
Jean85 Jan 11, 2023
4331b12
Update all deps
Jean85 Jan 11, 2023
12ee018
Rework warning
Jean85 Jan 12, 2023
060197e
Move log parsing logic into value objects
Jean85 Jan 12, 2023
bc9d573
Refactor parser namespace to use LogData
Jean85 Jan 13, 2023
2cd4cde
Fix DI and use LogData to write logs
Jean85 Jan 13, 2023
f7c607a
Silence PHPUnit deprecations
Jean85 Jan 13, 2023
35c056e
Improve getService typing
Jean85 Jan 13, 2023
6659bf0
Fix AbnormalTerminatedParserTest
Jean85 Jan 13, 2023
222761e
Update all JSON log stubs
Jean85 Jan 13, 2023
3baf71d
Handle unserializable logs with Unknown state
Jean85 Jan 13, 2023
30a0722
Fix all unit tests and PHPStan errors
Jean85 Jan 13, 2023
fe562a4
Improve test assertions
Jean85 Jan 13, 2023
362e78c
Make coverage driver choice explicit at instantiation
Jean85 Jan 13, 2023
86caf39
Make coverage driver choice explicit at instantiation
Jean85 Jan 13, 2023
b3ed839
Improve LogData validation
Jean85 Jan 13, 2023
d6705a0
Remove spurious file
Jean85 Jan 13, 2023
b2aaee1
Fix Warning fixture (and mark test as incomplete)
Jean85 Jan 13, 2023
3063bc7
Fix warning handling
Jean85 Jan 13, 2023
8cf7db7
Add new RiskyParser
Jean85 Jan 15, 2023
3ef62d5
Fix Warning fixture (again)
Jean85 Jan 16, 2023
1f0ea47
Fix warning handler behavior
Jean85 Jan 16, 2023
77f7de6
Fix risky fixture
Jean85 Jan 16, 2023
369857b
Mark incomplete tests
Jean85 Jan 16, 2023
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"facile-it/facile-coding-standard": "^0.5.1",
"jangregor/phpstan-prophecy": "^1.0.0",
"phpspec/prophecy": "dev-allow-sebastian-comparator-5 as 1.15",
"phpspec/prophecy-phpunit": "dev-allow-phpunit-10",
"phpspec/prophecy-phpunit": "dev-phpunit-10",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.7",
"phpstan/phpstan-phpunit": "^1.1",
Expand Down
1,136 changes: 602 additions & 534 deletions composer.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ RUN apk --no-cache add \
git \
zsh \
openssh-client \
linux-headers \
supervisor \
sudo \
less \
vim \
nano \
libzip-dev \
&& docker-php-ext-install -j5 zip pcntl \
&& pecl install xdebug \
libzip-dev
RUN docker-php-ext-install -j5 zip pcntl
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

#COMPOSER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ private function configureCoverage(ContainerBuilder $container): void
new Reference(CoverageMerger::class),
]));
$container->setDefinition(CoveragePrinter::class, new Definition(CoveragePrinter::class, [
new Reference(PHPDbgBinFile::class),
new Reference(XDebugProxy::class),
new Reference(PcovProxy::class),
new Reference(CommandLineWithCoverage::class),
new Reference(OutputInterface::class),
]));
}
Expand Down
24 changes: 12 additions & 12 deletions src/Configuration/DependencyInjection/ParserDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
use Paraunit\Parser\DeprecationParser;
use Paraunit\Parser\JSON\AbnormalTerminatedParser;
use Paraunit\Parser\JSON\GenericParser;
use Paraunit\Parser\JSON\Log;
use Paraunit\Parser\JSON\LogFetcher;
use Paraunit\Parser\JSON\LogParser;
use Paraunit\Parser\JSON\RetryParser;
use Paraunit\Parser\JSON\RiskyParser;
use Paraunit\Parser\JSON\UnknownResultParser;
use Paraunit\Parser\JSON\WarningParser;
use Paraunit\Parser\ValueObject\TestStatus;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand Down Expand Up @@ -55,40 +57,38 @@ private function defineParsers(ContainerBuilder $container): array
$parserDefinitions = [
'paraunit.parser.success_parser' => new Definition(GenericParser::class, [
new Reference('paraunit.test_result.success_container'),
Log::STATUS_SUCCESSFUL,
TestStatus::Passed,
]),
'paraunit.parser.incomplete_parser' => new Definition(GenericParser::class, [
new Reference('paraunit.test_result.incomplete_container'),
Log::STATUS_INCOMPLETE,
TestStatus::MarkedIncomplete,
]),
'paraunit.parser.skipped_parser' => new Definition(GenericParser::class, [
new Reference('paraunit.test_result.skipped_container'),
Log::STATUS_SKIPPED,
TestStatus::Skipped,
]),
'paraunit.parser.risky_parser' => new Definition(GenericParser::class, [
'paraunit.parser.risky_parser' => new Definition(RiskyParser::class, [
new Reference('paraunit.test_result.risky_container'),
Log::STATUS_RISKY,
]),
'paraunit.parser.warning_parser' => new Definition(GenericParser::class, [
'paraunit.parser.warning_parser' => new Definition(WarningParser::class, [
new Reference('paraunit.test_result.warning_container'),
Log::STATUS_WARNING,
TestStatus::WarningTriggered,
]),
'paraunit.parser.failure_parser' => new Definition(GenericParser::class, [
new Reference('paraunit.test_result.failure_container'),
Log::STATUS_FAILURE,
TestStatus::Failed,
]),
'paraunit.parser.error_parser' => new Definition(GenericParser::class, [
new Reference('paraunit.test_result.error_container'),
Log::STATUS_ERROR,
TestStatus::Errored,
]),
AbnormalTerminatedParser::class => new Definition(AbnormalTerminatedParser::class, [
new Reference('paraunit.test_result.abnormal_terminated_container'),
new Reference(ChunkSize::class),
LogFetcher::LOG_ENDING_STATUS,
TestStatus::LogTerminated,
]),
UnknownResultParser::class => new Definition(UnknownResultParser::class, [
new Reference('paraunit.test_result.unknown_container'),
'',
]),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ private function getFormatDefinitions(): array
'fail',
'failures',
]),
'warning' => new Definition(TestResultWithSymbolFormat::class, [
'W',
'warning' => new Definition(TestResultFormat::class, [
'warning',
'warnings',
]),
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 XDEBUG_MODE = 'XDEBUG_MODE';
}
4 changes: 2 additions & 2 deletions src/Configuration/register_subscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Paraunit\Parser\JSON\TestHook;
use Paraunit\Parser\TestHook;
use PHPUnit\Event\Facade;

// TODO - wait for feedback and refactor accordingly
Expand All @@ -15,5 +15,5 @@
Facade::registerSubscriber(new TestHook\Incomplete());
Facade::registerSubscriber(new TestHook\Risky());
Facade::registerSubscriber(new TestHook\Skipped());
Facade::registerSubscriber(new TestHook\Successful());
Facade::registerSubscriber(new TestHook\Passed());
Facade::registerSubscriber(new TestHook\Warning());
12 changes: 12 additions & 0 deletions src/Coverage/CoverageDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Paraunit\Coverage;

enum CoverageDriver
{
case Xdebug;
case Pcov;
case PHPDbg;
}
11 changes: 4 additions & 7 deletions src/Parser/DeprecationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
namespace Paraunit\Parser;

use Paraunit\Lifecycle\ProcessParsingCompleted;
use Paraunit\Parser\ValueObject\Test;
use Paraunit\Process\AbstractParaunitProcess;
use Paraunit\TestResult\Interfaces\TestResultHandlerInterface;
use Paraunit\TestResult\TestResultWithMessage;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class DeprecationParser implements EventSubscriberInterface
{
/** @var TestResultHandlerInterface */
private $testResultContainer;

public function __construct(TestResultHandlerInterface $testResultContainer)
public function __construct(private readonly TestResultHandlerInterface $testResultContainer)
{
$this->testResultContainer = $testResultContainer;
}

/**
Expand All @@ -38,7 +35,7 @@ public function handleDeprecations(ProcessParsingCompleted $event): void
return;
}

if (strpos($process->getOutput(), 'deprecation') !== false) {
if (str_contains($process->getOutput(), 'deprecation')) {
$testResult = $this->createTestResult($process);
$this->testResultContainer->handleTestResult($process, $testResult);
}
Expand All @@ -47,7 +44,7 @@ public function handleDeprecations(ProcessParsingCompleted $event): void
private function createTestResult(AbstractParaunitProcess $process): TestResultWithMessage
{
return new TestResultWithMessage(
$process->getTestClassName() ?? $process->getFilename(),
new Test($process->getTestClassName() ?? $process->getFilename()),
$process->getOutput()
);
}
Expand Down
26 changes: 13 additions & 13 deletions src/Parser/JSON/AbnormalTerminatedParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace Paraunit\Parser\JSON;

use Paraunit\Configuration\ChunkSize;
use Paraunit\Parser\ValueObject\LogData;
use Paraunit\Parser\ValueObject\Test;
use Paraunit\Parser\ValueObject\TestStatus;
use Paraunit\Process\AbstractParaunitProcess;
use Paraunit\TestResult\Interfaces\TestResultHandlerInterface;
use Paraunit\TestResult\Interfaces\TestResultInterface;
Expand All @@ -13,23 +16,19 @@

class AbnormalTerminatedParser extends GenericParser
{
/** @var ChunkSize */
private $chunkSize;

/** @var string */
private $lastStartedTest = '[UNKNOWN]';
private Test $lastStartedTest;

public function __construct(
TestResultHandlerInterface $testResultHandler,
ChunkSize $chunkSize
private readonly ChunkSize $chunkSize,
) {
parent::__construct($testResultHandler, LogFetcher::LOG_ENDING_STATUS);
$this->chunkSize = $chunkSize;
parent::__construct($testResultHandler, TestStatus::LogTerminated);
$this->lastStartedTest = Test::unknown();
}

public function handleLogItem(AbstractParaunitProcess $process, Log $logItem): ?TestResultInterface
public function handleLogItem(AbstractParaunitProcess $process, LogData $logItem): ?TestResultInterface
{
if ($logItem->getStatus() === Log::STATUS_TEST_START) {
if ($logItem->status === TestStatus::Prepared) {
$process->setWaitingForTestResult(true);
$this->saveTestFQCN($process, $logItem);

Expand All @@ -51,9 +50,9 @@ public function handleLogItem(AbstractParaunitProcess $process, Log $logItem): ?
return null;
}

private function saveTestFQCN(AbstractParaunitProcess $process, Log $logItem): void
private function saveTestFQCN(AbstractParaunitProcess $process, LogData $logItem): void
{
$this->lastStartedTest = $logItem->getTest();
$this->lastStartedTest = $logItem->test;

if ($process->getTestClassName()) {
return;
Expand All @@ -62,8 +61,9 @@ private function saveTestFQCN(AbstractParaunitProcess $process, Log $logItem): v
if ($this->chunkSize->isChunked()) {
$suiteName = basename($process->getFilename());
} else {
$suiteName = explode('::', $logItem->getTest())[0];
$suiteName = explode('::', $logItem->test->name)[0];
}

$process->setTestClassName($suiteName);
}
}
32 changes: 12 additions & 20 deletions src/Parser/JSON/GenericParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Paraunit\Parser\JSON;

use Paraunit\Parser\ValueObject\LogData;
use Paraunit\Parser\ValueObject\TestStatus;
use Paraunit\Process\AbstractParaunitProcess;
use Paraunit\TestResult\Interfaces\TestResultHandlerInterface;
use Paraunit\TestResult\Interfaces\TestResultInterface;
Expand All @@ -12,27 +14,19 @@

class GenericParser implements ParserChainElementInterface
{
/** @var TestResultHandlerInterface */
protected $testResultContainer;

/** @var string */
protected $status;

/**
* @param string $status The status that the parser should catch
* @param TestStatus $status The status that the parser should catch
*/
public function __construct(
TestResultHandlerInterface $testResultContainer,
string $status
protected readonly TestResultHandlerInterface $testResultContainer,
protected readonly TestStatus $status,
) {
$this->testResultContainer = $testResultContainer;
$this->status = $status;
}

/**
* {@inheritdoc}
*/
public function handleLogItem(AbstractParaunitProcess $process, Log $logItem): ?TestResultInterface
public function handleLogItem(AbstractParaunitProcess $process, LogData $logItem): ?TestResultInterface
{
if ($this->logMatches($logItem)) {
$testResult = $this->createFromLog($logItem);
Expand All @@ -45,19 +39,17 @@ public function handleLogItem(AbstractParaunitProcess $process, Log $logItem): ?
return null;
}

protected function logMatches(Log $log): bool
protected function logMatches(LogData $log): bool
{
return $log->getStatus() === $this->status;
return $log->status === $this->status;
}

private function createFromLog(Log $logItem): TestResultInterface
protected function createFromLog(LogData $logItem): TestResultInterface
{
$message = $logItem->getMessage();

if ($message) {
return new TestResultWithMessage($logItem->getTest(), $message);
if ($logItem->message) {
return new TestResultWithMessage($logItem->test, $logItem->message);
}

return new MuteTestResult($logItem->getTest());
return new MuteTestResult($logItem->test);
}
}
55 changes: 0 additions & 55 deletions src/Parser/JSON/Log.php

This file was deleted.

Loading