Skip to content

Commit

Permalink
fix(tests): ignore composer.json files in nested vendor folders
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Jun 13, 2024
1 parent 11bd5c7 commit 869d5a5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion tests/functional/nested-composer-projects/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
}
],
"require": {
"kcs/class-finder": "^0.5@dev"
"kcs/class-finder": "dev-master"
}
}
68 changes: 37 additions & 31 deletions tests/install-deps.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@
declare(strict_types=1);

foreach (glob(__DIR__ . '/*') as $path) {
if (is_dir($path)) {
$files = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS),
static fn (SplFileInfo $file): bool => $file->getBasename()[0] !== '.',
),
RecursiveIteratorIterator::LEAVES_ONLY | RecursiveIteratorIterator::CHILD_FIRST,
);

foreach ($files as $filepath => $info) {
if (! $info->isFile()) {
continue;
}

if ($info->getFilename() === 'composer.json') {
if (basename(dirname($info->getPath())) === 'vendor') {
continue;
}

$descriptorspec = [STDIN, STDOUT, STDERR];
$proc = proc_open(trim('composer install ' . getenv('COMPOSER_FLAGS') ?: ''), $descriptorspec, $pipes, $info->getPath());
for ($running = true; $running;) {
$status = proc_get_status($proc);
$running = $status['running'];
$exitcode = $status['exitcode'];
}

if ($exitcode !== 0) {
return;
}
}
if (! is_dir($path)) {
continue;
}

$files = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS),
static fn (SplFileInfo $file): bool => $file->getBasename()[0] !== '.',
),
RecursiveIteratorIterator::LEAVES_ONLY | RecursiveIteratorIterator::CHILD_FIRST,
);

foreach ($files as $filepath => $info) {
if (! $info->isFile()) {
continue;
}

if ($info->getFilename() !== 'composer.json') {
continue;
}

if (str_contains(dirname($info->getPath()), '/vendor/')) {
continue;
}

echo 'Processing ' . $info->getPath() . "...\n";

$descriptorspec = [STDIN, STDOUT, STDERR];
$proc = proc_open(trim('composer install ' . getenv('COMPOSER_FLAGS') ?: ''), $descriptorspec, $pipes, $info->getPath());
for ($running = true; $running;) {
$status = proc_get_status($proc);
$running = $status['running'];
$exitcode = $status['exitcode'];
}

if ($exitcode !== 0) {
return;
}
}
}
2 changes: 1 addition & 1 deletion tests/issue-13/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
],
"require": {
"symfony/cache": "^6.4 || ^7.0",
"kcs/class-finder": "^1.0@dev"
"kcs/class-finder": "dev-master"
}
}

0 comments on commit 869d5a5

Please sign in to comment.