Skip to content

Commit dab9a1d

Browse files
authored
Merge pull request #339 from bowphp/refactor/code-base
Fix seeder runner
2 parents 06f3389 + e9ce369 commit dab9a1d

7 files changed

Lines changed: 32 additions & 30 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ services:
1818
image: mysql:8.3.0
1919
restart: unless-stopped
2020
ports:
21-
- "3306:3306"
21+
- "3308:3306"
2222
environment:
2323
MYSQL_DATABASE: test_db
2424
MYSQL_ROOT_PASSWORD: password

src/Console/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function call(string $command, string $action, ...$rest): mixed
9999
$this->throwFailsCommand("The command $command not found !");
100100
}
101101

102-
if (!preg_match('/^(migration)/', $command)) {
102+
if (!preg_match('/^(migration|seed)/', $command)) {
103103
$method = "run";
104104
} else {
105105
$method = $action;

src/Console/Command/Generator/GenerateValidationCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function run(string $validation): void
2626
if ($generator->fileExists()) {
2727
echo Color::red('The validation already exists.');
2828

29-
exit(0);
29+
exit(1);
3030
}
3131

3232
$generator->write('validation', [

src/Console/Console.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,12 @@ public function bind(Loader $kernel): void
171171
/**
172172
* Launch Bow task runner
173173
*
174-
* @return mixed
175174
* @throws
176175
*/
177-
public function run(): mixed
176+
public function run()
178177
{
179178
if ($this->booted) {
180-
return false;
179+
exit(0);
181180
}
182181

183182
// Boot kernel and console
@@ -207,7 +206,8 @@ public function run(): mixed
207206
}
208207

209208
try {
210-
return $this->call($command);
209+
$this->call($command);
210+
exit(0);
211211
} catch (Exception $exception) {
212212
echo Color::red($exception->getMessage());
213213
echo Color::green($exception->getTraceAsString());
@@ -238,7 +238,8 @@ public function call(?string $command): mixed
238238
if (!in_array($command, array_keys($commands))) {
239239
// Try to execute the custom command
240240
if (array_key_exists($this->arg->getRawCommand(), static::$registers) || array_key_exists($command, static::$registers)) {
241-
return $this->executeCustomCommand($this->arg->getRawCommand() ?? $command);
241+
$this->executeCustomCommand($this->arg->getRawCommand() ?? $command);
242+
exit(0);
242243
}
243244
}
244245

@@ -256,7 +257,8 @@ public function call(?string $command): mixed
256257
}
257258

258259
try {
259-
return call_user_func_array([$this, $command], [$this->arg->getRawCommand()]);
260+
call_user_func_array([$this, $command], [$this->arg->getRawCommand()]);
261+
exit(0);
260262
} catch (Exception $e) {
261263
echo Color::red(sprintf("$command command failed with: %s\n", $e->getMessage()));
262264
exit(1);

src/Database/Barry/Relations/HasOne.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(Model $related, Model $parent, string $foreign_key,
3434
public function getResults(): ?Model
3535
{
3636
$key = $this->query->getTable() . ":hasone:" . $this->related->getTable() . ":" . $this->foreign_key;
37-
37+
3838
$cache = Cache::store('file')->get($key);
3939

4040
if (!is_null($cache)) {

tests/Support/ArraydotifyTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function test_get_nested_array_contains_keys()
7474
$this->assertArrayHasKey('city', $location);
7575
$this->assertArrayHasKey('tel', $location);
7676
$this->assertArrayHasKey('state', $location);
77-
77+
7878
$state = $this->dot['code.location.state'];
7979
$this->assertTrue(is_array($state));
8080
$this->assertArrayHasKey('code', $state);
@@ -207,7 +207,7 @@ public function test_set_creates_nested_structure()
207207
$dot = new Arraydotify();
208208
$dot['app.name'] = 'MyApp';
209209
$this->assertEquals('MyApp', $dot['app.name']);
210-
210+
211211
$array = $dot->toArray();
212212
$this->assertArrayHasKey('app', $array);
213213
$this->assertArrayHasKey('name', $array['app']);
@@ -219,7 +219,7 @@ public function test_set_deeply_nested_creates_path()
219219
$dot = new Arraydotify();
220220
$dot['level1.level2.level3.level4.value'] = 'deep';
221221
$this->assertEquals('deep', $dot['level1.level2.level3.level4.value']);
222-
222+
223223
$this->assertTrue($dot->has('level1'));
224224
$this->assertTrue($dot->has('level1.level2'));
225225
$this->assertTrue($dot->has('level1.level2.level3'));
@@ -230,7 +230,7 @@ public function test_set_array_value()
230230
{
231231
$dot = new Arraydotify(['data' => []]);
232232
$dot['data.items'] = ['apple', 'banana', 'orange'];
233-
233+
234234
$items = $dot['data.items'];
235235
$this->assertIsArray($items);
236236
$this->assertCount(3, $items);
@@ -252,7 +252,7 @@ public function test_set_overwrites_nested_structure()
252252
'app' => ['name' => 'OldApp']
253253
]
254254
]);
255-
255+
256256
$dot['config.app'] = 'NewValue';
257257
$this->assertEquals('NewValue', $dot['config.app']);
258258
$this->assertFalse($dot->has('config.app.name'));
@@ -264,11 +264,11 @@ public function test_set_multiple_values_same_path()
264264
$dot['user.name'] = 'John';
265265
$dot['user.email'] = 'john@example.com';
266266
$dot['user.age'] = 30;
267-
267+
268268
$this->assertEquals('John', $dot['user.name']);
269269
$this->assertEquals('john@example.com', $dot['user.email']);
270270
$this->assertEquals(30, $dot['user.age']);
271-
271+
272272
$user = $dot['user'];
273273
$this->assertIsArray($user);
274274
$this->assertCount(3, $user);
@@ -280,7 +280,7 @@ public function test_set_with_numeric_index()
280280
$dot['items.0'] = 'first';
281281
$dot['items.1'] = 'second';
282282
$dot['items.2'] = 'third';
283-
283+
284284
$this->assertEquals('first', $dot['items.0']);
285285
$this->assertEquals('second', $dot['items.1']);
286286
$this->assertEquals('third', $dot['items.2']);
@@ -291,7 +291,7 @@ public function test_set_boolean_values()
291291
$dot = new Arraydotify();
292292
$dot['settings.enabled'] = true;
293293
$dot['settings.disabled'] = false;
294-
294+
295295
$this->assertTrue($dot['settings.enabled']);
296296
$this->assertFalse($dot['settings.disabled']);
297297
}
@@ -302,7 +302,7 @@ public function test_set_integer_and_float_values()
302302
$dot['numbers.integer'] = 42;
303303
$dot['numbers.float'] = 3.14;
304304
$dot['numbers.negative'] = -10;
305-
305+
306306
$this->assertSame(42, $dot['numbers.integer']);
307307
$this->assertSame(3.14, $dot['numbers.float']);
308308
$this->assertSame(-10, $dot['numbers.negative']);
@@ -316,9 +316,9 @@ public function test_set_preserves_existing_siblings()
316316
'version' => '1.0'
317317
]
318318
]);
319-
319+
320320
$dot['config.debug'] = true;
321-
321+
322322
$this->assertEquals('MyApp', $dot['config.app']);
323323
$this->assertEquals('1.0', $dot['config.version']);
324324
$this->assertTrue($dot['config.debug']);
@@ -328,11 +328,11 @@ public function test_set_updates_both_storage_and_origin()
328328
{
329329
$dot = new Arraydotify();
330330
$dot['new.path.value'] = 'test';
331-
331+
332332
// Check dotified storage
333333
$dotified = $dot->getDotified();
334334
$this->assertArrayHasKey('new.path.value', $dotified);
335-
335+
336336
// Check original structure
337337
$array = $dot->toArray();
338338
$this->assertEquals('test', $array['new']['path']['value']);
@@ -351,7 +351,7 @@ public function test_set_zero_value()
351351
$dot = new Arraydotify();
352352
$dot['zero.int'] = 0;
353353
$dot['zero.float'] = 0.0;
354-
354+
355355
$this->assertSame(0, $dot['zero.int']);
356356
$this->assertSame(0.0, $dot['zero.float']);
357357
}
@@ -362,11 +362,11 @@ public function test_set_method_with_complex_path()
362362
$dot->set('api.endpoints.users.list', '/api/v1/users');
363363
$dot->set('api.endpoints.users.create', '/api/v1/users/create');
364364
$dot->set('api.endpoints.posts.list', '/api/v1/posts');
365-
365+
366366
$this->assertEquals('/api/v1/users', $dot->get('api.endpoints.users.list'));
367367
$this->assertEquals('/api/v1/users/create', $dot->get('api.endpoints.users.create'));
368368
$this->assertEquals('/api/v1/posts', $dot->get('api.endpoints.posts.list'));
369-
369+
370370
$endpoints = $dot['api.endpoints'];
371371
$this->assertIsArray($endpoints);
372372
$this->assertArrayHasKey('users', $endpoints);

tests/Support/HttpClientTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function test_get_method_with_custom_headers()
2929
{
3030
$http = new HttpClient();
3131
$http->addHeaders(["X-Api-Key" => "Fake-Key"]);
32-
32+
3333
$response = $http->get("https://www.google.com");
3434

3535
$this->assertEquals(200, $response->statusCode());
@@ -39,7 +39,7 @@ public function test_get_method_fails_with_non_existent_path()
3939
{
4040
$http = new HttpClient("https://www.google.com");
4141
$http->addHeaders(["X-Api-Key" => "Fake-Key"]);
42-
42+
4343
$response = $http->get("/the-fake-url");
4444

4545
$this->assertEquals(404, $response->statusCode());
@@ -71,7 +71,7 @@ public function test_post_method_with_json_data()
7171
{
7272
$http = new HttpClient();
7373
$http->addHeaders(['Content-Type' => 'application/json']);
74-
74+
7575
$response = $http->post("https://httpbin.org/post", [
7676
'name' => 'test',
7777
'value' => 'example'

0 commit comments

Comments
 (0)