Repository navigation
Expand file tree
/
Copy pathExplainModelTest.php
More file actions
55 lines (42 loc) · 1.6 KB
/
Copy pathExplainModelTest.php
File metadata and controls
55 lines (42 loc) · 1.6 KB
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
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Models;
use PHPUnit\Framework\Attributes\Group;
use Tests\Support\Models\UserModel;
/**
* @internal
*/
#[Group('DatabaseLive')]
final class ExplainModelTest extends LiveModelTestCase
{
public function testExplainRespectsSoftDeletesInTestMode(): void
{
if (in_array($this->db->DBDriver, ['OCI8', 'SQLSRV'], true)) {
$this->markTestSkipped($this->db->DBDriver . ' does not support explain().');
}
$this->createModel(UserModel::class);
$sql = $this->model->where('id', 1)->explain(test: true);
$expectedPrefix = $this->db->DBDriver === 'SQLite3'
? 'EXPLAIN QUERY PLAN SELECT'
: 'EXPLAIN SELECT';
$this->assertStringStartsWith($expectedPrefix, str_replace("\n", ' ', (string) $sql));
$this->assertStringContainsString('deleted_at', (string) $sql);
}
public function testExplainWithDeletedOmitsSoftDeleteConstraintInTestMode(): void
{
if (in_array($this->db->DBDriver, ['OCI8', 'SQLSRV'], true)) {
$this->markTestSkipped($this->db->DBDriver . ' does not support explain().');
}
$this->createModel(UserModel::class);
$sql = $this->model->withDeleted()->where('id', 1)->explain(test: true);
$this->assertStringNotContainsString('deleted_at', (string) $sql);
}
}