first commit
This commit is contained in:
38
tests/Post/PostFtsUsernameSyncIntegrationTest.php
Normal file
38
tests/Post/PostFtsUsernameSyncIntegrationTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Post;
|
||||
|
||||
use App\Post\PostRepository;
|
||||
use App\Shared\Database\Migrator;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class PostFtsUsernameSyncIntegrationTest extends TestCase
|
||||
{
|
||||
private PDO $db;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->db = new PDO('sqlite::memory:', options: [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
$this->db->sqliteCreateFunction('strip_tags', 'strip_tags', 1);
|
||||
Migrator::run($this->db);
|
||||
|
||||
$this->db->exec("INSERT INTO users (id, username, email, password_hash, role, created_at) VALUES (1, 'alice', 'alice@example.com', 'hash', 'user', '2024-01-01 00:00:00')");
|
||||
$this->db->exec("INSERT INTO posts (id, title, content, slug, author_id, created_at, updated_at) VALUES (1, 'Guide Slim', '<p>Contenu</p>', 'guide-slim', 1, '2024-01-01 00:00:00', '2024-01-01 00:00:00')");
|
||||
}
|
||||
|
||||
public function testSearchReflectsUpdatedAuthorUsernameInFtsIndex(): void
|
||||
{
|
||||
$this->db->exec("UPDATE users SET username = 'alice_renamed' WHERE id = 1");
|
||||
|
||||
$results = (new PostRepository($this->db))->search('alice_renamed');
|
||||
|
||||
self::assertCount(1, $results);
|
||||
self::assertSame('alice_renamed', $results[0]->getAuthorUsername());
|
||||
self::assertSame('Guide Slim', $results[0]->getTitle());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user