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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"league/flysystem-read-only": "^3.3",
"league/flysystem-sftp-v3": "^3.0",
"mockery/mockery": "^1.5.1",
"orchestra/testbench-core": "^8.4",
"orchestra/testbench-core": "^8.10",
"pda/pheanstalk": "^4.0",
"phpstan/phpstan": "^1.4.7",
"phpunit/phpunit": "^10.0.7",
Expand Down
37 changes: 37 additions & 0 deletions tests/Integration/Generators/CastMakeCommandTest.php
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');
}
}
22 changes: 22 additions & 0 deletions tests/Integration/Generators/ChannelMakeCommandTest.php
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');
}
}
53 changes: 53 additions & 0 deletions tests/Integration/Generators/ComponentMakeCommandTest.php
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 tests/Integration/Generators/ControllerMakeCommandTest.php
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');
}
}
21 changes: 21 additions & 0 deletions tests/Integration/Generators/EventMakeCommandTest.php
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');
}
}
75 changes: 75 additions & 0 deletions tests/Integration/Generators/ExceptionMakeCommandTest.php
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');
}
}
Loading