Skip to content

Commit 7f83f81

Browse files
committed
Address PR lchrusciel#209 review comments: improve diff output formatting
- Remove redundant matcher error message from assertResponseContent The detailed "Value X does not match pattern Y" message was duplicating information already visible in the contextual diff - Move expected file path to end of diff output in absolute format The file path now appears at the bottom as "Expected file: /absolute/path" making it easier to reference after reviewing the diff - Update all tests to reflect the new file path format Note: Pattern matcher normalization (avoiding display of passing pattern matches in diff) remains a complex issue requiring deeper refactoring of how expected responses are compared with actual responses. https://claude.ai/code/session_014m1n4X3T8cCXz2HguPjWFH
1 parent 680b12d commit 7f83f81

5 files changed

Lines changed: 10 additions & 13 deletions

File tree

src/ApiTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected function assertResponseContent(string $actualResponse, string $filenam
192192
'expectedFilePath' => $expectedFilePath,
193193
]);
194194

195-
self::fail($matcher->getError() . \PHP_EOL . $diff->render($renderer));
195+
self::fail($diff->render($renderer));
196196
}
197197
}
198198

src/Renderer/ContextualDiffRenderer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ public function render(): string
4949
{
5050
$output = '';
5151

52-
// Add expected file path if provided
53-
if ($this->expectedFilePath !== null) {
54-
$output .= sprintf("--- Expected: %s\n", $this->expectedFilePath);
55-
$output .= "+++ Actual\n";
56-
}
57-
5852
$opCodes = $this->diff->getGroupedOpcodes();
5953

6054
foreach ($opCodes as $group) {
@@ -100,6 +94,12 @@ public function render(): string
10094
}
10195
}
10296

97+
// Add expected file path at the end if provided
98+
if ($this->expectedFilePath !== null) {
99+
$absolutePath = realpath($this->expectedFilePath) ?: $this->expectedFilePath;
100+
$output .= sprintf("\nExpected file: %s\n", $absolutePath);
101+
}
102+
103103
return $output;
104104
}
105105

test/src/Tests/Controller/SampleControllerJsonTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ public function testDiffVisualizationShowsContextAndColors(): void
168168
} catch (AssertionFailedError $e) {
169169
$message = $e->getMessage();
170170

171-
$this->assertStringContainsString('--- Expected:', $message);
171+
$this->assertStringContainsString('Expected file:', $message);
172172
$this->assertStringContainsString('incorrect_hello_world.json', $message);
173-
$this->assertStringContainsString('+++ Actual', $message);
174173
$this->assertStringContainsString('-', $message);
175174
$this->assertStringContainsString('+', $message);
176175
$this->assertStringContainsString('message', $message);

test/src/Tests/Controller/SampleControllerXmlTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ public function testDiffVisualizationShowsContextAndColors(): void
102102
} catch (AssertionFailedError $e) {
103103
$message = $e->getMessage();
104104

105-
$this->assertStringContainsString('--- Expected:', $message);
105+
$this->assertStringContainsString('Expected file:', $message);
106106
$this->assertStringContainsString('incorrect_hello_world.xml', $message);
107-
$this->assertStringContainsString('+++ Actual', $message);
108107
$this->assertStringContainsString('-', $message);
109108
$this->assertStringContainsString('+', $message);
110109
}

test/src/Tests/Renderer/ContextualDiffRendererTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public function testRenderIncludesExpectedFilePath(): void
7070
]);
7171
$output = $diff->render($renderer);
7272

73-
$this->assertStringContainsString('--- Expected: /path/to/expected.json', $output);
74-
$this->assertStringContainsString('+++ Actual', $output);
73+
$this->assertStringContainsString('Expected file: /path/to/expected.json', $output);
7574
}
7675

7776
public function testRenderHandlesInsertions(): void

0 commit comments

Comments
 (0)