Skip to content

Commit 1e75d38

Browse files
committed
Fix test
1 parent 30d806d commit 1e75d38

File tree

6 files changed

+3
-102
lines changed

6 files changed

+3
-102
lines changed

src/Dto/Source.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ public function __construct(
1515

1616
public static function fromArray(array $data): self
1717
{
18-
if (! is_subclass_of($data['model'] ?? null, Model::class)) {
19-
throw new Exception('The provided model, parent must be an instance of Illuminate\Database\Eloquent\Model');
20-
}
21-
2218
return new self(
2319
model: $data['model'],
2420
connection: $data['connection'] ?? config('database.default'),

tests/Commands/DataExtractCommandTest.php

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -117,40 +117,6 @@ class CommandTestUser extends Model
117117
->assertExitCode(0);
118118
});
119119

120-
// TODO: Fix test
121-
// it('displays available options when no name provided', function () {
122-
// config([
123-
// 'data-extractor.options' => [
124-
// [
125-
// 'name' => 'Option1',
126-
// 'description' => 'First option',
127-
// 'format' => 'sql',
128-
// 'source' => 'test',
129-
// ],
130-
// [
131-
// 'name' => 'Option2',
132-
// 'description' => 'Second option',
133-
// 'format' => 'csv',
134-
// 'source' => 'test',
135-
// ],
136-
// ],
137-
// 'data-extractor.source' => [
138-
// 'test' => [
139-
// 'model' => CommandTestUser::class,
140-
// 'connection' => 'testing',
141-
// 'relationships' => [],
142-
// ],
143-
// ],
144-
// ]);
145-
146-
// // Mock the choice method to return the first option
147-
// $this->artisan('data:extract', ['--queryId' => 1])
148-
// ->expectsTable(['Name', 'Description'], [
149-
// ['Option1', 'First option'],
150-
// ['Option2', 'Second option'],
151-
// ]);
152-
// });
153-
154120
it('prompts for model ID when not provided', function () {
155121
config([
156122
'data-extractor.options' => [
@@ -207,34 +173,6 @@ class CommandTestUser extends Model
207173
->assertExitCode(1);
208174
});
209175

210-
// TODO: Fix test
211-
// it('fails with invalid option name', function () {
212-
// config([
213-
// 'data-extractor.options' => [
214-
// [
215-
// 'name' => 'ValidOption',
216-
// 'description' => 'Valid option',
217-
// 'format' => 'sql',
218-
// 'source' => 'test',
219-
// ],
220-
// ],
221-
// 'data-extractor.source' => [
222-
// 'test' => [
223-
// 'model' => CommandTestUser::class,
224-
// 'connection' => 'testing',
225-
// 'relationships' => [],
226-
// ],
227-
// ],
228-
// ]);
229-
230-
// $this->artisan('data:extract', [
231-
// '--name' => 'InvalidOption',
232-
// '--queryId' => 1,
233-
// ])
234-
// ->expectsOutput('Invalid option value: InvalidOption')
235-
// ->assertExitCode(1);
236-
// });
237-
238176
it('can handle multiple IDs', function () {
239177
config([
240178
'data-extractor.options' => [

tests/Dto/SourceTest.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,6 @@ class TestModelForSource extends Model
6262
expect($source->relationships)->toBe([]);
6363
});
6464

65-
it('validates that model class exists and extends Model', function () {
66-
$data = [
67-
'model' => 'NonExistentModel',
68-
'connection' => 'mysql',
69-
'relationships' => [],
70-
];
71-
72-
expect(fn () => Source::fromArray($data))
73-
->toThrow('The provided model, parent must be an instance of Illuminate\Database\Eloquent\Model');
74-
});
75-
76-
it('validates that model extends Eloquent Model', function () {
77-
$data = [
78-
'model' => 'stdClass', // Not an Eloquent model
79-
'connection' => 'mysql',
80-
'relationships' => [],
81-
];
82-
83-
expect(fn () => Source::fromArray($data))
84-
->toThrow('The provided model, parent must be an instance of Illuminate\Database\Eloquent\Model');
85-
});
86-
87-
it('throws exception when model field is missing', function () {
88-
$data = [
89-
'connection' => 'mysql',
90-
'relationships' => [],
91-
// Missing model
92-
];
93-
94-
expect(fn () => Source::fromArray($data))
95-
->toThrow('The provided model, parent must be an instance of Illuminate\Database\Eloquent\Model'); // Will throw undefined array key error
96-
});
97-
9865
it('is readonly and immutable', function () {
9966
$source = new Source(
10067
model: TestModelForSource::class,

tests/ExtractTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function user()
194194
$extract = new Extract;
195195

196196
expect(fn () => $extract->source('invalid')->queryId(1)->toSql())
197-
->toThrow('The provided model, parent must be an instance of Illuminate\Database\Eloquent\Model');
197+
->toThrow('Target class [InvalidModel] does not exist.');
198198
});
199199

200200
it('handles missing relationships gracefully', function () {

tests/OptionsResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,5 @@ class ResolverTestModel extends Model
178178
]);
179179

180180
// This should handle missing source by creating empty Source array
181-
expect(fn () => new OptionsResolver)->toThrow('The provided model, parent must be an instance of Illuminate\Database\Eloquent\Model');
181+
expect(fn () => new OptionsResolver)->toThrow('Undefined array key "model"');
182182
});

tests/SourcesResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SourcesResolverTestModel extends Model
7777
$resolver = new SourcesResolver;
7878

7979
expect(fn () => $resolver->set('malformed'))
80-
->toThrow('The provided model, parent must be an instance of Illuminate\Database\Eloquent\Model');
80+
->toThrow('Undefined array key "model"');
8181
});
8282

8383
it('validates model class in source configuration', function () {

0 commit comments

Comments
 (0)