Skip to content

Commit 790a021

Browse files
committed
Normalize longhand syntax
1 parent 563af3f commit 790a021

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

src/Blueprint.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public function parse($content)
2222
return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2];
2323
}, $content);
2424

25+
$content = preg_replace_callback('/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?): true$/mi', function ($matches) {
26+
return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2];
27+
}, $content);
28+
2529
return Yaml::parse($content);
2630
}
2731

tests/Feature/BlueprintTest.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,33 @@ public function it_parses_shorthands_with_timezones()
107107
], $this->subject->parse($blueprint));
108108
}
109109

110+
/**
111+
* @test
112+
*/
113+
public function it_parses_longhands()
114+
{
115+
$blueprint = $this->fixture('definitions/longhands.bp');
116+
117+
$this->assertEquals([
118+
'models' => [
119+
'Proper' => [
120+
'id' => 'id',
121+
'softdeletes' => 'softDeletes',
122+
'timestamps' => 'timestamps',
123+
],
124+
'Lower' => [
125+
'id' => 'id',
126+
'softdeletes' => 'softdeletes',
127+
'timestampstz' => 'timestampstz',
128+
],
129+
'Timezone' => [
130+
'softdeletestz' => 'softdeletestz',
131+
'timestampstz' => 'timestampsTz',
132+
],
133+
],
134+
], $this->subject->parse($blueprint));
135+
}
136+
110137
/**
111138
* @test
112139
*/
@@ -221,4 +248,4 @@ public function generate_uses_registered_generators_and_returns_generated_files(
221248
'deleted' => ['one/trashed.php', 'two/trashed.php'],
222249
], $this->subject->generate($tree));
223250
}
224-
}
251+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
models:
2+
Proper:
3+
id: true
4+
softDeletes: true
5+
timestamps: true
6+
7+
Lower:
8+
id: id
9+
softdeletes: true
10+
timestampstz: true
11+
12+
Timezone:
13+
softdeletestz: true
14+
timestampsTz: true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
models:
22
Comment:
33
post_id: id
4-
softdeletes
4+
softdeletes

0 commit comments

Comments
 (0)