Skip to content

Commit

Permalink
Merge pull request #10 from dystcz/feature/update-tests
Browse files Browse the repository at this point in the history
Simplify, update & fix tests
  • Loading branch information
repl6669 authored Mar 15, 2024
2 parents 6a1aa55 + 1d2a039 commit c928393
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 61 deletions.
36 changes: 18 additions & 18 deletions .env.testing.example
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
APP_NAME=Laravel
APP_ENV=testing
APP_KEY=AckfSECXIvnK5r28GVIWUAxmbBSjTsmF
APP_DEBUG=true
APP_URL=http://localhost
DB_CONNECTION="sqlite"
DB_DATABASE=":memory:"
REDIS_HOST=redis
REDIS_PASSWORD=secret_redis
REDIS_PORT=6379
PAYMENT_DRIVER=stripe
STRIPE_PUBLIC_KEY=pk_test_
STRIPE_SECRET_KEY=sk_test_
STRIPE_WEBHOOK_SECRET=whsec_
APP_NAME=Laravel
APP_ENV=testing
APP_KEY=AckfSECXIvnK5r28GVIWUAxmbBSjTsmF
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION="sqlite"
DB_DATABASE=":memory:"

REDIS_HOST=redis
REDIS_PASSWORD=secret_redis
REDIS_PORT=6379

PAYMENTS_TYPE=stripe

STRIPE_PUBLIC_KEY=pk_test_
STRIPE_SECRET_KEY=sk_test_
STRIPE_WEBHOOK_SECRET=whsec_
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"description": "Lunar API Stripe Adapter",
"keywords": [
"dystcz",
"laravel",
"php",
"lunar",
"lunar-api",
"lunar-api-stripe-adapter",
"laravel",
"php"
"stripe"
],
"homepage": "https://github.com/dystcz/lunar-api-stripe-adapter",
"license": "MIT",
Expand All @@ -26,9 +27,8 @@
"spatie/laravel-stripe-webhooks": "^3.6"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.8",
"nunomaduro/larastan": "^2.0.1",
"laravel/pint": "^1.7",
"nunomaduro/larastan": "^2.5.1",
"orchestra/testbench": "^8.8",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-arch": "^2.0",
Expand All @@ -41,17 +41,17 @@
},
"autoload": {
"psr-4": {
"Dystcz\\LunarApiStripeAdapter\\": "src/"
"Dystcz\\LunarApiStripeAdapter\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Dystcz\\LunarApiStripeAdapter\\Tests\\": "tests/"
"Dystcz\\LunarApiStripeAdapter\\Tests\\": "tests"
}
},
"scripts": {
"post-autoload-dump": "@composer run prepare",
"clear": "@php vendor/bin/testbench package:purge-lunar-api-stripe-adapter --ansi",
"clear": "@php vendor/bin/testbench package:purge --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
Expand Down
7 changes: 4 additions & 3 deletions tests/Feature/CreatePaymentIntentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Lunar\Facades\CartSession;
use Lunar\Models\Transaction;

uses(TestCase::class, RefreshDatabase::class);

Expand Down Expand Up @@ -55,7 +56,7 @@
expect($response->json('meta.payment_intent.id'))
->toBe($this->order->fresh()->meta['payment_intent']);

})->group('payments-intents')->with(['stripe']);
})->group('payment-intents')->with(['stripe']);

it('creates a transaction when creating a payement intent', function (string $paymentMethod) {
/** @var TestCase $this */
Expand All @@ -78,7 +79,7 @@

$response->assertSuccessful();

$this->assertDatabaseHas('transactions', [
$this->assertDatabaseHas((new Transaction)->getTable(), [
'order_id' => $this->order->getRouteKey(),
'success' => true,
'type' => 'intent',
Expand All @@ -87,4 +88,4 @@
'reference' => $response->json('meta.payment_intent.id'),
]);

})->group('payments-intents')->with(['stripe'])->todo();
})->group('payment-intents')->with(['stripe']);
1 change: 0 additions & 1 deletion tests/Feature/HandleStripeWebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function constructEvent(string $jsonPayload, string $signature, string $s

$this->cart = $cart;
$this->order = $order;

});

it('can handle payment_intent.succeeded event', function () {
Expand Down
48 changes: 17 additions & 31 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Dystcz\LunarApiStripeAdapter\Tests\Stubs\Carts\Modifiers\TestShippingModifier;
use Dystcz\LunarApiStripeAdapter\Tests\Stubs\Lunar\TestTaxDriver;
use Dystcz\LunarApiStripeAdapter\Tests\Stubs\Lunar\TestUrlGenerator;
use Dystcz\LunarApiStripeAdapter\Tests\Stubs\Users\User;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
Expand All @@ -15,11 +14,7 @@
use LaravelJsonApi\Testing\TestExceptionHandler;
use Lunar\Base\ShippingModifiers;
use Lunar\Facades\Taxes;
use Lunar\Models\Channel;
use Lunar\Models\Country;
use Lunar\Models\Currency;
use Lunar\Models\CustomerGroup;
use Lunar\Models\TaxClass;
use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
Expand All @@ -30,6 +25,13 @@ protected function setUp(): void
{
parent::setUp();

$this->setUpDatabase();

Config::set('auth.providers.users', [
'driver' => 'eloquent',
'model' => \Dystcz\LunarApiStripeAdapter\Tests\Stubs\Users\User::class,
]);

Taxes::extend(
'test',
fn (Application $app) => $app->make(TestTaxDriver::class),
Expand All @@ -40,26 +42,6 @@ protected function setUp(): void
'decimal_places' => 2,
]);

Country::factory()->create([
'name' => 'United Kingdom',
'iso3' => 'GBR',
'iso2' => 'GB',
'phonecode' => '+44',
'capital' => 'London',
'currency' => 'GBP',
'native' => 'English',
]);

Channel::factory()->create([
'default' => true,
]);

CustomerGroup::factory()->create([
'default' => true,
]);

TaxClass::factory()->create();

App::get(ShippingModifiers::class)->add(TestShippingModifier::class);

activity()->disableLogging();
Expand Down Expand Up @@ -117,11 +99,6 @@ public function getEnvironmentSetUp($app): void
$app->useEnvironmentPath(__DIR__.'/..');
$app->bootstrapWith([LoadEnvironmentVariables::class]);

Config::set('auth.providers.users', [
'driver' => 'eloquent',
'model' => User::class,
]);

/**
* Lunar configuration
*/
Expand Down Expand Up @@ -182,10 +159,19 @@ protected function determineStripeSignature(array $payload, ?string $configKey =
*/
protected function defineDatabaseMigrations(): void
{
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
$this->loadLaravelMigrations();
}

/**
* Set up the database.
*/
protected function setUpDatabase()
{
$migration = include __DIR__.'/../vendor/spatie/laravel-webhook-client/database/migrations/create_webhook_calls_table.php.stub';

$migration->up();
}

/**
* Resolve application HTTP exception handler implementation.
*/
Expand Down

0 comments on commit c928393

Please sign in to comment.