Skip to content

Commit 2d4686c

Browse files
authored
Merge pull request #116 from RonasIT/112_fix_assert_event_chain_method
fix: assertEventPushedChain method
2 parents 7dc0f06 + ea020d8 commit 2d4686c

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

tests/ControllerGeneratorTest.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public function testRoutesStubNotExist()
109109
$this->assertGeneratedFileEquals('empty_api.php', 'routes/api.php');
110110

111111
$this->assertEventPushedChain([
112-
WarningEvent::class => 'Generation of routes has been skipped cause the view incorrect_stub from the config entity-generator.stubs.routes is not exists. Please check that config has the correct view name value.',
113-
SuccessCreateMessage::class => 'Created a new Controller: PostController',
112+
WarningEvent::class => ['Generation of routes has been skipped cause the view incorrect_stub from the config entity-generator.stubs.routes is not exists. Please check that config has the correct view name value.'],
113+
SuccessCreateMessage::class => ['Created a new Controller: PostController'],
114114
]);
115115
}
116116

@@ -129,8 +129,8 @@ public function testUseRoutesStubNotExist()
129129
$this->assertGeneratedFileEquals('empty_api.php', 'routes/api.php');
130130

131131
$this->assertEventPushedChain([
132-
WarningEvent::class => 'Generation of use routes has been skipped cause the view incorrect_stub from the config entity-generator.stubs.use_routes is not exists. Please check that config has the correct view name value.',
133-
SuccessCreateMessage::class => 'Created a new Controller: PostController',
132+
WarningEvent::class => ['Generation of use routes has been skipped cause the view incorrect_stub from the config entity-generator.stubs.use_routes is not exists. Please check that config has the correct view name value.'],
133+
SuccessCreateMessage::class => ['Created a new Controller: PostController'],
134134
]);
135135
}
136136

@@ -146,11 +146,15 @@ public function testSuccess()
146146
$this->assertGeneratedFileEquals('created_controller.php', 'app/Http/Controllers/PostController.php');
147147
$this->assertGeneratedFileEquals('api.php', 'routes/api.php');
148148

149-
$this->assertEventPushed(SuccessCreateMessage::class, "Created a new Route: Route::post('posts', 'create');");
150-
$this->assertEventPushed(SuccessCreateMessage::class, "Created a new Route: Route::put('posts/{id}', 'update');");
151-
$this->assertEventPushed(SuccessCreateMessage::class, "Created a new Route: Route::delete('posts/{id}', 'delete');");
152-
$this->assertEventPushed(SuccessCreateMessage::class, "Created a new Route: Route::get('posts/{id}', 'get');");
153-
$this->assertEventPushed(SuccessCreateMessage::class, "Created a new Route: Route::get('posts', 'search');");
154-
$this->assertEventPushed(SuccessCreateMessage::class, 'Created a new Controller: PostController');
149+
$this->assertEventPushedChain([
150+
SuccessCreateMessage::class => [
151+
"Created a new Route: Route::post('posts', 'create');",
152+
"Created a new Route: Route::put('posts/{id}', 'update');",
153+
"Created a new Route: Route::delete('posts/{id}', 'delete');",
154+
"Created a new Route: Route::get('posts/{id}', 'get');",
155+
"Created a new Route: Route::get('posts', 'search');",
156+
'Created a new Controller: PostController',
157+
],
158+
]);
155159
}
156160
}

tests/TestCase.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,16 @@ protected function assertEventPushed(string $className, string $message): void
9595
);
9696
}
9797

98-
protected function assertEventPushedChain(array $events): void
98+
protected function assertEventPushedChain(array $expectedEvents): void
9999
{
100-
foreach ($events as $className => $message) {
101-
$this->assertEventPushed($className, $message);
100+
$dispatchedEvents = Event::dispatchedEvents();
101+
102+
$this->assertEquals(array_keys($expectedEvents), array_keys($dispatchedEvents));
103+
104+
foreach ($dispatchedEvents as $event => $messages) {
105+
$messages = array_map(fn ($message) => Arr::first($message)->message, $messages);
106+
107+
$this->assertEquals($expectedEvents[$event], $messages);
102108
}
103109
}
104110

0 commit comments

Comments
 (0)