forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCase.php
82 lines (69 loc) · 2.61 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
78
79
80
81
82
<?php
declare(strict_types=1);
namespace MongoDB\Laravel\Tests;
use Illuminate\Foundation\Application;
use MongoDB\Driver\Exception\ServerException;
use MongoDB\Laravel\MongoDBServiceProvider;
use MongoDB\Laravel\Schema\Builder;
use MongoDB\Laravel\Tests\Models\User;
use MongoDB\Laravel\Validation\ValidationServiceProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
class TestCase extends OrchestraTestCase
{
/**
* Get package providers.
*
* @param Application $app
*/
protected function getPackageProviders($app): array
{
return [
MongoDBServiceProvider::class,
ValidationServiceProvider::class,
];
}
/**
* Define environment setup.
*
* @param Application $app
*/
protected function getEnvironmentSetUp($app): void
{
// reset base path to point to our package's src directory
//$app['path.base'] = __DIR__ . '/../src';
$config = require 'config/database.php';
$app['config']->set('app.key', 'ZsZewWyUJ5FsKp9lMwv4tYbNlegQilM7');
$app['config']->set('database.default', 'mongodb');
$app['config']->set('database.connections.sqlite', $config['connections']['sqlite']);
$app['config']->set('database.connections.mongodb', $config['connections']['mongodb']);
$app['config']->set('database.connections.mongodb2', $config['connections']['mongodb']);
$app['config']->set('auth.model', User::class);
$app['config']->set('auth.providers.users.model', User::class);
$app['config']->set('cache.driver', 'array');
$app['config']->set('cache.stores.mongodb', [
'driver' => 'mongodb',
'connection' => 'mongodb',
'collection' => 'foo_cache',
]);
$app['config']->set('queue.default', 'database');
$app['config']->set('queue.connections.database', [
'driver' => 'mongodb',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
]);
$app['config']->set('queue.failed.database', 'mongodb2');
$app['config']->set('queue.failed.driver', 'mongodb');
}
public function skipIfSearchIndexManagementIsNotSupported(): void
{
try {
$this->getConnection('mongodb')->getCollection('test')->listSearchIndexes(['name' => 'just_for_testing']);
} catch (ServerException $e) {
if (Builder::isAtlasSearchNotSupportedException($e)) {
self::markTestSkipped('Search index management is not supported on this server');
}
throw $e;
}
}
}