Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into mutator/mbstring
Browse files Browse the repository at this point in the history
  • Loading branch information
majkel89 committed Mar 30, 2019
2 parents 2205316 + 16958e6 commit 4dadcf2
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 58 deletions.
1 change: 1 addition & 0 deletions infection.json.dist
Expand Up @@ -12,6 +12,7 @@
}
},
"mutators": {
"@default": true,
"MethodCallRemoval": {
"ignore": [
"Infection\\Finder\\SourceFilesFinder::__construct::63"
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,
];

$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
4 changes: 4 additions & 0 deletions src/Json/JsonFile.php
Expand Up @@ -71,6 +71,10 @@ public function decode(): \stdClass

private function parse(): void
{
if (!is_file($this->path)) {
throw ParseException::invalidJson($this->path, 'file not found');
}

$data = json_decode((string) file_get_contents($this->path));

if (null === $data && JSON_ERROR_NONE !== json_last_error()) {
Expand Down
20 changes: 4 additions & 16 deletions src/Mutator/FunctionSignature/ProtectedVisibility.php
Expand Up @@ -95,22 +95,10 @@ private function hasSameProtectedParentMethod(Node $node): bool
return true;
}

$parent = $reflection->getParentClass();

while ($parent) {
try {
$method = $parent->getMethod($node->name->name);

if ($method->isProtected()) {
return true;
}
} catch (\ReflectionException $e) {
return false;
} finally {
$parent = $parent->getParentClass();
}
try {
return $reflection->getMethod($node->name->name)->getPrototype()->isProtected();
} catch (\ReflectionException $e) {
return false;
}

return false;
}
}
43 changes: 4 additions & 39 deletions src/Mutator/FunctionSignature/PublicVisibility.php
Expand Up @@ -95,45 +95,10 @@ private function hasSamePublicParentMethod(Node $node): bool
return true;
}

return $this->hasSamePublicMethodInInterface($node, $reflection) || $this->hasSamePublicMethodInParentClass($node, $reflection);
}

private function hasSamePublicMethodInInterface(Node $node, \ReflectionClass $reflection): bool
{
foreach ($reflection->getInterfaces() as $reflectionInterface) {
try {
$method = $reflectionInterface->getMethod($node->name->name);

if ($method->isPublic()) {
// we can't mutate because interface requires the same public visibility
return true;
}
} catch (\ReflectionException $e) {
continue;
}
}

return false;
}

private function hasSamePublicMethodInParentClass(Node $node, \ReflectionClass $reflection): bool
{
$parent = $reflection->getParentClass();

while ($parent) {
try {
$method = $parent->getMethod($node->name->name);

if ($method->isPublic()) {
return true;
}
} catch (\ReflectionException $e) {
return false;
} finally {
$parent = $parent->getParentClass();
}
try {
return $reflection->getMethod($node->name->name)->getPrototype()->isPublic();
} catch (\ReflectionException $e) {
return false;
}

return false;
}
}
1 change: 1 addition & 0 deletions tests/Fixtures/e2e/Initial_Configuration/.gitignore
@@ -0,0 +1 @@
/infection.json*
@@ -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
@@ -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
@@ -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" "1\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 "\nTest succeeded!\n"
exit 0
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 suffix=".php">Initial_Configuration/</directory>
</whitelist>
</filter>
</phpunit>
26 changes: 26 additions & 0 deletions tests/Fixtures/e2e/Initial_Configuration/run_tests.bash
@@ -0,0 +1,26 @@
#!/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

trap 'echo Final check failed: $(tail -n+$LINENO $0 | head -n1)' ERR

test -f infection.json.dist
@@ -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());
}
}
10 changes: 10 additions & 0 deletions tests/Json/JsonFileTest.php
Expand Up @@ -101,6 +101,16 @@ public function test_it_throws_parse_exception_with_invalid_json(): void
(new JsonFile($jsonPath))->decode();
}

public function test_it_throws_parse_exception_when_file_is_not_found(): void
{
$jsonPath = $this->tmpDir . '/missing-invalid.json';
self::assertFileNotExists($jsonPath);

self::expectException(ParseException::class);

(new JsonFile($jsonPath))->decode();
}

public function test_it_throws_schema_validation_exception(): void
{
$jsonString = '{"timeout": 25}';
Expand Down

0 comments on commit 4dadcf2

Please sign in to comment.