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)'); + }); +});