Skip to content

Commit 0b13338

Browse files
authored
[10.x] Test Improvements (#48390)
* [10.x] Test Improvements Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 03613ec commit 0b13338

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Generators;
4+
5+
class ConsoleMakeCommandTest extends TestCase
6+
{
7+
protected $files = [
8+
'app/Console/Commands/FooCommand.php',
9+
];
10+
11+
public function testItCanGenerateConsoleFile()
12+
{
13+
$this->artisan('make:command', ['name' => 'FooCommand'])
14+
->assertExitCode(0);
15+
16+
$this->assertFileContains([
17+
'namespace App\Console\Commands;',
18+
'use Illuminate\Console\Command;',
19+
'class FooCommand extends Command',
20+
'protected $signature = \'app:foo-command\';',
21+
], 'app/Console/Commands/FooCommand.php');
22+
}
23+
24+
public function testItCanGenerateConsoleFileWithCommandOption()
25+
{
26+
$this->artisan('make:command', ['name' => 'FooCommand', '--command' => 'foo:bar'])
27+
->assertExitCode(0);
28+
29+
$this->assertFileContains([
30+
'namespace App\Console\Commands;',
31+
'use Illuminate\Console\Command;',
32+
'class FooCommand extends Command',
33+
'protected $signature = \'foo:bar\';',
34+
], 'app/Console/Commands/FooCommand.php');
35+
}
36+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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

Comments
 (0)