From 62a1c627c35e9a9fce4e65195730b851258ab601 Mon Sep 17 00:00:00 2001 From: borNfreee Date: Sun, 25 Nov 2018 11:31:56 +0300 Subject: [PATCH 1/2] Add a test to check Infection works with PSR-0 compliant autoloader --- tests/Fixtures/e2e/PSR_0_Autoloader/README.md | 5 +++++ .../e2e/PSR_0_Autoloader/composer.json | 15 +++++++++++++++ .../e2e/PSR_0_Autoloader/expected-output.txt | 6 ++++++ .../e2e/PSR_0_Autoloader/infection.json | 12 ++++++++++++ .../Fixtures/e2e/PSR_0_Autoloader/phpunit.xml | 18 ++++++++++++++++++ .../src/PSR_0_Autoloader/SourceClass.php | 11 +++++++++++ .../PSR_0_Autoloader/Tests/SourceClassTest.php | 15 +++++++++++++++ 7 files changed, 82 insertions(+) create mode 100644 tests/Fixtures/e2e/PSR_0_Autoloader/README.md create mode 100644 tests/Fixtures/e2e/PSR_0_Autoloader/composer.json create mode 100644 tests/Fixtures/e2e/PSR_0_Autoloader/expected-output.txt create mode 100644 tests/Fixtures/e2e/PSR_0_Autoloader/infection.json create mode 100644 tests/Fixtures/e2e/PSR_0_Autoloader/phpunit.xml create mode 100644 tests/Fixtures/e2e/PSR_0_Autoloader/src/PSR_0_Autoloader/SourceClass.php create mode 100644 tests/Fixtures/e2e/PSR_0_Autoloader/tests/PSR_0_Autoloader/Tests/SourceClassTest.php 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..7deafe800 --- /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 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()); + } +} From a3e11a887f456547839dc33610d2aadbed082dea Mon Sep 17 00:00:00 2001 From: borNfreee Date: Sun, 25 Nov 2018 17:27:47 +0300 Subject: [PATCH 2/2] Add PSR-0 autloading to e2e tests --- tests/Console/E2ETest.php | 15 ++++++++++++++- .../e2e/PSR_0_Autoloader/expected-output.txt | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) 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/expected-output.txt b/tests/Fixtures/e2e/PSR_0_Autoloader/expected-output.txt index 7deafe800..99606b97d 100644 --- a/tests/Fixtures/e2e/PSR_0_Autoloader/expected-output.txt +++ b/tests/Fixtures/e2e/PSR_0_Autoloader/expected-output.txt @@ -3,4 +3,4 @@ Killed: 1 Errored: 0 Escaped: 0 Timed Out: 0 -Not Covered: 0 +Not Covered: 0 \ No newline at end of file