-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Ignore the global plugin when updating local projects #39
Ignore the global plugin when updating local projects #39
Conversation
89d18a5
to
1389111
Compare
This patch also has the added benefit of fixing another crash. After removing Running:
Admittedly this can be circumvented using |
@Ocramius managed to get an E2E test working - it's a bit gross so I'd appreciate any pointers for it 😄 |
|
||
$composer = $composerEvent->getComposer(); | ||
$io = $composerEvent->getIO(); | ||
$io->write('<info>ocramius/package-versions:</info> Generating version class...'); |
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.
I'll add an info message in the previous block as well. Otherwise, users may get confused on why this isn't running.
/** | ||
* @author Aydin Hassan <aydin@hotmail.co.uk> | ||
*/ | ||
class E2EInstaller extends PHPUnit_Framework_TestCase |
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.
Going to rename/move this class around. Also will add @coversNothing
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.
Sure thing - wasn't really sure how to name it
*/ | ||
class E2EInstaller extends PHPUnit_Framework_TestCase | ||
{ | ||
private $tempGlobalComposerHome; |
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.
To be added: docblocks
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.
added
{ | ||
$this->createPackageVersionsArtifact(); | ||
|
||
file_put_contents($this->tempGlobalComposerHome . '/composer.json', json_encode([ |
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.
This alignment is not PSR-2 compliant
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.
fixed up - I introduced a method to write
$this->exec(__DIR__ . '/../../vendor/bin/composer global update'); | ||
|
||
$this->createArtifact(); | ||
file_put_contents($this->tempLocalComposerHome . '/composer.json', json_encode([ |
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.
Same
$filePath = substr($file->getRealPath(), strlen(realpath(__DIR__ . '/../../')) + 1); | ||
|
||
if (substr($filePath, 0, 4) === '.git' | ||
|| substr($filePath, 0, 5) === '.idea' |
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.
Simply skip anything that starts with .
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.
There's something in the recursive directory iterator for that, btw
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.
You got a link? I couldn't find anything other than SKIP_DOTS
which doesn't consider anything other than ..
& .
I've simplified it now anyway - so should be better
function (SplFileInfo $file) { | ||
$filePath = substr($file->getRealPath(), strlen(realpath(__DIR__ . '/../../')) + 1); | ||
|
||
if (substr($filePath, 0, 4) === '.git' |
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.
This block is a negated boolean expression, not an if/else block
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.
I've simplified this a little
$zip->addFromString('composer.json', json_encode([ | ||
'name' => 'test/package', | ||
'version' => '2.0.0', | ||
], JSON_PRETTY_PRINT)). |
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.
Alignment broken here too
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.
fixed
); | ||
} | ||
|
||
private function createPackageVersionsArtifact() |
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.
Should this return the path to the generated artifact?
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.
I dont think so - the path to the zip isn't used for anything, just the folder where they reside
|
||
private function exec(string $command) : array | ||
{ | ||
exec($command . ' 2> /dev/null', $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.
You need to assert that the exit code is 0
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.
Added an assertion in
Seems to be failing on lowest deps - trying to figure out now |
Hmm - the composer exec output seems to print errors such as
On further investigation I would say this is a bug with Composer:
|
We should then report it in composer and bump the required version there, I suppose... |
I've filed composer/composer#5828 & created composer/composer#5831 to fix it (maybe). I've bumped the minimum in here to |
@@ -16,7 +16,8 @@ | |||
"require-dev": { | |||
"phpunit/phpunit": "^5.4.7", | |||
"composer/composer": "^1.2.0", | |||
"ext-zip": "*" | |||
"ext-zip": "*", | |||
"symfony/process": "^2.3" |
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.
Note: this required should be pushed into composer
OK composer/composer#5831 is merged now - guessing you want to wait for a tag before we pursue this? |
hey @Ocramius composer 1.3 has been released with the necessary fixes. Tests are passing now 😄 . |
@AydinHassan looking good! Going through a quick sweep of the code, then merging :-) |
|
||
$io->write('<info>ocramius/package-versions:</info> Generating version class...'); | ||
if (!isset($versions['ocramius/package-versions'])) { | ||
//plugin must be globally installed - we only want to generate versions for projects which specifically |
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.
@AydinHassan just a doubt, given that there's no real way to know from the code: what about when the package is indirectly depending on package-versions
? Will it still run?
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.
Also: what about when we are currently operating in package-versions?
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.
@Ocramius will run in both contexts as it would be in the lock file - is that expected?
The first is actually my use case - A globally installed tool depends on PackageVersions
.
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.
@AydinHassan great, thanks!
|
||
$io->write('<info>ocramius/package-versions:</info> Generating version class...'); | ||
if (!isset($versions['ocramius/package-versions'])) { |
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.
Should probably be an array_key_exists()
at this point - don't trust the value below it
mkdir($this->tempLocalComposerHome, 0777, true); | ||
mkdir($this->tempArtifact, 0777, true); | ||
|
||
putenv('COMPOSER_HOME=' . $this->tempGlobalComposerHome); |
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.
This environment variable must be reset in tearDown
$this->tempGlobalComposerHome = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true) . '/global'; | ||
$this->tempLocalComposerHome = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true) . '/local'; | ||
$this->tempArtifact = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true) . '/artifacts'; | ||
mkdir($this->tempGlobalComposerHome, 0777, true); |
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.
Please use 0700
for test runs
$this->tempLocalComposerHome = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true) . '/local'; | ||
$this->tempArtifact = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true) . '/artifacts'; | ||
mkdir($this->tempGlobalComposerHome, 0777, true); | ||
mkdir($this->tempLocalComposerHome, 0777, true); |
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.
Please use 0700
for test runs
$this->tempArtifact = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true) . '/artifacts'; | ||
mkdir($this->tempGlobalComposerHome, 0777, true); | ||
mkdir($this->tempLocalComposerHome, 0777, true); | ||
mkdir($this->tempArtifact, 0777, true); |
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.
Please use 0700
for test runs
LGTM! \o/ |
@samsonasik are there chances this will get backported to your fork? There's no way to report issues on forks, unfortunately. |
@weirdan I tried backport but it seems needs very long time to get it work as I state at samsonasik#3 (comment) . Pull Request open if you can invest a time to patch ;) |
I know @samsonasik did the backport with good intentions, but if you want to talk about older PHP versions support here, I'm gonna lock the thread: just upgrade your installation to a contemporary PHP binary. |
Oh, we were merely talking about porting changes from upstream to the fork. And I'm running 7.1, which, last time I checked, was pretty contemporary. |
Then you don't need the fork ;-) |
I had to refactor a little to reduce repeating code, anyway this fixes #38.
However, I've had a think and I don't know how we can provide an e2e test. We could provide some project assets but we'd have to mess with the systems global composer project, which I don't think we can do safely.
I've also had to modify existing tests, I wasn't sure how to get them working now that we need
ocramius/package-versions
to be present in the locker.Thoughts @Ocramius ?