Skip to content

Commit

Permalink
[11.x] Add tests for make:interface & make:trait when the folders…
Browse files Browse the repository at this point in the history
… exists (#51094)

* Update TraitMakeCommandTest.php

* Update TraitMakeCommandTest.php

* Update InterfaceMakeCommandTest.php

* Update InterfaceMakeCommandTest.php

* Update InterfaceMakeCommandTest.php
  • Loading branch information
milwad-dev authored Apr 17, 2024
1 parent 4e3de10 commit 724af37
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/Integration/Generators/InterfaceMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

class InterfaceMakeCommandTest extends TestCase
{
protected $files = [
'app/Gateway.php',
'app/Contracts/Gateway.php',
'app/Interfaces/Gateway.php',
];

public function testItCanGenerateInterfaceFile()
{
$this->artisan('make:interface', ['name' => 'Gateway'])
Expand All @@ -16,4 +22,44 @@ public function testItCanGenerateInterfaceFile()
'interface Gateway',
], 'app/Gateway.php');
}

public function testItCanGenerateInterfaceFileWhenContractsFolderExists()
{
$interfacesFolderPath = app_path('Contracts');

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

$files->ensureDirectoryExists($interfacesFolderPath);

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

$this->assertFileContains([
'namespace App\Contracts;',
'interface Gateway',
], 'app/Contracts/Gateway.php');

$files->deleteDirectory($interfacesFolderPath);
}

public function testItCanGenerateInterfaceFileWhenInterfacesFolderExists()
{
$interfacesFolderPath = app_path('Interfaces');

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

$files->ensureDirectoryExists($interfacesFolderPath);

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

$this->assertFileContains([
'namespace App\Interfaces;',
'interface Gateway',
], 'app/Interfaces/Gateway.php');

$files->deleteDirectory($interfacesFolderPath);
}
}
40 changes: 40 additions & 0 deletions tests/Integration/Generators/TraitMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,44 @@ public function testItCanGenerateTraitFile()
'trait FooTrait',
], 'app/FooTrait.php');
}

public function testItCanGenerateTraitFileWhenTraitsFolderExists()
{
$traitsFolderPath = app_path('Traits');

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

$files->ensureDirectoryExists($traitsFolderPath);

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

$this->assertFileContains([
'namespace App\Traits;',
'trait FooTrait',
], 'app/Traits/FooTrait.php');

$files->deleteDirectory($traitsFolderPath);
}

public function testItCanGenerateTraitFileWhenConcernsFolderExists()
{
$traitsFolderPath = app_path('Concerns');

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

$files->ensureDirectoryExists($traitsFolderPath);

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

$this->assertFileContains([
'namespace App\Concerns;',
'trait FooTrait',
], 'app/Concerns/FooTrait.php');

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

0 comments on commit 724af37

Please sign in to comment.