Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 45 additions & 0 deletions tests/Feature/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down