Skip to content

Commit 9bd7cd5

Browse files
authored
Merge pull request #110 from TYPO3GmbH/bugfix/update-composer-2-1.5.x
2 parents ce5588c + 9344f44 commit 9bd7cd5

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

src/Installer/ExtensionInstaller.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,11 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
196196
if ($promise instanceof PromiseInterface) {
197197
$binaryInstaller = $this->binaryInstaller;
198198
$installPath = $this->getInstallPath($target);
199-
return $promise->then(function () use ($binaryInstaller, $installPath, $package, $repo) {
200-
$binaryInstaller->installBinaries($package, $installPath);
201-
if (!$repo->hasPackage($package)) {
202-
$repo->addPackage(clone $package);
199+
return $promise->then(function () use ($binaryInstaller, $installPath, $target, $initial, $repo) {
200+
$binaryInstaller->installBinaries($target, $installPath);
201+
$repo->removePackage($initial);
202+
if (!$repo->hasPackage($target)) {
203+
$repo->addPackage(clone $target);
203204
}
204205
});
205206
}

tests/Installer/ExtensionInstallerTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
namespace TYPO3\CMS\ComposerTest\Installer;
1717

18+
use Composer\Composer;
1819
use Composer\Package\Package;
20+
use TYPO3\CMS\Composer\Plugin\Util\Filesystem as TYPO3Filesystem;
1921

2022
class ExtensionInstallerTest extends InstallerTestCase
2123
{
@@ -96,4 +98,64 @@ public function extensionInstallPathDataProvider()
9698
],
9799
];
98100
}
101+
102+
public function testUpdate()
103+
{
104+
$filesystem = $this->getMockBuilder(TYPO3Filesystem::class)
105+
->getMock();
106+
$filesystem
107+
->expects($this->once())
108+
->method('rename')
109+
->with('/typo3conf/ext/old', '/typo3conf/ext/new');
110+
111+
/** @var Package $package */
112+
$initial = $this->createPackage('somevendor/somepackage-extension', 'typo3-cms-extension');
113+
$initial->setExtra([
114+
'typo3/cms' => [
115+
'extension-key' => 'old',
116+
],
117+
]);
118+
119+
/** @var Package $package */
120+
$target = $this->createPackage('somevendor/somepackage-extension', 'typo3-cms-extension');
121+
$target->setExtra([
122+
'typo3/cms' => [
123+
'extension-key' => 'new',
124+
],
125+
]);
126+
127+
$this->repository
128+
->expects($this->exactly(3))
129+
->method('hasPackage')
130+
->will($this->onConsecutiveCalls(true, false, false));
131+
132+
if (!defined('Composer\Composer::RUNTIME_API_VERSION') || version_compare(Composer::RUNTIME_API_VERSION, '2.0.0') < 0) {
133+
$this->downloadManager
134+
->expects($this->once())
135+
->method('update')
136+
->with($initial, $target, '/typo3conf/ext/new');
137+
} else {
138+
$this->downloadManager
139+
->expects($this->once())
140+
->method('update')
141+
->with($initial, $target, '/typo3conf/ext/new')
142+
->will($this->returnValue(\React\Promise\resolve()));
143+
}
144+
145+
$this->repository
146+
->expects($this->once())
147+
->method('removePackage')
148+
->with($initial);
149+
150+
$this->repository
151+
->expects($this->once())
152+
->method('addPackage')
153+
->with($target);
154+
155+
$installer = $this->createExtensionInstaller($filesystem);
156+
$installer->update($this->repository, $initial, $target);
157+
158+
$this->setExpectedException('InvalidArgumentException');
159+
$installer->update($this->repository, $initial, $target);
160+
}
99161
}

tests/Installer/InstallerTestCase.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use TYPO3\CMS\Composer\Installer\CoreInstaller;
3030
use TYPO3\CMS\Composer\Installer\ExtensionInstaller;
3131
use TYPO3\CMS\Composer\Plugin\Config as TYPO3Config;
32+
use TYPO3\CMS\Composer\Plugin\Util\Filesystem as TYPO3Filesystem;
3233
use TYPO3\CMS\ComposerTest\TestCase;
3334

3435
class InstallerTestCase extends TestCase
@@ -53,6 +54,11 @@ class InstallerTestCase extends TestCase
5354
*/
5455
protected $composer;
5556

57+
/**
58+
* DownloadManager|\PHPUnit_Framework_MockObject_MockObject
59+
*/
60+
protected $downloadManager;
61+
5662
/**
5763
* @var InstalledRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
5864
*/
@@ -77,8 +83,8 @@ protected function setUp()
7783
$this->composer->setInstallationManager($installationManager);
7884

7985
/** @var DownloadManager */
80-
$downloadManager = $this->getMockBuilder(DownloadManager::class)->disableOriginalConstructor()->getMock();
81-
$this->composer->setDownloadManager($downloadManager);
86+
$this->downloadManager = $this->getMockBuilder(DownloadManager::class)->disableOriginalConstructor()->getMock();
87+
$this->composer->setDownloadManager($this->downloadManager);
8288

8389
/** @var RootPackage|\PHPUnit_Framework_MockObject_MockObject $package */
8490
$package = $this->createMock(RootPackageInterface::class);
@@ -123,11 +129,12 @@ protected function createCoreInstaller()
123129
}
124130

125131
/**
132+
* @param null|mixed $filesystem
126133
* @return InstallerInterface
127134
*/
128-
protected function createExtensionInstaller()
135+
protected function createExtensionInstaller($filesystem = null)
129136
{
130-
$filesystem = new \TYPO3\CMS\Composer\Plugin\Util\Filesystem();
137+
$filesystem = $filesystem ?? new TYPO3Filesystem();
131138
$binaryInstaller = new BinaryInstaller($this->io, rtrim($this->composer->getConfig()->get('bin-dir'), '/'), $this->composer->getConfig()->get('bin-compat'), $filesystem);
132139
$config = TYPO3Config::load($this->composer);
133140
return new ExtensionInstaller($this->io, $this->composer, $filesystem, $config, $binaryInstaller);

0 commit comments

Comments
 (0)