mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\ORM\Tests\Connect;
|
|
|
|
use ReflectionMethod;
|
|
use SilverStripe\Core\Environment;
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\ORM\Connect\DBQueryBuilder;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
class DBQueryBuilderTest extends SapphireTest
|
|
{
|
|
protected $usesDatabase = false;
|
|
|
|
public static function provideShouldBuildTraceComment(): array
|
|
{
|
|
return [
|
|
[
|
|
'envValue' => null,
|
|
'yamlValue' => true,
|
|
'expected' => true,
|
|
],
|
|
[
|
|
'envValue' => null,
|
|
'yamlValue' => false,
|
|
'expected' => false,
|
|
],
|
|
[
|
|
'envValue' => true,
|
|
'yamlValue' => true,
|
|
'expected' => true,
|
|
],
|
|
[
|
|
'envValue' => true,
|
|
'yamlValue' => false,
|
|
'expected' => true,
|
|
],
|
|
[
|
|
'envValue' => false,
|
|
'yamlValue' => false,
|
|
'expected' => false,
|
|
],
|
|
[
|
|
'envValue' => false,
|
|
'yamlValue' => true,
|
|
'expected' => false,
|
|
],
|
|
];
|
|
}
|
|
|
|
#[DataProvider('provideShouldBuildTraceComment')]
|
|
public function testShouldBuildTraceComment(?bool $envValue, bool $yamlValue, bool $expected): void
|
|
{
|
|
$queryBuilder = new DBQueryBuilder();
|
|
$reflectionMethod = new ReflectionMethod($queryBuilder, 'shouldBuildTraceComment');
|
|
$reflectionMethod->setAccessible(true);
|
|
|
|
if ($envValue !== null) {
|
|
Environment::setEnv('SS_TRACE_DB_QUERY_ORIGIN', $envValue);
|
|
}
|
|
DBQueryBuilder::config()->set('trace_query_origin', $yamlValue);
|
|
|
|
$this->assertSame($expected, $reflectionMethod->invoke($queryBuilder));
|
|
}
|
|
}
|