|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Illuminate\Tests\Integration\Generators; |
| 4 | + |
| 5 | +class ListenerMakeCommandTest extends TestCase |
| 6 | +{ |
| 7 | + protected $files = [ |
| 8 | + 'app/Listeners/FooListener.php', |
| 9 | + 'tests/Feature/Listeners/FooListenerTest.php', |
| 10 | + ]; |
| 11 | + |
| 12 | + public function testItCanGenerateListenerFile() |
| 13 | + { |
| 14 | + $this->artisan('make:listener', ['name' => 'FooListener']) |
| 15 | + ->assertExitCode(0); |
| 16 | + |
| 17 | + $this->assertFileContains([ |
| 18 | + 'namespace App\Listeners;', |
| 19 | + 'class FooListener', |
| 20 | + 'public function handle(object $event)', |
| 21 | + ], 'app/Listeners/FooListener.php'); |
| 22 | + |
| 23 | + $this->assertFileNotContains([ |
| 24 | + 'class FooListener implements ShouldQueue', |
| 25 | + ], 'app/Listeners/FooListener.php'); |
| 26 | + } |
| 27 | + |
| 28 | + public function testItCanGenerateListenerFileForEvent() |
| 29 | + { |
| 30 | + $this->artisan('make:listener', ['name' => 'FooListener', '--event' => 'FooListenerCreated']) |
| 31 | + ->assertExitCode(0); |
| 32 | + |
| 33 | + $this->assertFileContains([ |
| 34 | + 'namespace App\Listeners;', |
| 35 | + 'use App\Events\FooListenerCreated;', |
| 36 | + 'class FooListener', |
| 37 | + 'public function handle(FooListenerCreated $event)', |
| 38 | + ], 'app/Listeners/FooListener.php'); |
| 39 | + } |
| 40 | + |
| 41 | + public function testItCanGenerateListenerFileForIlluminateEvent() |
| 42 | + { |
| 43 | + $this->artisan('make:listener', ['name' => 'FooListener', '--event' => 'Illuminate\Auth\Events\Login']) |
| 44 | + ->assertExitCode(0); |
| 45 | + |
| 46 | + $this->assertFileContains([ |
| 47 | + 'namespace App\Listeners;', |
| 48 | + 'use Illuminate\Auth\Events\Login;', |
| 49 | + 'class FooListener', |
| 50 | + 'public function handle(Login $event)', |
| 51 | + ], 'app/Listeners/FooListener.php'); |
| 52 | + } |
| 53 | + |
| 54 | + public function testItCanGenerateQueuedListenerFile() |
| 55 | + { |
| 56 | + $this->artisan('make:listener', ['name' => 'FooListener', '--queued' => true]) |
| 57 | + ->assertExitCode(0); |
| 58 | + |
| 59 | + $this->assertFileContains([ |
| 60 | + 'namespace App\Listeners;', |
| 61 | + 'use Illuminate\Contracts\Queue\ShouldQueue;', |
| 62 | + 'use Illuminate\Queue\InteractsWithQueue;', |
| 63 | + 'class FooListener implements ShouldQueue', |
| 64 | + 'public function handle(object $event)', |
| 65 | + ], 'app/Listeners/FooListener.php'); |
| 66 | + } |
| 67 | + |
| 68 | + public function testItCanGenerateQueuedListenerFileForEvent() |
| 69 | + { |
| 70 | + $this->artisan('make:listener', ['name' => 'FooListener', '--queued' => true, '--event' => 'FooListenerCreated']) |
| 71 | + ->assertExitCode(0); |
| 72 | + |
| 73 | + $this->assertFileContains([ |
| 74 | + 'namespace App\Listeners;', |
| 75 | + 'use App\Events\FooListenerCreated;', |
| 76 | + 'use Illuminate\Contracts\Queue\ShouldQueue;', |
| 77 | + 'use Illuminate\Queue\InteractsWithQueue;', |
| 78 | + 'class FooListener implements ShouldQueue', |
| 79 | + 'public function handle(FooListenerCreated $event)', |
| 80 | + ], 'app/Listeners/FooListener.php'); |
| 81 | + } |
| 82 | + |
| 83 | + public function testItCanGenerateQueuedListenerFileForIlluminateEvent() |
| 84 | + { |
| 85 | + $this->artisan('make:listener', ['name' => 'FooListener', '--queued' => true, '--event' => 'Illuminate\Auth\Events\Login']) |
| 86 | + ->assertExitCode(0); |
| 87 | + |
| 88 | + $this->assertFileContains([ |
| 89 | + 'namespace App\Listeners;', |
| 90 | + 'use Illuminate\Auth\Events\Login;', |
| 91 | + 'use Illuminate\Contracts\Queue\ShouldQueue;', |
| 92 | + 'use Illuminate\Queue\InteractsWithQueue;', |
| 93 | + 'class FooListener implements ShouldQueue', |
| 94 | + 'public function handle(Login $event)', |
| 95 | + ], 'app/Listeners/FooListener.php'); |
| 96 | + } |
| 97 | + |
| 98 | + public function testItCanGenerateQueuedListenerFileWithTest() |
| 99 | + { |
| 100 | + $this->artisan('make:listener', ['name' => 'FooListener', '--test' => true]) |
| 101 | + ->assertExitCode(0); |
| 102 | + |
| 103 | + $this->assertFilenameExists('app/Listeners/FooListener.php'); |
| 104 | + $this->assertFilenameExists('tests/Feature/Listeners/FooListenerTest.php'); |
| 105 | + } |
| 106 | +} |
0 commit comments