Skip to content

Commit

Permalink
Fix InstalledVersions installed (#712)
Browse files Browse the repository at this point in the history
Closes #678
  • Loading branch information
theofidry authored Nov 6, 2022
1 parent 759f6d6 commit 1b01869
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 1 deletion.
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

0 comments on commit 1b01869

Please sign in to comment.