Skip to content

Commit e0665f6

Browse files
committed
fix:
- renamed WarningMessage to WarningEvent - moved Events:fake to setup method - removed getSuccessMessageCallback and getWarningMessageCallback
1 parent ad316d1 commit e0665f6

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

src/Commands/MakeEntityCommand.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Illuminate\Support\Facades\Config;
99
use Illuminate\Support\Str;
1010
use RonasIT\Support\Events\SuccessCreateMessage;
11-
use RonasIT\Support\Events\WarningMessage;
11+
use RonasIT\Support\Events\WarningEvent;
1212
use RonasIT\Support\Exceptions\ClassNotExistsException;
1313
use RonasIT\Support\Exceptions\EntityCreateException;
1414
use RonasIT\Support\Generators\ControllerGenerator;
@@ -162,15 +162,22 @@ public function __construct()
162162
/**
163163
* Execute the console command.
164164
*
165-
* @return mixed
165+
* @return void
166166
*/
167-
public function handle()
167+
public function handle(): void
168168
{
169169
$this->validateInput();
170170
$this->checkConfigs();
171171

172-
$this->eventDispatcher->listen(SuccessCreateMessage::class, $this->getSuccessMessageCallback());
173-
$this->eventDispatcher->listen(WarningMessage::class, $this->getWarningMessageCallback());
172+
$this->eventDispatcher->listen(
173+
events: SuccessCreateMessage::class,
174+
listener: fn (SuccessCreateMessage $event) => $this->info($event->message),
175+
);
176+
177+
$this->eventDispatcher->listen(
178+
events: WarningEvent::class,
179+
listener: fn (WarningEvent $event) => $this->warn($event->message),
180+
);
174181

175182
try {
176183
$this->generate();
@@ -303,16 +310,6 @@ protected function getRelations()
303310
];
304311
}
305312

306-
protected function getSuccessMessageCallback(): Closure
307-
{
308-
return fn (SuccessCreateMessage $event) => $this->info($event->message);
309-
}
310-
311-
protected function getWarningMessageCallback(): Closure
312-
{
313-
return fn (WarningMessage $event) => $this->warn($event->message);
314-
}
315-
316313
protected function getFields()
317314
{
318315
return Arr::only($this->options(), EntityGenerator::AVAILABLE_FIELDS);

src/Events/WarningMessage.php renamed to src/Events/WarningEvent.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44

55
use Illuminate\Queue\SerializesModels;
66

7-
class WarningMessage
7+
class WarningEvent
88
{
99
use SerializesModels;
1010

11-
public string $message;
12-
1311
/**
1412
* Create a new event instance.
1513
*
1614
* @return void
1715
*/
18-
public function __construct($message)
19-
{
20-
$this->message = $message;
16+
public function __construct(
17+
public readonly string $message,
18+
) {
2119
}
2220
}

src/Generators/SeederGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Support\Arr;
66
use RonasIT\Support\Events\SuccessCreateMessage;
7-
use RonasIT\Support\Events\WarningMessage;
7+
use RonasIT\Support\Events\WarningEvent;
88
use RonasIT\Support\Exceptions\EntityCreateException;
99

1010
class SeederGenerator extends EntityGenerator
@@ -51,7 +51,7 @@ protected function createDatabaseSeeder(): void
5151

5252
$message = "You are using the deprecated value for 'entity-generator.stubs.database_empty_seeder' config. Please use 'entity-generator::database_empty_seeder'.";
5353

54-
event(new WarningMessage($message));
54+
event(new WarningEvent($message));
5555
}
5656

5757
$content = "<?php \n\n" . view($stubPath, [

tests/SeederGeneratorTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
namespace RonasIT\Support\Tests;
44

55
use Illuminate\Support\Facades\Event;
6-
use RonasIT\Support\Events\WarningMessage;
6+
use RonasIT\Support\Events\WarningEvent;
77
use RonasIT\Support\Generators\SeederGenerator;
88
use RonasIT\Support\Tests\Support\SeederGeneratorMockTrait;
99

1010
class SeederGeneratorTest extends TestCase
1111
{
1212
use SeederGeneratorMockTrait;
1313

14+
public function setUp(): void
15+
{
16+
parent::setUp();
17+
18+
Event::fake();
19+
}
20+
1421
public function testCreateSeeder()
1522
{
1623
$this->mockViewsNamespace();
@@ -35,7 +42,6 @@ public function testCreateSeeder()
3542

3643
public function testCreateSeederWithOldConfig()
3744
{
38-
Event::fake();
3945
$this->mockViewsNamespace();
4046
$this->mockConfigurations();
4147
$this->mockFilesystem();
@@ -56,6 +62,8 @@ public function testCreateSeederWithOldConfig()
5662

5763
$this->rollbackToDefaultBasePath();
5864

59-
Event::assertDispatched(WarningMessage::class);
65+
Event::assertDispatched(WarningEvent::class, function ($event) {
66+
return $event->message === "You are using the deprecated value for 'entity-generator.stubs.database_empty_seeder' config. Please use 'entity-generator::database_empty_seeder'.";
67+
});
6068
}
6169
}

0 commit comments

Comments
 (0)