Skip to content

Commit

Permalink
bug symfony#239 Guaranteeing that Flex is installed THEN fwbundle (we…
Browse files Browse the repository at this point in the history
…averryan)

This PR was merged into the 1.0-dev branch.

Discussion
----------

Guaranteeing that Flex is installed THEN fwbundle

See symfony#238.

I talked with @nicolas-grekas about this. By merging the Flex recipe into FWBundle, we created a possibility (which I hit while creating our upgrade tutorial) that the `.env.dist` file is not present. And then, recipes may start installing incorrectly because this file is needed (so that recipes can update it and `.env`).

The fix is this PR + to revert symfony/recipes#295

Commits
-------

611f7d6 guaranteeing that Flex is installed THEN fwbundle
  • Loading branch information
fabpot committed Dec 11, 2017
2 parents 73436bc + 611f7d6 commit c3980f5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
16 changes: 14 additions & 2 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,20 @@ public function record(PackageEvent $event)
{
$operation = $event->getOperation();
if ($this->shouldRecordOperation($operation)) {
if ($operation instanceof InstallOperation && 'symfony/framework-bundle' === $operation->getPackage()->getName()) {
array_unshift($this->operations, $operation);
if ($operation instanceof InstallOperation && in_array($packageName = $operation->getPackage()->getName(), ['symfony/framework-bundle', 'symfony/flex'])) {
if ('symfony/flex' === $packageName) {
array_unshift($this->operations, $operation);
} else {
if ($this->operations && $this->operations[0] instanceof InstallOperation && 'symfony/flex' === $this->operations[0]->getPackage()->getName()) {
// framework-bundle should be *after* flex
$flexOperation = $this->operations[0];
unset($this->operations[0]);
array_unshift($this->operations, $operation);
array_unshift($this->operations, $flexOperation);
} else {
array_unshift($this->operations, $operation);
}
}
} else {
$this->operations[] = $operation;
}
Expand Down
37 changes: 28 additions & 9 deletions tests/FlexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@

class FlexTest extends TestCase
{
public function testFrameworkBundleRecord()
/**
* @dataProvider getRecordTests
*/
public function testFrameworkBundleRecord(array $actualInstallOperations, $expectedFinalOperators)
{
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
$lock->expects($this->any())->method('has')->will($this->returnValue(false));
Expand All @@ -43,20 +46,36 @@ public function testFrameworkBundleRecord()

return $flex;
}, null, Flex::class)->__invoke();
/** @var InstallOperation[] $list */
$list = [
$operationFlex = new InstallOperation(new Package('symfony/flex', '1.0.0', '1.0.0')),
$operationFB = new InstallOperation(new Package('symfony/framework-bundle', '1.0.0', '1.0.0')),
$operationFoo = new InstallOperation(new Package('vendor/foo', '1.0.0', '1.0.0')),
];
foreach ($list as $operation) {

/** @var InstallOperation[] $actualInstallOperations */
foreach ($actualInstallOperations as $operation) {
$event = $this->getMockBuilder(PackageEvent::class)->disableOriginalConstructor()->getMock();
$event->expects($this->once())->method('getOperation')->willReturn($operation);

$flex->record($event);
}

$this->assertAttributeEquals([$operationFB, $operationFlex, $operationFoo], 'operations', $flex);
$this->assertAttributeEquals($expectedFinalOperators, 'operations', $flex);
}

public function getRecordTests()
{
$operationFoo = new InstallOperation(new Package('vendor/foo', '1.0.0', '1.0.0'));
$operationFB = new InstallOperation(new Package('symfony/framework-bundle', '1.0.0', '1.0.0'));
$operationFlex = new InstallOperation(new Package('symfony/flex', '1.0.0', '1.0.0'));

return [
[
// install order
[$operationFoo, $operationFB, $operationFlex],
// expected final order
[$operationFlex, $operationFB, $operationFoo],
],
[
[$operationFoo, $operationFlex, $operationFB],
[$operationFlex, $operationFB, $operationFoo],
],
];
}

public function testPostInstall()
Expand Down

0 comments on commit c3980f5

Please sign in to comment.