- Create tests/Integration/ConnectionTest.php, skipped unless CAMELIA_TEST_HOST, CAMELIA_TEST_DATABASE and CAMELIA_TEST_USER are set, so composer test:integration no longer fails on a missing directory. - Move coverage reports to phpunit.coverage.xml.dist: a coverage driver is optional and failOnWarning would turn its absence into a failed gate. - Add a composer coverage script and document the requirement. - Exclude development-only files from the distribution archive via export-ignore. - Add a Gitea Actions workflow running composer check on PHP 8.3 and 8.4. - Align the README title with the package name and add Packagist and CI badges.
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Camelia\Orm\Tests\Integration;
|
|
|
|
use Camelia\Orm\Orm;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Integration tests require a live MariaDB/MySQL server. The suite is skipped unless
|
|
* CAMELIA_TEST_HOST, CAMELIA_TEST_DATABASE and CAMELIA_TEST_USER are set, so
|
|
* `composer test` stays hermetic and needs no database.
|
|
*/
|
|
final class ConnectionTest extends TestCase
|
|
{
|
|
/**
|
|
* @return array{host: string, user: string, database: string, password: string, port: int}
|
|
*/
|
|
private function optionsOrSkip(): array
|
|
{
|
|
$host = getenv('CAMELIA_TEST_HOST');
|
|
$database = getenv('CAMELIA_TEST_DATABASE');
|
|
$user = getenv('CAMELIA_TEST_USER');
|
|
|
|
if ($host === false || $database === false || $user === false) {
|
|
self::markTestSkipped(
|
|
'CAMELIA_TEST_HOST, CAMELIA_TEST_DATABASE and CAMELIA_TEST_USER are required.',
|
|
);
|
|
}
|
|
|
|
$port = getenv('CAMELIA_TEST_PORT');
|
|
$password = getenv('CAMELIA_TEST_PASSWORD');
|
|
|
|
return [
|
|
'host' => $host,
|
|
'user' => $user,
|
|
'database' => $database,
|
|
'password' => $password === false ? '' : $password,
|
|
'port' => $port === false ? 3306 : (int) $port,
|
|
];
|
|
}
|
|
|
|
#[Test]
|
|
public function it_connects_to_the_configured_database(): void
|
|
{
|
|
$orm = Orm::fromArray($this->optionsOrSkip());
|
|
|
|
self::assertSame(1, (int) $orm->connection()->scalar('SELECT 1'));
|
|
}
|
|
}
|