Skip to content
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

Ensure extra.zf configuration is renamed to extra.laminas #58

Merged
merged 4 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ matrix:
env:
- COMPAT_VERSION=7.4

before_install:
- composer self-update --1

install:
- composer update $COMPOSER_ARGS
- if [[ $RUN_TESTS != '' ]]; then composer require $RUN_TESTS ; fi
Expand Down
2 changes: 2 additions & 0 deletions src/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Laminas\Migration\DependencyPlugin;
use Laminas\Migration\FileFilter;
use Laminas\Migration\MigrateProject;
use Laminas\Migration\SpecialCase\ComposerJsonExtraZFSpecialCase;
use Laminas\Migration\SpecialCase\ComposerJsonZendFrameworkPackageSpecialCase;
use Laminas\Migration\VendorDirectory;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -247,6 +248,7 @@ private function injectDependencyPlugin($path, $noPluginOption, SymfonyStyle $io
private function migrateProjectFiles($path, callable $filter, SymfonyStyle $io)
{
$migration = new MigrateProject([
new ComposerJsonExtraZFSpecialCase(),
new ComposerJsonZendFrameworkPackageSpecialCase(),
]);
$migration($path, $filter, $io);
Expand Down
45 changes: 45 additions & 0 deletions src/SpecialCase/ComposerJsonExtraZFSpecialCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @see https://github.com/laminas/laminas-migration for the canonical source repository
* @copyright https://github.com/laminas/laminas-migration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-migration/blob/master/LICENSE.md New BSD License
*/

namespace Laminas\Migration\SpecialCase;

class ComposerJsonExtraZFSpecialCase implements SpecialCaseInterface
{
public function matches($filename, $content)
{
if (! preg_match('#\bcomposer\.json$#', $filename)) {
return false;
}

$composer = json_decode($content, true);
return isset($composer['extra']['zf']);
}

public function replace($content)
{
$composer = json_decode($content, true);
$composer = $this->updateComposer($composer);

return json_encode($composer, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}

/**
* @return array The updated Composer array.
*/
private function updateComposer(array $composer)
{
$extraZf = $composer['extra']['zf'];
$extraLaminas = isset($composer['extra']['laminas']) ? $composer['extra']['laminas'] : [];

unset($composer['extra']['zf']);
$composer['extra']['laminas'] = array_replace_recursive($extraZf, $extraLaminas);


return $composer;
}
}
32 changes: 32 additions & 0 deletions test/SpecialCase/ComposerJsonExtraZFSpecialCaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* @see https://github.com/laminas/laminas-migration for the canonical source repository
* @copyright https://github.com/laminas/laminas-migration/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-migration/blob/master/LICENSE.md New BSD License
*/

namespace LaminasTest\Migration\SpecialCase;

use Laminas\Migration\SpecialCase\ComposerJsonExtraZFSpecialCase;
use PHPUnit\Framework\TestCase;

class ComposerJsonExtraZFSpecialCaseTest extends TestCase
{
public function testReplacesZendFrameworkPackageWithAppropriatePackagesAtAppropriateConstraint()
{
$specialCase = new ComposerJsonExtraZFSpecialCase();
$file = sprintf('%s/fixtures/extra/composer.json', __DIR__);
$expectedFile = sprintf('%s/fixtures/extra/composer.updated.json', __DIR__);
$contents = file_get_contents($file);
$expectedContents = file_get_contents($expectedFile);
$expected = json_decode($expectedContents, true);

$this->assertTrue($specialCase->matches($file, $contents));

$result = $specialCase->replace($contents);
$replacements = json_decode($result, true);

$this->assertEquals($expected, $replacements);
}
}
5 changes: 5 additions & 0 deletions test/SpecialCase/fixtures/extra/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extra": {
"zf": {}
}
}
5 changes: 5 additions & 0 deletions test/SpecialCase/fixtures/extra/composer.updated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extra": {
"laminas": {}
}
}