-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [10.x] Test Improvements Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * 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]> Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
5f8d1a2
commit 33a206e
Showing
24 changed files
with
1,178 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Generators; | ||
|
||
class CastMakeCommandTest extends TestCase | ||
{ | ||
protected $files = [ | ||
'app/Casts/Foo.php', | ||
]; | ||
|
||
public function testItCanGenerateCastFile() | ||
{ | ||
$this->artisan('make:cast', ['name' => 'Foo']) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Casts;', | ||
'use Illuminate\Contracts\Database\Eloquent\CastsAttributes;', | ||
'class Foo implements CastsAttributes', | ||
'public function get(Model $model, string $key, mixed $value, array $attributes): mixed', | ||
'public function set(Model $model, string $key, mixed $value, array $attributes): mixed', | ||
], 'app/Casts/Foo.php'); | ||
} | ||
|
||
public function testItCanGenerateInboundCastFile() | ||
{ | ||
$this->artisan('make:cast', ['name' => 'Foo', '--inbound' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Casts;', | ||
'use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes;', | ||
'class Foo implements CastsInboundAttributes', | ||
'public function set(Model $model, string $key, mixed $value, array $attributes): mixed', | ||
], 'app/Casts/Foo.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Generators; | ||
|
||
class ChannelMakeCommandTest extends TestCase | ||
{ | ||
protected $files = [ | ||
'app/Broadcasting/FooChannel.php', | ||
]; | ||
|
||
public function testItCanGenerateChannelFile() | ||
{ | ||
$this->artisan('make:channel', ['name' => 'FooChannel']) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Broadcasting;', | ||
'use Illuminate\Foundation\Auth\User;', | ||
'class FooChannel', | ||
], 'app/Broadcasting/FooChannel.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Generators; | ||
|
||
class ComponentMakeCommandTest extends TestCase | ||
{ | ||
protected $files = [ | ||
'app/View/Components/Foo.php', | ||
'resources/views/components/foo.blade.php', | ||
'tests/Feature/View/Components/FooTest.php', | ||
]; | ||
|
||
public function testItCanGenerateComponentFile() | ||
{ | ||
$this->artisan('make:component', ['name' => 'Foo']) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\View\Components;', | ||
'use Illuminate\View\Component;', | ||
'class Foo extends Component', | ||
"return view('components.foo');", | ||
], 'app/View/Components/Foo.php'); | ||
|
||
$this->assertFilenameExists('resources/views/components/foo.blade.php'); | ||
$this->assertFilenameNotExists('tests/Feature/View/Components/FooTest.php'); | ||
} | ||
|
||
public function testItCanGenerateInlineComponentFile() | ||
{ | ||
$this->artisan('make:component', ['name' => 'Foo', '--inline' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\View\Components;', | ||
'use Illuminate\View\Component;', | ||
'class Foo extends Component', | ||
"return <<<'blade'", | ||
], 'app/View/Components/Foo.php'); | ||
|
||
$this->assertFilenameNotExists('resources/views/components/foo.blade.php'); | ||
} | ||
|
||
public function testItCanGenerateComponentFileWithTest() | ||
{ | ||
$this->artisan('make:component', ['name' => 'Foo', '--test' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFilenameExists('app/View/Components/Foo.php'); | ||
$this->assertFilenameExists('resources/views/components/foo.blade.php'); | ||
$this->assertFilenameExists('tests/Feature/View/Components/FooTest.php'); | ||
} | ||
} |
169 changes: 169 additions & 0 deletions
169
tests/Integration/Generators/ControllerMakeCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Generators; | ||
|
||
class ControllerMakeCommandTest extends TestCase | ||
{ | ||
protected $files = [ | ||
'app/Http/Controllers/FooController.php', | ||
'app/Models/Bar.php', | ||
'app/Models/Foo.php', | ||
'tests/Feature/Http/Controllers/FooControllerTest.php', | ||
]; | ||
|
||
public function testItCanGenerateControllerFile() | ||
{ | ||
$this->artisan('make:controller', ['name' => 'FooController']) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Controllers;', | ||
'use Illuminate\Http\Request;', | ||
'class FooController extends Controller', | ||
], 'app/Http/Controllers/FooController.php'); | ||
|
||
$this->assertFileNotContains([ | ||
'public function __invoke(Request $request)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
|
||
$this->assertFilenameNotExists('tests/Feature/Http/Controllers/FooControllerTest.php'); | ||
} | ||
|
||
public function testItCanGenerateControllerFileWithInvokableTypeOption() | ||
{ | ||
$this->artisan('make:controller', ['name' => 'FooController', '--type' => 'invokable']) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Controllers;', | ||
'use Illuminate\Http\Request;', | ||
'class FooController extends Controller', | ||
'public function __invoke(Request $request)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
} | ||
|
||
public function testItCanGenerateControllerFileWithInvokableOption() | ||
{ | ||
$this->artisan('make:controller', ['name' => 'FooController', '--invokable' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Controllers;', | ||
'use Illuminate\Http\Request;', | ||
'class FooController extends Controller', | ||
'public function __invoke(Request $request)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
} | ||
|
||
public function testItCanGenerateControllerFileWithModelOption() | ||
{ | ||
$this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Foo']) | ||
->expectsQuestion('A App\Models\Foo model does not exist. Do you want to generate it?', false) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Controllers;', | ||
'use App\Models\Foo;', | ||
'public function index()', | ||
'public function create()', | ||
'public function store(Request $request)', | ||
'public function show(Foo $foo)', | ||
'public function edit(Foo $foo)', | ||
'public function update(Request $request, Foo $foo)', | ||
'public function destroy(Foo $foo)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
} | ||
|
||
public function testItCanGenerateControllerFileWithModelAndParentOption() | ||
{ | ||
$this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Bar', '--parent' => 'Foo']) | ||
->expectsQuestion('A App\Models\Foo model does not exist. Do you want to generate it?', false) | ||
->expectsQuestion('A App\Models\Bar model does not exist. Do you want to generate it?', false) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Controllers;', | ||
'use App\Models\Bar;', | ||
'use App\Models\Foo;', | ||
'public function index(Foo $foo)', | ||
'public function create(Foo $foo)', | ||
'public function store(Request $request, Foo $foo)', | ||
'public function show(Foo $foo, Bar $bar)', | ||
'public function edit(Foo $foo, Bar $bar)', | ||
'public function update(Request $request, Foo $foo, Bar $bar)', | ||
'public function destroy(Foo $foo, Bar $bar)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
} | ||
|
||
public function testItCanGenerateControllerFileWithApiOption() | ||
{ | ||
$this->artisan('make:controller', ['name' => 'FooController', '--api' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Controllers;', | ||
'use Illuminate\Http\Request;', | ||
'class FooController extends Controller', | ||
'public function index()', | ||
'public function store(Request $request)', | ||
'public function update(Request $request, string $id)', | ||
'public function destroy(string $id)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
|
||
$this->assertFileNotContains([ | ||
'public function create()', | ||
'public function edit($id)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
} | ||
|
||
public function testItCanGenerateControllerFileWithInvokableIgnoresApiOption() | ||
{ | ||
$this->artisan('make:controller', ['name' => 'FooController', '--api' => true, '--invokable' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Controllers;', | ||
'use Illuminate\Http\Request;', | ||
'class FooController extends Controller', | ||
'public function __invoke(Request $request)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
|
||
$this->assertFileNotContains([ | ||
'public function index()', | ||
'public function store(Request $request)', | ||
'public function update(Request $request, $id)', | ||
'public function destroy($id)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
} | ||
|
||
public function testItCanGenerateControllerFileWithApiAndModelOption() | ||
{ | ||
$this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Foo', '--api' => true]) | ||
->expectsQuestion('A App\Models\Foo model does not exist. Do you want to generate it?', false) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Controllers;', | ||
'use App\Models\Foo;', | ||
'public function index()', | ||
'public function store(Request $request)', | ||
'public function show(Foo $foo)', | ||
'public function update(Request $request, Foo $foo)', | ||
'public function destroy(Foo $foo)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
|
||
$this->assertFileNotContains([ | ||
'public function create()', | ||
'public function edit(Foo $foo)', | ||
], 'app/Http/Controllers/FooController.php'); | ||
} | ||
|
||
public function testItCanGenerateControllerFileWithTest() | ||
{ | ||
$this->artisan('make:controller', ['name' => 'FooController', '--test' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFilenameExists('app/Http/Controllers/FooController.php'); | ||
$this->assertFilenameExists('tests/Feature/Http/Controllers/FooControllerTest.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Generators; | ||
|
||
class EventMakeCommandTest extends TestCase | ||
{ | ||
protected $files = [ | ||
'app/Events/FooCreated.php', | ||
]; | ||
|
||
public function testItCanGenerateEventFile() | ||
{ | ||
$this->artisan('make:event', ['name' => 'FooCreated']) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Events;', | ||
'class FooCreated', | ||
], 'app/Events/FooCreated.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Generators; | ||
|
||
class ExceptionMakeCommandTest extends TestCase | ||
{ | ||
protected $files = [ | ||
'app/Exceptions/FooException.php', | ||
]; | ||
|
||
public function testItCanGenerateExceptionFile() | ||
{ | ||
$this->artisan('make:exception', ['name' => 'FooException']) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Exceptions;', | ||
'use Exception;', | ||
'class FooException extends Exception', | ||
], 'app/Exceptions/FooException.php'); | ||
|
||
$this->assertFileNotContains([ | ||
'public function report()', | ||
'public function render($request)', | ||
], 'app/Exceptions/FooException.php'); | ||
} | ||
|
||
public function testItCanGenerateExceptionFileWithReportOption() | ||
{ | ||
$this->artisan('make:exception', ['name' => 'FooException', '--report' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Exceptions;', | ||
'use Exception;', | ||
'class FooException extends Exception', | ||
'public function report()', | ||
], 'app/Exceptions/FooException.php'); | ||
|
||
$this->assertFileNotContains([ | ||
'public function render($request)', | ||
], 'app/Exceptions/FooException.php'); | ||
} | ||
|
||
public function testItCanGenerateExceptionFileWithRenderOption() | ||
{ | ||
$this->artisan('make:exception', ['name' => 'FooException', '--render' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Exceptions;', | ||
'use Exception;', | ||
'class FooException extends Exception', | ||
'public function render(Request $request): Response', | ||
], 'app/Exceptions/FooException.php'); | ||
|
||
$this->assertFileNotContains([ | ||
'public function report()', | ||
], 'app/Exceptions/FooException.php'); | ||
} | ||
|
||
public function testItCanGenerateExceptionFileWithReportAndRenderOption() | ||
{ | ||
$this->artisan('make:exception', ['name' => 'FooException', '--report' => true, '--render' => true]) | ||
->assertExitCode(0); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Exceptions;', | ||
'use Exception;', | ||
'class FooException extends Exception', | ||
'public function render(Request $request): Response', | ||
'public function report()', | ||
], 'app/Exceptions/FooException.php'); | ||
} | ||
} |
Oops, something went wrong.