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:
commit
66e93e3070
97 files changed
+12188
No files matched your search
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Camelia\Orm\Tests\Unit;
|
||||
|
||||
use Camelia\Orm\Pagination\Page;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class PageTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function it_computes_total_pages_as_int(): void
|
||||
{
|
||||
$page = Page::of([], 1, 10, 25);
|
||||
|
||||
self::assertSame(3, $page->totalPages);
|
||||
self::assertIsInt($page->totalPages);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_reports_next_and_prev(): void
|
||||
{
|
||||
$page = Page::of([], 2, 10, 25);
|
||||
|
||||
self::assertTrue($page->hasNext());
|
||||
self::assertTrue($page->hasPrev());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_does_not_report_next_on_the_last_page(): void
|
||||
{
|
||||
$page = Page::of([], 3, 10, 25);
|
||||
|
||||
self::assertFalse($page->hasNext());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_clamps_invalid_pagination_inputs(): void
|
||||
{
|
||||
$page = Page::of([], 0, 5000, 10);
|
||||
|
||||
self::assertSame(1, $page->page);
|
||||
self::assertSame(Page::MAX_PER_PAGE, $page->perPage);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_serializes_in_snake_case(): void
|
||||
{
|
||||
$array = Page::of([], 1, 10, 3)->toArray();
|
||||
|
||||
self::assertSame(
|
||||
['items', 'page', 'per_page', 'total', 'total_pages', 'has_next', 'has_prev'],
|
||||
array_keys($array),
|
||||
);
|
||||
self::assertSame(1, $array['total_pages']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user