Skip to content

Commit

Permalink
feat(SqlTestEnable): add fake connector for sql lite
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna authored and pionl committed Jul 30, 2024
1 parent 998f757 commit 7468a7c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"psr/simple-cache": "^3.0"
},
"require-dev": {
"ext-pdo": "*",
"ext-sqlite3": "*",
"mockery/mockery": "^1.5.0",
"nette/php-generator": "v4.0.5",
"nikic/php-parser": "v4.15.2",
Expand Down
36 changes: 36 additions & 0 deletions src/Tests/Traits/SqlTestEnable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace LaraStrict\Tests\Traits;

use Illuminate\Contracts\Database\Query\Builder;
use Illuminate\Database\ConnectionResolver;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\SQLiteConnection;
use PDO;
use PHPUnit\Framework\Assert;

trait SqlTestEnable
{
/**
* @beforeClass
*/
final public static function beforeClassSqlTestEnable(): void
{
$resolver = new ConnectionResolver([
'default' => new SQLiteConnection(new PDO('sqlite::memory:')),
]);
$resolver->setDefaultConnection('default');
Model::setConnectionResolver($resolver);
}

final protected static function assertQuerySql(
string $expectedSql,
array $expectedBindings,
Builder $query,
): void {
Assert::assertSame(trim($expectedSql), $query->toSql());
Assert::assertSame($expectedBindings, $query->getBindings());
}
}

0 comments on commit 7468a7c

Please sign in to comment.