-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from weierophinney/fix/extra-zf-migration
Ensure extra.zf configuration is renamed to extra.laminas
- Loading branch information
Showing
6 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extra": { | ||
"zf": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extra": { | ||
"laminas": {} | ||
} | ||
} |