diff --git a/composer.json b/composer.json index 5a3a473..4341fe9 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "test": "vendor/bin/phpunit" }, "require": { - "payavel/orchestration": "^2.0" + "payavel/orchestration": "dev-master" }, "require-dev": { "orchestra/testbench": "^8.0|^9.0" diff --git a/database/factories/TransactionEventFactory.php b/database/factories/TransactionEventFactory.php index 55de0cf..a1f297e 100644 --- a/database/factories/TransactionEventFactory.php +++ b/database/factories/TransactionEventFactory.php @@ -8,7 +8,7 @@ use Payavel\Checkout\Models\Payment; use Payavel\Checkout\Models\Refund; use Payavel\Checkout\Models\TransactionEvent; -use Payavel\Orchestration\Support\ServiceConfig; +use Payavel\Orchestration\ServiceConfig; class TransactionEventFactory extends Factory { @@ -38,7 +38,7 @@ public function definition() */ public function configure() { - $this->model = ServiceConfig::get('checkout', 'models.' . $this->model, $this->model); + $this->model = ServiceConfig::find('checkout')->get('models.' . $this->model, $this->model); return $this->afterMaking(function (TransactionEvent $transactionEvent) { if (is_null($transactionEvent->payment_id)) { diff --git a/database/migrations/2024_01_01_000010_create_base_checkout_tables.php b/database/migrations/2024_01_01_000010_create_base_checkout_tables.php index f1b5088..adfbaa8 100644 --- a/database/migrations/2024_01_01_000010_create_base_checkout_tables.php +++ b/database/migrations/2024_01_01_000010_create_base_checkout_tables.php @@ -3,7 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -use Payavel\Orchestration\Support\ServiceConfig; +use Payavel\Orchestration\ServiceConfig; return new class () extends Migration { /** @@ -13,7 +13,7 @@ */ public function up() { - $usingDatabaseDriver = ServiceConfig::get('checkout', 'defaults.driver') === 'database'; + $usingDatabaseDriver = ServiceConfig::find('checkout')->get('defaults.driver') === 'database'; Schema::create('payment_types', function (Blueprint $table) { $table->string('id')->primary(); diff --git a/src/CheckoutGateway.php b/src/CheckoutGateway.php index 61d93d6..dcd166c 100644 --- a/src/CheckoutGateway.php +++ b/src/CheckoutGateway.php @@ -10,4 +10,24 @@ public function __construct() { parent::__construct('checkout'); } + + /** + * Get or set the service's config. + * + * @param string|array $key + * @param mixed $default + * @return mixed + */ + public function config($key, $default = null) + { + if (is_array($key)) { + foreach ($key as $key => $value) { + $this->config->set($key, $value); + } + + return; + } + + return $this->config->get($key, $default); + } } diff --git a/src/Facades/Checkout.php b/src/Facades/Checkout.php index cd134e4..ac2c890 100644 --- a/src/Facades/Checkout.php +++ b/src/Facades/Checkout.php @@ -6,6 +6,7 @@ use Payavel\Checkout\CheckoutGateway; /** + * @method static mixed config($key, $default) * @method static \Payavel\Checkout\CheckoutGateway provider($provider) * @method static \Payavel\Orchestration\Contracts\Providable getProvider() * @method static void setProvider($provider) @@ -13,8 +14,8 @@ * @method static \Payavel\Checkout\CheckoutGateway account($account) * @method static \Payavel\Orchestration\Contracts\Accountable getAccount() * @method static void setAccount($account, $strict = true) - * @method static void reset() * @method static string|int|\Payavel\Orchestration\Contracts\Accountable getDefaultAccount() + * @method static void reset() * @method static \Payavel\Checkout\CheckoutResponse getWallet(\Payavel\Checkout\Models\Wallet $wallet) * @method static \Payavel\Checkout\CheckoutResponse getPaymentInstrument(\Payavel\Checkout\Models\PaymentInstrument $paymentInstrument) * @method static \Payavel\Checkout\CheckoutResponse tokenizePaymentInstrument(\Payavel\Checkout\Contracts\Billable $billable, $data) diff --git a/src/Models/Dispute.php b/src/Models/Dispute.php index 1095c96..89a2d4f 100644 --- a/src/Models/Dispute.php +++ b/src/Models/Dispute.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\Support\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class Dispute extends Model @@ -52,7 +52,7 @@ protected static function getFactoryNamespace() */ public function payment() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . Payment::class, Payment::class)); + return $this->belongsTo(Checkout::config('models.' . Payment::class, Payment::class)); } /** @@ -62,6 +62,6 @@ public function payment() */ public function transactionEvents() { - return $this->morphMany(ServiceConfig::get('checkout', 'models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); + return $this->morphMany(Checkout::config('models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); } } diff --git a/src/Models/Payment.php b/src/Models/Payment.php index 4af5c60..66bf682 100644 --- a/src/Models/Payment.php +++ b/src/Models/Payment.php @@ -3,10 +3,10 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Contracts\Orchestrable; use Payavel\Orchestration\Models\Account; use Payavel\Orchestration\Models\Provider; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Traits\OrchestratesService; use Payavel\Orchestration\Traits\HasFactory; @@ -64,7 +64,7 @@ protected static function getFactoryNamespace() */ public function provider() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . Provider::class, Provider::class)); + return $this->belongsTo(Checkout::config('models.' . Provider::class, Provider::class)); } /** @@ -74,7 +74,7 @@ public function provider() */ public function account() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . Account::class, Account::class)); + return $this->belongsTo(Checkout::config('models.' . Account::class, Account::class)); } /** @@ -84,7 +84,7 @@ public function account() */ public function rail() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . PaymentRail::class, PaymentRail::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentRail::class, PaymentRail::class)); } /** @@ -94,7 +94,7 @@ public function rail() */ public function instrument() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . PaymentInstrument::class, PaymentInstrument::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentInstrument::class, PaymentInstrument::class)); } /** @@ -104,7 +104,7 @@ public function instrument() */ public function events() { - return $this->hasMany(ServiceConfig::get('checkout', 'models.' . TransactionEvent::class, TransactionEvent::class)); + return $this->hasMany(Checkout::config('models.' . TransactionEvent::class, TransactionEvent::class)); } /** @@ -114,7 +114,7 @@ public function events() */ public function transactionEvents() { - return $this->morphMany(ServiceConfig::get('checkout', 'models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); + return $this->morphMany(Checkout::config('models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); } /** diff --git a/src/Models/PaymentInstrument.php b/src/Models/PaymentInstrument.php index ed0bfd7..00e11b4 100644 --- a/src/Models/PaymentInstrument.php +++ b/src/Models/PaymentInstrument.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\Support\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class PaymentInstrument extends Model @@ -53,7 +53,7 @@ protected static function getFactoryNamespace() */ public function wallet() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . Wallet::class, Wallet::class)); + return $this->belongsTo(Checkout::config('models.' . Wallet::class, Wallet::class)); } /** @@ -63,7 +63,7 @@ public function wallet() */ public function type() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . PaymentType::class, PaymentType::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentType::class, PaymentType::class)); } /** @@ -73,7 +73,7 @@ public function type() */ public function payments() { - return $this->hasMany(ServiceConfig::get('checkout', 'models.' . Payment::class, Payment::class), 'instrument_id'); + return $this->hasMany(Checkout::config('models.' . Payment::class, Payment::class), 'instrument_id'); } /** diff --git a/src/Models/PaymentRail.php b/src/Models/PaymentRail.php index e5e3257..fd3ff2a 100644 --- a/src/Models/PaymentRail.php +++ b/src/Models/PaymentRail.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\Support\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class PaymentRail extends Model @@ -54,7 +54,7 @@ protected static function getFactoryNamespace() */ public function parentType() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . PaymentType::class, PaymentType::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentType::class, PaymentType::class)); } /** @@ -64,7 +64,7 @@ public function parentType() */ public function type() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . PaymentType::class, PaymentType::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentType::class, PaymentType::class)); } /** @@ -74,6 +74,6 @@ public function type() */ public function payments() { - return $this->hasMany(ServiceConfig::get('checkout', 'models.' . Payment::class, Payment::class), 'rail_id'); + return $this->hasMany(Checkout::config('models.' . Payment::class, Payment::class), 'rail_id'); } } diff --git a/src/Models/PaymentType.php b/src/Models/PaymentType.php index e242f50..3d388d4 100644 --- a/src/Models/PaymentType.php +++ b/src/Models/PaymentType.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\Support\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class PaymentType extends Model @@ -41,7 +41,7 @@ protected static function getFactoryNamespace() */ public function rails() { - return $this->hasMany(ServiceConfig::get('checkout', 'models.' . PaymentRail::class, PaymentRail::class), 'parent_type_id'); + return $this->hasMany(Checkout::config('models.' . PaymentRail::class, PaymentRail::class), 'parent_type_id'); } /** @@ -51,6 +51,6 @@ public function rails() */ public function instruments() { - return $this->hasMany(ServiceConfig::get('checkout', 'models.' . PaymentInstrument::class, PaymentInstrument::class), 'type_id'); + return $this->hasMany(Checkout::config('models.' . PaymentInstrument::class, PaymentInstrument::class), 'type_id'); } } diff --git a/src/Models/Refund.php b/src/Models/Refund.php index 69fe10f..0773ecb 100644 --- a/src/Models/Refund.php +++ b/src/Models/Refund.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\Support\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class Refund extends Model @@ -52,7 +52,7 @@ protected static function getFactoryNamespace() */ public function payment() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . Payment::class, Payment::class)); + return $this->belongsTo(Checkout::config('models.' . Payment::class, Payment::class)); } /** @@ -62,6 +62,6 @@ public function payment() */ public function transactionEvents() { - return $this->morphMany(ServiceConfig::get('checkout', 'models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); + return $this->morphMany(Checkout::config('models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); } } diff --git a/src/Models/TransactionEvent.php b/src/Models/TransactionEvent.php index ca93308..f9108ea 100644 --- a/src/Models/TransactionEvent.php +++ b/src/Models/TransactionEvent.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\Support\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class TransactionEvent extends Model @@ -52,7 +52,7 @@ protected static function getFactoryNamespace() */ public function payment() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . Payment::class, Payment::class)); + return $this->belongsTo(Checkout::config('models.' . Payment::class, Payment::class)); } /** diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 58b476d..b068386 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -3,11 +3,11 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Contracts\Orchestrable; use Payavel\Orchestration\Traits\OrchestratesService; use Payavel\Orchestration\Models\Account; use Payavel\Orchestration\Models\Provider; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Traits\HasFactory; class Wallet extends Model implements Orchestrable @@ -63,7 +63,7 @@ public function billable() */ public function provider() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . Provider::class, Provider::class)); + return $this->belongsTo(Checkout::config('models.' . Provider::class, Provider::class)); } /** @@ -73,7 +73,7 @@ public function provider() */ public function account() { - return $this->belongsTo(ServiceConfig::get('checkout', 'models.' . Account::class, Account::class)); + return $this->belongsTo(Checkout::config('models.' . Account::class, Account::class)); } /** @@ -83,7 +83,7 @@ public function account() */ public function paymentInstruments() { - return $this->hasMany(ServiceConfig::get('checkout', 'models.' . PaymentInstrument::class, PaymentInstrument::class)); + return $this->hasMany(Checkout::config('models.' . PaymentInstrument::class, PaymentInstrument::class)); } /** diff --git a/src/Traits/Billable.php b/src/Traits/Billable.php index bf60cb9..5737a9b 100644 --- a/src/Traits/Billable.php +++ b/src/Traits/Billable.php @@ -2,8 +2,8 @@ namespace Payavel\Checkout\Traits; +use Payavel\Checkout\Facades\Checkout; use Payavel\Checkout\Models\Wallet; -use Payavel\Orchestration\Support\ServiceConfig; trait Billable { @@ -14,6 +14,6 @@ trait Billable */ public function wallets() { - return $this->morphMany(ServiceConfig::get('checkout', 'models.' . Wallet::class, Wallet::class), 'billable'); + return $this->morphMany(Checkout::config('models.' . Wallet::class, Wallet::class), 'billable'); } } diff --git a/tests/Feature/Console/Commands/ConfigCheckoutProviderCommandTest.php b/tests/Feature/Console/Commands/ConfigCheckoutProviderCommandTest.php deleted file mode 100644 index d28d14b..0000000 --- a/tests/Feature/Console/Commands/ConfigCheckoutProviderCommandTest.php +++ /dev/null @@ -1,12 +0,0 @@ -createProvider($this->checkoutService); - $account = $this->createAccount($this->checkoutService); - - $checkoutServiceConfig = $this->configPath($this->checkoutService); - $checkoutServiceContract = $this->contractPath($this->checkoutService); - $fakeGateway = $this->gatewayPath($this->checkoutService); - $providerGateway = $this->gatewayPath($provider); - - $ds = DIRECTORY_SEPARATOR; - $this->artisan('checkout:install') - ->expectsQuestion("Choose a driver for the {$this->checkoutService->getName()} service.", Config::get('orchestration.defaults.driver')) - ->expectsQuestion("How should the {$this->checkoutService->getName()} provider be named?", $provider->getName()) - ->expectsQuestion("How should the {$this->checkoutService->getName()} provider be identified?", $provider->getId()) - ->expectsConfirmation("Would you like to add another {$this->checkoutService->getName()} provider?", 'no') - ->expectsQuestion("How should the {$this->checkoutService->getName()} account be named?", $account->getName()) - ->expectsQuestion("How should the {$this->checkoutService->getName()} account be identified?", $account->getId()) - ->expectsConfirmation("Would you like to add another {$this->checkoutService->getName()} account?", 'no') - ->expectsOutputToContain("Config [config{$ds}{$checkoutServiceConfig->orchestration}] created successfully.") - ->expectsOutputToContain("Config [config{$ds}{$checkoutServiceConfig->service}] created successfully.") - ->expectsOutputToContain("Contract [app{$ds}{$checkoutServiceContract->requester}] created successfully.") - ->expectsOutputToContain("Contract [app{$ds}{$checkoutServiceContract->responder}] created successfully.") - ->expectsOutputToContain("Gateway [app{$ds}{$fakeGateway->request}] created successfully.") - ->expectsOutputToContain("Gateway [app{$ds}{$fakeGateway->response}] created successfully.") - ->expectsOutputToContain("Gateway [app{$ds}{$providerGateway->request}] created successfully.") - ->expectsOutputToContain("Gateway [app{$ds}{$providerGateway->response}] created successfully.") - ->assertSuccessful(); - - $config = require(config_path($checkoutServiceConfig->service)); - - $this->assertContractExists($this->checkoutService); - $this->assertGatewayExists($this->checkoutService); - $this->assertGatewayExists($provider); - - $this->assertEquals($provider->getId(), $config['defaults']['provider']); - $this->assertEquals($account->getId(), $config['defaults']['account']); - - $this->makeSureProviderExists($provider); - $this->makeSureAccountExists($account); - $this->makeSureProviderIsLinkedToAccount($provider, $account); - - $this->assertTrue(unlink(config_path($checkoutServiceConfig->service))); - } - - protected function makeSureProviderExists(Providable $provider) - { - // - } - - protected function makeSureAccountExists(Accountable $account) - { - // - } - - protected function makeSureProviderIsLinkedToAccount(Providable $provider, Accountable $account) - { - // - } -} diff --git a/tests/Feature/Console/Commands/ConfigCheckoutInstallCommandTest.php b/tests/Feature/Console/Config/CheckoutInstallCommandTest.php similarity index 66% rename from tests/Feature/Console/Commands/ConfigCheckoutInstallCommandTest.php rename to tests/Feature/Console/Config/CheckoutInstallCommandTest.php index 78168a8..c652836 100644 --- a/tests/Feature/Console/Commands/ConfigCheckoutInstallCommandTest.php +++ b/tests/Feature/Console/Config/CheckoutInstallCommandTest.php @@ -1,33 +1,34 @@ checkoutService->getId()) . '.php')); + $config = require(config_path(Str::slug($this->checkoutConfig->id) . '.php')); $this->assertIsArray($config['providers']); $this->assertIsArray($config['providers'][$provider->getId()]); $this->assertEquals( - 'App\\Services\\' . Str::studly($this->checkoutService->getId()) . '\\' . Str::studly($provider->getId()) . Str::studly($this->checkoutService->getId()) . 'Request', + 'App\\Services\\' . Str::studly($this->checkoutConfig->id) . '\\' . Str::studly($provider->getId()) . Str::studly($this->checkoutConfig->id) . 'Request', $config['providers'][$provider->getId()]['gateway'] ); } protected function makeSureAccountExists(Accountable $account) { - $config = require(config_path(Str::slug($this->checkoutService->getId()) . '.php')); + $config = require(config_path(Str::slug($this->checkoutConfig->id) . '.php')); $this->assertIsArray($config['accounts']); $this->assertIsArray($config['accounts'][$account->getId()]); @@ -37,7 +38,7 @@ protected function makeSureAccountExists(Accountable $account) protected function makeSureProviderIsLinkedToAccount(Providable $provider, Accountable $account) { - $config = require(config_path(Str::slug($this->checkoutService->getId()) . '.php')); + $config = require(config_path(Str::slug($this->checkoutConfig->id) . '.php')); $this->assertIsArray($config['accounts'][$account->getId()]['providers'][$provider->getId()]); } diff --git a/tests/Feature/Console/Config/CheckoutProviderCommandTest.php b/tests/Feature/Console/Config/CheckoutProviderCommandTest.php new file mode 100644 index 0000000..fadf96c --- /dev/null +++ b/tests/Feature/Console/Config/CheckoutProviderCommandTest.php @@ -0,0 +1,13 @@ +assertNotNull($provider); $this->assertEquals( - 'App\\Services\\' . Str::studly($this->checkoutService->getId()) . '\\' . Str::studly($provider->getId()) . Str::studly($this->checkoutService->getId()) . 'Request', + 'App\\Services\\' . Str::studly($this->checkoutConfig->id) . '\\' . Str::studly($provider->getId()) . Str::studly($this->checkoutConfig->id) . 'Request', $provider->gateway ); } @@ -62,8 +63,8 @@ private function migrate() return; } - Account::where('service_id', $this->checkoutService->getId())->delete(); - Provider::where('service_id', $this->checkoutService->getId())->delete(); + Account::where('service_id', $this->checkoutConfig->id)->delete(); + Provider::where('service_id', $this->checkoutConfig->id)->delete(); $this->artisan('migrate'); diff --git a/tests/Feature/Console/Commands/DatabaseCheckoutProviderCommandTest.php b/tests/Feature/Console/Database/CheckoutProviderCommandTest.php similarity index 50% rename from tests/Feature/Console/Commands/DatabaseCheckoutProviderCommandTest.php rename to tests/Feature/Console/Database/CheckoutProviderCommandTest.php index db47475..bee3f18 100644 --- a/tests/Feature/Console/Commands/DatabaseCheckoutProviderCommandTest.php +++ b/tests/Feature/Console/Database/CheckoutProviderCommandTest.php @@ -1,11 +1,12 @@ createProvider($this->checkoutConfig); + $account = $this->createAccount($this->checkoutConfig); + + $configPath = $this->configPath($this->checkoutConfig); + $contractPath = $this->contractPath($this->checkoutConfig); + $fakeGatewayPath = $this->gatewayPath($this->checkoutConfig); + $providerGatewayPath = $this->gatewayPath($this->checkoutConfig, $provider); + + $ds = DIRECTORY_SEPARATOR; + $this->artisan('checkout:install') + ->expectsQuestion("Choose a driver for the {$this->checkoutConfig->name} service.", Config::get('orchestration.defaults.driver')) + ->expectsQuestion("How should the {$this->checkoutConfig->name} provider be named?", $provider->getName()) + ->expectsQuestion("How should the {$this->checkoutConfig->name} provider be identified?", $provider->getId()) + ->expectsConfirmation("Would you like to add another {$this->checkoutConfig->name} provider?", 'no') + ->expectsQuestion("How should the {$this->checkoutConfig->name} account be named?", $account->getName()) + ->expectsQuestion("How should the {$this->checkoutConfig->name} account be identified?", $account->getId()) + ->expectsConfirmation("Would you like to add another {$this->checkoutConfig->name} account?", 'no') + ->expectsOutputToContain("Config [config{$ds}{$configPath->orchestration}] created successfully.") + ->expectsOutputToContain("Config [config{$ds}{$configPath->service}] created successfully.") + ->expectsOutputToContain("Contract [app{$ds}{$contractPath->requester}] created successfully.") + ->expectsOutputToContain("Contract [app{$ds}{$contractPath->responder}] created successfully.") + ->expectsOutputToContain("Gateway [app{$ds}{$fakeGatewayPath->request}] created successfully.") + ->expectsOutputToContain("Gateway [app{$ds}{$fakeGatewayPath->response}] created successfully.") + ->expectsOutputToContain("Gateway [app{$ds}{$providerGatewayPath->request}] created successfully.") + ->expectsOutputToContain("Gateway [app{$ds}{$providerGatewayPath->response}] created successfully.") + ->assertSuccessful(); + + $serviceConfig = require(config_path($configPath->service)); + + $this->assertContractExists($this->checkoutConfig); + $this->assertGatewayExists($this->checkoutConfig); + $this->assertGatewayExists($this->checkoutConfig, $provider); + + $this->assertEquals($provider->getId(), $serviceConfig['defaults']['provider']); + $this->assertEquals($account->getId(), $serviceConfig['defaults']['account']); + + $this->makeSureProviderExists($provider); + $this->makeSureAccountExists($account); + $this->makeSureProviderIsLinkedToAccount($provider, $account); + + $this->assertTrue(unlink(config_path($configPath->service))); + } + + protected function makeSureProviderExists(Providable $provider) + { + // + } + + protected function makeSureAccountExists(Accountable $account) + { + // + } + + protected function makeSureProviderIsLinkedToAccount(Providable $provider, Accountable $account) + { + // + } +} diff --git a/tests/Feature/Console/Commands/TestCheckoutProviderCommand.php b/tests/Feature/Console/TestCheckoutProviderCommand.php similarity index 58% rename from tests/Feature/Console/Commands/TestCheckoutProviderCommand.php rename to tests/Feature/Console/TestCheckoutProviderCommand.php index 8d03c26..d2f0473 100644 --- a/tests/Feature/Console/Commands/TestCheckoutProviderCommand.php +++ b/tests/Feature/Console/TestCheckoutProviderCommand.php @@ -1,6 +1,6 @@ createProvider($this->checkoutService); + $provider = $this->createProvider($this->checkoutConfig); - $gateway = $this->gatewayPath($provider); + $providerGatewayPath = $this->gatewayPath($this->checkoutConfig, $provider); $ds = DIRECTORY_SEPARATOR; $this->artisan('checkout:provider', [ 'provider' => $provider->getName(), '--id' => $provider->getId(), ]) - ->expectsOutputToContain("Gateway [app{$ds}{$gateway->request}] created successfully.") - ->expectsOutputToContain("Gateway [app{$ds}{$gateway->response}] created successfully.") + ->expectsOutputToContain("Gateway [app{$ds}{$providerGatewayPath->request}] created successfully.") + ->expectsOutputToContain("Gateway [app{$ds}{$providerGatewayPath->response}] created successfully.") ->assertSuccessful(); - $this->assertGatewayExists($provider); + $this->assertGatewayExists($this->checkoutConfig, $provider); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 7ff13c2..2f7b849 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,7 +5,7 @@ use Payavel\Checkout\Contracts\Billable; use Payavel\Checkout\CheckoutServiceProvider; use Payavel\Checkout\Traits\Billable as BillableTrait; -use Payavel\Orchestration\Contracts\Serviceable; +use Payavel\Orchestration\ServiceConfig; use Payavel\Orchestration\OrchestrationServiceProvider; use Payavel\Orchestration\Tests\Traits\CreatesServices; @@ -13,7 +13,7 @@ class TestCase extends \Payavel\Orchestration\Tests\TestCase { use CreatesServices; - protected Serviceable $checkoutService; + protected ServiceConfig $checkoutConfig; protected function getPackageProviders($app) { @@ -30,6 +30,7 @@ protected function getEnvironmentSetUp($app) 'driver' => 'sqlite', 'database' => ':memory:', ]); + $app['config']->set('orchestration.services.checkout', 'checkout'); } /** @@ -41,7 +42,7 @@ protected function setUp(): void { parent::setUp(); - $this->checkoutService = $this->createService([ + $this->checkoutConfig = $this->createServiceConfig([ 'name' => 'Checkout', 'id' => 'checkout', ]); diff --git a/tests/Unit/CheckoutConfigTest.php b/tests/Unit/CheckoutConfigTest.php new file mode 100644 index 0000000..67d41d4 --- /dev/null +++ b/tests/Unit/CheckoutConfigTest.php @@ -0,0 +1,43 @@ +assertTrue(Checkout::config('test', false)); + } + + #[Test] + public function set_checkout_config_via_facade() + { + Checkout::config([ + 'test' => [ + 'one' => true, + 'two' => true, + ] + ]); + + $this->assertIsArray(Config::get('checkout.test')); + $this->assertCount(2, Config::get('checkout.test')); + $this->assertTrue(Config::get('checkout.test.one', false)); + + Checkout::config([ + 'test.one' => false, + 'test.three' => true, + ]); + + $this->assertCount(3, Config::get('checkout.test')); + $this->assertFalse(Config::get('checkout.test.one', true)); + $this->assertArrayHasKey('three', Config::get('checkout.test', [])); + } +} diff --git a/tests/Unit/Database/PaymentModelTest.php b/tests/Unit/Database/PaymentModelTest.php index 9b4bbe1..5917423 100644 --- a/tests/Unit/Database/PaymentModelTest.php +++ b/tests/Unit/Database/PaymentModelTest.php @@ -8,7 +8,6 @@ use Payavel\Checkout\Tests\Unit\TestPaymentModel; use Payavel\Orchestration\Models\Account; use Payavel\Orchestration\Models\Provider; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Traits\CreatesDatabaseServiceables; use Payavel\Orchestration\Tests\Traits\SetsDatabaseDriver; use PHPUnit\Framework\Attributes\Test; @@ -22,14 +21,14 @@ class PaymentModelTest extends TestPaymentModel public function retrieve_payment_provider() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $paymentWithProvider = Payment::factory()->create($usingServiceables); $this->assertInstanceOf(Provider::class, $paymentWithProvider->provider); - ServiceConfig::set('checkout', 'models.' . Provider::class, TestProvider::class); + $this->checkoutConfig->set('models.' . Provider::class, TestProvider::class); $paymentWithOverriddenProvider = Payment::factory()->create($usingServiceables); $this->assertInstanceOf(TestProvider::class, $paymentWithOverriddenProvider->provider); } @@ -38,14 +37,14 @@ public function retrieve_payment_provider() public function retrieve_payment_account() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $paymentWithAccount = Payment::factory()->create($usingServiceables); $this->assertInstanceOf(Account::class, $paymentWithAccount->account); - ServiceConfig::set('checkout', 'models.' . Account::class, TestAccount::class); + $this->checkoutConfig->set('models.' . Account::class, TestAccount::class); $paymentWithOverriddenAccount = Payment::factory()->create($usingServiceables); $this->assertInstanceOf(TestAccount::class, $paymentWithOverriddenAccount->account); } diff --git a/tests/Unit/Database/WalletModelTest.php b/tests/Unit/Database/WalletModelTest.php index 4222810..8733309 100644 --- a/tests/Unit/Database/WalletModelTest.php +++ b/tests/Unit/Database/WalletModelTest.php @@ -8,7 +8,6 @@ use Payavel\Checkout\Tests\Unit\TestWalletModel; use Payavel\Orchestration\Models\Account; use Payavel\Orchestration\Models\Provider; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Traits\CreatesDatabaseServiceables; use Payavel\Orchestration\Tests\Traits\SetsDatabaseDriver; use PHPUnit\Framework\Attributes\Test; @@ -22,14 +21,14 @@ class WalletModelTest extends TestWalletModel public function retrieve_wallet_provider() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $walletWithProvider = Wallet::factory()->create($usingServiceables); $this->assertInstanceOf(Provider::class, $walletWithProvider->provider); - ServiceConfig::set('checkout', 'models.' . Provider::class, TestProvider::class); + $this->checkoutConfig->set('models.' . Provider::class, TestProvider::class); $walletWithOverriddenProvider = Wallet::factory()->create($usingServiceables); $this->assertInstanceOF(TestProvider::class, $walletWithOverriddenProvider->provider); } @@ -38,14 +37,14 @@ public function retrieve_wallet_provider() public function retrieve_wallet_account() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $walletWithAccount = Wallet::factory()->create($usingServiceables); $this->assertInstanceOf(Account::class, $walletWithAccount->account); - ServiceConfig::set('checkout', 'models.' . Account::class, TestAccount::class); + $this->checkoutConfig->set('models.' . Account::class, TestAccount::class); $walletWithOverriddenAccount = Wallet::factory()->create($usingServiceables); $this->assertInstanceOF(TestAccount::class, $walletWithOverriddenAccount->account); } diff --git a/tests/Unit/TestBillableTrait.php b/tests/Unit/TestBillableTrait.php index 2f6ded0..3a38854 100644 --- a/tests/Unit/TestBillableTrait.php +++ b/tests/Unit/TestBillableTrait.php @@ -6,7 +6,6 @@ use Payavel\Checkout\Tests\Models\TestWallet; use Payavel\Checkout\Tests\TestCase; use Payavel\Checkout\Tests\User; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test; @@ -19,16 +18,16 @@ public function retrieve_billable_wallets() $this->assertEmpty($billable->wallets); $billableWith2Wallets = User::factory()->has(Wallet::factory()->count(2)->sequence(fn () => [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]))->create(); $this->assertCount(2, $billableWith2Wallets->wallets); $this->assertContainsOnlyInstancesOf(Wallet::class, $billableWith2Wallets->wallets); - ServiceConfig::set('checkout', 'models.'.Wallet::class, TestWallet::class); + $this->checkoutConfig->set('models.'.Wallet::class, TestWallet::class); $billableWith3OverriddenWallets = User::factory()->has(Wallet::factory()->count(3)->sequence(fn () => [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]))->create(); $this->assertCount(3, $billableWith3OverriddenWallets->wallets); $this->assertContainsOnlyInstancesOf(TestWallet::class, $billableWith3OverriddenWallets->wallets); diff --git a/tests/Unit/TestCheckoutGateway.php b/tests/Unit/TestCheckoutGateway.php index 42d8018..4ae41e8 100644 --- a/tests/Unit/TestCheckoutGateway.php +++ b/tests/Unit/TestCheckoutGateway.php @@ -26,15 +26,15 @@ protected function setUp(): void { parent::setUp(); - $provider = $this->createProvider($this->checkoutService, [ + $provider = $this->createProvider($this->checkoutConfig, [ 'gateway' => TestCheckoutRequest::class, ]); - $account = $this->createAccount($this->checkoutService); + $account = $this->createAccount($this->checkoutConfig); $this->linkAccountToProvider($account, $provider); - $this->setDefaultsForService($this->checkoutService, $account, $provider); + $this->setDefaultsForService($this->checkoutConfig, $account, $provider); } #[Test] diff --git a/tests/Unit/TestDisputeModel.php b/tests/Unit/TestDisputeModel.php index a9f3d63..d5cbfd7 100644 --- a/tests/Unit/TestDisputeModel.php +++ b/tests/Unit/TestDisputeModel.php @@ -8,7 +8,6 @@ use Payavel\Checkout\Tests\Models\TestPayment; use Payavel\Checkout\Tests\Models\TestTransactionEvent; use Payavel\Checkout\Tests\TestCase; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test; @@ -18,14 +17,14 @@ abstract class TestDisputeModel extends TestCase implements CreatesServiceables public function retrieve_dispute_payment() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getID(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $disputeWithPayment = Dispute::factory()->for(Payment::factory()->create($usingServiceables))->create(); $this->assertInstanceOf(Payment::class, $disputeWithPayment->payment); - ServiceConfig::set('checkout', 'models.' . Payment::class, TestPayment::class); + $this->checkoutConfig->set('models.' . Payment::class, TestPayment::class); $disputeWithOverriddenPayment = Dispute::factory()->for(Payment::factory()->create($usingServiceables))->create(); $this->assertInstanceOf(TestPayment::class, $disputeWithOverriddenPayment->payment); } @@ -34,8 +33,8 @@ public function retrieve_dispute_payment() public function retrieve_dispute_transaction_events() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getID(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getID(), ]; $dispute = Dispute::factory()->for(Payment::factory()->create($usingServiceables))->create(); @@ -45,7 +44,7 @@ public function retrieve_dispute_transaction_events() $this->assertCount(2, $disputeWith2TransactionEvents->transactionEvents); $this->assertContainsOnlyInstancesOf(TransactionEvent::class, $disputeWith2TransactionEvents->transactionEvents); - ServiceConfig::set('checkout', 'models.' . TransactionEvent::class, TestTransactionEvent::class); + $this->checkoutConfig->set('models.' . TransactionEvent::class, TestTransactionEvent::class); $disputeWith3OverriddenTransactionEvents = Dispute::factory()->for($paymentForDisputeWith3TransactionEvents = Payment::factory()->create($usingServiceables))->hasTransactionEvents(3, ['payment_id' => $paymentForDisputeWith3TransactionEvents->id])->create(); $this->assertCount(3, $disputeWith3OverriddenTransactionEvents->transactionEvents); $this->assertContainsOnlyInstancesOf(TestTransactionEvent::class, $disputeWith3OverriddenTransactionEvents->transactionEvents); diff --git a/tests/Unit/TestPaymentInstrumentModel.php b/tests/Unit/TestPaymentInstrumentModel.php index 6542803..f0e85a2 100644 --- a/tests/Unit/TestPaymentInstrumentModel.php +++ b/tests/Unit/TestPaymentInstrumentModel.php @@ -10,7 +10,6 @@ use Payavel\Checkout\Tests\Models\TestPaymentType; use Payavel\Checkout\Tests\Models\TestWallet; use Payavel\Checkout\Tests\TestCase; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test; @@ -20,14 +19,14 @@ abstract class TestPaymentInstrumentModel extends TestCase implements CreatesSer public function retrieve_payment_instrument_wallet() { $wallet = Wallet::factory()->create([ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]); $paymentInstrumentWithWallet = PaymentInstrument::factory()->for($wallet)->create(); $this->assertInstanceOf(Wallet::class, $paymentInstrumentWithWallet->wallet); - ServiceConfig::set('checkout', 'models.' . Wallet::class, TestWallet::class); + $this->checkoutConfig->set('models.' . Wallet::class, TestWallet::class); $paymentInstrumentWithOverriddenWallet = PaymentInstrument::factory()->for($wallet)->create(); $this->assertInstanceOf(TestWallet::class, $paymentInstrumentWithOverriddenWallet->wallet); } @@ -36,14 +35,14 @@ public function retrieve_payment_instrument_wallet() public function retrieve_payment_instrument_type() { $wallet = Wallet::factory()->create([ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]); $paymentInstrumentWithType = PaymentInstrument::factory()->for($wallet)->create(); $this->assertInstanceOf(PaymentType::class, $paymentInstrumentWithType->type); - ServiceConfig::set('checkout', 'models.' . PaymentType::class, TestPaymentType::class); + $this->checkoutConfig->set('models.' . PaymentType::class, TestPaymentType::class); $paymentInstrumentWithOverriddenType = PaymentInstrument::factory()->for($wallet)->create(); $this->assertInstanceOf(TestPaymentType::class, $paymentInstrumentWithOverriddenType->type); } @@ -52,8 +51,8 @@ public function retrieve_payment_instrument_type() public function retrieve_payment_instrument_payments() { $wallet = Wallet::factory()->create([ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]); $paymentInstrument = PaymentInstrument::factory()->for($wallet)->create(); @@ -63,7 +62,7 @@ public function retrieve_payment_instrument_payments() $this->assertCount(2, $paymentInstrumentWith2Payments->payments); $this->assertContainsOnlyInstancesOf(Payment::class, $paymentInstrumentWith2Payments->payments); - ServiceConfig::set('checkout', 'models.' . Payment::class, TestPayment::class); + $this->checkoutConfig->set('models.' . Payment::class, TestPayment::class); $paymentInstrumentWith3OverriddenPayments = PaymentInstrument::factory()->for($wallet)->hasPayments(3)->create(); $this->assertCount(3, $paymentInstrumentWith3OverriddenPayments->payments); $this->assertContainsOnlyInstancesOf(TestPayment::class, $paymentInstrumentWith3OverriddenPayments->payments); diff --git a/tests/Unit/TestPaymentModel.php b/tests/Unit/TestPaymentModel.php index 32edda0..b43d28a 100644 --- a/tests/Unit/TestPaymentModel.php +++ b/tests/Unit/TestPaymentModel.php @@ -14,7 +14,6 @@ use Payavel\Checkout\Tests\TestCase; use Payavel\Orchestration\Contracts\Accountable; use Payavel\Orchestration\Contracts\Providable; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test; @@ -24,14 +23,14 @@ abstract class TestPaymentModel extends TestCase implements CreatesServiceables public function retrieve_payment_rail() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $paymentWithRail = Payment::factory()->create($usingServiceables); $this->assertInstanceOf(PaymentRail::class, $paymentWithRail->rail); - ServiceConfig::set('checkout', 'models.' . PaymentRail::class, TestPaymentRail::class); + $this->checkoutConfig->set('models.' . PaymentRail::class, TestPaymentRail::class); $paymentWithOverriddenRail = Payment::factory()->create($usingServiceables); $this->assertInstanceOf(TestPaymentRail::class, $paymentWithOverriddenRail->rail); } @@ -40,8 +39,8 @@ public function retrieve_payment_rail() public function retrieve_payment_instrument() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $payment = Payment::factory()->create($usingServiceables); @@ -50,7 +49,7 @@ public function retrieve_payment_instrument() $paymentWithInstrument = Payment::factory()->for(PaymentInstrument::factory()->for(Wallet::factory()->create($usingServiceables))->create(), 'instrument')->create($usingServiceables); $this->assertInstanceOf(PaymentInstrument::class, $paymentWithInstrument->instrument); - ServiceConfig::set('checkout', 'models.' . PaymentInstrument::class, TestPaymentInstrument::class); + $this->checkoutConfig->set('models.' . PaymentInstrument::class, TestPaymentInstrument::class); $paymentWithOverriddenInstrument = Payment::factory()->for(PaymentInstrument::factory()->for(Wallet::factory()->create($usingServiceables))->create(), 'instrument')->create($usingServiceables); $this->assertInstanceOf(TestPaymentInstrument::class, $paymentWithOverriddenInstrument->instrument); } @@ -59,8 +58,8 @@ public function retrieve_payment_instrument() public function retrieve_payment_events() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $payment = Payment::factory()->create($usingServiceables); @@ -70,7 +69,7 @@ public function retrieve_payment_events() $this->assertCount(2, $paymentWith2Events->events); $this->assertContainsOnlyInstancesOf(TransactionEvent::class, $paymentWith2Events->events); - ServiceConfig::set('checkout', 'models.' . TransactionEvent::class, TestTransactionEvent::class); + $this->checkoutConfig->set('models.' . TransactionEvent::class, TestTransactionEvent::class); $paymentWith3OverriddenEvents = Payment::factory()->hasEvents(3, ['status_code' => CheckoutStatus::AUTHORIZED])->create($usingServiceables); $this->assertCount(3, $paymentWith3OverriddenEvents->events); $this->assertContainsOnlyInstancesOf(TestTransactionEvent::class, $paymentWith3OverriddenEvents->events); @@ -80,8 +79,8 @@ public function retrieve_payment_events() public function retrieve_payment_transaction_events() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $payment = Payment::factory()->create($usingServiceables); @@ -91,7 +90,7 @@ public function retrieve_payment_transaction_events() $this->assertCount(2, $paymentWith2TransactionEvents->transactionEvents); $this->assertContainsOnlyInstancesOf(TransactionEvent::class, $paymentWith2TransactionEvents->transactionEvents); - ServiceConfig::set('checkout', 'models.' . TransactionEvent::class, TestTransactionEvent::class); + $this->checkoutConfig->set('models.' . TransactionEvent::class, TestTransactionEvent::class); $paymentWith3OverriddenTransactionEvents = Payment::factory()->hasTransactionEvents(3)->create($usingServiceables); $this->assertCount(3, $paymentWith3OverriddenTransactionEvents->transactionEvents); $this->assertContainsOnlyInstancesOf(TestTransactionEvent::class, $paymentWith3OverriddenTransactionEvents->transactionEvents); @@ -101,8 +100,8 @@ public function retrieve_payment_transaction_events() public function retrieve_payment_providable() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $payment = Payment::factory()->create($usingServiceables); @@ -113,8 +112,8 @@ public function retrieve_payment_providable() public function retrieve_payment_accountable() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $payment = Payment::factory()->create($usingServiceables); diff --git a/tests/Unit/TestPaymentRailModel.php b/tests/Unit/TestPaymentRailModel.php index fea7ddf..193f7b5 100644 --- a/tests/Unit/TestPaymentRailModel.php +++ b/tests/Unit/TestPaymentRailModel.php @@ -8,7 +8,6 @@ use Payavel\Checkout\Tests\Models\TestPayment; use Payavel\Checkout\Tests\Models\TestPaymentType; use Payavel\Checkout\Tests\TestCase; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test; @@ -47,7 +46,7 @@ public function retrieve_payment_rail_parent_type() $paymentRail = PaymentRail::factory()->create(); $this->assertInstanceOf(PaymentType::class, $paymentRail->parentType); - ServiceConfig::set('checkout', 'models.' . PaymentType::class, TestPaymentType::class); + $this->checkoutConfig->set('models.' . PaymentType::class, TestPaymentType::class); $paymentRailWithOverriddenParentType = PaymentRail::factory()->create(); $this->assertInstanceOf(TestPaymentType::class, $paymentRailWithOverriddenParentType->parentType); } @@ -58,7 +57,7 @@ public function retrieve_payment_rail_type() $paymentRail = PaymentRail::factory()->create(); $this->assertInstanceOf(PaymentType::class, $paymentRail->type); - ServiceConfig::set('checkout', 'models.' . PaymentType::class, TestPaymentType::class); + $this->checkoutConfig->set('models.' . PaymentType::class, TestPaymentType::class); $paymentRailWithOverriddenType = PaymentRail::factory()->create(); $this->assertInstanceOf(TestPaymentType::class, $paymentRailWithOverriddenType->type); } @@ -67,8 +66,8 @@ public function retrieve_payment_rail_type() public function retrieve_payment_rail_payments() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $paymentRail = PaymentRail::factory()->create(); @@ -78,7 +77,7 @@ public function retrieve_payment_rail_payments() $this->assertCount(2, $paymentRailWith2Payments->payments); $this->assertContainsOnlyInstancesOf(Payment::class, $paymentRailWith2Payments->payments); - ServiceConfig::set('checkout', 'models.' . Payment::class, TestPayment::class); + $this->checkoutConfig->set('models.' . Payment::class, TestPayment::class); $paymentRailWith3OverriddenPayments = PaymentRail::factory()->hasPayments(3, $usingServiceables)->create(); $this->assertCount(3, $paymentRailWith3OverriddenPayments->payments); $this->assertContainsOnlyInstancesOf(TestPayment::class, $paymentRailWith3OverriddenPayments->payments); diff --git a/tests/Unit/TestPaymentTypeModel.php b/tests/Unit/TestPaymentTypeModel.php index ad77667..6407744 100644 --- a/tests/Unit/TestPaymentTypeModel.php +++ b/tests/Unit/TestPaymentTypeModel.php @@ -9,7 +9,6 @@ use Payavel\Checkout\Tests\Models\TestPaymentInstrument; use Payavel\Checkout\Tests\Models\TestPaymentRail; use Payavel\Checkout\Tests\TestCase; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test; @@ -25,7 +24,7 @@ public function retrieve_payment_type_rails() $this->assertCount(2, $paymentTypeWith2Rails->rails); $this->assertContainsOnlyInstancesOf(PaymentRail::class, $paymentTypeWith2Rails->rails); - ServiceConfig::set('checkout', 'models.' . PaymentRail::class, TestPaymentRail::class); + $this->checkoutConfig->set('models.' . PaymentRail::class, TestPaymentRail::class); $paymentTypeWith3OverriddenRails = PaymentType::factory()->hasRails(3)->create(); $this->assertCount(3, $paymentTypeWith3OverriddenRails->rails); $this->assertContainsOnlyInstancesOf(TestPaymentRail::class, $paymentTypeWith3OverriddenRails->rails); @@ -35,8 +34,8 @@ public function retrieve_payment_type_rails() public function retrieve_payment_type_instruments() { $wallet = Wallet::factory()->create([ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]); $paymentType = PaymentType::factory()->create(); @@ -46,7 +45,7 @@ public function retrieve_payment_type_instruments() $this->assertCount(2, $paymentTypeWith2Instruments->instruments); $this->assertContainsOnlyInstancesOf(PaymentInstrument::class, $paymentTypeWith2Instruments->instruments); - ServiceConfig::set('checkout', 'models.' . PaymentInstrument::class, TestPaymentInstrument::class); + $this->checkoutConfig->set('models.' . PaymentInstrument::class, TestPaymentInstrument::class); $paymentTypeWith3OverriddenInstruments = PaymentType::factory()->has(PaymentInstrument::factory()->count(3)->for($wallet), 'instruments')->create(); $this->assertCount(3, $paymentTypeWith3OverriddenInstruments->instruments); $this->assertContainsOnlyInstancesOf(TestPaymentInstrument::class, $paymentTypeWith3OverriddenInstruments->instruments); diff --git a/tests/Unit/TestRefundModel.php b/tests/Unit/TestRefundModel.php index 1aa1910..ed84faa 100644 --- a/tests/Unit/TestRefundModel.php +++ b/tests/Unit/TestRefundModel.php @@ -8,7 +8,6 @@ use Payavel\Checkout\Tests\Models\TestPayment; use Payavel\Checkout\Tests\Models\TestTransactionEvent; use Payavel\Checkout\Tests\TestCase; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test; @@ -18,14 +17,14 @@ abstract class TestRefundModel extends TestCase implements CreatesServiceables public function retrieve_refund_payment() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $refundWithPayment = Refund::factory()->for(Payment::factory()->create($usingServiceables))->create(); $this->assertInstanceOf(Payment::class, $refundWithPayment->payment); - ServiceConfig::set('checkout', 'models.' . Payment::class, TestPayment::class); + $this->checkoutConfig->set('models.' . Payment::class, TestPayment::class); $refundWithOverriddenPayment = Refund::factory()->for(Payment::factory()->create($usingServiceables))->create(); $this->assertInstanceOf(TestPayment::class, $refundWithOverriddenPayment->payment); } @@ -34,8 +33,8 @@ public function retrieve_refund_payment() public function retrieve_refund_transaction_events() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $refund = Refund::factory()->for(Payment::factory()->create($usingServiceables))->create(); @@ -45,7 +44,7 @@ public function retrieve_refund_transaction_events() $this->assertCount(2, $refundWith2TransactionEvents->transactionEvents); $this->assertContainsOnlyInstancesOf(TransactionEvent::class, $refundWith2TransactionEvents->transactionEvents); - ServiceConfig::set('checkout', 'models.' . TransactionEvent::class, TestTransactionEvent::class); + $this->checkoutConfig->set('models.' . TransactionEvent::class, TestTransactionEvent::class); $refundWith3OverriddenTransactionEvents = Refund::factory()->for($paymentForRefundWith3TransactionEvents = Payment::factory()->create($usingServiceables))->hasTransactionEvents(3, ['payment_id' => $paymentForRefundWith3TransactionEvents->id])->create(); $this->assertCount(3, $refundWith3OverriddenTransactionEvents->transactionEvents); $this->assertContainsOnlyInstancesOf(TestTransactionEvent::class, $refundWith3OverriddenTransactionEvents->transactionEvents); diff --git a/tests/Unit/TestTransactionEventModel.php b/tests/Unit/TestTransactionEventModel.php index 1f0f215..6d4306d 100644 --- a/tests/Unit/TestTransactionEventModel.php +++ b/tests/Unit/TestTransactionEventModel.php @@ -10,7 +10,6 @@ use Payavel\Checkout\Tests\Models\TestDispute; use Payavel\Checkout\Tests\Models\TestPayment; use Payavel\Checkout\Tests\TestCase; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test; @@ -20,14 +19,14 @@ abstract class TestTransactionEventModel extends TestCase implements CreatesServ public function retrieve_transaction_event_payment() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $transactionEventWithPayment = TransactionEvent::factory()->for(Payment::factory()->create($usingServiceables))->create(['status_code' => CheckoutStatus::AUTHORIZED]); $this->assertInstanceOf(Payment::class, $transactionEventWithPayment->payment); - ServiceConfig::set('checkout', 'models.' . Payment::class, TestPayment::class); + $this->checkoutConfig->set('models.' . Payment::class, TestPayment::class); $transactionEventWithOverriddenPayment = TransactionEvent::factory()->for(Payment::factory()->create($usingServiceables))->create(['status_code' => CheckoutStatus::AUTHORIZED]); $this->assertInstanceOf(TestPayment::class, $transactionEventWithOverriddenPayment->payment); } @@ -36,8 +35,8 @@ public function retrieve_transaction_event_payment() public function retrieve_transaction_event_transactionable() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $transactionEvent = TransactionEvent::factory()->for(Payment::factory()->create($usingServiceables))->create(['status_code' => CheckoutStatus::AUTHORIZED]); @@ -46,7 +45,7 @@ public function retrieve_transaction_event_transactionable() $transactionEventWithTransactionable = TransactionEvent::factory()->for($paymentForTransactionEventWithTransactionable = Payment::factory()->create($usingServiceables))->for(Refund::factory()->for($paymentForTransactionEventWithTransactionable)->create(), 'transactionable')->create(['status_code' => CheckoutStatus::AUTHORIZED]); $this->assertInstanceOf(Refund::class, $transactionEventWithTransactionable->transactionable); - ServiceConfig::set('checkout', 'models.' . Dispute::class, TestDispute::class); + $this->checkoutConfig->set('models.' . Dispute::class, TestDispute::class); $transactionEventWithOverriddenTransactionable = TransactionEvent::factory()->for($paymentForTransactionEventWithOverriddenTransactionable = Payment::factory()->create($usingServiceables))->create(['status_code' => CheckoutStatus::AUTHORIZED]); $transactionEventWithOverriddenTransactionable->transactionable()->associate(transform(Dispute::factory()->for($paymentForTransactionEventWithOverriddenTransactionable)->create(), fn ($dispute) => TestDispute::find($dispute->id))); $this->assertInstanceOf(TestDispute::class, $transactionEventWithOverriddenTransactionable->transactionable); diff --git a/tests/Unit/TestWalletModel.php b/tests/Unit/TestWalletModel.php index 99d2828..70deeb8 100644 --- a/tests/Unit/TestWalletModel.php +++ b/tests/Unit/TestWalletModel.php @@ -5,16 +5,11 @@ use Payavel\Checkout\Contracts\Billable; use Payavel\Checkout\Models\PaymentInstrument; use Payavel\Checkout\Models\Wallet; -use Payavel\Checkout\Tests\Models\TestAccount; use Payavel\Checkout\Tests\Models\TestPaymentInstrument; -use Payavel\Checkout\Tests\Models\TestProvider; use Payavel\Checkout\Tests\TestCase; use Payavel\Checkout\Tests\User; use Payavel\Orchestration\Contracts\Accountable; use Payavel\Orchestration\Contracts\Providable; -use Payavel\Orchestration\Models\Account; -use Payavel\Orchestration\Models\Provider; -use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test; @@ -24,8 +19,8 @@ abstract class TestWalletModel extends TestCase implements CreatesServiceables public function retrieve_wallet_billable() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $wallet = Wallet::factory()->create($usingServiceables); @@ -40,8 +35,8 @@ public function retrieve_wallet_billable() public function retrieve_wallet_payment_instruments() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $wallet = Wallet::factory()->create($usingServiceables); @@ -51,7 +46,7 @@ public function retrieve_wallet_payment_instruments() $this->assertCount(2, $walletWith2PaymentInstruments->paymentInstruments); $this->assertContainsOnlyInstancesOf(PaymentInstrument::class, $walletWith2PaymentInstruments->paymentInstruments); - ServiceConfig::set('checkout', 'models.' . PaymentInstrument::class, TestPaymentInstrument::class); + $this->checkoutConfig->set('models.' . PaymentInstrument::class, TestPaymentInstrument::class); $walletWith3OverriddenPaymentInstruments = Wallet::factory()->hasPaymentInstruments(3)->create($usingServiceables); $this->assertCount(3, $walletWith3OverriddenPaymentInstruments->paymentInstruments); $this->assertContainsOnlyInstancesOf(TestPaymentInstrument::class, $walletWith3OverriddenPaymentInstruments->paymentInstruments); @@ -61,8 +56,8 @@ public function retrieve_wallet_payment_instruments() public function retrieve_wallet_providable() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $wallet = Wallet::factory()->create($usingServiceables); @@ -73,8 +68,8 @@ public function retrieve_wallet_providable() public function retrieve_wallet_accountable() { $usingServiceables = [ - 'provider_id' => $this->createProvider($this->checkoutService)->getId(), - 'account_id' => $this->createAccount($this->checkoutService)->getId(), + 'provider_id' => $this->createProvider($this->checkoutConfig)->getId(), + 'account_id' => $this->createAccount($this->checkoutConfig)->getId(), ]; $wallet = Wallet::factory()->create($usingServiceables);