diff --git a/src/Commands/MakeCouponCommand.php b/src/Commands/MakeCouponCommand.php new file mode 100644 index 0000000..d176fa5 --- /dev/null +++ b/src/Commands/MakeCouponCommand.php @@ -0,0 +1,62 @@ +argument('name'); + $directory = app_path('Cart/Coupons'); + $path = "{$directory}/{$name}.php"; + + if (file_exists($path)) { + $this->error("Coupon already exists: app/Cart/Coupons/{$name}.php"); + return self::FAILURE; + } + + if (! is_dir($directory)) { + mkdir($directory, 0755, true); + } + + file_put_contents($path, static::stub($name)); + $this->info("Coupon created: app/Cart/Coupons/{$name}.php"); + + return self::SUCCESS; + } + + public static function stub(string $className): string + { + return <<toContain('class TenPercentCoupon extends Coupon'); + }); + + test('stub uses the App\\Cart\\Coupons namespace', function () { + $stub = MakeCouponCommand::stub('TenPercentCoupon'); + expect($stub)->toContain('namespace App\\Cart\\Coupons'); + }); + + test('stub imports the Coupon base class', function () { + $stub = MakeCouponCommand::stub('TenPercentCoupon'); + expect($stub)->toContain('use Wearepixel\\Cart\\Coupons\\Coupon'); + }); + + test('stub declares isValid() method', function () { + $stub = MakeCouponCommand::stub('TenPercentCoupon'); + expect($stub)->toContain('public function isValid(): bool'); + }); + + test('stub uses strict_types', function () { + $stub = MakeCouponCommand::stub('TenPercentCoupon'); + expect($stub)->toContain('declare(strict_types=1)'); + }); +});