diff --git a/infection.json.dist b/infection.json.dist index e6852ad96..8188b4511 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -12,6 +12,7 @@ } }, "mutators": { + "@default": true, "MethodCallRemoval": { "ignore": [ "Infection\\Finder\\SourceFilesFinder::__construct::63" diff --git a/src/Command/InfectionCommand.php b/src/Command/InfectionCommand.php index fcc82a668..2ac1cf8ae 100644 --- a/src/Command/InfectionCommand.php +++ b/src/Command/InfectionCommand.php @@ -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); diff --git a/src/Config/InfectionConfig.php b/src/Config/InfectionConfig.php index 152e19d75..7a65eba23 100644 --- a/src/Config/InfectionConfig.php +++ b/src/Config/InfectionConfig.php @@ -35,6 +35,7 @@ namespace Infection\Config; +use Infection\TestFramework\TestFrameworkTypes; use Symfony\Component\Filesystem\Filesystem; /** @@ -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 diff --git a/src/Json/JsonFile.php b/src/Json/JsonFile.php index e98bb5f7c..7939a3f07 100644 --- a/src/Json/JsonFile.php +++ b/src/Json/JsonFile.php @@ -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()) { diff --git a/src/Mutator/FunctionSignature/ProtectedVisibility.php b/src/Mutator/FunctionSignature/ProtectedVisibility.php index 5c55917f7..c1375d460 100644 --- a/src/Mutator/FunctionSignature/ProtectedVisibility.php +++ b/src/Mutator/FunctionSignature/ProtectedVisibility.php @@ -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; } } diff --git a/src/Mutator/FunctionSignature/PublicVisibility.php b/src/Mutator/FunctionSignature/PublicVisibility.php index df7c09a33..2f0244fee 100644 --- a/src/Mutator/FunctionSignature/PublicVisibility.php +++ b/src/Mutator/FunctionSignature/PublicVisibility.php @@ -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; } } diff --git a/tests/Fixtures/e2e/Initial_Configuration/.gitignore b/tests/Fixtures/e2e/Initial_Configuration/.gitignore new file mode 100644 index 000000000..564f7c1a0 --- /dev/null +++ b/tests/Fixtures/e2e/Initial_Configuration/.gitignore @@ -0,0 +1 @@ +/infection.json* diff --git a/tests/Fixtures/e2e/Initial_Configuration/Initial_Configuration/SourceClass.php b/tests/Fixtures/e2e/Initial_Configuration/Initial_Configuration/SourceClass.php new file mode 100644 index 000000000..97f01f9ac --- /dev/null +++ b/tests/Fixtures/e2e/Initial_Configuration/Initial_Configuration/SourceClass.php @@ -0,0 +1,11 @@ + + + + + ./tests/ + + + + + + Initial_Configuration/ + + + diff --git a/tests/Fixtures/e2e/Initial_Configuration/run_tests.bash b/tests/Fixtures/e2e/Initial_Configuration/run_tests.bash new file mode 100755 index 000000000..6f76dea43 --- /dev/null +++ b/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 diff --git a/tests/Fixtures/e2e/Initial_Configuration/tests/Initial_Configuration_Test.php b/tests/Fixtures/e2e/Initial_Configuration/tests/Initial_Configuration_Test.php new file mode 100644 index 000000000..47b486b42 --- /dev/null +++ b/tests/Fixtures/e2e/Initial_Configuration/tests/Initial_Configuration_Test.php @@ -0,0 +1,13 @@ +assertSame('hello', $sourceClass->hello()); + } +} diff --git a/tests/Json/JsonFileTest.php b/tests/Json/JsonFileTest.php index 6fdbb9b26..96bbab908 100644 --- a/tests/Json/JsonFileTest.php +++ b/tests/Json/JsonFileTest.php @@ -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}';