summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-04-21 10:27:21 +0100
committerGreg Roach <fisharebest@webtrees.net>2019-04-21 10:31:35 +0100
commite16a1bfdc151cca06b727ccf08cd4f43ed7d6e55 (patch)
treed0d215c0f9501515f1d011c533decae5e33dda14 /tests
parentb332fbfe03234b00be6347dca582f1d7a29c87d7 (diff)
downloadwebtrees-e16a1bfdc151cca06b727ccf08cd4f43ed7d6e55.tar.gz
webtrees-e16a1bfdc151cca06b727ccf08cd4f43ed7d6e55.tar.bz2
webtrees-e16a1bfdc151cca06b727ccf08cd4f43ed7d6e55.zip
Refactor database connection as middleware
Diffstat (limited to 'tests')
-rw-r--r--tests/TestCase.php8
-rw-r--r--tests/app/DatabaseTest.php34
2 files changed, 7 insertions, 35 deletions
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 3faa06dba9..4f2197d56f 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -31,6 +31,7 @@ use Fisharebest\Webtrees\Services\UserService;
use Illuminate\Cache\ArrayStore;
use Illuminate\Cache\Repository;
use Illuminate\Database\Capsule\Manager as DB;
+use Illuminate\Database\Query\Builder;
use League\Flysystem\Filesystem;
use League\Flysystem\Memory\MemoryAdapter;
use Nyholm\Psr7\Factory\Psr17Factory;
@@ -110,7 +111,12 @@ class TestCase extends \PHPUnit\Framework\TestCase implements StatusCodeInterfac
'database' => ':memory:',
]);
$capsule->setAsGlobal();
- Database::registerMacros();
+
+ Builder::macro('whereContains', function ($column, string $search, string $boolean = 'and'): Builder {
+ $search = strtr($search, ['\\' => '\\\\', '%' => '\\%', '_' => '\\_', ' ' => '%']);
+
+ return $this->where($column, 'LIKE', '%' . $search . '%', $boolean);
+ });
// Migrations create logs, which requires an IP address, which requires a request
self::createRequest();
diff --git a/tests/app/DatabaseTest.php b/tests/app/DatabaseTest.php
deleted file mode 100644
index 45b6ef14f4..0000000000
--- a/tests/app/DatabaseTest.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
- * webtrees: online genealogy
- * Copyright (C) 2019 webtrees development team
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-declare(strict_types=1);
-
-namespace Fisharebest\Webtrees;
-
-/**
- * Test harness for the class Statement
- */
-class DatabaseTest extends TestCase
-{
- /**
- * Test that the class exists
- *
- * @return void
- */
- public function testClassExists(): void
- {
- $this->assertTrue(class_exists('\Fisharebest\Webtrees\Database'));
- }
-}