diff --git a/src/Blueprint.php b/src/Blueprint.php index 6bf460b7..24c1bbe4 100644 --- a/src/Blueprint.php +++ b/src/Blueprint.php @@ -26,20 +26,22 @@ public static function relativeNamespace(string $fullyQualifiedClassName) public function parse($content) { + $content = str_replace(["\r\n", "\r"], "\n", $content); + $content = preg_replace_callback('/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?)$/mi', function ($matches) { - return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2]; + return $matches[1].strtolower($matches[2]).': '.$matches[2]; }, $content); $content = preg_replace_callback('/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?): true$/mi', function ($matches) { - return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2]; + return $matches[1].strtolower($matches[2]).': '.$matches[2]; }, $content); $content = preg_replace_callback('/^(\s+)resource(: true)?$/mi', function ($matches) { - return $matches[1] . 'resource: all'; + return $matches[1].'resource: all'; }, $content); $content = preg_replace_callback('/^(\s+)uuid(: true)?$/mi', function ($matches) { - return $matches[1] . 'id: uuid primary'; + return $matches[1].'id: uuid primary'; }, $content); return Yaml::parse($content); diff --git a/tests/Feature/BlueprintTest.php b/tests/Feature/BlueprintTest.php index 891fdfda..8fc98492 100644 --- a/tests/Feature/BlueprintTest.php +++ b/tests/Feature/BlueprintTest.php @@ -213,6 +213,51 @@ public function it_parses_the_readme_example() ], $this->subject->parse($blueprint)); } + /** + * @test + */ + public function it_parses_the_readme_example_with_different_platform_eols() + { + $definition = $this->fixture('definitions/readme-example.bp'); + + $LF = "\n"; + $CR = "\r"; + $CRLF = "\r\n"; + + $definition_mac_eol = str_replace($LF, $CR, $definition); + $definition_windows_eol = str_replace($LF, $CRLF, $definition); + + $expected = [ + 'models' => [ + 'Post' => [ + 'title' => 'string:400', + 'content' => 'longtext', + 'published_at' => 'nullable timestamp', + ], + ], + 'controllers' => [ + 'Post' => [ + 'index' => [ + 'query' => 'all:posts', + 'render' => 'post.index with:posts', + ], + 'store' => [ + 'validate' => 'title, content', + 'save' => 'post', + 'send' => 'ReviewNotification to:post.author with:post', + 'dispatch' => 'SyncMedia with:post', + 'fire' => 'NewPost with:post', + 'flash' => 'post.title', + 'redirect' => 'post.index', + ], + ], + ], + ]; + + $this->assertEquals($expected, $this->subject->parse($definition_mac_eol)); + $this->assertEquals($expected, $this->subject->parse($definition_windows_eol)); + } + /** * @test */