test: split unit and integration suites and add coverage config
- 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.
This commit is contained in:
1 parent
725bcfdaf4
commit
f9010e2c63
7 files changed
+144
-3
No files matched your search
@@ -1 +1,14 @@
|
|||||||
* text=auto eol=lf
|
* text=auto eol=lf
|
||||||
|
|
||||||
|
# Files excluded from the distribution archive installed by Composer.
|
||||||
|
/tests export-ignore
|
||||||
|
/.gitattributes export-ignore
|
||||||
|
/.gitignore export-ignore
|
||||||
|
/.github export-ignore
|
||||||
|
/AGENTS.md export-ignore
|
||||||
|
/especificaciones-orm.md export-ignore
|
||||||
|
/mago.toml export-ignore
|
||||||
|
/mago-baseline.toml export-ignore
|
||||||
|
/phpstan.neon export-ignore
|
||||||
|
/phpunit.xml.dist export-ignore
|
||||||
|
/phpunit.integration.xml.dist export-ignore
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
php: ['8.3', '8.4']
|
||||||
|
|
||||||
|
name: PHP ${{ matrix.php }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
extensions: mbstring, pdo, pdo_mysql, json
|
||||||
|
coverage: none
|
||||||
|
tools: composer:v2
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: composer update --prefer-dist --no-interaction --no-progress
|
||||||
|
|
||||||
|
- name: Run gate
|
||||||
|
run: composer check
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
# camelia-orm
|
# camelia/orm
|
||||||
|
|
||||||
Lightweight attribute-mapped Active Record ORM for MariaDB/MySQL over PDO, by Dr2g Sistemas.
|
[](https://packagist.org/packages/camelia/orm)
|
||||||
|
[](https://packagist.org/packages/camelia/orm)
|
||||||
|
[](https://packagist.org/packages/camelia/orm)
|
||||||
|
[](https://git.dr2gsistemas.duckdns.org/dr2gsistemas/camelia-orm/actions)
|
||||||
|
|
||||||
|
Lightweight attribute-mapped Active Record ORM for MariaDB/MySQL over PDO.
|
||||||
|
|
||||||
- **Package:** `camelia/orm` · **Namespace:** `Camelia\Orm`
|
- **Package:** `camelia/orm` · **Namespace:** `Camelia\Orm`
|
||||||
- **PHP** `>=8.3`, extensions `pdo_mysql` and `mbstring`
|
- **PHP** `>=8.3`, extensions `pdo_mysql` and `mbstring`
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "phpunit --configuration phpunit.xml.dist",
|
"test": "phpunit --configuration phpunit.xml.dist",
|
||||||
"test:integration": "phpunit --configuration phpunit.integration.xml.dist",
|
"test:integration": "phpunit --configuration phpunit.integration.xml.dist",
|
||||||
|
"coverage": "phpunit --configuration phpunit.coverage.xml.dist --coverage-text",
|
||||||
"fmt": "mago fmt",
|
"fmt": "mago fmt",
|
||||||
"fmt:check": "mago fmt --check",
|
"fmt:check": "mago fmt --check",
|
||||||
"lint": "mago lint",
|
"lint": "mago lint",
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Coverage configuration, kept out of phpunit.xml.dist on purpose: a coverage report
|
||||||
|
needs Xdebug or PCOV, and `failOnWarning` turns the missing driver into a failed run.
|
||||||
|
Invoke it explicitly with `composer coverage` on a machine that has a driver.
|
||||||
|
-->
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
colors="true"
|
||||||
|
cacheDirectory=".phpunit.cache"
|
||||||
|
failOnRisky="true"
|
||||||
|
failOnEmptyTestSuite="true">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="unit">
|
||||||
|
<directory>tests/Unit</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<source>
|
||||||
|
<include>
|
||||||
|
<directory>src</directory>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
|
<coverage>
|
||||||
|
<report>
|
||||||
|
<text outputFile="php://stdout" showOnlySummary="true"/>
|
||||||
|
<clover outputFile="coverage/clover.xml"/>
|
||||||
|
<html outputDirectory="coverage/html"/>
|
||||||
|
</report>
|
||||||
|
</coverage>
|
||||||
|
</phpunit>
|
||||||
@@ -12,6 +12,11 @@
|
|||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<php>
|
<php>
|
||||||
<env name="CAMELIA_TEST_DSN" value=""/>
|
<!-- Provide these to run the integration suite; without them each test is skipped. -->
|
||||||
|
<env name="CAMELIA_TEST_HOST" value="" force="false"/>
|
||||||
|
<env name="CAMELIA_TEST_DATABASE" value="" force="false"/>
|
||||||
|
<env name="CAMELIA_TEST_USER" value="" force="false"/>
|
||||||
|
<env name="CAMELIA_TEST_PASSWORD" value="" force="false"/>
|
||||||
|
<env name="CAMELIA_TEST_PORT" value="" force="false"/>
|
||||||
</php>
|
</php>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user