@@ -110,6 +110,90 @@ public function getId(): string
110
110
$ this ->assertEquals ($ expected , File::get ($ destination ));
111
111
}
112
112
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
+
113
197
/**
114
198
* @param \Illuminate\Foundation\Application $app
115
199
*/
0 commit comments