From b8140166c9f2f73700e462134a65222be6906b40 Mon Sep 17 00:00:00 2001 From: Joel Male Date: Wed, 27 May 2026 21:43:14 +1000 Subject: [PATCH] feat: add cart:make:tax command --- src/Commands/MakeTaxCommand.php | 62 ++++++++++++++++++++++ tests/Unit/Commands/MakeTaxCommandTest.php | 30 +++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/Commands/MakeTaxCommand.php create mode 100644 tests/Unit/Commands/MakeTaxCommandTest.php diff --git a/src/Commands/MakeTaxCommand.php b/src/Commands/MakeTaxCommand.php new file mode 100644 index 0000000..8295443 --- /dev/null +++ b/src/Commands/MakeTaxCommand.php @@ -0,0 +1,62 @@ +argument('name'); + $directory = app_path('Cart/Tax'); + $path = "{$directory}/{$name}.php"; + + if (file_exists($path)) { + $this->error("Tax rule already exists: app/Cart/Tax/{$name}.php"); + return self::FAILURE; + } + + if (! is_dir($directory)) { + mkdir($directory, 0755, true); + } + + file_put_contents($path, static::stub($name)); + $this->info("Tax rule created: app/Cart/Tax/{$name}.php"); + + return self::SUCCESS; + } + + public static function stub(string $className): string + { + return <<toContain('class GstTaxRule extends TaxRule'); + }); + + test('stub uses the App\\Cart\\Tax namespace', function () { + $stub = MakeTaxCommand::stub('GstTaxRule'); + expect($stub)->toContain('namespace App\\Cart\\Tax'); + }); + + test('stub imports the TaxRule base class', function () { + $stub = MakeTaxCommand::stub('GstTaxRule'); + expect($stub)->toContain('use Wearepixel\\Cart\\Tax\\TaxRule'); + }); + + test('stub declares isApplicable() method', function () { + $stub = MakeTaxCommand::stub('GstTaxRule'); + expect($stub)->toContain('public function isApplicable(): bool'); + }); + + test('stub uses strict_types', function () { + $stub = MakeTaxCommand::stub('GstTaxRule'); + expect($stub)->toContain('declare(strict_types=1)'); + }); +});