feat: initial commit of camelia/orm

Attribute-mapped Active Record ORM for MariaDB/MySQL over PDO.

- Attribute-driven metadata: TableName, PrimaryKey, AutoIncrement, Column,
  Guarded, Ignore, Required, Enum, Nullable, Length, Precision, Unique,
  UniqueGroup, Index, MaxLength.
- Relationship mapping: BelongsTo, HasOne, HasMany, BelongsToMany with
  batched eager loading and a 3-level depth limit.
- Orm entry point with fromArray, fromPdo, fromEnv and nested transactions.
- Immutable Query with Cond operators and GroupCond grouping.
- Repository read and write API, pagination, and typed exception hierarchy.
- Declares PHP >=8.3; Mago and PHPStan pin the parser to 8.3.
- MIT license.
This commit is contained in:
dgarcia committed 2026-11-15 10:14:22 -03:00
commit 66e93e3070
97 files changed
+12188

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace Camelia\Orm\Tests\Unit;
use Camelia\Orm\Orm;
use Camelia\Orm\Repository;
use Camelia\Orm\Tests\Fixture\Usuario;
use Camelia\Orm\Tests\Support\FakeConnection;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class OrmTest extends TestCase
{
#[Test]
public function it_returns_a_repository_for_a_model(): void
{
$orm = Orm::fromConnection(new FakeConnection());
self::assertInstanceOf(Repository::class, $orm->repository(Usuario::class));
}
#[Test]
public function it_reuses_the_same_repository_instance(): void
{
$orm = Orm::fromConnection(new FakeConnection());
self::assertSame($orm->repository(Usuario::class), $orm->repository(Usuario::class));
}
#[Test]
public function it_commits_a_successful_transaction(): void
{
$connection = new FakeConnection();
$orm = Orm::fromConnection($connection);
$result = $orm->transaction(static fn(): string => 'ok');
self::assertSame('ok', $result);
self::assertSame(1, $connection->commitCount);
self::assertSame(0, $connection->rollBackCount);
}
#[Test]
public function it_rolls_back_and_rethrows(): void
{
$connection = new FakeConnection();
$orm = Orm::fromConnection($connection);
$this->expectException(\RuntimeException::class);
try {
$orm->transaction(static function (): void {
throw new \RuntimeException('boom');
});
} finally {
self::assertSame(1, $connection->rollBackCount);
self::assertSame(0, $connection->commitCount);
}
}
#[Test]
public function it_exposes_the_connection(): void
{
$connection = new FakeConnection();
self::assertSame($connection, Orm::fromConnection($connection)->connection());
}
}