Skip to content

Commit 0c797e3

Browse files
committed
Fix using -m|--mapping option in MakeEntityCommand.
1 parent 62e231b commit 0c797e3

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

src/Commands/MakeEntityCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function handle()
5353
protected function createMapping(): void
5454
{
5555
$this->call('make:mapping', [
56-
'class' => $this->getNameInput(),
56+
'name' => $this->getNameInput(),
5757
'--force' => $this->option('force')
5858
]);
5959
}

tests/Feature/MakeEntityCommandTest.php

+84
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,90 @@ public function getId(): string
110110
$this->assertEquals($expected, File::get($destination));
111111
}
112112

113+
/**
114+
* @test
115+
*/
116+
public function it_allows_creating_mapping_with_entity_class(): void
117+
{
118+
$entityFilePath = app_path('Entities/Foo.php');
119+
$mappingFilePath = app_path('Database/Doctrine/Mappings/FooMapping.php');
120+
121+
// Make sure we're starting from a clean base.
122+
if (File::exists($entityFilePath)) {
123+
File::delete($entityFilePath);
124+
}
125+
// Make sure we're starting from a clean base.
126+
if (File::exists($mappingFilePath)) {
127+
File::delete($mappingFilePath);
128+
}
129+
130+
$this->assertFalse(File::exists($entityFilePath), 'The destination entity file already exists.');
131+
$this->assertFalse(File::exists($mappingFilePath), 'The destination mapping file already exists.');
132+
133+
Artisan::call('make:entity -m Foo');
134+
135+
$this->assertTrue(File::exists($entityFilePath), 'The entity file was not generated where we expect.');
136+
$this->assertTrue(File::exists($mappingFilePath), 'The mapping file was not generated where we expect.');
137+
138+
$entity = <<<'CLASS'
139+
<?php declare(strict_types=1);
140+
141+
namespace App\Entities;
142+
143+
use Illuminate\Contracts\Support\{Arrayable, Jsonable};
144+
use JsonSerializable;
145+
use Ramsey\Uuid\{Uuid, UuidInterface};
146+
use Zain\LaravelDoctrine\Jetpack\Serializer\SerializesAttributes;
147+
148+
class Foo implements Arrayable, Jsonable, JsonSerializable
149+
{
150+
use SerializesAttributes;
151+
152+
protected UuidInterface $id;
153+
154+
public function __construct()
155+
{
156+
$this->id = Uuid::uuid1();
157+
}
158+
159+
public function getId(): string
160+
{
161+
return $this->id->toString();
162+
}
163+
}
164+
165+
CLASS;
166+
167+
$this->assertEquals($entity, File::get($entityFilePath));
168+
169+
$mapping = <<<'CLASS'
170+
<?php declare(strict_types=1);
171+
172+
namespace App\Database\Doctrine\Mappings;
173+
174+
use App\Entities\Foo;
175+
use LaravelDoctrine\Fluent\EntityMapping;
176+
use LaravelDoctrine\Fluent\Fluent;
177+
178+
class FooMapping extends EntityMapping
179+
{
180+
public function mapFor()
181+
{
182+
return Foo::class;
183+
}
184+
185+
public function map(Fluent $map)
186+
{
187+
$map->uuidPrimaryKey();
188+
// ...
189+
$map->timestamps();
190+
}
191+
}
192+
193+
CLASS;
194+
$this->assertEquals($mapping, File::get($mappingFilePath));
195+
}
196+
113197
/**
114198
* @param \Illuminate\Foundation\Application $app
115199
*/

0 commit comments

Comments
 (0)