1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
<?php
namespace Illuminate\Tests\Integration\Console;
use Orchestra\Testbench\Concerns\InteractsWithPublishedFiles;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class GeneratorCommandTest extends TestCase
{
use InteractsWithPublishedFiles;
protected $files = [
'app/Console/Commands/FooCommand.php',
'resources/views/foo/php.blade.php',
'tests/Feature/fixtures.php/SomeTest.php',
];
public function testItChopsPhpExtension()
{
$this->artisan('make:command', ['name' => 'FooCommand.php'])
->assertExitCode(0);
$this->assertFilenameExists('app/Console/Commands/FooCommand.php');
$this->assertFileContains([
'class FooCommand extends Command',
], 'app/Console/Commands/FooCommand.php');
}
public function testItChopsPhpExtensionFromMakeViewCommands()
{
$this->artisan('make:view', ['name' => 'foo.php'])
->assertExitCode(0);
$this->assertFilenameExists('resources/views/foo/php.blade.php');
}
public function testItOnlyChopsPhpExtensionFromFilename()
{
$this->artisan('make:test', ['name' => 'fixtures.php/SomeTest'])
->assertExitCode(0);
$this->assertFilenameExists('tests/Feature/fixtures.php/SomeTest.php');
$this->assertFileContains([
'class SomeTest extends TestCase',
], 'tests/Feature/fixtures.php/SomeTest.php');
}
#[DataProvider('reservedNamesDataProvider')]
public function testItCannotGenerateClassUsingReservedName($given)
{
$this->artisan('make:command', ['name' => $given])
->expectsOutputToContain('The name "'.$given.'" is reserved by PHP.')
->assertExitCode(0);
}
public static function reservedNamesDataProvider()
{
yield ['__halt_compiler'];
yield ['__HALT_COMPILER'];
yield ['array'];
yield ['ARRAY'];
yield ['__class__'];
yield ['__CLASS__'];
}
}
|