Skip to content

Commit

Permalink
Test checkout:install command
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Aug 24, 2023
1 parent e7adba6 commit 9f211b8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 9 deletions.
55 changes: 55 additions & 0 deletions tests/Feature/Console/Commands/InstallCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

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

use Illuminate\Support\Str;
use Payavel\Checkout\Tests\TestCase;
use Payavel\Serviceable\Service;
use Payavel\Serviceable\Tests\Traits\AssertGatewayExists;
use Payavel\Serviceable\Tests\Traits\CreateServiceables;

class InstallCommandTest extends TestCase
{
use AssertGatewayExists,
CreateServiceables;

/** @test */
public function install_command_defaults_to_checkout_service()
{
$service = Service::find('checkout');
$lowerCaseService = Str::lower($service->getName());

$provider = $this->createProvider($service);

$merchant = $this->createMerchant($service);

$this->artisan('checkout:install')
->expectsQuestion('What ' . $lowerCaseService . ' provider would you like to add?', $provider->getName())
->expectsQuestion('How would you like to identify the ' . $provider->getName() . ' ' . $lowerCaseService . ' provider?', $provider->getId())
->expectsConfirmation('Would you like to add another ' . $lowerCaseService . ' provider?', 'no')
->expectsQuestion('What ' . $lowerCaseService . ' merchant would you like to add?', $merchant->getName())
->expectsQuestion('How would you like to identify the ' . $merchant->getName() . ' ' . $lowerCaseService . ' merchant?', $merchant->getId())
->expectsConfirmation('Would you like to add another ' . $lowerCaseService . ' merchant?', 'no')
->expectsOutput('The ' . $lowerCaseService . ' config has been successfully generated.')
->expectsOutput('Fake ' . $lowerCaseService . ' gateway generated successfully!')
->expectsOutput($provider->getName() . ' ' . $lowerCaseService . ' gateway generated successfully!')
->assertExitCode(0);

$configFile = Str::slug($service->getName()) . '.php';

$this->assertFileExists(config_path($configFile));
$config = require(config_path($configFile));

$this->assertGatewayExists($service);

$this->assertEquals($provider->getId(), $config['defaults']['provider']);
$this->assertEquals($merchant->getId(), $config['defaults']['merchant']);
$this->assertEquals($provider->getName(), $config['providers'][$provider->getId()]['name']);
$this->assertEquals($merchant->getName(), $config['merchants'][$merchant->getId()]['name']);
$this->assertNotNull($config['merchants'][$merchant->getId()]['providers'][$provider->getId()]);

$this->assertGatewayExists($provider);

$this->assertTrue(unlink(config_path($configFile)));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

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

use Payavel\Checkout\Tests\TestCase;
use Payavel\Serviceable\Service;
use Payavel\Serviceable\Tests\Traits\AssertGatewayExists;
use Payavel\Serviceable\Tests\Traits\CreateServiceables;
Expand All @@ -11,13 +12,6 @@ class MakeProviderCommandTest extends TestCase
use AssertGatewayExists,
CreateServiceables;

protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);

$this->createService(['id' => 'checkout', 'name' => 'Checkout']);
}

/** @test */
public function make_provider_command_defaults_to_checkout_service()
{
Expand Down
15 changes: 14 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
use Payavel\Checkout\PaymentServiceProvider;
use Payavel\Checkout\Traits\Billable as BillableTrait;
use Payavel\Serviceable\ServiceableServiceProvider;
use Payavel\Serviceable\Tests\Traits\CreateServiceables;
use Payavel\Serviceable\Tests\Traits\SetUpDriver;

abstract class TestCase extends \Orchestra\Testbench\TestCase
{
use RefreshDatabase, WithFaker;
use CreateServiceables,
RefreshDatabase,
SetUpDriver,
WithFaker;

protected function getPackageProviders($app)
{
Expand All @@ -41,8 +46,16 @@ protected function getEnvironmentSetUp($app)
*/
protected function setUp(): void
{
$this->afterApplicationRefreshedCallbacks = [
function() {
$this->setUpDriver();
}
];

parent::setUp();

$this->createService(['id' => 'checkout', 'name' => 'Checkout']);

Schema::create('users', function ($table) {
$table->id();
$table->string('email')->unique();
Expand Down

0 comments on commit 9f211b8

Please sign in to comment.