Skip to content

Commit

Permalink
Use new config data when Infection has been executed at the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Mar 4, 2019
1 parent b956858 commit 38fb93c
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Command/InfectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private function runConfigurationCommand(Locator $locator): void
$locator->locateOneOf(InfectionConfig::POSSIBLE_CONFIG_FILE_NAMES);
} catch (\Exception $e) {
$configureCommand = $this->getApplication()->find('configure');
$config = $this->getContainer()->get('infection.config');
$config = $this->getContainer()->get('infection.config.initial');

$args = [
'--test-framework' => $this->input->getOption('test-framework') ?: $config->getTestFramework(),
Expand Down
9 changes: 8 additions & 1 deletion src/Console/InfectionContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,19 @@ public function __construct(array $values = [])

public function buildDynamicDependencies(InputInterface $input): void
{
$this['infection.config'] = function () use ($input): InfectionConfig {
$infectionConfigMaker = function () use ($input): InfectionConfig {
$facade = new ConfigCreatorFacade($this['locator'], $this['filesystem']);

return $facade->createConfig($input->getOption('configuration'));
};

/*
* Configuration step needs a distinct instance of a configuration as it may be inexistent.
* Therefore we can avoid using this stale and invalid configuration later on.
*/
$this['infection.config.initial'] = $infectionConfigMaker;
$this['infection.config'] = $infectionConfigMaker;

$this['coverage.path'] = function () use ($input): string {
$existingCoveragePath = '';

Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/e2e/Initial_Configuration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./infection.json*
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Initial_Configuration;

class SourceClass
{
public function hello(): string
{
return 'hello';
}
}
15 changes: 15 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"require-dev": {
"phpunit/phpunit": "^6.5"
},
"autoload": {
"psr-4": {
"Initial_Configuration\\": "Initial_Configuration/"
}
},
"autoload-dev": {
"psr-0": {
"Initial_Configuration": "tests/"
}
}
}
28 changes: 28 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/do_configure.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env expect
set timeout 20
eval spawn $env(INFECTION)

proc configure { input value } {
expect $input {
send $value
} timeout {
send_user "Test failed\n"
exit 1
}
}

configure "directories do you want to include" "2\r"
configure "Any directories to exclude from" "\r"
configure "timeout in seconds" "\r"
configure "text log file?" "\r"

expect {
"does not exist" {
close
exit 1
}
"Please note that some mutants will inevitably be harmless"
}

send_user "Test succeeded!\n"
exit 0
8 changes: 8 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/expected.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Escaped mutants:
================

Timed Out mutants:
==================

Not Covered mutants:
====================
18 changes: 18 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">Initial_Configuration/</directory>
</whitelist>
</filter>
</phpunit>
25 changes: 25 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/run_tests.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

if test ! -f "$(which expect)"; then
test -x $(which tput) && tput setaf 1 # red
echo "Please install expect; it is readily available from apt and brew"
exit 1;
fi

cd $(dirname $0)
rm -v -f infection.json.dist infection.log

set -e

if [ "$PHPDBG" = "1" ]
then
INFECTION="phpdbg -qrr ../../../../bin/infection"
else
INFECTION="php ../../../../bin/infection"
fi
export INFECTION

./do_configure.expect

test -f infection.log
diff -u expected.log infection.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use Initial_Configuration\SourceClass;
use PHPUnit\Framework\TestCase;

class Initial_Configuration_Test extends TestCase
{
public function test_hello()
{
$sourceClass = new SourceClass();
$this->assertSame('hello', $sourceClass->hello());
}
}

0 comments on commit 38fb93c

Please sign in to comment.