-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize line endings in test assertions for Windows platform
Refactor test assertions to use a helper method for normalizing line endings. This ensures consistency across different operating systems and prevents test failures due to line ending discrepancies.
- Loading branch information
Showing
1 changed file
with
17 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ public function testInstanceCompileString(): void | |
return 'bear'; | ||
EOT; | ||
$this->assertSame($expected, (string) $code); | ||
$this->assertSame($this->normalizeLineEndings($expected), (string) $code); | ||
} | ||
|
||
public function testInstanceCompileInt(): void | ||
|
@@ -45,7 +45,7 @@ public function testInstanceCompileInt(): void | |
return 1; | ||
EOT; | ||
$this->assertSame($expected, (string) $code); | ||
$this->assertSame($this->normalizeLineEndings($expected), (string) $code); | ||
} | ||
|
||
public function testInstanceCompileArray(): void | ||
|
@@ -58,8 +58,8 @@ public function testInstanceCompileArray(): void | |
return array(1, 2, 3); | ||
EOT; | ||
$this->assertContains((string) $code, [ | ||
str_replace('array(1, 2, 3)', '[1, 2, 3]', $expected), | ||
$expected, | ||
str_replace('array(1, 2, 3)', '[1, 2, 3]', $this->normalizeLineEndings($expected)), | ||
$this->normalizeLineEndings($expected), | ||
]); | ||
} | ||
|
||
|
@@ -88,9 +88,9 @@ public function testDependencyCompile(): void | |
str_replace( | ||
'array(\'Ray\\Compiler\\FakeCar\', \'setHandle\', \'handle\')', | ||
'[\'Ray\\Compiler\\FakeCar\', \'setHandle\', \'handle\']', | ||
str_replace('\\\\', '\\', $expected) | ||
str_replace('\\\\', '\\', $this->normalizeLineEndings($expected)) | ||
), | ||
$expected, | ||
$this->normalizeLineEndings($expected), | ||
]); | ||
} | ||
|
||
|
@@ -108,7 +108,7 @@ public function testDependencyProviderCompile(): void | |
$isSingleton = false; | ||
return $instance->get(); | ||
EOT; | ||
$this->assertSame($expected, (string) $code); | ||
$this->assertSame($this->normalizeLineEndings($expected), (string) $code); | ||
} | ||
|
||
public function testDependencyInstanceCompile(): void | ||
|
@@ -121,7 +121,7 @@ public function testDependencyInstanceCompile(): void | |
return 'momo'; | ||
EOT; | ||
$this->assertSame($expected, (string) $code); | ||
$this->assertSame($this->normalizeLineEndings($expected), (string) $code); | ||
} | ||
|
||
public function testDependencyObjectInstanceCompile(): void | ||
|
@@ -135,8 +135,8 @@ public function testDependencyObjectInstanceCompile(): void | |
return unserialize('O:23:"Ray\\Compiler\\FakeEngine":0:{}'); | ||
EOT; | ||
$this->assertContains((string) $code, [ | ||
str_replace('\\\\', '\\', $expected), | ||
$expected, | ||
str_replace('\\\\', '\\', $this->normalizeLineEndings($expected)), | ||
$this->normalizeLineEndings($expected), | ||
]); | ||
} | ||
|
||
|
@@ -165,6 +165,12 @@ public function testContextualProviderCompile(): void | |
$isSingleton = false; | ||
return $instance->get(); | ||
EOT; | ||
$this->assertSame($expected, (string) $code); | ||
$this->assertSame($this->normalizeLineEndings($expected), (string) $code); | ||
} | ||
|
||
private function normalizeLineEndings($content) | ||
Check failure on line 171 in tests/DependencyCompilerTest.php GitHub Actions / cs / Coding Standards
Check failure on line 171 in tests/DependencyCompilerTest.php GitHub Actions / cs / Coding Standards
Check failure on line 171 in tests/DependencyCompilerTest.php GitHub Actions / sa / PHPStan
|
||
{ | ||
// Convert Windows (CRLF: \r\n) and old Mac (CR: \r) to Unix (LF: \n) | ||
return str_replace(["\r\n", "\r"], "\n", $content); | ||
} | ||
} |