mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
feat: add cart:install command
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Wearepixel\Cart\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class InstallCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'cart:install';
|
||||||
|
|
||||||
|
protected $description = 'Publish the cart config and scaffold the app/Cart directory structure.';
|
||||||
|
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
$this->call('vendor:publish', ['--tag' => 'cart-config', '--ansi' => true]);
|
||||||
|
|
||||||
|
static::scaffoldDirectories(app_path('Cart'));
|
||||||
|
|
||||||
|
$this->info('Cart installed successfully.');
|
||||||
|
$this->newLine();
|
||||||
|
$this->line(' Next steps:');
|
||||||
|
$this->line(' 1. Review <comment>config/cart.php</comment> and set your preferred storage driver.');
|
||||||
|
$this->line(' 2. Run <comment>php artisan cart:make:coupon MyCoupon</comment> to create your first coupon.');
|
||||||
|
$this->line(' 3. Run <comment>php artisan cart:make:tax MyTax</comment> to add a tax rule.');
|
||||||
|
$this->line(' 4. Run <comment>php artisan cart:make:shipping MyShipping</comment> to add a shipping rate.');
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function scaffoldDirectories(string $base): void
|
||||||
|
{
|
||||||
|
foreach (['Coupons', 'Tax', 'Shipping', 'Drivers'] as $subdir) {
|
||||||
|
$path = "{$base}/{$subdir}";
|
||||||
|
if (! is_dir($path)) {
|
||||||
|
mkdir($path, 0755, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Wearepixel\Cart\Commands\InstallCommand;
|
||||||
|
|
||||||
|
describe('InstallCommand', function () {
|
||||||
|
test('scaffoldDirectories() creates the expected subdirectories', function () {
|
||||||
|
$base = sys_get_temp_dir() . '/cart-install-' . uniqid();
|
||||||
|
|
||||||
|
InstallCommand::scaffoldDirectories($base);
|
||||||
|
|
||||||
|
expect(is_dir("{$base}/Coupons"))->toBeTrue();
|
||||||
|
expect(is_dir("{$base}/Tax"))->toBeTrue();
|
||||||
|
expect(is_dir("{$base}/Shipping"))->toBeTrue();
|
||||||
|
expect(is_dir("{$base}/Drivers"))->toBeTrue();
|
||||||
|
|
||||||
|
foreach (["{$base}/Coupons", "{$base}/Tax", "{$base}/Shipping", "{$base}/Drivers", $base] as $dir) {
|
||||||
|
@rmdir($dir);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('scaffoldDirectories() is idempotent - does not throw if dirs already exist', function () {
|
||||||
|
$base = sys_get_temp_dir() . '/cart-install-idem-' . uniqid();
|
||||||
|
|
||||||
|
InstallCommand::scaffoldDirectories($base);
|
||||||
|
InstallCommand::scaffoldDirectories($base);
|
||||||
|
|
||||||
|
expect(is_dir("{$base}/Coupons"))->toBeTrue();
|
||||||
|
|
||||||
|
foreach (["{$base}/Coupons", "{$base}/Tax", "{$base}/Shipping", "{$base}/Drivers", $base] as $dir) {
|
||||||
|
@rmdir($dir);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user