From bca4974b0b35e7a06cca93bc3c2399768c83ea91 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Thu, 26 Aug 2021 15:40:21 +0200 Subject: [PATCH] Make split platform independend --- src/DocBlock/DescriptionFactory.php | 2 +- .../integration/InterpretingDocBlocksTest.php | 14 ++++++++++++-- .../unit/DocBlock/DescriptionFactoryTest.php | 4 +++- tests/unit/DocBlock/SerializerTest.php | 19 +++++++++++++------ tests/unit/DocBlockFactoryTest.php | 16 +++------------- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index b53b9c4..c125af0 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -146,7 +146,7 @@ class DescriptionFactory */ private function removeSuperfluousStartingWhitespace(string $contents): string { - $lines = explode("\n", $contents); + $lines = Utils::pregSplit("/\r\n?|\n/", $contents); // if there is only one line then we don't have lines with superfluous whitespace and // can use the contents as-is diff --git a/tests/integration/InterpretingDocBlocksTest.php b/tests/integration/InterpretingDocBlocksTest.php index 7ef37ba..2c8358c 100644 --- a/tests/integration/InterpretingDocBlocksTest.php +++ b/tests/integration/InterpretingDocBlocksTest.php @@ -79,7 +79,14 @@ DESCRIPTION; $this->assertInstanceOf(DocBlock::class, $docblock); $this->assertSame('This is an example of a summary.', $summary); $this->assertInstanceOf(Description::class, $description); - $this->assertSame($descriptionText, $description->render()); + $this->assertSame( + str_replace( + PHP_EOL, + "\n", + $descriptionText + ), + $description->render() + ); $this->assertEmpty($docblock->getTags()); } @@ -124,6 +131,9 @@ DESCRIPTION; include(__DIR__ . '/../../examples/playing-with-descriptions/02-escaping.php'); $this->assertSame( + str_replace( + PHP_EOL, + "\n", <<<'DESCRIPTION' You can escape the @-sign by surrounding it with braces, for example: @. And escape a closing brace within an inline tag by adding an opening brace in front of it like this: }. @@ -135,7 +145,7 @@ Here are example texts where you can see how they could be used in a real life s Do note that an {@internal inline tag that has an opening brace ({) does not break out}. DESCRIPTION - , + ), $foundDescription ); } diff --git a/tests/unit/DocBlock/DescriptionFactoryTest.php b/tests/unit/DocBlock/DescriptionFactoryTest.php index 237c650..394f845 100644 --- a/tests/unit/DocBlock/DescriptionFactoryTest.php +++ b/tests/unit/DocBlock/DescriptionFactoryTest.php @@ -20,6 +20,8 @@ use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag; use phpDocumentor\Reflection\Types\Context; use PHPUnit\Framework\TestCase; +use function str_replace; + /** * @coversDefaultClass \phpDocumentor\Reflection\DocBlock\DescriptionFactory * @covers :: @@ -192,7 +194,7 @@ DESCRIPTION; $description = $factory->create($descriptionText, new Context('')); - $this->assertSame($expectedDescription, $description->render()); + $this->assertSame(str_replace(PHP_EOL, "\n", $expectedDescription), $description->render()); } /** diff --git a/tests/unit/DocBlock/SerializerTest.php b/tests/unit/DocBlock/SerializerTest.php index 28ca510..bf92744 100644 --- a/tests/unit/DocBlock/SerializerTest.php +++ b/tests/unit/DocBlock/SerializerTest.php @@ -63,7 +63,7 @@ DOCCOMMENT; ] ); - $this->assertSame($expected, $fixture->getDocComment($docBlock)); + $this->assertSameString($expected, $fixture->getDocComment($docBlock)); } /** @@ -98,7 +98,7 @@ DOCCOMMENT; ] ); - $this->assertSame($expected, $fixture->getDocComment($docBlock)); + $this->assertSameString($expected, $fixture->getDocComment($docBlock)); } /** @@ -133,7 +133,7 @@ DOCCOMMENT; ] ); - $this->assertSame($expected, $fixture->getDocComment($docBlock)); + $this->assertSameString($expected, $fixture->getDocComment($docBlock)); } /** @@ -174,7 +174,7 @@ DOCCOMMENT; ] ); - $this->assertSame($expected, $fixture->getDocComment($docBlock)); + $this->assertSameString($expected, $fixture->getDocComment($docBlock)); } /** @@ -198,9 +198,16 @@ DOCCOMMENT_AFTER_REMOVE; $genericTag = new DocBlock\Tags\Generic('unknown-tag'); $docBlock = new DocBlock('', null, [$genericTag]); - $this->assertSame($expected, $fixture->getDocComment($docBlock)); + $this->assertSameString($expected, $fixture->getDocComment($docBlock)); $docBlock->removeTag($genericTag); - $this->assertSame($expectedAfterRemove, $fixture->getDocComment($docBlock)); + $this->assertSameString($expectedAfterRemove, $fixture->getDocComment($docBlock)); + } + + public function assertSameString(string $expected, string $actual): void + { + $expected = str_replace(PHP_EOL, "\n", $expected); + + self::assertSame($expected, $actual); } } diff --git a/tests/unit/DocBlockFactoryTest.php b/tests/unit/DocBlockFactoryTest.php index 5fa429c..0397181 100644 --- a/tests/unit/DocBlockFactoryTest.php +++ b/tests/unit/DocBlockFactoryTest.php @@ -134,7 +134,7 @@ class DocBlockFactoryTest extends TestCase $docblock = $fixture->create($given); $this->assertSame($summary, $docblock->getSummary()); - $this->assertEquals(new Description($description), $docblock->getDescription()); + $this->assertEquals(new Description(str_replace(PHP_EOL, "\n", $description)), $docblock->getDescription()); } /** @@ -159,12 +159,7 @@ class DocBlockFactoryTest extends TestCase */ DOCBLOCK; - $description = <<create($given); @@ -180,14 +175,9 @@ DESCRIPTION; */ public function testTagsAreInterpretedUsingFactory(): void { - $tagString = << This is with - multiline description. -TAG; - $tag = m::mock(Tag::class); $tagFactory = m::mock(TagFactory::class); - $tagFactory->shouldReceive('create')->with($tagString, m::type(Context::class))->andReturn($tag); + $tagFactory->shouldReceive('create')->with(m::any(), m::type(Context::class))->andReturn($tag); $fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory);