From d074609f4389020d314e9290ef2b222a07c24435 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 17:47:02 +0800 Subject: [PATCH 01/11] wip Signed-off-by: Mior Muhammad Zaki --- canvas | 7 +++++-- composer.json | 12 ++++++++---- src/Canvas.php | 25 +++++++++++++++++++++---- src/LaravelServiceProvider.php | 2 +- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/canvas b/canvas index 0eb4dfe4..cc307f97 100755 --- a/canvas +++ b/canvas @@ -2,12 +2,15 @@ is_file("{$workingPath}/artisan") ? 'laravel' : 'package']; require $_composer_autoload_path ?? __DIR__.'/vendor/autoload.php'; -if (file_exists("{$workingPath}/canvas.yaml")) { - $config = Symfony\Component\Yaml\Yaml::parseFile("{$workingPath}/canvas.yaml"); +if (file_exists($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml')) { + $config = Symfony\Component\Yaml\Yaml::parseFile($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml'); } $files = new Illuminate\Filesystem\Filesystem(); diff --git a/composer.json b/composer.json index 104a7025..a652939e 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "require-dev": { "laravel/pint": "^1.6", - "orchestra/testbench": "^8.8.1", + "orchestra/testbench": "^8.9", "phpstan/phpstan": "^1.10.5", "phpunit/phpunit": "^10.1" }, @@ -55,11 +55,15 @@ } }, "scripts": { - "post-autoload-dump": "@composer run prepare", + "post-autoload-dump": "@prepare", "prepare": "@php testbench package:discover --ansi", "ci": [ - "@composer audit", - "@composer run prepare", + "@audit", + "@prepare", + "@lint", + "@test" + ], + "lint": [ "@php vendor/bin/phpstan analyse", "@php vendor/bin/pint" ], diff --git a/src/Canvas.php b/src/Canvas.php index f9b3f1a4..4fddd6ce 100644 --- a/src/Canvas.php +++ b/src/Canvas.php @@ -7,13 +7,30 @@ class Canvas { + public static function presetFromEnvironment(string $workingPath): string + { + /** detect `testbench.yaml` */ + $testbenchYaml = Collection::make([ + 'testbench.yaml', + 'testbench.yaml.example', + 'testbench.yaml.dist', + ])->filter(fn ($filename) => file_exists($workingPath.DIRECTORY_SEPARATOR.$workingPath)) + ->first(); + + if (! \is_null($testbenchYaml)) { + return 'package'; + } + + + } + /** * Make Preset from configuration. * * @param array $config * @return \Orchestra\Canvas\Core\Presets\Preset */ - public static function preset(array $config, string $basePath, Filesystem $files): Core\Presets\Preset + public static function preset(array $config, string $workingPath, Filesystem $files): Core\Presets\Preset { /** @var array $configuration */ $configuration = Arr::except($config, 'preset'); @@ -22,9 +39,9 @@ public static function preset(array $config, string $basePath, Filesystem $files switch ($preset) { case 'package': - return new Core\Presets\Package($configuration, $basePath, $files); + return new Core\Presets\Package($configuration, $workingPath, $files); case 'laravel': - return new Core\Presets\Laravel($configuration, $basePath, $files); + return new Core\Presets\Laravel($configuration, $workingPath, $files); default: if (class_exists($preset)) { /** @@ -32,7 +49,7 @@ public static function preset(array $config, string $basePath, Filesystem $files * * @return \Orchestra\Canvas\Core\Presets\Preset */ - return new $preset($configuration, $basePath, $files); + return new $preset($configuration, $workingPath, $files); } return new Core\Presets\Laravel($configuration, $basePath, $files); diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index 06f3c2d0..155cb2e4 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -57,7 +57,7 @@ public function boot() */ $preset = $app->make('orchestra.canvas'); - if ($app->runningUnitTests()) { + if (defined('TESTBENCH_WORKING_PATH') || $app->runningUnitTests()) { $artisan->add(new Commands\Channel($preset)); $artisan->add(new Commands\Component($preset)); $artisan->add(new Commands\Console($preset)); From 09b7e30aec05d3532dd2048683e0b55693c3baa0 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 20:08:05 +0800 Subject: [PATCH 02/11] wip Signed-off-by: Mior Muhammad Zaki --- canvas | 2 +- src/Canvas.php | 25 +++++--- src/LaravelServiceProvider.php | 34 +++++++++-- src/Presets/PackageWorkbench.php | 97 ++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 13 deletions(-) create mode 100644 src/Presets/PackageWorkbench.php diff --git a/canvas b/canvas index cc307f97..dd8d44e7 100755 --- a/canvas +++ b/canvas @@ -5,7 +5,7 @@ $workingPath = getcwd(); define('CANVAS_WORKING_PATH', $workingPath); -$config = ['preset' => is_file("{$workingPath}/artisan") ? 'laravel' : 'package']; +$config = ['preset' => Orchestra\Canvas\Canvas::presetFromEnvironment($workingPath)]; require $_composer_autoload_path ?? __DIR__.'/vendor/autoload.php'; diff --git a/src/Canvas.php b/src/Canvas.php index 4fddd6ce..c8c6ff0f 100644 --- a/src/Canvas.php +++ b/src/Canvas.php @@ -4,24 +4,33 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Arr; +use Illuminate\Support\Collection; class Canvas { - public static function presetFromEnvironment(string $workingPath): string + /** + * Assume the preset from environment. + */ + public static function presetFromEnvironment(string $basePath): string { /** detect `testbench.yaml` */ $testbenchYaml = Collection::make([ 'testbench.yaml', 'testbench.yaml.example', 'testbench.yaml.dist', - ])->filter(fn ($filename) => file_exists($workingPath.DIRECTORY_SEPARATOR.$workingPath)) - ->first(); + ])->filter(fn ($filename) => file_exists($basePath.DIRECTORY_SEPARATOR.$filename)) + ->first(); if (! \is_null($testbenchYaml)) { return 'package'; } - + return Collection::make([ + file_exists($basePath.DIRECTORY_SEPARATOR.'artisan'), + file_exists($basePath.DIRECTORY_SEPARATOR.'bootstrap'.DIRECTORY_SEPARATOR.'app.php'), + is_dir($basePath.DIRECTORY_SEPARATOR.'bootstrap'.DIRECTORY_SEPARATOR.'cache'), + ])->reject(fn ($condition) => $condition === true) + ->isEmpty() ? 'laravel' : 'package'; } /** @@ -30,7 +39,7 @@ public static function presetFromEnvironment(string $workingPath): string * @param array $config * @return \Orchestra\Canvas\Core\Presets\Preset */ - public static function preset(array $config, string $workingPath, Filesystem $files): Core\Presets\Preset + public static function preset(array $config, string $basePath, Filesystem $files): Core\Presets\Preset { /** @var array $configuration */ $configuration = Arr::except($config, 'preset'); @@ -39,9 +48,9 @@ public static function preset(array $config, string $workingPath, Filesystem $fi switch ($preset) { case 'package': - return new Core\Presets\Package($configuration, $workingPath, $files); + return new Core\Presets\Package($configuration, $basePath, $files); case 'laravel': - return new Core\Presets\Laravel($configuration, $workingPath, $files); + return new Core\Presets\Laravel($configuration, $basePath, $files); default: if (class_exists($preset)) { /** @@ -49,7 +58,7 @@ public static function preset(array $config, string $workingPath, Filesystem $fi * * @return \Orchestra\Canvas\Core\Presets\Preset */ - return new $preset($configuration, $workingPath, $files); + return new $preset($configuration, $basePath, $files); } return new Core\Presets\Laravel($configuration, $basePath, $files); diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index 155cb2e4..8c7937be 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -5,8 +5,11 @@ use Illuminate\Console\Application as Artisan; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Arr; use Illuminate\Support\ServiceProvider; +use Orchestra\Canvas\Core\Presets\Preset; +use Orchestra\Workbench\Workbench; use Symfony\Component\Yaml\Yaml; class LaravelServiceProvider extends ServiceProvider implements DeferrableProvider @@ -21,11 +24,15 @@ class LaravelServiceProvider extends ServiceProvider implements DeferrableProvid public function register() { $this->app->singleton('orchestra.canvas', function (Application $app) { - $files = $app->make('files'); + $filesystem = $app->make('files'); + + if (\defined('TESTBENCH_WORKING_PATH') && class_exists(Workbench::class)) { + return $this->registerCanvasForWorkbench($filesystem); + } $config = ['preset' => 'laravel']; - if ($files->exists($app->basePath('canvas.yaml'))) { + if ($filesystem->exists($app->basePath('canvas.yaml'))) { $config = Yaml::parseFile($app->basePath('canvas.yaml')); } else { Arr::set($config, 'testing.extends', [ @@ -38,7 +45,7 @@ public function register() $config['user-auth-provider'] = $this->userProviderModel(); - return Canvas::preset($config, $app->basePath(), $files); + return Canvas::preset($config, $app->basePath(), $filesystem); }); } @@ -57,7 +64,7 @@ public function boot() */ $preset = $app->make('orchestra.canvas'); - if (defined('TESTBENCH_WORKING_PATH') || $app->runningUnitTests()) { + if (\defined('TESTBENCH_WORKING_PATH') || $app->runningUnitTests()) { $artisan->add(new Commands\Channel($preset)); $artisan->add(new Commands\Component($preset)); $artisan->add(new Commands\Console($preset)); @@ -89,6 +96,25 @@ public function boot() }); } + /** + * Regiseter canvas for workbench. + */ + protected function registerCanvasForWorkbench(Filesystem $filesystem): Preset + { + return Canvas::preset( + [ + 'preset' => Presets\PackageWorkbench::class, + 'testing' => [ + 'extends' => ['unit' => 'PHPUnit\Framework\TestCase', + 'feature' => 'Orchestra\Testbench\TestCase', + ], + ], + ], + Workbench::packagePath(), + $filesystem + ); + } + /** * Get the services provided by the provider. * diff --git a/src/Presets/PackageWorkbench.php b/src/Presets/PackageWorkbench.php new file mode 100644 index 00000000..99b0860f --- /dev/null +++ b/src/Presets/PackageWorkbench.php @@ -0,0 +1,97 @@ + Date: Sat, 19 Aug 2023 20:38:07 +0800 Subject: [PATCH 03/11] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 22 ++++++++++++++----- src/Presets/PackageWorkbench.php | 18 ++++++++++++++- src/Processors/GeneratesFactoryCode.php | 2 +- src/Processors/GeneratesSeederCode.php | 2 +- testbench.yaml | 2 ++ tests/Feature/CommandsProviderTest.php | 2 +- .../Generators/Database/EloquentTest.php | 20 ++++++++--------- .../Generators/Database/SeederTest.php | 4 ++-- workbench/app/.gitkeep | 0 workbench/database/factories/.gitkeep | 0 workbench/database/migrations/.gitkeep | 0 workbench/database/seeders/.gitkeep | 0 12 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 testbench.yaml create mode 100644 workbench/app/.gitkeep create mode 100644 workbench/database/factories/.gitkeep create mode 100644 workbench/database/migrations/.gitkeep create mode 100644 workbench/database/seeders/.gitkeep diff --git a/composer.json b/composer.json index a652939e..0a0fad53 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,10 @@ }, "autoload-dev": { "psr-4": { - "Orchestra\\Canvas\\Tests\\": "tests/" + "Orchestra\\Canvas\\Tests\\": "tests/", + "Workbench\\App\\": "workbench/app/", + "Workbench\\Database\\Factories\\": "workbench/database/factories/", + "Workbench\\Database\\Seeders\\": "workbench/database/seeders/" } }, "require": { @@ -32,7 +35,7 @@ "composer/semver": "^3.0", "illuminate/database": "^10.17", "illuminate/support": "^10.17", - "orchestra/canvas-core": "^8.3", + "orchestra/canvas-core": "^8.4", "symfony/yaml": "^6.2" }, "require-dev": { @@ -55,8 +58,11 @@ } }, "scripts": { - "post-autoload-dump": "@prepare", - "prepare": "@php testbench package:discover --ansi", + "post-autoload-dump": [ + "@clear", + "@prepare" + ], + "prepare": "@php vendor/bin/testbench package:discover --ansi", "ci": [ "@audit", "@prepare", @@ -67,7 +73,13 @@ "@php vendor/bin/phpstan analyse", "@php vendor/bin/pint" ], - "test": "@php vendor/bin/phpunit -c ./ --color" + "test": "@php vendor/bin/phpunit -c ./ --color", + "clear": "@php vendor/bin/testbench package:purge-skeleton --ansi", + "build": "@php vendor/bin/testbench workbench:build", + "serve": [ + "@build", + "@php vendor/bin/testbench serve" + ] }, "minimum-stability": "dev" } diff --git a/src/Presets/PackageWorkbench.php b/src/Presets/PackageWorkbench.php index 99b0860f..5f9c8437 100644 --- a/src/Presets/PackageWorkbench.php +++ b/src/Presets/PackageWorkbench.php @@ -28,7 +28,7 @@ public function laravelPath(): string */ public function sourcePath(): string { - return Workbench::path(); + return Workbench::path('app'); } /** @@ -55,6 +55,22 @@ public function providerNamespace(): string return 'Workbench\App\Providers'; } + /** + * Databases namespace. + */ + public function factoryNamespace(): string + { + return 'Workbench\Database\Factories'; + } + + /** + * Databases namespace. + */ + public function seederNamespace(): string + { + return 'Workbench\Database\Seeders'; + } + /** * Get the path to the resource directory. */ diff --git a/src/Processors/GeneratesFactoryCode.php b/src/Processors/GeneratesFactoryCode.php index 3722e6f5..99b7d7b0 100644 --- a/src/Processors/GeneratesFactoryCode.php +++ b/src/Processors/GeneratesFactoryCode.php @@ -23,7 +23,7 @@ protected function buildClass(string $name): string $model = class_basename($namespaceModel); - $factoryNamespace = $this->preset->config('factory.namespace', 'Database\Factories'); + $factoryNamespace = $this->preset->factoryNamespace(); if (Str::startsWith($namespaceModel, 'App\\Models')) { $namespace = Str::beforeLast($factoryNamespace.'\\'.Str::after($namespaceModel, 'App\\Models\\'), '\\'); diff --git a/src/Processors/GeneratesSeederCode.php b/src/Processors/GeneratesSeederCode.php index ea8467d1..806dfdaa 100644 --- a/src/Processors/GeneratesSeederCode.php +++ b/src/Processors/GeneratesSeederCode.php @@ -40,6 +40,6 @@ protected function getNamespace(string $name): string */ protected function rootNamespace(): string { - return 'Database\Seeders\\'; + return $this->preset->seederNamespace(); } } diff --git a/testbench.yaml b/testbench.yaml new file mode 100644 index 00000000..f8ac602c --- /dev/null +++ b/testbench.yaml @@ -0,0 +1,2 @@ +providers: + - Orchestra\Canvas\LaravelServiceProvider diff --git a/tests/Feature/CommandsProviderTest.php b/tests/Feature/CommandsProviderTest.php index c6b3e048..ea366ed2 100644 --- a/tests/Feature/CommandsProviderTest.php +++ b/tests/Feature/CommandsProviderTest.php @@ -29,6 +29,6 @@ public function it_can_setup_laravel_preset() $this->assertSame("{$directory}/resources", $preset->resourcePath()); $this->assertSame("{$directory}/database/factories", $preset->factoryPath()); $this->assertSame("{$directory}/database/migrations", $preset->migrationPath()); - $this->assertSame("{$directory}/database/seeds", $preset->seederPath()); + $this->assertSame("{$directory}/database/seeders", $preset->seederPath()); } } diff --git a/tests/Feature/Generators/Database/EloquentTest.php b/tests/Feature/Generators/Database/EloquentTest.php index 5766cf27..2aa89c21 100644 --- a/tests/Feature/Generators/Database/EloquentTest.php +++ b/tests/Feature/Generators/Database/EloquentTest.php @@ -12,7 +12,7 @@ class EloquentTest extends TestCase 'app/Http/Controllers/FooController.php', 'app/Http/Controllers/BarController.php', 'database/factories/FooFactory.php', - 'database/seeds/FooSeeder.php', + 'database/seeders/FooSeeder.php', ]; /** @test */ @@ -84,7 +84,7 @@ public function it_can_generate_eloquent_with_controller_options_file() ], 'app/Http/Controllers/FooController.php'); $this->assertFilenameNotExists('database/factories/FooFactory.php'); - $this->assertFilenameNotExists('database/seeds/FooSeeder.php'); + $this->assertFilenameNotExists('database/seeders/FooSeeder.php'); } /** @test */ @@ -114,7 +114,7 @@ public function it_can_generate_eloquent_with_resource_controller_options_file() ], 'app/Http/Controllers/FooController.php'); $this->assertFilenameNotExists('database/factories/FooFactory.php'); - $this->assertFilenameNotExists('database/seeds/FooSeeder.php'); + $this->assertFilenameNotExists('database/seeders/FooSeeder.php'); } /** @test */ @@ -131,7 +131,7 @@ public function it_can_generate_eloquent_with_factory_options_file() $this->assertFilenameNotExists('app/Http/Controllers/FooController.php'); $this->assertFilenameExists('database/factories/FooFactory.php'); - $this->assertFilenameNotExists('database/seeds/FooSeeder.php'); + $this->assertFilenameNotExists('database/seeders/FooSeeder.php'); } /** @test */ @@ -155,7 +155,7 @@ public function it_can_generate_eloquent_with_migration_options_file() $this->assertFilenameNotExists('app/Http/Controllers/FooController.php'); $this->assertFilenameNotExists('database/factories/FooFactory.php'); - $this->assertFilenameNotExists('database/seeds/FooSeeder.php'); + $this->assertFilenameNotExists('database/seeders/FooSeeder.php'); } /** @test */ @@ -172,7 +172,7 @@ public function it_can_generate_eloquent_with_seeder_options_file() $this->assertFilenameNotExists('app/Http/Controllers/FooController.php'); $this->assertFilenameNotExists('database/factories/FooFactory.php'); - $this->assertFilenameExists('database/seeds/FooSeeder.php'); + $this->assertFilenameExists('database/seeders/FooSeeder.php'); } /** @test */ @@ -194,7 +194,7 @@ public function it_can_generate_nested_eloquent_with_controller_options_file() ], 'app/Http/Controllers/BarController.php'); $this->assertFilenameNotExists('database/factories/FooFactory.php'); - $this->assertFilenameNotExists('database/seeds/FooSeeder.php'); + $this->assertFilenameNotExists('database/seeders/FooSeeder.php'); } /** @test */ @@ -224,7 +224,7 @@ public function it_can_generate_nested_eloquent_with_resource_controller_options ], 'app/Http/Controllers/BarController.php'); $this->assertFilenameNotExists('database/factories/FooFactory.php'); - $this->assertFilenameNotExists('database/seeds/FooSeeder.php'); + $this->assertFilenameNotExists('database/seeders/FooSeeder.php'); } /** @test */ @@ -252,7 +252,7 @@ public function it_can_generate_nested_eloquent_with_api_controller_options_file ], 'app/Http/Controllers/BarController.php'); $this->assertFilenameNotExists('database/factories/FooFactory.php'); - $this->assertFilenameNotExists('database/seeds/FooSeeder.php'); + $this->assertFilenameNotExists('database/seeders/FooSeeder.php'); } /** @test */ @@ -276,6 +276,6 @@ public function it_can_generate_eloquent_with_all_options_file() $this->assertFilenameExists('app/Http/Controllers/FooController.php'); $this->assertFilenameExists('database/factories/FooFactory.php'); - $this->assertFilenameExists('database/seeds/FooSeeder.php'); + $this->assertFilenameExists('database/seeders/FooSeeder.php'); } } diff --git a/tests/Feature/Generators/Database/SeederTest.php b/tests/Feature/Generators/Database/SeederTest.php index 29f7178d..47f6a812 100644 --- a/tests/Feature/Generators/Database/SeederTest.php +++ b/tests/Feature/Generators/Database/SeederTest.php @@ -7,7 +7,7 @@ class SeederTest extends TestCase { protected $files = [ - 'database/seeds/FooSeeder.php', + 'database/seeders/FooSeeder.php', ]; /** @test */ @@ -21,6 +21,6 @@ public function it_can_generate_seeder_file() 'use Illuminate\Database\Seeder;', 'class FooSeeder extends Seeder', 'public function run()', - ], 'database/seeds/FooSeeder.php'); + ], 'database/seeders/FooSeeder.php'); } } diff --git a/workbench/app/.gitkeep b/workbench/app/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/workbench/database/factories/.gitkeep b/workbench/database/factories/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/workbench/database/migrations/.gitkeep b/workbench/database/migrations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/workbench/database/seeders/.gitkeep b/workbench/database/seeders/.gitkeep new file mode 100644 index 00000000..e69de29b From 025ff6bb2f83ce86f50a499089eaed5218903706 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 20:53:42 +0800 Subject: [PATCH 04/11] wip Signed-off-by: Mior Muhammad Zaki --- .../Feature/Presets/PackageWorkbenchTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Feature/Presets/PackageWorkbenchTest.php diff --git a/tests/Feature/Presets/PackageWorkbenchTest.php b/tests/Feature/Presets/PackageWorkbenchTest.php new file mode 100644 index 00000000..1f0131be --- /dev/null +++ b/tests/Feature/Presets/PackageWorkbenchTest.php @@ -0,0 +1,46 @@ +assertSame('workbench', $preset->name()); + $this->assertSame([], $preset->config()); + $this->assertTrue($preset->is('workbench')); + $this->assertFalse($preset->is('package')); + $this->assertFalse($preset->is('laravel')); + + $this->assertSame($directory, $preset->basePath()); + $this->assertSame("{$directory}/vendor/orchestra/testbench-core/laravel", $preset->laravelPath()); + + $this->assertSame('Workbench\App', $preset->rootNamespace()); + $this->assertSame('Workbench\App\Models', $preset->modelNamespace()); + $this->assertSame('Workbench\App\Providers', $preset->providerNamespace()); + + $this->assertSame("{$directory}/workbench/app", $preset->sourcePath()); + $this->assertSame("{$directory}/vendor", $preset->vendorPath()); + $this->assertSame("{$directory}/workbench/resources", $preset->resourcePath()); + $this->assertSame("{$directory}/workbench/database/factories", $preset->factoryPath()); + $this->assertSame("{$directory}/workbench/database/migrations", $preset->migrationPath()); + $this->assertSame("{$directory}/workbench/database/seeders", $preset->seederPath()); + + $this->assertFalse($preset->hasCustomStubPath()); + $this->assertNull($preset->getCustomStubPath()); + + $this->assertSame($files, $preset->filesystem()); + } +} From fce13ad87ed8dd0585aedf388e2160cbf7de95dd Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 20:54:23 +0800 Subject: [PATCH 05/11] wip Signed-off-by: Mior Muhammad Zaki --- tests/Feature/Presets/PackageWorkbenchTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Feature/Presets/PackageWorkbenchTest.php b/tests/Feature/Presets/PackageWorkbenchTest.php index 1f0131be..bc96ab94 100644 --- a/tests/Feature/Presets/PackageWorkbenchTest.php +++ b/tests/Feature/Presets/PackageWorkbenchTest.php @@ -30,6 +30,8 @@ public function it_has_proper_signatures() $this->assertSame('Workbench\App', $preset->rootNamespace()); $this->assertSame('Workbench\App\Models', $preset->modelNamespace()); $this->assertSame('Workbench\App\Providers', $preset->providerNamespace()); + $this->assertSame('Workbench\Database\Factories', $preset->factoryNamespace()); + $this->assertSame('Workbench\Database\Seeders', $preset->seederNamespace()); $this->assertSame("{$directory}/workbench/app", $preset->sourcePath()); $this->assertSame("{$directory}/vendor", $preset->vendorPath()); From 6c5c78fafef5588e90692308f16aac5beb6c144f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 20:54:27 +0800 Subject: [PATCH 06/11] wip Signed-off-by: Mior Muhammad Zaki --- tests/Feature/Presets/PackageWorkbenchTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Feature/Presets/PackageWorkbenchTest.php b/tests/Feature/Presets/PackageWorkbenchTest.php index bc96ab94..6471d0d0 100644 --- a/tests/Feature/Presets/PackageWorkbenchTest.php +++ b/tests/Feature/Presets/PackageWorkbenchTest.php @@ -3,7 +3,6 @@ namespace Orchestra\Canvas\Tests\Feature\Presets; use Illuminate\Filesystem\Filesystem; -use Orchestra\Canvas\Core\Presets\Package; use Orchestra\Canvas\Presets\PackageWorkbench; use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase; From fd25421b26ac31136a2299bb087e9e12c5b6d0a9 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 21:02:10 +0800 Subject: [PATCH 07/11] wip Signed-off-by: Mior Muhammad Zaki --- .../Feature/Presets/PackageWorkbenchTest.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/Feature/Presets/PackageWorkbenchTest.php b/tests/Feature/Presets/PackageWorkbenchTest.php index 6471d0d0..3b38a3b4 100644 --- a/tests/Feature/Presets/PackageWorkbenchTest.php +++ b/tests/Feature/Presets/PackageWorkbenchTest.php @@ -24,7 +24,7 @@ public function it_has_proper_signatures() $this->assertFalse($preset->is('laravel')); $this->assertSame($directory, $preset->basePath()); - $this->assertSame("{$directory}/vendor/orchestra/testbench-core/laravel", $preset->laravelPath()); + $this->assertSame(static::normalisePath("{$directory}/vendor/orchestra/testbench-core/laravel"), $preset->laravelPath()); $this->assertSame('Workbench\App', $preset->rootNamespace()); $this->assertSame('Workbench\App\Models', $preset->modelNamespace()); @@ -32,16 +32,22 @@ public function it_has_proper_signatures() $this->assertSame('Workbench\Database\Factories', $preset->factoryNamespace()); $this->assertSame('Workbench\Database\Seeders', $preset->seederNamespace()); - $this->assertSame("{$directory}/workbench/app", $preset->sourcePath()); - $this->assertSame("{$directory}/vendor", $preset->vendorPath()); - $this->assertSame("{$directory}/workbench/resources", $preset->resourcePath()); - $this->assertSame("{$directory}/workbench/database/factories", $preset->factoryPath()); - $this->assertSame("{$directory}/workbench/database/migrations", $preset->migrationPath()); - $this->assertSame("{$directory}/workbench/database/seeders", $preset->seederPath()); + $this->assertSame($this->normalisePath("{$directory}/workbench/app"), $preset->sourcePath()); + $this->assertSame(static::normalisePath("{$directory}/workbench/app"), $preset->sourcePath()); + $this->assertSame(static::normalisePath("{$directory}/vendor"), $preset->vendorPath()); + $this->assertSame(static::normalisePath("{$directory}/workbench/resources"), $preset->resourcePath()); + $this->assertSame(static::normalisePath("{$directory}/workbench/database/factories"), $preset->factoryPath()); + $this->assertSame(static::normalisePath("{$directory}/workbench/database/migrations"), $preset->migrationPath()); + $this->assertSame(static::normalisePath("{$directory}/workbench/database/seeders"), $preset->seederPath()); $this->assertFalse($preset->hasCustomStubPath()); $this->assertNull($preset->getCustomStubPath()); $this->assertSame($files, $preset->filesystem()); } + + public static function normalisePath(string $path): string + { + return str_replace('/', DIRECTORY_SEPARATOR, $path); + } } From 44698d4a94587eb668328808dab772750ded88e3 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 21:12:10 +0800 Subject: [PATCH 08/11] wip Signed-off-by: Mior Muhammad Zaki --- tests/Feature/Presets/PackageWorkbenchTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/Presets/PackageWorkbenchTest.php b/tests/Feature/Presets/PackageWorkbenchTest.php index 3b38a3b4..c1056c31 100644 --- a/tests/Feature/Presets/PackageWorkbenchTest.php +++ b/tests/Feature/Presets/PackageWorkbenchTest.php @@ -34,7 +34,7 @@ public function it_has_proper_signatures() $this->assertSame($this->normalisePath("{$directory}/workbench/app"), $preset->sourcePath()); $this->assertSame(static::normalisePath("{$directory}/workbench/app"), $preset->sourcePath()); - $this->assertSame(static::normalisePath("{$directory}/vendor"), $preset->vendorPath()); + $this->assertSame("{$directory}/vendor", $preset->vendorPath()); $this->assertSame(static::normalisePath("{$directory}/workbench/resources"), $preset->resourcePath()); $this->assertSame(static::normalisePath("{$directory}/workbench/database/factories"), $preset->factoryPath()); $this->assertSame(static::normalisePath("{$directory}/workbench/database/migrations"), $preset->migrationPath()); From 91f241904561e0882086f858a00bb0556ecb6a67 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 21:15:14 +0800 Subject: [PATCH 09/11] wip Signed-off-by: Mior Muhammad Zaki --- tests/Feature/Presets/PackageWorkbenchTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Feature/Presets/PackageWorkbenchTest.php b/tests/Feature/Presets/PackageWorkbenchTest.php index c1056c31..c54d9392 100644 --- a/tests/Feature/Presets/PackageWorkbenchTest.php +++ b/tests/Feature/Presets/PackageWorkbenchTest.php @@ -6,6 +6,7 @@ use Orchestra\Canvas\Presets\PackageWorkbench; use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase; +use Orchestra\Workbench\Workbench; class PackageWorkbenchTest extends TestCase { @@ -14,7 +15,7 @@ class PackageWorkbenchTest extends TestCase /** @test */ public function it_has_proper_signatures() { - $directory = realpath(__DIR__.'/../../../'); + $directory = __DIR__; $preset = new PackageWorkbench([], $directory, $files = new Filesystem()); $this->assertSame('workbench', $preset->name()); @@ -24,7 +25,7 @@ public function it_has_proper_signatures() $this->assertFalse($preset->is('laravel')); $this->assertSame($directory, $preset->basePath()); - $this->assertSame(static::normalisePath("{$directory}/vendor/orchestra/testbench-core/laravel"), $preset->laravelPath()); + $this->assertSame(Workbench::laravelPath(), $preset->laravelPath()); $this->assertSame('Workbench\App', $preset->rootNamespace()); $this->assertSame('Workbench\App\Models', $preset->modelNamespace()); @@ -32,13 +33,12 @@ public function it_has_proper_signatures() $this->assertSame('Workbench\Database\Factories', $preset->factoryNamespace()); $this->assertSame('Workbench\Database\Seeders', $preset->seederNamespace()); - $this->assertSame($this->normalisePath("{$directory}/workbench/app"), $preset->sourcePath()); - $this->assertSame(static::normalisePath("{$directory}/workbench/app"), $preset->sourcePath()); + $this->assertSame(Workbench::path('app'), $preset->sourcePath()); $this->assertSame("{$directory}/vendor", $preset->vendorPath()); - $this->assertSame(static::normalisePath("{$directory}/workbench/resources"), $preset->resourcePath()); - $this->assertSame(static::normalisePath("{$directory}/workbench/database/factories"), $preset->factoryPath()); - $this->assertSame(static::normalisePath("{$directory}/workbench/database/migrations"), $preset->migrationPath()); - $this->assertSame(static::normalisePath("{$directory}/workbench/database/seeders"), $preset->seederPath()); + $this->assertSame(Workbench::path('resources'), $preset->resourcePath()); + $this->assertSame(Workbench::path('database/factories'), $preset->factoryPath()); + $this->assertSame(Workbench::path('database/migrations'), $preset->migrationPath()); + $this->assertSame(Workbench::path('database/seeders'), $preset->seederPath()); $this->assertFalse($preset->hasCustomStubPath()); $this->assertNull($preset->getCustomStubPath()); From c68bf72f434b7f36cfe011cae1edaa738973e347 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 21:19:18 +0800 Subject: [PATCH 10/11] wip Signed-off-by: Mior Muhammad Zaki --- src/LaravelServiceProvider.php | 2 +- tests/Feature/Presets/PackageWorkbenchTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index 8c7937be..3567f44d 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -110,7 +110,7 @@ protected function registerCanvasForWorkbench(Filesystem $filesystem): Preset ], ], ], - Workbench::packagePath(), + rtrim(Workbench::packagePath(), DIRECTORY_SEPARATOR), $filesystem ); } diff --git a/tests/Feature/Presets/PackageWorkbenchTest.php b/tests/Feature/Presets/PackageWorkbenchTest.php index c54d9392..e8fb7de3 100644 --- a/tests/Feature/Presets/PackageWorkbenchTest.php +++ b/tests/Feature/Presets/PackageWorkbenchTest.php @@ -15,7 +15,7 @@ class PackageWorkbenchTest extends TestCase /** @test */ public function it_has_proper_signatures() { - $directory = __DIR__; + $directory = rtrim(Workbench::packagePath(), DIRECTORY_SEPARATOR); $preset = new PackageWorkbench([], $directory, $files = new Filesystem()); $this->assertSame('workbench', $preset->name()); @@ -34,7 +34,7 @@ public function it_has_proper_signatures() $this->assertSame('Workbench\Database\Seeders', $preset->seederNamespace()); $this->assertSame(Workbench::path('app'), $preset->sourcePath()); - $this->assertSame("{$directory}/vendor", $preset->vendorPath()); + $this->assertSame(Workbench::packagePath('vendor'), $preset->vendorPath()); $this->assertSame(Workbench::path('resources'), $preset->resourcePath()); $this->assertSame(Workbench::path('database/factories'), $preset->factoryPath()); $this->assertSame(Workbench::path('database/migrations'), $preset->migrationPath()); From 3ea67c76f460053aa1d7e8703e45bd8b57d4c86c Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 19 Aug 2023 21:23:26 +0800 Subject: [PATCH 11/11] wip Signed-off-by: Mior Muhammad Zaki --- tests/Feature/Presets/PackageWorkbenchTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/Presets/PackageWorkbenchTest.php b/tests/Feature/Presets/PackageWorkbenchTest.php index e8fb7de3..5dd0cf4c 100644 --- a/tests/Feature/Presets/PackageWorkbenchTest.php +++ b/tests/Feature/Presets/PackageWorkbenchTest.php @@ -34,7 +34,7 @@ public function it_has_proper_signatures() $this->assertSame('Workbench\Database\Seeders', $preset->seederNamespace()); $this->assertSame(Workbench::path('app'), $preset->sourcePath()); - $this->assertSame(Workbench::packagePath('vendor'), $preset->vendorPath()); + $this->assertSame("{$directory}/vendor", $preset->vendorPath()); $this->assertSame(Workbench::path('resources'), $preset->resourcePath()); $this->assertSame(Workbench::path('database/factories'), $preset->factoryPath()); $this->assertSame(Workbench::path('database/migrations'), $preset->migrationPath());