Skip to content

Commit

Permalink
Merge branch '7.x' into 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Sep 13, 2023
2 parents a812ca2 + 50da75c commit 27ad3d1
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 3 deletions.
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
},
"autoload-dev": {
"psr-4": {
"Orchestra\\Canvas\\Core\\Tests\\": "tests/"
"Orchestra\\Canvas\\Core\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"require": {
Expand Down Expand Up @@ -57,8 +60,13 @@
}
},
"scripts": {
"post-autoload-dump": "@prepare",
"post-autoload-dump": [
"@clear",
"@prepare"
],
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"lint": [
"@php vendor/bin/phpstan analyse",
"@php vendor/bin/pint"
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getDefaultNamespace(string $rootNamespace): string
/**
* Generator options.
*
* @return array{name: string}
* @return array<string, mixed>
*/
public function generatorOptions(): array
{
Expand Down
2 changes: 2 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
providers:
- Orchestra\Canvas\Core\LaravelServiceProvider
31 changes: 31 additions & 0 deletions tests/Unit/Presets/LaravelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
namespace Orchestra\Canvas\Core\Tests\Unit\Presets;

use Illuminate\Filesystem\Filesystem;
use Mockery as m;
use Orchestra\Canvas\Commands;
use Orchestra\Canvas\Core\Presets\Laravel;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;

class LaravelTest extends TestCase
{
/**
* Teardown the test environment.
*/
protected function tearDown(): void
{
m::close();
}

/** @test */
public function it_has_proper_signatures()
{
Expand All @@ -23,6 +34,7 @@ public function it_has_proper_signatures()
$this->assertSame($preset->basePath(), $preset->laravelPath());

$this->assertSame('App', $preset->rootNamespace());
$this->assertSame('Tests', $preset->testingNamespace());
$this->assertSame('App\Models', $preset->modelNamespace());
$this->assertSame('App\Providers', $preset->providerNamespace());
$this->assertSame('Database\Factories', $preset->factoryNamespace());
Expand Down Expand Up @@ -62,4 +74,23 @@ public function it_can_configure_provider_namespace()
$this->assertSame('App\Models', $preset->modelNamespace());
$this->assertSame('App', $preset->providerNamespace());
}

/** @test */
public function it_can_add_additional_commands()
{
Laravel::commands([
Commands\Code::class,
]);

$app = m::mock(Application::class);
$app->shouldReceive('add')
->once()
->with(m::type(Commands\Code::class))
->andReturnUsing(fn ($generator) => $this->assertInstanceOf(Commands\Code::class, $generator));

$directory = __DIR__;
$preset = new Laravel(['namespace' => 'App', 'provider' => ['namespace' => 'App']], $directory, new Filesystem());

$preset->addAdditionalCommands($app);
}
}
23 changes: 23 additions & 0 deletions tests/Unit/Presets/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace Orchestra\Canvas\Core\Tests\Unit\Presets;

use Illuminate\Filesystem\Filesystem;
use Mockery as m;
use Orchestra\Canvas\Commands;
use Orchestra\Canvas\Core\Presets\Package;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;

class PackageTest extends TestCase
{
Expand All @@ -23,6 +26,7 @@ public function it_has_proper_signatures()
$this->assertSame("{$directory}/vendor/orchestra/testbench-core/laravel", $preset->laravelPath());

$this->assertSame('FooBar', $preset->rootNamespace());
$this->assertSame('FooBar\Tests', $preset->testingNamespace());
$this->assertSame('FooBar', $preset->modelNamespace());
$this->assertSame('FooBar', $preset->providerNamespace());
$this->assertSame('Database\Factories', $preset->factoryNamespace());
Expand Down Expand Up @@ -73,4 +77,23 @@ public function it_requires_root_namespace_to_be_configured()

$preset->rootNamespace();
}

/** @test */
public function it_can_add_additional_commands()
{
Package::commands([
Commands\Code::class,
]);

$app = m::mock(Application::class);
$app->shouldReceive('add')
->once()
->with(m::type(Commands\Code::class))
->andReturnUsing(fn ($generator) => $this->assertInstanceOf(Commands\Code::class, $generator));

$directory = __DIR__;
$preset = new Package(['namespace' => 'App', 'provider' => ['namespace' => 'App']], $directory, new Filesystem());

$preset->addAdditionalCommands($app);
}
}
Empty file added workbench/app/.gitkeep
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 27ad3d1

Please sign in to comment.