Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Test Improvements #48390

Merged
merged 4 commits into from
Sep 14, 2023
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
36 changes: 36 additions & 0 deletions tests/Integration/Generators/ConsoleMakeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Illuminate\Tests\Integration\Generators;

class ConsoleMakeCommandTest extends TestCase
{
protected $files = [
'app/Console/Commands/FooCommand.php',
];

public function testItCanGenerateConsoleFile()
{
$this->artisan('make:command', ['name' => 'FooCommand'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Console\Commands;',
'use Illuminate\Console\Command;',
'class FooCommand extends Command',
'protected $signature = \'app:foo-command\';',
], 'app/Console/Commands/FooCommand.php');
}

public function testItCanGenerateConsoleFileWithCommandOption()
{
$this->artisan('make:command', ['name' => 'FooCommand', '--command' => 'foo:bar'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Console\Commands;',
'use Illuminate\Console\Command;',
'class FooCommand extends Command',
'protected $signature = \'foo:bar\';',
], 'app/Console/Commands/FooCommand.php');
}
}
106 changes: 106 additions & 0 deletions tests/Integration/Generators/ListenerMakeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace Illuminate\Tests\Integration\Generators;

class ListenerMakeCommandTest extends TestCase
{
protected $files = [
'app/Listeners/FooListener.php',
'tests/Feature/Listeners/FooListenerTest.php',
];

public function testItCanGenerateListenerFile()
{
$this->artisan('make:listener', ['name' => 'FooListener'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Listeners;',
'class FooListener',
'public function handle(object $event)',
], 'app/Listeners/FooListener.php');

$this->assertFileNotContains([
'class FooListener implements ShouldQueue',
], 'app/Listeners/FooListener.php');
}

public function testItCanGenerateListenerFileForEvent()
{
$this->artisan('make:listener', ['name' => 'FooListener', '--event' => 'FooListenerCreated'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Listeners;',
'use App\Events\FooListenerCreated;',
'class FooListener',
'public function handle(FooListenerCreated $event)',
], 'app/Listeners/FooListener.php');
}

public function testItCanGenerateListenerFileForIlluminateEvent()
{
$this->artisan('make:listener', ['name' => 'FooListener', '--event' => 'Illuminate\Auth\Events\Login'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Listeners;',
'use Illuminate\Auth\Events\Login;',
'class FooListener',
'public function handle(Login $event)',
], 'app/Listeners/FooListener.php');
}

public function testItCanGenerateQueuedListenerFile()
{
$this->artisan('make:listener', ['name' => 'FooListener', '--queued' => true])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Listeners;',
'use Illuminate\Contracts\Queue\ShouldQueue;',
'use Illuminate\Queue\InteractsWithQueue;',
'class FooListener implements ShouldQueue',
'public function handle(object $event)',
], 'app/Listeners/FooListener.php');
}

public function testItCanGenerateQueuedListenerFileForEvent()
{
$this->artisan('make:listener', ['name' => 'FooListener', '--queued' => true, '--event' => 'FooListenerCreated'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Listeners;',
'use App\Events\FooListenerCreated;',
'use Illuminate\Contracts\Queue\ShouldQueue;',
'use Illuminate\Queue\InteractsWithQueue;',
'class FooListener implements ShouldQueue',
'public function handle(FooListenerCreated $event)',
], 'app/Listeners/FooListener.php');
}

public function testItCanGenerateQueuedListenerFileForIlluminateEvent()
{
$this->artisan('make:listener', ['name' => 'FooListener', '--queued' => true, '--event' => 'Illuminate\Auth\Events\Login'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Listeners;',
'use Illuminate\Auth\Events\Login;',
'use Illuminate\Contracts\Queue\ShouldQueue;',
'use Illuminate\Queue\InteractsWithQueue;',
'class FooListener implements ShouldQueue',
'public function handle(Login $event)',
], 'app/Listeners/FooListener.php');
}

public function testItCanGenerateQueuedListenerFileWithTest()
{
$this->artisan('make:listener', ['name' => 'FooListener', '--test' => true])
->assertExitCode(0);

$this->assertFilenameExists('app/Listeners/FooListener.php');
$this->assertFilenameExists('tests/Feature/Listeners/FooListenerTest.php');
}
}