Skip to content

Commit f2e8574

Browse files
committed
minor symfony#59894 [Console] fix tests on Windows (xabbuh)
This PR was merged into the 7.3 branch. Discussion ---------- [Console] fix tests on Windows | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- 456126f fix tests on Windows
2 parents d34aebf + 456126f commit f2e8574

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

src/Symfony/Component/Console/Tests/Helper/TreeHelperTest.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testRenderWithoutNode()
2525
$tree = TreeHelper::createTree($output);
2626

2727
$tree->render();
28-
$this->assertSame("\n", $output->fetch());
28+
$this->assertSame(PHP_EOL, $output->fetch());
2929
}
3030

3131
public function testRenderSingleNode()
@@ -35,7 +35,7 @@ public function testRenderSingleNode()
3535
$tree = TreeHelper::createTree($output, $rootNode);
3636

3737
$tree->render();
38-
$this->assertSame("Root\n", $output->fetch());
38+
$this->assertSame("Root\n", self::normalizeLineBreaks($output->fetch()));
3939
}
4040

4141
public function testRenderTwoLevelTree()
@@ -55,7 +55,7 @@ public function testRenderTwoLevelTree()
5555
Root
5656
├── Child 1
5757
└── Child 2
58-
TREE, trim($output->fetch()));
58+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
5959
}
6060

6161
public function testRenderThreeLevelTree()
@@ -78,7 +78,7 @@ public function testRenderThreeLevelTree()
7878
├── Child 1
7979
│ └── SubChild 1
8080
└── Child 2
81-
TREE, trim($output->fetch()));
81+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
8282
}
8383

8484
public function testRenderMultiLevelTree()
@@ -107,7 +107,7 @@ public function testRenderMultiLevelTree()
107107
│ │ └── SubSubChild 1
108108
│ └── SubChild 2
109109
└── Child 2
110-
TREE, trim($output->fetch()));
110+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
111111
}
112112

113113
public function testRenderSingleNodeTree()
@@ -119,7 +119,7 @@ public function testRenderSingleNodeTree()
119119
$tree->render();
120120
$this->assertSame(<<<TREE
121121
Root
122-
TREE, trim($output->fetch()));
122+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
123123
}
124124

125125
public function testRenderEmptyTree()
@@ -131,7 +131,7 @@ public function testRenderEmptyTree()
131131
$tree->render();
132132
$this->assertSame(<<<TREE
133133
Root
134-
TREE, trim($output->fetch()));
134+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
135135
}
136136

137137
public function testRenderDeeplyNestedTree()
@@ -169,7 +169,7 @@ public function testRenderDeeplyNestedTree()
169169
└── Level 8
170170
└── Level 9
171171
└── Level 10
172-
TREE, trim($output->fetch()));
172+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
173173
}
174174

175175
public function testRenderNodeWithMultipleChildren()
@@ -192,7 +192,7 @@ public function testRenderNodeWithMultipleChildren()
192192
├── Child 1
193193
├── Child 2
194194
└── Child 3
195-
TREE, trim($output->fetch()));
195+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
196196
}
197197

198198
public function testRenderTreeWithDuplicateNodeNames()
@@ -215,7 +215,7 @@ public function testRenderTreeWithDuplicateNodeNames()
215215
├── Child
216216
│ └── Child
217217
└── Child
218-
TREE, trim($output->fetch()));
218+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
219219
}
220220

221221
public function testRenderTreeWithComplexNodeNames()
@@ -238,7 +238,7 @@ public function testRenderTreeWithComplexNodeNames()
238238
├── Child 1 (special)
239239
│ └── Node with spaces
240240
└── Child_2@#$
241-
TREE, trim($output->fetch()));
241+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
242242
}
243243

244244
public function testRenderTreeWithCycle()
@@ -272,7 +272,7 @@ public function testRenderWideTree()
272272
$tree = TreeHelper::createTree($output, $rootNode);
273273
$tree->render();
274274

275-
$lines = explode("\n", trim($output->fetch()));
275+
$lines = explode("\n", self::normalizeLineBreaks(trim($output->fetch())));
276276
$this->assertCount(101, $lines);
277277
$this->assertSame('Root', $lines[0]);
278278
$this->assertSame('└── Child 100', end($lines));
@@ -290,7 +290,7 @@ public function testCreateWithRoot()
290290
root
291291
├── child1
292292
└── child2
293-
TREE, trim($output->fetch()));
293+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
294294
}
295295

296296
public function testCreateWithNestedArray()
@@ -309,7 +309,7 @@ public function testCreateWithNestedArray()
309309
│ └── child2.2
310310
│ └── child2.2.1
311311
└── child3
312-
TREE, trim($output->fetch()));
312+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
313313
}
314314

315315
public function testCreateWithoutRoot()
@@ -323,7 +323,7 @@ public function testCreateWithoutRoot()
323323
$this->assertSame(<<<TREE
324324
├── child1
325325
└── child2
326-
TREE, trim($output->fetch()));
326+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
327327
}
328328

329329
public function testCreateWithEmptyArray()
@@ -334,6 +334,11 @@ public function testCreateWithEmptyArray()
334334
$tree = TreeHelper::createTree($output, null, $array);
335335

336336
$tree->render();
337-
$this->assertSame('', trim($output->fetch()));
337+
$this->assertSame('', self::normalizeLineBreaks(trim($output->fetch())));
338+
}
339+
340+
private static function normalizeLineBreaks($text)
341+
{
342+
return str_replace(\PHP_EOL, "\n", $text);
338343
}
339344
}

src/Symfony/Component/Console/Tests/Helper/TreeStyleTest.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testDefaultStyle()
4141
│ │ └── B12
4242
│ └── B2
4343
└── C
44-
TREE, trim($output->fetch()));
44+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
4545
}
4646

4747
public function testBoxStyle()
@@ -63,7 +63,7 @@ public function testBoxStyle()
6363
┃ ┃ ┗╸ B12
6464
┃ ┗╸ B2
6565
┗╸ C
66-
TREE, trim($output->fetch()));
66+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
6767
}
6868

6969
public function testBoxDoubleStyle()
@@ -85,7 +85,7 @@ public function testBoxDoubleStyle()
8585
║ ║ ╚═ B12
8686
║ ╚═ B2
8787
╚═ C
88-
TREE, trim($output->fetch()));
88+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
8989
}
9090

9191
public function testCompactStyle()
@@ -107,7 +107,7 @@ public function testCompactStyle()
107107
│ │ └ B12
108108
│ └ B2
109109
└ C
110-
TREE, trim($output->fetch()));
110+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
111111
}
112112

113113
public function testLightStyle()
@@ -129,7 +129,7 @@ public function testLightStyle()
129129
| | `-- B12
130130
| `-- B2
131131
`-- C
132-
TREE, trim($output->fetch()));
132+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
133133
}
134134

135135
public function testMinimalStyle()
@@ -151,7 +151,7 @@ public function testMinimalStyle()
151151
. . . B12
152152
. . B2
153153
. C
154-
TREE, trim($output->fetch()));
154+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
155155
}
156156

157157
public function testRoundedStyle()
@@ -173,7 +173,7 @@ public function testRoundedStyle()
173173
│ │ ╰─ B12
174174
│ ╰─ B2
175175
╰─ C
176-
TREE, trim($output->fetch()));
176+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
177177
}
178178

179179
public function testCustomPrefix()
@@ -196,7 +196,7 @@ public function testCustomPrefix()
196196
C D D B F B12
197197
C D B F B2
198198
C B F C
199-
TREE, trim($output->fetch()));
199+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
200200
}
201201

202202
private static function createTree(OutputInterface $output, ?TreeStyle $style = null): TreeHelper
@@ -223,4 +223,9 @@ private static function createTree(OutputInterface $output, ?TreeStyle $style =
223223

224224
return TreeHelper::createTree($output, $root, [], $style);
225225
}
226+
227+
private static function normalizeLineBreaks($text)
228+
{
229+
return str_replace(\PHP_EOL, "\n", $text);
230+
}
226231
}

src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function testTree()
187187
│ │ └── B12
188188
│ └── B2
189189
└── C
190-
TREE, trim($output->fetch()));
190+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
191191
}
192192

193193
public function testCreateTreeWithArray()
@@ -208,7 +208,7 @@ public function testCreateTreeWithArray()
208208
│ │ └── B12
209209
│ └── B2
210210
└── C
211-
TREE, trim($output->fetch()));
211+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
212212
}
213213

214214
public function testCreateTreeWithIterable()
@@ -229,7 +229,7 @@ public function testCreateTreeWithIterable()
229229
│ │ └── B12
230230
│ └── B2
231231
└── C
232-
TREE, trim($output->fetch()));
232+
TREE, self::normalizeLineBreaks(trim($output->fetch())));
233233
}
234234

235235
public function testCreateTreeWithConsoleOutput()
@@ -314,4 +314,9 @@ public function testAskAndClearExpectFullSectionCleared()
314314
escapeshellcmd(stream_get_contents($output->getStream()))
315315
);
316316
}
317+
318+
private static function normalizeLineBreaks($text)
319+
{
320+
return str_replace(\PHP_EOL, "\n", $text);
321+
}
317322
}

0 commit comments

Comments
 (0)