Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add some test for make:enum when Enums or Enumerations folder already exists #50911

Merged
merged 2 commits into from
Apr 4, 2024
Merged
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
47 changes: 47 additions & 0 deletions tests/Integration/Generators/EnumMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

class EnumMakeCommandTest extends TestCase
{
protected $files = [
'app/IntEnum.php',
'app/StatusEnum.php',
'app/StringEnum.php',
'app/*/OrderStatusEnum.php',
];

public function testItCanGenerateEnumFile()
{
$this->artisan('make:enum', ['name' => 'StatusEnum'])
Expand Down Expand Up @@ -38,4 +45,44 @@ public function testItCanGenerateEnumFileWithInt()
'enum IntEnum: int',
], 'app/IntEnum.php');
}

public function testItCanGenerateEnumFileInEnumsFolder()
{
$enumsFolderPath = app_path('Enums');

/** @var \Illuminate\Filesystem\Filesystem $files */
$files = $this->app['files'];

$files->ensureDirectoryExists($enumsFolderPath);

$this->artisan('make:enum', ['name' => 'OrderStatusEnum'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Enums;',
'enum OrderStatusEnum',
], 'app/Enums/OrderStatusEnum.php');

$files->deleteDirectory($enumsFolderPath);
}

public function testItCanGenerateEnumFileInEnumerationsFolder()
{
$enumerationsFolderPath = app_path('Enumerations');

/** @var \Illuminate\Filesystem\Filesystem $files */
$files = $this->app['files'];

$files->ensureDirectoryExists($enumerationsFolderPath);

$this->artisan('make:enum', ['name' => 'OrderStatusEnum'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Enumerations;',
'enum OrderStatusEnum',
], 'app/Enumerations/OrderStatusEnum.php');

$files->deleteDirectory($enumerationsFolderPath);
}
}