|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use Grimzy\LaravelMysqlSpatial\SpatialServiceProvider; |
4 | 3 | use Grimzy\LaravelMysqlSpatial\Types\GeometryCollection; |
5 | 4 | use Grimzy\LaravelMysqlSpatial\Types\LineString; |
6 | 5 | use Grimzy\LaravelMysqlSpatial\Types\MultiPoint; |
7 | 6 | use Grimzy\LaravelMysqlSpatial\Types\MultiPolygon; |
8 | 7 | use Grimzy\LaravelMysqlSpatial\Types\Point; |
9 | 8 | use Grimzy\LaravelMysqlSpatial\Types\Polygon; |
10 | | -use Illuminate\Filesystem\Filesystem; |
11 | | -use Illuminate\Support\Facades\DB; |
12 | | -use Laravel\BrowserKitTesting\TestCase as BaseTestCase; |
13 | 9 |
|
14 | | -class SpatialTest extends BaseTestCase |
| 10 | +class SpatialTest extends IntegrationBaseTestCase |
15 | 11 | { |
16 | | - protected $after_fix = false; |
17 | | - |
18 | | - /** |
19 | | - * Boots the application. |
20 | | - * |
21 | | - * @return \Illuminate\Foundation\Application |
22 | | - */ |
23 | | - public function createApplication() |
24 | | - { |
25 | | - $app = require __DIR__.'/../../vendor/laravel/laravel/bootstrap/app.php'; |
26 | | - $app->register(SpatialServiceProvider::class); |
27 | | - |
28 | | - $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap(); |
29 | | - |
30 | | - $app['config']->set('database.default', 'mysql'); |
31 | | - $app['config']->set('database.connections.mysql.host', env('DB_HOST', '127.0.0.1')); |
32 | | - $app['config']->set('database.connections.mysql.database', 'spatial_test'); |
33 | | - $app['config']->set('database.connections.mysql.username', 'root'); |
34 | | - $app['config']->set('database.connections.mysql.password', ''); |
35 | | - $app['config']->set('database.connections.mysql.modes', [ |
36 | | - 'ONLY_FULL_GROUP_BY', |
37 | | - 'STRICT_TRANS_TABLES', |
38 | | - 'NO_ZERO_IN_DATE', |
39 | | - 'NO_ZERO_DATE', |
40 | | - 'ERROR_FOR_DIVISION_BY_ZERO', |
41 | | - 'NO_ENGINE_SUBSTITUTION', |
42 | | - ]); |
43 | | - |
44 | | - return $app; |
45 | | - } |
46 | | - |
47 | | - /** |
48 | | - * Setup DB before each test. |
49 | | - * |
50 | | - * @return void |
51 | | - */ |
52 | | - public function setUp() |
53 | | - { |
54 | | - parent::setUp(); |
55 | | - |
56 | | - $this->after_fix = $this->isMySQL8AfterFix(); |
57 | | - |
58 | | - $this->onMigrations(function ($migrationClass) { |
59 | | - (new $migrationClass())->up(); |
60 | | - }); |
61 | | - |
62 | | - //\DB::listen(function($sql) { |
63 | | - // var_dump($sql); |
64 | | - //}); |
65 | | - } |
66 | | - |
67 | | - public function tearDown() |
68 | | - { |
69 | | - $this->onMigrations(function ($migrationClass) { |
70 | | - (new $migrationClass())->down(); |
71 | | - }, true); |
72 | | - |
73 | | - parent::tearDown(); |
74 | | - } |
75 | | - |
76 | | - // MySQL 8.0.4 fixed bug #26941370 and bug #88031 |
77 | | - private function isMySQL8AfterFix() |
78 | | - { |
79 | | - $results = DB::select(DB::raw('select version()')); |
80 | | - $mysql_version = $results[0]->{'version()'}; |
81 | | - |
82 | | - return version_compare($mysql_version, '8.0.4', '>='); |
83 | | - } |
84 | | - |
85 | | - protected function assertDatabaseHas($table, array $data, $connection = null) |
86 | | - { |
87 | | - if (method_exists($this, 'seeInDatabase')) { |
88 | | - $this->seeInDatabase($table, $data, $connection); |
89 | | - } else { |
90 | | - parent::assertDatabaseHas($table, $data, $connection); |
91 | | - } |
92 | | - } |
93 | | - |
94 | | - protected function assertException($exceptionName) |
95 | | - { |
96 | | - if (method_exists(parent::class, 'expectException')) { |
97 | | - parent::expectException($exceptionName); |
98 | | - } else { |
99 | | - $this->setExpectedException($exceptionName); |
100 | | - } |
101 | | - } |
102 | | - |
103 | | - private function onMigrations(\Closure $closure, $reverse_sort = false) |
104 | | - { |
105 | | - $fileSystem = new Filesystem(); |
106 | | - $classFinder = new Tools\ClassFinder(); |
107 | | - |
108 | | - $migrations = $fileSystem->files(__DIR__.'/Migrations'); |
109 | | - $reverse_sort ? rsort($migrations, SORT_STRING) : sort($migrations, SORT_STRING); |
110 | | - |
111 | | - foreach ($migrations as $file) { |
112 | | - $fileSystem->requireOnce($file); |
113 | | - $migrationClass = $classFinder->findClass($file); |
114 | | - |
115 | | - $closure($migrationClass); |
116 | | - } |
117 | | - } |
| 12 | + protected $migrations = [ |
| 13 | + CreateLocationTable::class, |
| 14 | + UpdateLocationTable::class |
| 15 | + ]; |
118 | 16 |
|
119 | 17 | public function testSpatialFieldsNotDefinedException() |
120 | 18 | { |
|
0 commit comments