Skip to content

Commit

Permalink
fix(tests): recursively install deps in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Mar 21, 2024
1 parent 29131dc commit 36f4cab
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 15 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ jobs:
composer-options: ${{ matrix.composer_flags }}

- name: Install Composer dependencies (tests)
uses: ramsey/composer-install@v3
with:
composer-options: ${{ matrix.composer_flags }}
working-directory: tests/issue-13
run: php tests/install-deps.php
env:
COMPOSER_FLAGS: ${{ matrix.composer_flags }}

- run: vendor/bin/phpunit
if: ${{ matrix.php_version != '8.2' }}
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<directory suffix="Test.php">tests/unit/</directory>
</testsuite>
<testsuite name="Functional tests">
<directory suffix=".phpt">tests/functional/</directory>
<directory suffix=".phpt">tests/functional/error-handler/</directory>
<file>tests/functional/nested-composer-projects/test.phpt</file>
<file>tests/issue-13/test.phpt</file>
<file>tests/issue-13/test-path-callback.phpt</file>
</testsuite>
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/lists-all-classes-in-project.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ ComposerFinder - should list all classes in a project w/o autoloading
require __DIR__ . '/../../vendor/autoload.php';

$finder = (new Kcs\ClassFinder\Finder\ComposerFinder())->useAutoloading(false);
$classes = iterator_to_array($finder);
iterator_to_array($finder);

printf('> found %d class(es)' . PHP_EOL, count($classes));
echo "OK";
?>
--EXPECTF--
> found %d class(es)
--EXPECT--
OK
11 changes: 11 additions & 0 deletions tests/functional/nested-composer-projects/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"repositories": [
{
"type": "vcs",
"url": "../../.."
}
],
"require": {
"kcs/class-finder": "^1.0@dev"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"nikic/php-parser": "^4.18 || ^5.0"
}
}
14 changes: 14 additions & 0 deletions tests/functional/nested-composer-projects/test.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
ComposerFinder - nested composer projects
--FILE--
<?php
require_once 'vendor/autoload.php';
$otherProjectClassLoader = require __DIR__ . '/otherProject/vendor/autoload.php';

$finder = new Kcs\ClassFinder\Finder\ComposerFinder($otherProjectClassLoader);
iterator_to_array($finder);

echo "OK";
?>
--EXPECT--
OK
39 changes: 39 additions & 0 deletions tests/install-deps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

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;
}
}
}
}
}
7 changes: 4 additions & 3 deletions tests/issue-13/test-path-callback.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ $count = 0;
foreach ($finder as $className => $reflector) {
++$count;
}
printf('> found %d class(es)' . PHP_EOL, $count);

echo "OK"
?>
--EXPECTF--
> found %d class(es)
--EXPECT--
OK
7 changes: 4 additions & 3 deletions tests/issue-13/test.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ $count = 0;
foreach ($finder as $className => $reflector) {
++$count;
}
printf('> found %d class(es)' . PHP_EOL, $count);

echo "OK"
?>
--EXPECTF--
> found %d class(es)
--EXPECT--
OK

0 comments on commit 36f4cab

Please sign in to comment.