Skip to content

Commit

Permalink
init pest
Browse files Browse the repository at this point in the history
  • Loading branch information
milwad-dev committed Jun 26, 2024
1 parent 33df0f2 commit fe43b0f
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/

uses(Tests\TestCase::class)->in('Feature');

/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/

expect()->extend('toBeOne', function () {
return $this->toBe(1);
});

/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/

function something()
{
// ..
}
46 changes: 46 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Tests;

use Binafy\LaravelDiscount\Providers\LaravelDiscountServiceProvider;
use Illuminate\Encryption\Encrypter;

abstract class TestCase extends \Orchestra\Testbench\TestCase
{
/**
* Load package service provider.
*
* @param \Illuminate\Foundation\Application $app
*/
protected function getPackageProviders($app): array
{
return [LaravelDiscountServiceProvider::class];
}

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app): void
{
// Set default database to use sqlite :memory:
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);

// Set app key
$app['config']->set('app.key', 'base64:'.base64_encode(
Encrypter::generateKey(config()['app.cipher'])
));

// Set user model
// $app['config']->set('auth.providers.users.model', User::class);

// Set user model for monitoring config
// $app['config']->set('laravel-discount.user.model', User::class);
}
}

0 comments on commit fe43b0f

Please sign in to comment.