Skip to content

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 8, 2026

An issue when using the MakerTestCase to test maker classes provided by other packages, is that it depends on the tests directory of the symfony/maker-bundle package.

In this PR, we use Composer\InstalledVersions::getRootPackage() to retrieve the path and name of the root package under test. This way, that's the tested package that is linked into the temporary test projects.

This assumes a certain structure of the maker package (src, tests and tests/fixtures dirs, tests/tmp ignored, tools/twigcs subproject).

@GromNaN GromNaN added the Feature New Feature label Jan 8, 2026
@GromNaN GromNaN requested a review from jrushlow January 9, 2026 09:31
unset($composerJson['require-dev']);

$composerJson['repositories']['symfony/maker-bundle'] = [
$composerJson['repositories'][$this->packageName] = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Composer 2.9 is deprecating the usage of object-based structure for repositories (as JSON technically does not guarantee an order for object keys). It might make sense to avoid relying on it, using the array-based structure instead (maybe using the composer repo command)


namespace Symfony\Bundle\MakerBundle\Test;

use Composer\InstalledVersions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should declare a dependency on composer-runtime-api with a constraint matching the version of the runtime API providing the info you rely on (probably 2.0 as lowest bound for that case, unless some of the feature you rely on was added later).

Copy link
Member Author

@GromNaN GromNaN Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The install_path was added in Composer 2.1 by composer/composer#9699

@GromNaN GromNaN changed the title Make the package name and root dynamically discovered in MakerTestCase Make the root package name and path dynamically discovered in MakerTestCase Jan 9, 2026

file_put_contents($composerJsonPath, json_encode($composerJson, \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES));
MakerTestProcess::create(\sprintf(
'composer repo add %s \'%s\' ',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work on Windows (where you cannot use single-quote to wrap arguments).

I think the best solution would be to make MakerTestProcess support the array-based signature to define a Process (which is a lot safer than building a command-line that is parsed by a shell as it solves the need for shell escaping)

Copy link
Member Author

@GromNaN GromNaN Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize that was already possible. I added the param type to the relevant methods (all internal or final).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants