silverstripe-framework/tests/php/ORM/Connect/DBQueryBuilderTest.php
2024-09-18 13:53:44 +12:00

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));
}
}