Skip to content

Commit 7d0578b

Browse files
committed
Fixes tests.
1 parent 0f94263 commit 7d0578b

File tree

3 files changed

+9
-164
lines changed

3 files changed

+9
-164
lines changed

tests/Integration/IntegrationBaseTestCase.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ public function createApplication()
2121

2222
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
2323

24-
/**
25-
* @param \Illuminate\Contracts\Config\Repository $config
26-
*/
27-
$config = $app->config;
28-
$config->set('database.default', 'mysql');
29-
$config->set('database.connections.mysql.host', env('DB_HOST', '127.0.0.1'));
30-
$config->set('database.connections.mysql.database', 'spatial_test');
31-
$config->set('database.connections.mysql.username', 'root');
32-
$config->set('database.connections.mysql.password', '');
33-
$config->set('database.connections.mysql.modes', [
24+
$app['config']->set('database.default', 'mysql');
25+
$app['config']->set('database.connections.mysql.host', env('DB_HOST'));
26+
$app['config']->set('database.connections.mysql.port', env('DB_PORT'));
27+
$app['config']->set('database.connections.mysql.database', env('DB_DATABASE'));
28+
$app['config']->set('database.connections.mysql.username', env('DB_USERNAME'));
29+
$app['config']->set('database.connections.mysql.password', env('DB_PASSWORD'));
30+
$app['config']->set('database.connections.mysql.modes', [
3431
'ONLY_FULL_GROUP_BY',
3532
'STRICT_TRANS_TABLES',
3633
'NO_ZERO_IN_DATE',

tests/Integration/SpatialTest.php

Lines changed: 1 addition & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -11,161 +11,9 @@ class SpatialTest extends IntegrationBaseTestCase
1111
{
1212
protected $migrations = [
1313
CreateLocationTable::class,
14-
UpdateLocationTable::class
14+
UpdateLocationTable::class,
1515
];
1616

17-
protected $after_fix = false;
18-
19-
public static function setUpBeforeClass()
20-
{
21-
self::cleanDatabase(true);
22-
23-
parent::setUpBeforeClass();
24-
}
25-
26-
public static function tearDownAfterClass()
27-
{
28-
self::cleanDatabase();
29-
30-
parent::tearDownAfterClass();
31-
}
32-
33-
/**
34-
* Deletes the database.
35-
*
36-
* @param bool $recreate If true, then creates the database after deletion
37-
*/
38-
private static function cleanDatabase($recreate = false)
39-
{
40-
$database = env('DB_DATABASE');
41-
42-
try {
43-
$pdo = new PDO(
44-
sprintf(
45-
'mysql:host=%s;port=%d;',
46-
env('DB_HOST'),
47-
env('DB_PORT')
48-
),
49-
env('DB_USERNAME'),
50-
env('DB_PASSWORD')
51-
);
52-
53-
$pdo->exec(sprintf('DROP DATABASE IF EXISTS %s', $database));
54-
if ($recreate) {
55-
$pdo->exec(sprintf(
56-
'CREATE DATABASE %s CHARACTER SET %s COLLATE %s;',
57-
$database,
58-
env('DB_CHARSET', 'utf8mb4'),
59-
env('DB_COLLATION', 'utf8mb4_unicode_ci')
60-
));
61-
}
62-
} catch (RuntimeException $exception) {
63-
throw $exception;
64-
}
65-
}
66-
67-
/**
68-
* Boots the application.
69-
*
70-
* @return \Illuminate\Foundation\Application
71-
*/
72-
public function createApplication()
73-
{
74-
$app = require __DIR__.'/../../vendor/laravel/laravel/bootstrap/app.php';
75-
$app->register(SpatialServiceProvider::class);
76-
77-
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
78-
79-
$app['config']->set('database.default', 'mysql');
80-
$app['config']->set('database.connections.mysql.host', env('DB_HOST'));
81-
$app['config']->set('database.connections.mysql.port', env('DB_PORT'));
82-
$app['config']->set('database.connections.mysql.database', env('DB_DATABASE'));
83-
$app['config']->set('database.connections.mysql.username', env('DB_USERNAME'));
84-
$app['config']->set('database.connections.mysql.password', env('DB_PASSWORD'));
85-
$app['config']->set('database.connections.mysql.modes', [
86-
'ONLY_FULL_GROUP_BY',
87-
'STRICT_TRANS_TABLES',
88-
'NO_ZERO_IN_DATE',
89-
'NO_ZERO_DATE',
90-
'ERROR_FOR_DIVISION_BY_ZERO',
91-
'NO_ENGINE_SUBSTITUTION',
92-
]);
93-
94-
return $app;
95-
}
96-
97-
/**
98-
* Setup DB before each test.
99-
*
100-
* @return void
101-
*/
102-
public function setUp()
103-
{
104-
parent::setUp();
105-
106-
$this->after_fix = $this->isMySQL8AfterFix();
107-
108-
$this->onMigrations(function ($migrationClass) {
109-
(new $migrationClass())->up();
110-
});
111-
112-
// \DB::listen(function($sql) {
113-
// var_dump($sql);
114-
// });
115-
}
116-
117-
public function tearDown()
118-
{
119-
$this->onMigrations(function ($migrationClass) {
120-
(new $migrationClass())->down();
121-
}, true);
122-
123-
parent::tearDown();
124-
}
125-
126-
// MySQL 8.0.4 fixed bug #26941370 and bug #88031
127-
private function isMySQL8AfterFix()
128-
{
129-
$results = DB::select(DB::raw('select version()'));
130-
$mysql_version = $results[0]->{'version()'};
131-
132-
return version_compare($mysql_version, '8.0.4', '>=');
133-
}
134-
135-
protected function assertDatabaseHas($table, array $data, $connection = null)
136-
{
137-
if (method_exists($this, 'seeInDatabase')) {
138-
$this->seeInDatabase($table, $data, $connection);
139-
} else {
140-
parent::assertDatabaseHas($table, $data, $connection);
141-
}
142-
}
143-
144-
protected function assertException($exceptionName)
145-
{
146-
if (method_exists(parent::class, 'expectException')) {
147-
parent::expectException($exceptionName);
148-
} else {
149-
$this->setExpectedException($exceptionName);
150-
}
151-
}
152-
153-
private function onMigrations(\Closure $closure, $reverse_sort = false)
154-
{
155-
$fileSystem = new Filesystem();
156-
$classFinder = new Tools\ClassFinder();
157-
158-
$migrations = $fileSystem->files(__DIR__.'/Migrations');
159-
$reverse_sort ? rsort($migrations, SORT_STRING) : sort($migrations, SORT_STRING);
160-
161-
foreach ($migrations as $file) {
162-
$fileSystem->requireOnce($file);
163-
$migrationClass = $classFinder->findClass($file);
164-
165-
$closure($migrationClass);
166-
}
167-
}
168-
16917
public function testSpatialFieldsNotDefinedException()
17018
{
17119
$geo = new NoSpatialFieldsModel();

tests/Integration/SridSpatialTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SridSpatialTest extends IntegrationBaseTestCase
1111
{
1212
protected $migrations = [
1313
CreateLocationTable::class,
14-
UpdateLocationTable::class
14+
UpdateLocationTable::class,
1515
];
1616

1717
public function testInsertPointWithSrid()

0 commit comments

Comments
 (0)