Skip to content

Commit bca4974

Browse files
committed
Make split platform independend
1 parent c5ac781 commit bca4974

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

src/DocBlock/DescriptionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private function lex(string $contents): array
146146
*/
147147
private function removeSuperfluousStartingWhitespace(string $contents): string
148148
{
149-
$lines = explode("\n", $contents);
149+
$lines = Utils::pregSplit("/\r\n?|\n/", $contents);
150150

151151
// if there is only one line then we don't have lines with superfluous whitespace and
152152
// can use the contents as-is

tests/integration/InterpretingDocBlocksTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@ public function testInterpretingASimpleDocBlock(): void
7979
$this->assertInstanceOf(DocBlock::class, $docblock);
8080
$this->assertSame('This is an example of a summary.', $summary);
8181
$this->assertInstanceOf(Description::class, $description);
82-
$this->assertSame($descriptionText, $description->render());
82+
$this->assertSame(
83+
str_replace(
84+
PHP_EOL,
85+
"\n",
86+
$descriptionText
87+
),
88+
$description->render()
89+
);
8390
$this->assertEmpty($docblock->getTags());
8491
}
8592

@@ -124,6 +131,9 @@ public function testDescriptionsCanEscapeAtSignsAndClosingBraces(): void
124131
include(__DIR__ . '/../../examples/playing-with-descriptions/02-escaping.php');
125132

126133
$this->assertSame(
134+
str_replace(
135+
PHP_EOL,
136+
"\n",
127137
<<<'DESCRIPTION'
128138
You can escape the @-sign by surrounding it with braces, for example: @. And escape a closing brace within an
129139
inline tag by adding an opening brace in front of it like this: }.
@@ -135,7 +145,7 @@ public function testDescriptionsCanEscapeAtSignsAndClosingBraces(): void
135145
136146
Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
137147
DESCRIPTION
138-
,
148+
),
139149
$foundDescription
140150
);
141151
}

tests/unit/DocBlock/DescriptionFactoryTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use phpDocumentor\Reflection\Types\Context;
2121
use PHPUnit\Framework\TestCase;
2222

23+
use function str_replace;
24+
2325
/**
2426
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\DescriptionFactory
2527
* @covers ::<private>
@@ -192,7 +194,7 @@ public function testIfSuperfluousStartingSpacesAreRemoved(): void
192194

193195
$description = $factory->create($descriptionText, new Context(''));
194196

195-
$this->assertSame($expectedDescription, $description->render());
197+
$this->assertSame(str_replace(PHP_EOL, "\n", $expectedDescription), $description->render());
196198
}
197199

198200
/**

tests/unit/DocBlock/SerializerTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testReconstructsADocCommentFromADocBlock(): void
6363
]
6464
);
6565

66-
$this->assertSame($expected, $fixture->getDocComment($docBlock));
66+
$this->assertSameString($expected, $fixture->getDocComment($docBlock));
6767
}
6868

6969
/**
@@ -98,7 +98,7 @@ public function testAddPrefixToDocBlock(): void
9898
]
9999
);
100100

101-
$this->assertSame($expected, $fixture->getDocComment($docBlock));
101+
$this->assertSameString($expected, $fixture->getDocComment($docBlock));
102102
}
103103

104104
/**
@@ -133,7 +133,7 @@ public function testAddPrefixToDocBlockExceptFirstLine(): void
133133
]
134134
);
135135

136-
$this->assertSame($expected, $fixture->getDocComment($docBlock));
136+
$this->assertSameString($expected, $fixture->getDocComment($docBlock));
137137
}
138138

139139
/**
@@ -174,7 +174,7 @@ public function testWordwrapsAroundTheGivenAmountOfCharacters(): void
174174
]
175175
);
176176

177-
$this->assertSame($expected, $fixture->getDocComment($docBlock));
177+
$this->assertSameString($expected, $fixture->getDocComment($docBlock));
178178
}
179179

180180
/**
@@ -198,9 +198,16 @@ public function testNoExtraSpacesAfterTagRemoval(): void
198198
$genericTag = new DocBlock\Tags\Generic('unknown-tag');
199199

200200
$docBlock = new DocBlock('', null, [$genericTag]);
201-
$this->assertSame($expected, $fixture->getDocComment($docBlock));
201+
$this->assertSameString($expected, $fixture->getDocComment($docBlock));
202202

203203
$docBlock->removeTag($genericTag);
204-
$this->assertSame($expectedAfterRemove, $fixture->getDocComment($docBlock));
204+
$this->assertSameString($expectedAfterRemove, $fixture->getDocComment($docBlock));
205+
}
206+
207+
public function assertSameString(string $expected, string $actual): void
208+
{
209+
$expected = str_replace(PHP_EOL, "\n", $expected);
210+
211+
self::assertSame($expected, $actual);
205212
}
206213
}

tests/unit/DocBlockFactoryTest.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function testSummaryAndDescriptionAreSeparated(string $given, string $sum
134134
$docblock = $fixture->create($given);
135135

136136
$this->assertSame($summary, $docblock->getSummary());
137-
$this->assertEquals(new Description($description), $docblock->getDescription());
137+
$this->assertEquals(new Description(str_replace(PHP_EOL, "\n", $description)), $docblock->getDescription());
138138
}
139139

140140
/**
@@ -159,12 +159,7 @@ public function testDescriptionsRetainFormatting(): void
159159
*/
160160
DOCBLOCK;
161161

162-
$description = <<<DESCRIPTION
163-
This is a multiline Description
164-
that contains a code block.
165-
166-
See here: a CodeBlock
167-
DESCRIPTION;
162+
$description = "This is a multiline Description\nthat contains a code block.\n\n See here: a CodeBlock";
168163

169164
$docblock = $fixture->create($given);
170165

@@ -180,14 +175,9 @@ public function testDescriptionsRetainFormatting(): void
180175
*/
181176
public function testTagsAreInterpretedUsingFactory(): void
182177
{
183-
$tagString = <<<TAG
184-
@author Mike van Riel <[email protected]> This is with
185-
multiline description.
186-
TAG;
187-
188178
$tag = m::mock(Tag::class);
189179
$tagFactory = m::mock(TagFactory::class);
190-
$tagFactory->shouldReceive('create')->with($tagString, m::type(Context::class))->andReturn($tag);
180+
$tagFactory->shouldReceive('create')->with(m::any(), m::type(Context::class))->andReturn($tag);
191181

192182
$fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory);
193183

0 commit comments

Comments
 (0)