Skip to content

Fix InstalledVersions not found #712

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

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ blackfire: vendor

.PHONY: e2e
e2e: ## Runs end-to-end tests
e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020 e2e_022 e2e_023 e2e_024 e2e_025 e2e_026 e2e_027 e2e_028 e2e_029 e2e_030 e2e_031 e2e_032 e2e_033
e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020 e2e_022 e2e_023 e2e_024 e2e_025 e2e_026 e2e_027 e2e_028 e2e_029 e2e_030 e2e_031 e2e_032 e2e_033 e2e_034

.PHONY: e2e_004
e2e_004: ## Runs end-to-end tests for the fixture set 004 — Minimalistic codebase
Expand Down Expand Up @@ -495,6 +495,25 @@ e2e_033: $(PHP_SCOPER_PHAR_BIN)
diff fixtures/set033-user-global-function/expected-output build/set033-user-global-function/output



.PHONY: e2e_034
e2e_034: ## Runs end-to-end tests for the fixture set 034 — Leverage Composer InstalledVersions
e2e_034: $(PHP_SCOPER_PHAR_BIN)
$(PHP_SCOPER_PHAR) add-prefix \
--working-dir=fixtures/set034-installed-versions \
--output-dir=../../build/set034-installed-versions \
--force \
--no-interaction \
--stop-on-failure

php fixtures/set034-installed-versions/index.php > fixtures/set034-installed-versions/expected-output

composer --working-dir=build/set034-installed-versions dump-autoload --no-dev
php build/set034-installed-versions/index.php > build/set034-installed-versions/output

diff fixtures/set034-installed-versions/expected-output build/set034-installed-versions/output


#
# Rules from files
#---------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions fixtures/set034-installed-versions/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"bin": "index.php",
"require": {
"nikic/iter": "^2.0"
}
}
69 changes: 69 additions & 0 deletions fixtures/set034-installed-versions/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fixtures/set034-installed-versions/expected-output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ok.
15 changes: 15 additions & 0 deletions fixtures/set034-installed-versions/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace Acme;

use Composer\InstalledVersions;
use function file_exists;
use const PHP_EOL;

require file_exists(__DIR__.'/vendor/scoper-autoload.php')
? __DIR__.'/vendor/scoper-autoload.php'
: __DIR__.'/vendor/autoload.php';

if (InstalledVersions::isInstalled('nikic/iter')) {
echo "ok.".PHP_EOL;
}
12 changes: 12 additions & 0 deletions fixtures/set034-installed-versions/scoper.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use Isolated\Symfony\Component\Finder\Finder;

return [
'finders' => [
(new Finder())
->files()
->in(__DIR__),
],
'exclude-functions' => ['trigger_deprecation'],
];
2 changes: 2 additions & 0 deletions src/Autoload/ScoperAutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function dump(): string

namespace {
\$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';
}

{$statements}
Expand All @@ -95,6 +96,7 @@ public function dump(): string
// scoper-autoload.php @generated by PhpScoper

\$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

{$statements}

Expand Down
8 changes: 8 additions & 0 deletions tests/Autoload/ScoperAutoloadGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static function provideRegistry(): iterable
// scoper-autoload.php @generated by PhpScoper

$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

return $loader;

Expand All @@ -65,6 +66,7 @@ public static function provideRegistry(): iterable
// scoper-autoload.php @generated by PhpScoper

$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

// Exposed functions. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-functions
Expand Down Expand Up @@ -100,6 +102,7 @@ function bar() {

namespace {
$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';
}

// Exposed functions. For more information see:
Expand Down Expand Up @@ -146,6 +149,7 @@ function baz() {
// scoper-autoload.php @generated by PhpScoper

$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

// Exposed classes. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-classes
Expand All @@ -172,6 +176,7 @@ function baz() {
// scoper-autoload.php @generated by PhpScoper

$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

// Exposed classes. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-classes
Expand Down Expand Up @@ -207,6 +212,7 @@ function baz() {

namespace {
$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';
}

// Exposed classes. For more information see:
Expand Down Expand Up @@ -276,6 +282,7 @@ function baz() {
// scoper-autoload.php @generated by PhpScoper

$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

// Exposed functions. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-functions
Expand Down Expand Up @@ -306,6 +313,7 @@ function __autoload($className) {

namespace {
$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';
}

// Exposed functions. For more information see:
Expand Down