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>
59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use App\Database;
|
|
use PDO;
|
|
|
|
class DatabaseTest extends TestCase
|
|
{
|
|
public function testGetInstanceReturnsPDO(): void
|
|
{
|
|
$db = Database::getInstance();
|
|
$this->assertInstanceOf(PDO::class, $db);
|
|
}
|
|
|
|
public function testGetInstanceReturnsSameInstance(): void
|
|
{
|
|
$db1 = Database::getInstance();
|
|
$db2 = Database::getInstance();
|
|
$this->assertSame($db1, $db2);
|
|
}
|
|
|
|
public function testDatabaseConnectionHasCorrectAttributes(): void
|
|
{
|
|
$db = Database::getInstance();
|
|
|
|
// Test error mode
|
|
$this->assertEquals(
|
|
PDO::ERRMODE_EXCEPTION,
|
|
$db->getAttribute(PDO::ATTR_ERRMODE)
|
|
);
|
|
|
|
// Test fetch mode
|
|
$this->assertEquals(
|
|
PDO::FETCH_ASSOC,
|
|
$db->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE)
|
|
);
|
|
}
|
|
|
|
public function testCanExecuteQuery(): void
|
|
{
|
|
$db = Database::getInstance();
|
|
$stmt = $db->query('SELECT 1 as test');
|
|
$this->assertNotFalse($stmt, 'Query failed');
|
|
$result = $stmt->fetch();
|
|
|
|
$this->assertEquals(['test' => 1], $result);
|
|
}
|
|
|
|
public function testCanPrepareStatement(): void
|
|
{
|
|
$db = Database::getInstance();
|
|
$stmt = $db->prepare('SELECT ? as test');
|
|
|
|
$this->assertInstanceOf(\PDOStatement::class, $stmt);
|
|
}
|
|
}
|