9 Commits
Author SHA1 Message Date
dgarcia 318b5b9da2 fix(criteria): compare backed enums by their scalar value
Using an enum as a criteria value reached PDO as an object and failed with
"Object of class X could not be converted to string". Filtering by a state
column - the most natural thing to do with an enum-mapped property - was
impossible.

CriteriaCompiler now unwraps \BackedEnum both for a plain value and inside an
an IN list.

Covered by CriteriaCompilerEnumTest.
2026-11-15 14:37:54 -03:00
dgarcia 1478b8f7f7 fix(typecaster): send booleans to the driver as 1/0
Tests / PHP 8.4 (push) Failing after 5m57s
PDO with ATTR_EMULATE_PREPARES = false sends a native PHP bool as an empty
string. MariaDB rejects it on a TINYINT column with "Incorrect integer
value: ''", so every boolean column was unwritable through the ORM:
inserting a model with a bool property always failed.

toDatabaseValue() now maps bool to 1/0. Other scalars, enums, dates and
BigDecimal keep their existing handling.

Covered by TypeCasterDatabaseValueTest.
2026-11-15 14:21:40 -03:00
dgarcia 227325e4b4 fix(repository): persist guarded columns passed to create()
Tests / PHP 8.4 (push) Failing after 5m9s
create() built the model through hydrate(), which skips #[Guarded]
properties on purpose: that is the right behaviour for an HTTP payload,
where a client must not set password_hash or a token. But create() is
called from trusted server code - a service, a seeder - and the guarded
value was silently dropped, so an account was inserted with an empty
password hash. The write succeeded and nothing failed loudly.

create() now re-applies guarded values after hydration, so every column
the caller passes is persisted. hydrate() keeps rejecting them, which is
what protects mass assignment.

Covered by CreateWithGuardedTest: one case for create() persisting the
hash, one asserting hydrate() still ignores it.
2026-11-15 13:37:39 -03:00
dgarcia 4faad2c46e fix(repository): hydrate enum columns instead of failing on read
Tests / PHP 8.4 (push) Failing after 4m31s
Repository::castDatabaseValue() called TypeCaster::cast() with the enum's
class name as the "type", so any row of a model declaring #[Enum] threw
"Cannot assign string to property X of type Y" the moment it was read.
Writes worked, which is why this survived 1.0.0: the select path is only
exercised on read.

castDatabaseValue() now delegates to TypeCaster::castEnum() when the
property declares one, and keeps the null passthrough. Covered by
EnumHydrationTest with a scalar value and a null.
2026-11-15 13:35:27 -03:00
dgarcia a655a6f3ae feat(console): add bin/camelia-orm with seed and make commands
Tests / PHP 8.4 (push) Failing after 3m23s
A command line for the library, kept deliberately small: no console
component, no dependency added to the consumer's tree.

- Application/Command/Input/Output: parsing, dispatch, exit codes and
  capturable output. Commands return an exit code instead of calling exit(),
  so every one is testable.
- seed: runs the registered SeederRunner inside one transaction, with
  --list and --only=name[,name].
- doctor: one round-trip that fails loudly when the DSN is wrong.
- make:model and make:seeder: live scaffolding into the consumer's code,
  sharing name validation, the overwrite guard and directory creation
  through MakeCommand.

The binary ships an empty runner; an application composes SeedCommand into
its own Application to register its seeders.
2026-11-15 13:31:14 -03:00
dgarcia 2acf2cc099 feat(seeding): add the seeder concept with an idempotent runner
A seeder fills reference or bootstrap data - the permission catalogue, the
built-in roles, the first administrator. It is not a migration: it never
touches the schema, it runs on demand, and it must be safe to run twice.

- Seeder: the contract (name + run).
- AbstractSeeder: seedOnce() inserts only when the criteria match nothing and
  records inserted/skipped counts. It never overwrites a row a user edited.
- SeederRunner: runs an ordered batch inside one transaction, so a failing
  seeder leaves the database untouched. Supports running a named subset.
- SeederResult: per-seeder outcome for reporting.
- ConfigurationException::unknownSeeder() lists the registered names.

docs/SEEDING.md documents the contract and how to write one.
2026-11-15 13:30:54 -03:00
dgarcia 0e756e45c7 refactor!: require PHP 8.4
Tests / PHP 8.4 (push) Failing after 5m34s
Drop support for PHP 8.3 and lower. The package now declares >=8.4, and CI runs
only on 8.4.

- composer.json: require php >=8.4.
- mago.toml: php-version = "8.4", matching the minimum supported version.
- phpstan.neon: phpVersion 80400.
- Upgrade phpstan/phpstan to ^2.3: 1.x cannot parse `new Foo()->bar()`, which the
  8.4 formatter now emits.
- Fix the type errors PHPStan 2 reports: class-string<static> variance,
  optional array offsets in fromEnvironment, list vs array for PdoConnection::$lru,
  ReflectionClass<Model> docblocks, Repository made covariant in T, and a redundant
  null comparison in validateRelationPath.
- CI: single PHP 8.4 job using the php:8.4-cli container instead of setup-php,
  which failed with a TLS handshake timeout on the runner.

BREAKING CHANGE: PHP 8.4 is now required.
2026-11-15 10:58:11 -03:00
dgarcia f9010e2c63 test: split unit and integration suites and add coverage config
Tests / PHP 8.3 (push) Failing after 3m42s
Tests / PHP 8.4 (push) Failing after 2m31s
- 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.
2026-11-15 10:21:11 -03:00
dgarcia 66e93e3070 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.
2026-11-15 10:14:22 -03:00