Skip to content

Commit

Permalink
Merge pull request #15 from cs278/polyfill-workaround
Browse files Browse the repository at this point in the history
Workaround polyfill not being loaded
  • Loading branch information
cs278 authored Jul 27, 2021
2 parents d6d3327 + 305eb3c commit fece67f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ jobs:
run: |
vendor/bin/simple-phpunit --version | head -n1 >&2
vendor/bin/simple-phpunit --verbose $args
echo "::group::Tests (w/ source composer/composer)"
vendor/bin/simple-phpunit --verbose
echo "::endgroup::"
echo "::group::Tests (w/ phar composer/composer)"
COMPOSER_AUDIT_TEST_COMPOSER_BINARY=$(which composer) vendor/bin/simple-phpunit --verbose
echo "::endgroup::"
# Verifies that the plugin entry point still parses on PHP 5.3, users of 5.3
# cannot use this Composer plugin but at least it won't break their Composer.
legacy:
Expand Down
2 changes: 1 addition & 1 deletion src/ComposerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ComposerPlugin implements PluginInterface, Capable
{
public function activate(Composer $composer, IOInterface $io)
{

PolyfillLoader::load($composer, $io);
}

public function deactivate(Composer $composer, IOInterface $io)
Expand Down
49 changes: 49 additions & 0 deletions src/PolyfillLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Cs278\ComposerAudit;

use Composer\Composer;
use Composer\IO\IOInterface;

/**
* Find Symfony Polyfill libraries and loads them.
*/
final class PolyfillLoader
{
public static function load(Composer $composer, IOInterface $io)
{
$packages = $composer->getRepositoryManager()->getLocalRepository()->getPackages();
$includeFiles = [];

foreach ($packages as $package) {
if (strpos($package->getName(), 'symfony/polyfill-') === 0) {
$io->debug(sprintf('PolyfillLoader finding files in: %s', $package->getName()));
$autoload = $package->getAutoload();

if (isset($autoload['files'])) {
$installPath = $composer->getInstallationManager()->getInstallPath($package);

foreach ($autoload['files'] as $file) {
$io->debug(sprintf('PolyfillLoader found: %s %s', $package->getName(), $file));
$includeFiles[] = $installPath.\DIRECTORY_SEPARATOR.$file;
}
}
}
}

foreach ($includeFiles as $includeFile) {
if (in_array($includeFile, \get_included_files(), true)) {
$io->debug(sprintf('PolyfillLoader %s is already loaded', $includeFile));
return;
}

$io->debug(sprintf('PolyfillLoader loading: %s', $includeFile));
self::incldueFile($includeFile);
}
}

private static function incldueFile($path): void
{
require $path;
}
}
13 changes: 11 additions & 2 deletions tests/integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,17 @@ public function testRun(int $expectedExit, string $expectedOutput, string $condi
}

$workingDir = temporaryDir();
$composer = function (...$args) use ($workingDir) {
array_unshift($args, getcwd().'/vendor/bin/composer');

// Environment variable instructs tests to use another Composer binary,
// this allows testing with the systems Composer installation.
$composerBin = getenv('COMPOSER_AUDIT_TEST_COMPOSER_BINARY');

if (!is_string($composerBin) || is_dir($composerBin) || !is_executable($composerBin)) {
$composerBin = getcwd().'/vendor/bin/composer';
}

$composer = function (...$args) use ($composerBin, $workingDir) {
array_unshift($args, $composerBin);

return new Process($args, $workingDir, [
'COMPOSER_HOME' => $workingDir.'/.composer',
Expand Down

0 comments on commit fece67f

Please sign in to comment.