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

Use new config data when Infection has been executed in a first time (without .json or json.dist) #577

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Command/BaseCommand.php
Expand Up @@ -74,8 +74,6 @@ public function getContainer(): Container

protected function initialize(InputInterface $input, OutputInterface $output): void
{
parent::initialize($input, $output);

$this->input = $input;
$this->output = $output;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Command/InfectionCommand.php
Expand Up @@ -362,10 +362,9 @@ 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');

$args = [
'--test-framework' => $this->input->getOption('test-framework') ?: $config->getTestFramework(),
'--test-framework' => $this->input->getOption('test-framework') ?: TestFrameworkTypes::PHPUNIT,
maks-rafalko marked this conversation as resolved.
Show resolved Hide resolved
];

$newInput = new ArrayInput($args);
Expand Down
3 changes: 2 additions & 1 deletion src/Config/InfectionConfig.php
Expand Up @@ -35,6 +35,7 @@

namespace Infection\Config;

use Infection\TestFramework\TestFrameworkTypes;
use Symfony\Component\Filesystem\Filesystem;

/**
Expand Down Expand Up @@ -152,7 +153,7 @@ public function getBootstrap(): string

public function getTestFramework(): string
{
return $this->config->testFramework ?? 'phpunit';
return $this->config->testFramework ?? TestFrameworkTypes::PHPUNIT;
}

public function getInitialTestsPhpOptions(): string
Expand Down
15 changes: 15 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/composer.json
@@ -0,0 +1,15 @@
{
"require-dev": {
"phpunit/phpunit": "^6.5"
},
"autoload": {
"psr-4": {
"Initial_Configuration\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Initial_Configuration\\Test\\": "tests/"
}
}
}
22 changes: 22 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/do_configure.expect
@@ -0,0 +1,22 @@
#!/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 "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
@@ -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
@@ -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>./src/</directory>
</whitelist>
</filter>
</phpunit>
25 changes: 25 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/run_tests.bash
@@ -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 -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
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Infection\Tests\Fixtures\e2e\Initial_Configuration\skipped_src;

class IgnoredSourceClass
{
public function doSmth()
{
return 10;
}
}
11 changes: 11 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/src/SourceClass.php
@@ -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/tests/SourceClassTest.php
@@ -0,0 +1,15 @@
<?php

namespace Initial_Configuration\Test;

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

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