Skip to content

Commit

Permalink
Merge branch 'master' into fix/anonymous-class
Browse files Browse the repository at this point in the history
  • Loading branch information
BackEndTea committed Feb 12, 2019
2 parents 87b9e96 + 92c66b9 commit 8dca727
Show file tree
Hide file tree
Showing 21 changed files with 1,079 additions and 18 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;
}
}
7 changes: 7 additions & 0 deletions .travis.yml
Expand Up @@ -108,6 +108,11 @@ jobs:
<<: *STANDARD_TEST_JOB
php: 7.3
env: PHPDBG=1

-
<<: *STANDARD_TEST_JOB
php: 7.4snapshot
env: PHPDBG=1

-
<<: *STANDARD_TEST_JOB
Expand Down Expand Up @@ -149,3 +154,5 @@ jobs:
allow_failures:
- php: nightly
env: PHPDBG=1
- php: 7.4snapshot
env: PHPDBG=1
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
20 changes: 10 additions & 10 deletions src/Finder/TestFrameworkFinder.php
Expand Up @@ -134,23 +134,23 @@ private function findTestFramework(): string
return $this->customPath;
}

$candidates = [];
/*
* There's a glitch where ExecutableFinder would find a non-executable
* file on Windows, even if there's a proper executable .bat by its side.
* Therefore we have to explicitly look for a .bat first.
*/
$candidates = [
$this->testFrameworkName . '.bat',
$this->testFrameworkName,
$this->testFrameworkName . '.phar',
];

if ($this->testFrameworkName === TestFrameworkTypes::PHPUNIT) {
$candidates[] = 'simple-phpunit.bat';
$candidates[] = 'simple-phpunit';
$candidates[] = 'simple-phpunit.phar';
}

/*
* There's a glitch where ExecutableFinder would find a non-executable
* file on Windows, even if there's a proper executable .bat by its side.
* Therefore we have to explicitly look for a .bat first.
*/
$candidates[] = $this->testFrameworkName . '.bat';
$candidates[] = $this->testFrameworkName;
$candidates[] = $this->testFrameworkName . '.phar';

$finder = new ExecutableFinder();

$cwd = getcwd();
Expand Down
54 changes: 54 additions & 0 deletions src/Mutator/Unwrap/UnwrapArrayUdiff.php
@@ -0,0 +1,54 @@
<?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\Mutator\Unwrap;

use PhpParser\Node;

/**
* @internal
*/
final class UnwrapArrayUdiff extends AbstractUnwrapMutator
{
protected function getFunctionName(): string
{
return 'array_udiff';
}

protected function getParameterIndexes(Node $node): \Generator
{
yield 0;
}
}
54 changes: 54 additions & 0 deletions src/Mutator/Unwrap/UnwrapArrayUdiffUassoc.php
@@ -0,0 +1,54 @@
<?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\Mutator\Unwrap;

use PhpParser\Node;

/**
* @internal
*/
final class UnwrapArrayUdiffUassoc extends AbstractUnwrapMutator
{
protected function getFunctionName(): string
{
return 'array_udiff_uassoc';
}

protected function getParameterIndexes(Node $node): \Generator
{
yield 0;
}
}
4 changes: 4 additions & 0 deletions src/Mutator/Util/MutatorProfile.php
Expand Up @@ -213,7 +213,9 @@ final class MutatorProfile
Mutator\Unwrap\UnwrapArrayReverse::class,
Mutator\Unwrap\UnwrapArraySlice::class,
Mutator\Unwrap\UnwrapArraySplice::class,
Mutator\Unwrap\UnwrapArrayUdiff::class,
Mutator\Unwrap\UnwrapArrayUdiffAssoc::class,
Mutator\Unwrap\UnwrapArrayUdiffUassoc::class,
Mutator\Unwrap\UnwrapArrayUnique::class,
Mutator\Unwrap\UnwrapArrayValues::class,
Mutator\Unwrap\UnwrapStrRepeat::class,
Expand Down Expand Up @@ -367,7 +369,9 @@ final class MutatorProfile
'UnwrapArrayReverse' => Mutator\Unwrap\UnwrapArrayReverse::class,
'UnwrapArraySlice' => Mutator\Unwrap\UnwrapArraySlice::class,
'UnwrapArraySplice' => Mutator\Unwrap\UnwrapArraySplice::class,
'UnwrapArrayUdiff' => Mutator\Unwrap\UnwrapArrayUdiff::class,
'UnwrapArrayUdiffAssoc' => Mutator\Unwrap\UnwrapArrayUdiffAssoc::class,
'UnwrapArrayUdiffUassoc' => Mutator\Unwrap\UnwrapArrayUdiffUassoc::class,
'UnwrapArrayUnique' => Mutator\Unwrap\UnwrapArrayUnique::class,
'UnwrapArrayValues' => Mutator\Unwrap\UnwrapArrayValues::class,
'UnwrapStrRepeat' => Mutator\Unwrap\UnwrapStrRepeat::class,
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
),
]);
}
}

0 comments on commit 8dca727

Please sign in to comment.