Skip to content

Commit 49444de

Browse files
committed
Separate test to drive making directory
1 parent e0e24fe commit 49444de

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

tests/Feature/Generator/FactoryGeneratorTest.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function output_writes_migration_for_model_tree($definition, $path, $migr
5555
->andReturn(file_get_contents('stubs/factory.stub'));
5656

5757
$this->files->expects('exists')
58-
->with(dirname($path))
58+
->with('database/factories')
5959
->andReturnTrue();
6060

6161
$this->files->expects('put')
@@ -81,9 +81,7 @@ public function output_respects_configuration()
8181

8282
$this->files->expects('exists')
8383
->with('database/factories')
84-
->andReturnFalse();
85-
$this->files->expects('makeDirectory')
86-
->with('database/factories', 0755, true);
84+
->andReturnTrue();
8785

8886
$this->files->expects('put')
8987
->with('database/factories/PostFactory.php', $this->fixture('factories/post-configured.php'));
@@ -94,14 +92,37 @@ public function output_respects_configuration()
9492
$this->assertEquals(['created' => ['database/factories/PostFactory.php']], $this->subject->output($tree));
9593
}
9694

95+
/**
96+
* @test
97+
*/
98+
public function output_creates_directory_for_nested_components()
99+
{
100+
$this->files->expects('stub')
101+
->with('factory.stub')
102+
->andReturn(file_get_contents('stubs/factory.stub'));
103+
104+
$this->files->expects('exists')
105+
->with('database/factories/Admin')
106+
->andReturnFalse();
107+
$this->files->expects('makeDirectory')
108+
->with('database/factories/Admin', 0755, true);
109+
110+
$this->files->expects('put')
111+
->with('database/factories/Admin/UserFactory.php', $this->fixture('factories/nested-components.php'));
112+
113+
$tokens = $this->blueprint->parse($this->fixture('definitions/nested-components.bp'));
114+
$tree = $this->blueprint->analyze($tokens);
115+
116+
$this->assertEquals(['created' => ['database/factories/Admin/UserFactory.php']], $this->subject->output($tree));
117+
}
118+
97119
public function modelTreeDataProvider()
98120
{
99121
return [
100122
['definitions/phone.bp', 'database/factories/PhoneFactory.php', 'factories/phone.php'],
101123
['definitions/post.bp', 'database/factories/PostFactory.php', 'factories/post.php'],
102124
['definitions/team.bp', 'database/factories/TeamFactory.php', 'factories/team.php'],
103125
['definitions/unconventional.bp', 'database/factories/TeamFactory.php', 'factories/unconventional.php'],
104-
['definitions/nested-components.bp', 'database/factories/Admin/UserFactory.php', 'factories/nested-components.php'],
105126
['definitions/model-modifiers.bp', 'database/factories/ModifierFactory.php', 'factories/model-modifiers.php'],
106127
['definitions/model-key-constraints.bp', 'database/factories/OrderFactory.php', 'factories/model-key-constraints.php']
107128
];

0 commit comments

Comments
 (0)