41 lines
1.5 KiB
PHP
41 lines
1.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Post;
|
|
|
|
use App\Post\Infrastructure\PdoPostRepository as PostRepository;
|
|
use App\Shared\Database\Migrator;
|
|
use PDO;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
|
|
|
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());
|
|
}
|
|
}
|