-
Notifications
You must be signed in to change notification settings - Fork 29
Fix vendor autoloader dev entries when target is vendor #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @BrianHenryIE, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request resolves an issue where development dependencies were incorrectly excluded from the autoloader when the build target directory was the vendor
directory itself. The changes introduce conditional logic to ensure dev
entries are properly retained in this specific scenario and optimize the autoloader generation process by skipping unnecessary prefixing. A new integration test has been added to validate the fix.
Highlights
- Autoloader Dev Entry Handling: The core logic for generating the autoloader in
DumpAutoload.php
has been modified. Previously,devMode
was unconditionally set tofalse
. Now,devMode
is only set tofalse
if thetarget_directory
is different from thevendor_directory
. This change ensures that development dependencies are correctly included in the autoloader when the autoloader is being generated directly into thevendor
directory, addressing the issue ofdev
entries being removed. - Autoloader Prefixing Optimization: A new conditional check has been added to the
prefixNewAutoloader
method inDumpAutoload.php
. This method will now return early and skip the prefixing process if thetarget_directory
is the same as thevendor_directory
. This prevents unnecessary prefixing operations in scenarios where the autoloader is being built directly within the vendor folder. - New Integration Test: A new integration test,
StraussIssue198Test.php
, has been introduced. This test specifically validates the fix by setting thetarget_directory
tovendor
and asserting that both regular and development dependencies are correctly present in the generatedinstalled.json
andautoload_psr4.php
files, confirming thatdev
entries are no longer removed. - Dependency Update: The
composer/composer
dependency incomposer.json
has been updated from a wildcard*
to a specific version constraint of^2.6.0
.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request fixes an issue where dev dependencies were being incorrectly removed during autoloader generation when the target directory is the vendor directory. The changes in DumpAutoload.php
are well-reasoned, and the new integration test validates the fix. The review focuses on improving test robustness and code clarity.
tests/Issues/StraussIssue198Test.php
Outdated
$php_string = file_get_contents($this->testsWorkingDir . 'vendor/composer/installed.json'); | ||
$this->assertStringContainsString("Company\\\\Project\\\\Psr\\\\Log\\\\", $php_string); | ||
$this->assertStringContainsString("\"Psr\\\\SimpleCache\\\\", $php_string); | ||
|
||
$php_string = file_get_contents($this->testsWorkingDir . 'vendor/composer/autoload_psr4.php'); | ||
$this->assertStringContainsString("Company\\\\Project\\\\Psr\\\\Log\\\\", $php_string); | ||
$this->assertStringContainsString("Psr\\\\SimpleCache\\\\", $php_string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file paths for file_get_contents
are constructed without a path separator. This will cause the function to look for a file in the wrong location (e.g., /path/to/workdirvendor/composer/installed.json
instead of /path/to/workdir/vendor/composer/installed.json
), causing the test to fail. Please add a directory separator. Using /
is generally safe for cross-platform compatibility in PHP.
$php_string = file_get_contents($this->testsWorkingDir . '/vendor/composer/installed.json');
$this->assertStringContainsString("Company\\Project\\Psr\\Log\\", $php_string);
$this->assertStringContainsString("\"Psr\\SimpleCache\\", $php_string);
$php_string = file_get_contents($this->testsWorkingDir . '/vendor/composer/autoload_psr4.php');
$this->assertStringContainsString("Company\\Project\\Psr\\Log\\", $php_string);
$this->assertStringContainsString("Psr\\SimpleCache\\", $php_string);
tests/Issues/StraussIssue198Test.php
Outdated
|
||
file_put_contents($this->testsWorkingDir . '/composer.json', $composerJsonString); | ||
|
||
exec('composer install'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exec('composer install')
call does not check for failure. If this command fails, the test will proceed and likely fail on a later assertion with a less clear error message. It would be better to capture the exit code and assert its success immediately to make debugging easier.
exec('composer install', $composerOutput, $composerExitCode);
$this->assertSame(0, $composerExitCode, "'composer install' failed. Output: \n" . implode("\n", $composerOutput));
tests/Issues/StraussIssue198Test.php
Outdated
|
||
exec('composer install'); | ||
$exitCode = $this->runStrauss($output); | ||
assert(0 === $exitCode, $output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assert()
language construct should generally be avoided in tests. Its behavior depends on the zend.assertions
php.ini setting, and it might not be executed at all, causing a failing test to pass silently. It's more reliable and idiomatic to use PHPUnit's assertion methods, like $this->assertSame()
, which also provide more descriptive failure messages.
$this->assertSame(0, $exitCode, 'Strauss execution failed. Output: ' . $output);
if ($this->config->getVendorDirectory() !== $this->config->getTargetDirectory()) { | ||
$generator->setDevMode(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strauss.phar.zip @ dd3af8d \n |
No description provided.