-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW Add a trace comment for queries in dev mode (#11065)
- Loading branch information
1 parent
26273bf
commit 5e53dbc
Showing
2 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace SilverStripe\ORM\Tests\Connect; | ||
|
||
use ReflectionMethod; | ||
use SilverStripe\Core\Environment; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\ORM\Connect\DBQueryBuilder; | ||
|
||
class DBQueryBuilderTest extends SapphireTest | ||
{ | ||
protected $usesDatabase = false; | ||
|
||
public 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)); | ||
} | ||
} |