-
-
Notifications
You must be signed in to change notification settings - Fork 235
/
TestCase.php
77 lines (64 loc) · 2.34 KB
/
TestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
declare(strict_types=1);
namespace Bavix\Wallet\Test\Infra;
use Bavix\Wallet\Test\Infra\PackageModels\Transaction;
use Bavix\Wallet\Test\Infra\PackageModels\Transfer;
use Bavix\Wallet\Test\Infra\PackageModels\Wallet;
use Bavix\Wallet\WalletServiceProvider;
use Illuminate\Config\Repository;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
/**
* @internal
*/
abstract class TestCase extends OrchestraTestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
DB::transactionLevel() && DB::rollBack();
}
public function expectExceptionMessageStrict(string $message): void
{
$this->expectExceptionMessageMatches("~^{$message}$~");
}
/**
* @param Application $app
*
* @return non-empty-array<int, string>
*/
protected function getPackageProviders($app): array
{
// Bind eloquent models to IoC container
$app['config']->set('wallet.services.exchange', MyExchangeService::class);
$app['config']->set('wallet.transaction.model', Transaction::class);
$app['config']->set('wallet.transfer.model', Transfer::class);
$app['config']->set('wallet.wallet.model', Wallet::class);
return [WalletServiceProvider::class, TestServiceProvider::class];
}
/**
* @param Application $app
*/
protected function getEnvironmentSetUp($app): void
{
/** @var Repository $config */
$config = $app['config'];
// database
$config->set('database.connections.testing.prefix', 'tests');
$config->set('database.connections.pgsql.prefix', 'tests');
$config->set('database.connections.mysql.prefix', 'tests');
$mysql = $config->get('database.connections.mysql');
$config->set('database.connections.mariadb', array_merge($mysql, [
'port' => 3307,
]));
// new table name's
$config->set('wallet.transaction.table', 'transaction');
$config->set('wallet.transfer.table', 'transfer');
$config->set('wallet.wallet.table', 'wallet');
$config->set('wallet.cache.driver', $config->get('cache.driver'));
$config->set('wallet.lock.driver', $config->get('cache.driver'));
}
}