Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Generators/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function buildTestCases(Controller $controller)
$assertion .= ', function ($notification)';

foreach ($statement->data() as $data) {
if (Str::studly(Str::singular($data)) === $context) {
if (Str::studly(Str::singular($data)) === $context || ! Str::contains($data, '.')) {
$variables[] .= '$' . $data;
$conditions[] .= sprintf('$notification->%s->is($%s)', $data, $data);
} else {
Expand Down Expand Up @@ -166,7 +166,7 @@ protected function buildTestCases(Controller $controller)
}

foreach ($statement->data() as $data) {
if (Str::studly(Str::singular($data)) === $context) {
if (Str::studly(Str::singular($data)) === $context || ! Str::contains($data, '.')) {
$variables[] .= '$' . $data;
$conditions[] .= sprintf('$mail->%s->is($%s)', $data, $data);
} else {
Expand Down Expand Up @@ -262,7 +262,7 @@ protected function buildTestCases(Controller $controller)
$assertion .= ', function ($job)';

foreach ($statement->data() as $data) {
if (Str::studly(Str::singular($data)) === $context) {
if (Str::studly(Str::singular($data)) === $context || ! Str::contains($data, '.')) {
$variables[] .= '$' . $data;
$conditions[] .= sprintf('$job->%s->is($%s)', $data, $data);
} else {
Expand Down Expand Up @@ -305,7 +305,7 @@ protected function buildTestCases(Controller $controller)
$assertion .= ', function ($event)';

foreach ($statement->data() as $data) {
if (Str::studly(Str::singular($data)) === $context) {
if (Str::studly(Str::singular($data)) === $context || ! Str::contains($data, '.')) {
$variables[] .= '$' . $data;
$conditions[] .= sprintf('$event->%s->is($%s)', $data, $data);
} else {
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Generators/TestGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public function controllerTreeDataProvider()
['drafts/respond-statements.yaml', 'tests/Feature/Http/Controllers/Api/PostControllerTest.php', 'tests/respond-statements.php'],
['drafts/full-crud-example.yaml', 'tests/Feature/Http/Controllers/PostControllerTest.php', 'tests/full-crud-example.php'],
['drafts/model-reference-validate.yaml', 'tests/Feature/Http/Controllers/CertificateControllerTest.php', 'tests/api-shorthand-validation.php'],
['drafts/controllers-only-no-context.yaml', 'tests/Feature/Http/Controllers/ReportControllerTest.php', 'tests/controllers-only-no-context.php'],
['drafts/call-to-a-member-function-columns-on-null.yaml', [
'tests/Feature/Http/Controllers/SubscriptionControllerTest.php',
'tests/Feature/Http/Controllers/TelegramControllerTest.php',
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/drafts/controllers-only-no-context.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
controllers:
Report:
invokable:
dispatch: GenerateReport with:event
fire: ExportReport with:event
notify: auth.user ReportGenerated with:event
send: SendReport with:event
render: report
48 changes: 48 additions & 0 deletions tests/fixtures/tests/controllers-only-no-context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Tests\Feature\Http\Controllers;

use App\Events\ExportReport;
use App\Jobs\GenerateReport;
use App\Mail\SendReport;
use App\Notification\ReportGenerated;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;

/**
* @see \App\Http\Controllers\ReportController
*/
class ReportControllerTest extends TestCase
{
/**
* @test
*/
public function __invoke_displays_view()
{
Queue::fake();
Event::fake();
Notification::fake();
Mail::fake();

$response = $this->get(route('report.__invoke'));

$response->assertOk();
$response->assertViewIs('report');

Queue::assertPushed(GenerateReport::class, function ($job) use ($event) {
return $job->event->is($event);
});
Event::assertDispatched(ExportReport::class, function ($event) use ($event) {
return $event->event->is($event);
});
Notification::assertSentTo($auth->user, ReportGenerated::class, function ($notification) use ($event) {
return $notification->event->is($event);
});
Mail::assertSent(SendReport::class, function ($mail) use ($event) {
return $mail->event->is($event);
});
}
}