Skip to content

Commit 6cf1f70

Browse files
committed
More normalization
1 parent 6d7b349 commit 6cf1f70

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/Package_Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public function path( $args ) {
531531
WP_CLI::error( 'Invalid package name.' );
532532
}
533533
}
534-
WP_CLI::line( $packages_dir );
534+
WP_CLI::line( Path::normalize( $packages_dir ) );
535535
}
536536

537537
/**
@@ -1158,7 +1158,7 @@ private function get_installed_package_by_name( $package_name ) {
11581158
* @return array Two-element array containing package name and version.
11591159
*/
11601160
private static function get_package_name_and_version_from_dir_package( $dir_package ) {
1161-
$composer_file = $dir_package . '/composer.json';
1161+
$composer_file = Path::normalize( $dir_package . '/composer.json' );
11621162
if ( ! file_exists( $composer_file ) ) {
11631163
WP_CLI::error( sprintf( "Invalid package: composer.json file '%s' not found.", $composer_file ) );
11641164
}

tests/phpunit/ComposerJsonTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ public function test_get_composer_json_path_backup_decoded() {
198198
}
199199

200200
private function mac_safe_path( $path ) {
201+
$path = \WP_CLI\Path::normalize( $path );
201202
$path = preg_replace( '#^/private/(var|tmp)/#i', '/$1/', $path );
202-
$path = str_replace( '\\', '/', $path );
203203
return $path;
204204
}
205205
}

tests/phpunit/JsonManipulatorTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testAddLink($json, $type, $package, $constraint, $expected)
2525
{
2626
$manipulator = new JsonManipulator($json);
2727
$this->assertTrue($manipulator->addLink($type, $package, $constraint));
28-
$this->assertEquals($expected, $manipulator->getContents());
28+
$this->assertJsonEquals($expected, $manipulator->getContents());
2929
}
3030

3131
public static function linkProvider()
@@ -1297,7 +1297,7 @@ public function testAddLinkAndSortPackages($json, $type, $package, $constraint,
12971297
{
12981298
$manipulator = new JsonManipulator($json);
12991299
$this->assertTrue($manipulator->addLink($type, $package, $constraint, $sortPackages));
1300-
$this->assertEquals($expected, $manipulator->getContents());
1300+
$this->assertJsonEquals($expected, $manipulator->getContents());
13011301
}
13021302

13031303
public static function providerAddLinkAndSortPackages()
@@ -1380,7 +1380,7 @@ public function testRemoveSubNode($json, $name, $expected, $expectedContent = nu
13801380

13811381
$this->assertEquals($expected, $manipulator->removeSubNode('repositories', $name));
13821382
if (null !== $expectedContent) {
1383-
$this->assertEquals($expectedContent, $manipulator->getContents());
1383+
$this->assertJsonEquals($expectedContent, $manipulator->getContents());
13841384
}
13851385
}
13861386

@@ -2578,4 +2578,7 @@ public static function providerRemoveSubNodeCaseInsensitive()
25782578
}
25792579
// WP_CLI: end caseInsensitive.
25802580

2581+
private function assertJsonEquals( $expected, $actual ) {
2582+
$this->assertEquals( preg_replace( '/\R/', "\n", $expected ), preg_replace( '/\R/', "\n", $actual ) );
2583+
}
25812584
}

0 commit comments

Comments
 (0)