Skip to content

Commit

Permalink
Merge branch '0.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Feb 10, 2019
2 parents 80b1777 + 0c028b4 commit 6d6e467
Show file tree
Hide file tree
Showing 12 changed files with 538 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .ci/travis-functions.sh
Expand Up @@ -32,4 +32,4 @@ function get-infection-pr-flags() {
fi

echo $INFECTION_PR_FLAGS;
}
}
6 changes: 6 additions & 0 deletions src/Command/InfectionCommand.php
Expand Up @@ -120,6 +120,12 @@ protected function configure(): void
InputOption::VALUE_NONE,
'Show mutations to the console'
)
->addOption(
'no-progress',
null,
InputOption::VALUE_NONE,
'Do not output progress bars'
)
->addOption(
'configuration',
'c',
Expand Down
44 changes: 41 additions & 3 deletions src/Process/Builder/SubscriberBuilder.php
Expand Up @@ -41,11 +41,15 @@
use Infection\Console\OutputFormatter\ProgressFormatter;
use Infection\Differ\DiffColorizer;
use Infection\EventDispatcher\EventDispatcherInterface;
use Infection\EventDispatcher\EventSubscriberInterface;
use Infection\Mutant\MetricsCalculator;
use Infection\Performance\Listener\PerformanceLoggerSubscriber;
use Infection\Performance\Memory\MemoryFormatter;
use Infection\Performance\Time\TimeFormatter;
use Infection\Performance\Time\Timer;
use Infection\Process\Listener\CiInitialTestsConsoleLoggerSubscriber;
use Infection\Process\Listener\CiMutantCreatingConsoleLoggerSubscriber;
use Infection\Process\Listener\CiMutationGeneratingConsoleLoggerSubscriber;
use Infection\Process\Listener\CleanUpAfterMutationTestingFinishedSubscriber;
use Infection\Process\Listener\InitialTestsConsoleLoggerSubscriber;
use Infection\Process\Listener\MutantCreatingConsoleLoggerSubscriber;
Expand Down Expand Up @@ -150,9 +154,9 @@ private function getSubscribers(
OutputInterface $output
): array {
$subscribers = [
new InitialTestsConsoleLoggerSubscriber($output, $testFrameworkAdapter),
new MutationGeneratingConsoleLoggerSubscriber($output),
new MutantCreatingConsoleLoggerSubscriber($output),
$this->getInitialTestsConsoleLoggerSubscriber($testFrameworkAdapter, $output),
$this->getMutantGeneratingConsoleLoggerSubscriber($output),
$this->getMutantCreatingConsoleLoggerSubscriber($output),
new MutationTestingConsoleLoggerSubscriber(
$output,
$this->getOutputFormatter($output),
Expand Down Expand Up @@ -199,4 +203,38 @@ private function getOutputFormatter(OutputInterface $output): OutputFormatter

throw new \InvalidArgumentException('Incorrect formatter. Possible values: "dot", "progress"');
}

private function getMutantCreatingConsoleLoggerSubscriber(OutputInterface $output): EventSubscriberInterface
{
if ($this->shouldSkipProgressBars()) {
return new CiMutantCreatingConsoleLoggerSubscriber($output);
}

return new MutantCreatingConsoleLoggerSubscriber($output);
}

private function getMutantGeneratingConsoleLoggerSubscriber(OutputInterface $output): EventSubscriberInterface
{
if ($this->shouldSkipProgressBars()) {
return new CiMutationGeneratingConsoleLoggerSubscriber($output);
}

return new MutationGeneratingConsoleLoggerSubscriber($output);
}

private function getInitialTestsConsoleLoggerSubscriber(AbstractTestFrameworkAdapter $testFrameworkAdapter, OutputInterface $output): EventSubscriberInterface
{
if ($this->shouldSkipProgressBars()) {
return new CiInitialTestsConsoleLoggerSubscriber($output, $testFrameworkAdapter);
}

return new InitialTestsConsoleLoggerSubscriber($output, $testFrameworkAdapter);
}

private function shouldSkipProgressBars(): bool
{
return $this->input->getOption('no-progress')
|| getenv('CI') === 'true'
|| getenv('CONTINUOUS_INTEGRATION') === 'true';
}
}
89 changes: 89 additions & 0 deletions src/Process/Listener/CiInitialTestsConsoleLoggerSubscriber.php
@@ -0,0 +1,89 @@
<?php
/**
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2017-2019, Maks Rafalko
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

declare(strict_types=1);

namespace Infection\Process\Listener;

use Infection\EventDispatcher\EventSubscriberInterface;
use Infection\Events\InitialTestSuiteStarted;
use Infection\TestFramework\AbstractTestFrameworkAdapter;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
final class CiInitialTestsConsoleLoggerSubscriber implements EventSubscriberInterface
{
/**
* @var OutputInterface
*/
private $output;

/**
* @var AbstractTestFrameworkAdapter
*/
private $testFrameworkAdapter;

public function __construct(OutputInterface $output, AbstractTestFrameworkAdapter $testFrameworkAdapter)
{
$this->output = $output;
$this->testFrameworkAdapter = $testFrameworkAdapter;
}

public function getSubscribedEvents(): array
{
return [
InitialTestSuiteStarted::class => [$this, 'onInitialTestSuiteStarted'],
];
}

public function onInitialTestSuiteStarted(InitialTestSuiteStarted $event): void
{
try {
$version = $this->testFrameworkAdapter->getVersion();
} catch (\InvalidArgumentException $e) {
$version = 'unknown';
}

$this->output->writeln([
'Running initial test suite...',
'',
sprintf(
'%s version: %s',
$this->testFrameworkAdapter->getName(),
$version
),
]);
}
}
71 changes: 71 additions & 0 deletions src/Process/Listener/CiMutantCreatingConsoleLoggerSubscriber.php
@@ -0,0 +1,71 @@
<?php
/**
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2017-2019, Maks Rafalko
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

declare(strict_types=1);

namespace Infection\Process\Listener;

use Infection\EventDispatcher\EventSubscriberInterface;
use Infection\Events\MutantsCreatingStarted;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
final class CiMutantCreatingConsoleLoggerSubscriber implements EventSubscriberInterface
{
/**
* @var OutputInterface
*/
private $output;

public function __construct(OutputInterface $output)
{
$this->output = $output;
}

public function getSubscribedEvents(): array
{
return [
MutantsCreatingStarted::class => [$this, 'onMutantsCreatingStarted'],
];
}

public function onMutantsCreatingStarted(MutantsCreatingStarted $event): void
{
$this->output->writeln([
'',
sprintf('Creating mutated files and processes: %s', $event->getMutantCount()),
]);
}
}
@@ -0,0 +1,73 @@
<?php
/**
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2017-2019, Maks Rafalko
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

declare(strict_types=1);

namespace Infection\Process\Listener;

use Infection\EventDispatcher\EventSubscriberInterface;
use Infection\Events\MutationGeneratingStarted;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
final class CiMutationGeneratingConsoleLoggerSubscriber implements EventSubscriberInterface
{
/**
* @var OutputInterface
*/
private $output;

public function __construct(OutputInterface $output)
{
$this->output = $output;
}

public function getSubscribedEvents(): array
{
return [
MutationGeneratingStarted::class => [$this, 'onMutationGeneratingStarted'],
];
}

public function onMutationGeneratingStarted(MutationGeneratingStarted $event): void
{
$this->output->writeln([
'',
'Generate mutants...',
'',
sprintf('Processing source code files: %s', $event->getMutableFilesCount()),
]);
}
}
2 changes: 1 addition & 1 deletion src/TestFramework/AbstractTestFrameworkAdapter.php
Expand Up @@ -198,7 +198,7 @@ public function getVersion(): string

$process->mustRun();

$version = null;
$version = 'unknown';

try {
$version = $this->versionParser->parse($process->getOutput());
Expand Down
4 changes: 4 additions & 0 deletions tests/Console/E2ETest.php
Expand Up @@ -67,6 +67,10 @@ final class E2ETest extends TestCase

protected function setUp(): void
{
if (\PHP_SAPI === 'phpdbg') {
$this->markTestSkipped('Running this test on PHPDBG causes failures on Travis, see https://github.com/infection/infection/pull/622.');
}

// Without overcommit this test fails with `proc_open(): fork failed - Cannot allocate memory`
if (strpos(PHP_OS, 'Linux') === 0 &&
is_readable('/proc/sys/vm/overcommit_memory') &&
Expand Down
9 changes: 6 additions & 3 deletions tests/Process/Builder/SubscriberBuilderTest.php
Expand Up @@ -57,10 +57,11 @@ final class SubscriberBuilderTest extends TestCase
public function test_it_registers_the_subscribers_when_debugging(): void
{
$input = $this->createMock(InputInterface::class);
$input->expects($this->exactly(6))
$input->expects($this->exactly(9))
->method('getOption')
->will($this->returnValueMap(
[
['ci-friendly', false],
['formatter', 'progress'],
['show-mutations', true],
['log-verbosity', 'all'],
Expand Down Expand Up @@ -94,10 +95,11 @@ public function test_it_registers_the_subscribers_when_debugging(): void
public function test_it_registers_the_subscribers_when_not_debugging(): void
{
$input = $this->createMock(InputInterface::class);
$input->expects($this->exactly(6))
$input->expects($this->exactly(9))
->method('getOption')
->will($this->returnValueMap(
[
['ci-friendly', false],
['formatter', 'progress'],
['show-mutations', true],
['log-verbosity', 'all'],
Expand Down Expand Up @@ -131,10 +133,11 @@ public function test_it_registers_the_subscribers_when_not_debugging(): void
public function test_it_throws_an_exception_when_output_formatter_is_invalid(): void
{
$input = $this->createMock(InputInterface::class);
$input->expects($this->exactly(2))
$input->expects($this->exactly(5))
->method('getOption')
->will($this->returnValueMap(
[
['ci-friendly', false],
['formatter', 'foo'],
['show-mutations', true],
]
Expand Down

0 comments on commit 6d6e467

Please sign in to comment.