Skip to content

Commit cbefff3

Browse files
committed
Update some unit tests for Windows
1 parent 08e15b6 commit cbefff3

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

tests/phpunit/ComposerJsonTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ public function set_up() {
3737
}
3838
$class_wp_cli_capture_exit->setValue( null, true );
3939

40-
$this->temp_dir = Utils\get_temp_dir() . uniqid( 'wp-cli-test-package-composer-json-', true ) . '/';
40+
$temp_dir = Utils\get_temp_dir();
41+
if ( Utils\is_windows() ) {
42+
$temp_dir = realpath( $temp_dir ) ?: $temp_dir;
43+
$temp_dir = str_replace( '\\', '/', $temp_dir );
44+
}
45+
$this->temp_dir = rtrim( $temp_dir, '/' ) . '/' . uniqid( 'wp-cli-test-package-composer-json-', true ) . '/';
4146
mkdir( $this->temp_dir );
4247
}
4348

@@ -193,6 +198,10 @@ public function test_get_composer_json_path_backup_decoded() {
193198
}
194199

195200
private function mac_safe_path( $path ) {
196-
return preg_replace( '#^/private/(var|tmp)/#i', '/$1/', $path );
201+
$path = preg_replace( '#^/private/(var|tmp)/#i', '/$1/', $path );
202+
if ( Utils\is_windows() ) {
203+
$path = str_replace( '\\', '/', $path );
204+
}
205+
return $path;
197206
}
198207
}

tests/phpunit/JsonManipulatorTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,10 +2167,11 @@ public function testAddMainKeyWithContentHavingDollarSignFollowedByDigit2()
21672167
$manipulator = new JsonManipulator('{}');
21682168

21692169
$this->assertTrue($manipulator->addMainKey('foo', '$1bar'));
2170-
$this->assertEquals('{
2170+
$expected = '{
21712171
"foo": "$1bar"
21722172
}
2173-
', $manipulator->getContents());
2173+
';
2174+
$this->assertEquals( str_replace( "\r\n", "\n", $expected ), str_replace( "\r\n", "\n", $manipulator->getContents() ) );
21742175
}
21752176

21762177
public function testUpdateMainKey()
@@ -2301,9 +2302,10 @@ public function testRemoveMainKey()
23012302

23022303
$this->assertTrue($manipulator->removeMainKey('require'));
23032304
$this->assertTrue($manipulator->removeMainKey('require-dev'));
2304-
$this->assertEquals('{
2305+
$expected = '{
23052306
}
2306-
', $manipulator->getContents());
2307+
';
2308+
$this->assertEquals( str_replace( "\r\n", "\n", $expected ), str_replace( "\r\n", "\n", $manipulator->getContents() ) );
23072309
}
23082310

23092311
public function testIndentDetection()

0 commit comments

Comments
 (0)