Add PHPUnit tests and update UI
- Add PHPUnit 11.0 testing framework - Create unit tests for Database and Crawler classes - Create integration tests for Crawler - Add phpunit.xml configuration - Change UI background color to rose - All 9 tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
48
tests/Unit/CrawlerTest.php
Normal file
48
tests/Unit/CrawlerTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Crawler;
|
||||
use App\Database;
|
||||
|
||||
class CrawlerTest extends TestCase
|
||||
{
|
||||
private int $testJobId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
// Create a test job
|
||||
$stmt = $db->prepare("INSERT INTO crawl_jobs (domain, status) VALUES (?, 'pending')");
|
||||
$stmt->execute(['https://example.com']);
|
||||
$this->testJobId = $db->lastInsertId();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
// Clean up test data
|
||||
$stmt = $db->prepare("DELETE FROM crawl_jobs WHERE id = ?");
|
||||
$stmt->execute([$this->testJobId]);
|
||||
}
|
||||
|
||||
public function testCrawlerCanBeInstantiated(): void
|
||||
{
|
||||
$crawler = new Crawler($this->testJobId);
|
||||
$this->assertInstanceOf(Crawler::class, $crawler);
|
||||
}
|
||||
|
||||
public function testCrawlerCreatesJobWithCorrectStatus(): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$stmt = $db->prepare("SELECT status FROM crawl_jobs WHERE id = ?");
|
||||
$stmt->execute([$this->testJobId]);
|
||||
$job = $stmt->fetch();
|
||||
|
||||
$this->assertEquals('pending', $job['status']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user