diff --git a/tests/Console/E2ETest.php b/tests/Console/E2ETest.php index fbe4aa2a6..039c36d89 100644 --- a/tests/Console/E2ETest.php +++ b/tests/Console/E2ETest.php @@ -216,7 +216,7 @@ private function installComposerDeps(): void */ /* - * E2E tests are expected to follow PSR-4. + * E2E tests are expected to follow PSR-0 or PSR-4. * * We exploit this to autoload only classes belonging to the test, * but not to vendored deps (so we don't need them here, but to run @@ -243,6 +243,19 @@ private function installComposerDeps(): void $loader->setPsr4($namespace, $paths); } + $mapPsr0 = require 'vendor/composer/autoload_namespaces.php'; + + foreach ($mapPsr0 as $namespace => $paths) { + foreach ($paths as $path) { + if (strpos($path, $vendorDir) !== false) { + // Skip known dependency from autoloading + continue 2; + } + } + + $loader->set($namespace, $paths); + } + $loader->register($prepend = false); // Note: not prepending, but appending to our autoloader $this->previousLoader = $loader; diff --git a/tests/Fixtures/e2e/PSR_0_Autoloader/README.md b/tests/Fixtures/e2e/PSR_0_Autoloader/README.md new file mode 100644 index 000000000..3c542ab48 --- /dev/null +++ b/tests/Fixtures/e2e/PSR_0_Autoloader/README.md @@ -0,0 +1,5 @@ +# PSR-0 test + +* Related to https://github.com/infection/infection/issues/564 + +This test checks that Infection correctly works with PSR-0 compliant autoloader diff --git a/tests/Fixtures/e2e/PSR_0_Autoloader/composer.json b/tests/Fixtures/e2e/PSR_0_Autoloader/composer.json new file mode 100644 index 000000000..47a6ad56e --- /dev/null +++ b/tests/Fixtures/e2e/PSR_0_Autoloader/composer.json @@ -0,0 +1,15 @@ +{ + "require-dev": { + "phpunit/phpunit": "^6.5" + }, + "autoload": { + "psr-0": { + "PSR_0_Autoloader": "src/" + } + }, + "autoload-dev": { + "psr-0": { + "PSR_0_Autoloader\\Tests": "tests/" + } + } +} diff --git a/tests/Fixtures/e2e/PSR_0_Autoloader/expected-output.txt b/tests/Fixtures/e2e/PSR_0_Autoloader/expected-output.txt new file mode 100644 index 000000000..99606b97d --- /dev/null +++ b/tests/Fixtures/e2e/PSR_0_Autoloader/expected-output.txt @@ -0,0 +1,6 @@ +Total: 1 +Killed: 1 +Errored: 0 +Escaped: 0 +Timed Out: 0 +Not Covered: 0 \ No newline at end of file diff --git a/tests/Fixtures/e2e/PSR_0_Autoloader/infection.json b/tests/Fixtures/e2e/PSR_0_Autoloader/infection.json new file mode 100644 index 000000000..7029746fb --- /dev/null +++ b/tests/Fixtures/e2e/PSR_0_Autoloader/infection.json @@ -0,0 +1,12 @@ +{ + "timeout": 25, + "source": { + "directories": [ + "src" + ] + }, + "logs": { + "summary": "infection.log" + }, + "tmpDir": "." +} diff --git a/tests/Fixtures/e2e/PSR_0_Autoloader/phpunit.xml b/tests/Fixtures/e2e/PSR_0_Autoloader/phpunit.xml new file mode 100644 index 000000000..9a836774d --- /dev/null +++ b/tests/Fixtures/e2e/PSR_0_Autoloader/phpunit.xml @@ -0,0 +1,18 @@ + + + + + ./tests/ + + + + + + ./src/ + + + diff --git a/tests/Fixtures/e2e/PSR_0_Autoloader/src/PSR_0_Autoloader/SourceClass.php b/tests/Fixtures/e2e/PSR_0_Autoloader/src/PSR_0_Autoloader/SourceClass.php new file mode 100644 index 000000000..a97e5c55c --- /dev/null +++ b/tests/Fixtures/e2e/PSR_0_Autoloader/src/PSR_0_Autoloader/SourceClass.php @@ -0,0 +1,11 @@ +assertSame('hello', $sourceClass->hello()); + } +}