Files
screamingFrog/tests/Integration/CrawlerIntegrationTest.php
Martin e569d189d5 Add comprehensive quality tooling and fix code style issues
Quality Tools Added:
- PHPStan (Level 8) for static analysis
- PHP_CodeSniffer (PSR-12) for code style
- Updated PHPUnit test suite with type safety

Code Improvements:
- Fixed all PHPStan Level 8 errors (13 issues)
- Auto-fixed 25 PSR-12 code style violations
- Added proper type hints for arrays and method parameters
- Fixed PDOStatement|false handling in api.php and tests
- Improved null-safety for parse_url() calls

Configuration:
- phpstan.neon: Level 8, analyzes src/ and tests/
- phpcs.xml: PSR-12 standard, excludes vendor/
- docker-compose.yml: Mount config files for tooling
- composer.json: Add phpstan, phpcs, phpcbf scripts

Documentation:
- Updated README.md with testing and quality sections
- Updated AGENTS.md with quality gates and workflows
- Added pre-commit checklist for developers

All tests pass (9/9), PHPStan clean (0 errors), PHPCS compliant (1 warning)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 23:58:21 +02:00

68 lines
1.9 KiB
PHP

<?php
namespace Tests\Integration;
use PHPUnit\Framework\TestCase;
use App\Crawler;
use App\Database;
class CrawlerIntegrationTest extends TestCase
{
private int $testJobId;
private \PDO $db;
protected function setUp(): void
{
$this->db = Database::getInstance();
// Create a test job
$stmt = $this->db->prepare("INSERT INTO crawl_jobs (domain, status) VALUES (?, 'pending')");
$stmt->execute(['https://httpbin.org']);
$lastId = $this->db->lastInsertId();
$this->testJobId = is_numeric($lastId) ? (int)$lastId : 0;
}
protected function tearDown(): void
{
// Clean up test data
$stmt = $this->db->prepare("DELETE FROM crawl_jobs WHERE id = ?");
$stmt->execute([$this->testJobId]);
}
public function testCrawlerUpdatesJobStatusToRunning(): void
{
$crawler = new Crawler($this->testJobId);
// Start crawl (will fail but should update status)
try {
$crawler->start('https://httpbin.org/html');
} catch (\Exception $e) {
// Expected to fail in test environment
}
$stmt = $this->db->prepare("SELECT status FROM crawl_jobs WHERE id = ?");
$stmt->execute([$this->testJobId]);
$job = $stmt->fetch();
// Status should be either 'running' or 'completed'
$this->assertContains($job['status'], ['running', 'completed', 'failed']);
}
public function testCrawlerCreatesQueueEntries(): void
{
$crawler = new Crawler($this->testJobId);
try {
$crawler->start('https://httpbin.org/html');
} catch (\Exception $e) {
// Expected to fail in test environment
}
$stmt = $this->db->prepare("SELECT COUNT(*) as count FROM crawl_queue WHERE crawl_job_id = ?");
$stmt->execute([$this->testJobId]);
$result = $stmt->fetch();
$this->assertGreaterThan(0, $result['count']);
}
}