Skip to content

Commit

Permalink
Refactor checkout:provider command test
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Apr 14, 2024
1 parent 543bcea commit 41ebf1a
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace Payavel\Checkout\Console\Commands;

use Payavel\Orchestration\Console\Commands\Install as Command;
use Illuminate\Support\Facades\Artisan;
use Payavel\Orchestration\Console\Commands\OrchestrateService as Command;

class Install extends Command
class CheckoutInstall extends Command
{
/**
* The name and signature of the console command.
Expand Down
6 changes: 3 additions & 3 deletions src/PaymentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
use Payavel\Checkout\Console\Commands\Install;
use Payavel\Checkout\Console\Commands\CheckoutInstall;
use Payavel\Checkout\Console\Commands\MakeProvider;
use Payavel\Orchestration\Service;

Expand All @@ -26,7 +26,7 @@ public function boot()
public function register()
{
$this->app->singleton(PaymentGateway::class, function ($app) {
return new PaymentGateway;
return new PaymentGateway();
});

$this->mergeConfigFrom(
Expand All @@ -50,7 +50,7 @@ protected function registerCommands()
{
$this->commands([
MakeProvider::class,
Install::class,
CheckoutInstall::class,
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Payavel\Checkout\Tests\Feature\Console\Commands;

use Payavel\Orchestration\Tests\Traits\CreatesConfigServiceables;
use Payavel\Orchestration\Tests\Traits\SetsConfigDriver;

class ConfigCheckoutProviderCommandTest extends TestCheckoutProviderCommand
{
use CreatesConfigServiceables;
use SetsConfigDriver;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Payavel\Checkout\Tests\Feature\Console\Commands;

use Payavel\Orchestration\Tests\Traits\CreatesDatabaseServiceables;
use Payavel\Orchestration\Tests\Traits\SetsDatabaseDriver;

class DatabaseCheckoutProviderCommandTest extends TestCheckoutProviderCommand
{
use CreatesDatabaseServiceables;
use SetsDatabaseDriver;
}
29 changes: 0 additions & 29 deletions tests/Feature/Console/Commands/MakeProviderCommandTest.php

This file was deleted.

21 changes: 18 additions & 3 deletions tests/Feature/Console/Commands/TestCheckoutInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Payavel\Checkout\Tests\Feature\Console\Commands;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use Payavel\Checkout\Tests\TestCase;
use Payavel\Orchestration\Service;
use Payavel\Orchestration\Contracts\Accountable;
use Payavel\Orchestration\Contracts\Providable;
use Payavel\Orchestration\Tests\Contracts\CreatesServiceables;
use Payavel\Orchestration\Tests\Traits\AssertsServiceExists;
use PHPUnit\Framework\Attributes\Test;
Expand All @@ -15,7 +15,7 @@ abstract class TestCheckoutInstallCommand extends TestCase implements CreatesSer
use AssertsServiceExists;

#[Test]
public function install_command_publishes_migration_and_generates_config_with_single_provider_and_account()
public function checkout_install_command_injects_checkout_service_into_orchestrate_service_command()
{
$provider = $this->createProvider($this->checkoutService);
$account = $this->createAccount($this->checkoutService);
Expand Down Expand Up @@ -58,4 +58,19 @@ public function install_command_publishes_migration_and_generates_config_with_si

$this->assertTrue(unlink(config_path($checkoutServiceConfig->service)));
}

protected function makeSureProviderExists(Providable $provider)
{
//
}

protected function makeSureAccountExists(Accountable $account)
{
//
}

protected function makeSureProviderIsLinkedToAccount(Providable $provider, Accountable $account)
{
//
}
}
30 changes: 30 additions & 0 deletions tests/Feature/Console/Commands/TestCheckoutProviderCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Payavel\Checkout\Tests\Feature\Console\Commands;

use Payavel\Checkout\Tests\TestCase;
use Payavel\Orchestration\Tests\Contracts\CreatesServiceables;
use Payavel\Orchestration\Tests\Traits\AssertsServiceExists;
use PHPUnit\Framework\Attributes\Test;

abstract class TestCheckoutProviderCommand extends TestCase implements CreatesServiceables
{
use AssertsServiceExists;

#[Test]
public function checkout_provider_command_injects_checkout_service_into_orchestrate_provider_command()
{
$provider = $this->createProvider($this->checkoutService);

$gateway = $this->gatewayPath($provider);

$this->artisan('orchestrate:provider', [
'provider' => $provider->getId(),
])
->expectsOutputToContain("Gateway [app/{$gateway->request}] created successfully.")
->expectsOutputToContain("Gateway [app/{$gateway->response}] created successfully.")
->assertSuccessful();

$this->assertGatewayExists($provider);
}
}

0 comments on commit 41ebf1a

Please sign in to comment.