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.
This commit is contained in:
1 parent
c15015d809
commit
0e756e45c7
20 files changed
+97
-107
No files matched your search
@@ -6,40 +6,28 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
jobs:
|
|
||||||
check:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
php: ['8.3', '8.4']
|
|
||||||
|
|
||||||
name: PHP ${{ matrix.php }}
|
|
||||||
|
|
||||||
# The PHP version comes from the job container image instead of shivammathur/setup-php:
|
# The PHP version comes from the job container image instead of shivammathur/setup-php:
|
||||||
# the runner in this Gitea instance reaches github.com intermittently and setup-php
|
# the runner in this Gitea instance reaches github.com intermittently and setup-php
|
||||||
# failed with "TLS handshake timeout". Fewer external actions, fewer failure modes.
|
# failed with "TLS handshake timeout". Fewer external actions, fewer failure modes.
|
||||||
container: php:${{ matrix.php }}-cli
|
jobs:
|
||||||
|
check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: PHP 8.4
|
||||||
|
container: php:8.4-cli
|
||||||
steps:
|
steps:
|
||||||
- name: Install system packages
|
- name: Install system packages
|
||||||
run: |
|
run: |
|
||||||
apt-get update -qq
|
apt-get update -qq
|
||||||
apt-get install -y -qq --no-install-recommends git unzip libonig-dev libxml2-dev > /dev/null
|
apt-get install -y -qq --no-install-recommends git unzip libonig-dev libxml2-dev > /dev/null
|
||||||
docker-php-ext-install -j"$(nproc)" mbstring pdo pdo_mysql > /dev/null
|
docker-php-ext-install -j"$(nproc)" mbstring pdo pdo_mysql > /dev/null
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Install Composer
|
- name: Install Composer
|
||||||
run: |
|
run: |
|
||||||
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
|
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
|
||||||
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --quiet
|
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --quiet
|
||||||
composer --version
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: composer update --prefer-dist --no-interaction --no-progress
|
run: composer update --prefer-dist --no-interaction --no-progress
|
||||||
|
|
||||||
- name: Run gate
|
- name: Run gate
|
||||||
run: composer check
|
run: composer check
|
||||||
@@ -26,8 +26,8 @@ Si tu memoria sugiere alguno de esos nombres, está obsoleta.
|
|||||||
|
|
||||||
## Entorno local
|
## Entorno local
|
||||||
|
|
||||||
- PHP: `C:\php8.4\php.exe` (8.4.19). La librería declara `>=8.2`, así que **no** uses sintaxis de
|
- PHP: `C:\php8.4\php.exe` (8.4.19). La librería declara `>=8.4`, así que toda la sintaxis de 8.4
|
||||||
8.3/8.4 (y por eso `(new Foo())->bar()` conserva los paréntesis).
|
está disponible y el formatter puede emitir `new Foo()->bar()`.
|
||||||
- `declare(strict_types=1)` en todo archivo.
|
- `declare(strict_types=1)` en todo archivo.
|
||||||
- Sin `.env` ni base configurada. Los tests unitarios usan `FakeConnection`; la integración
|
- Sin `.env` ni base configurada. Los tests unitarios usan `FakeConnection`; la integración
|
||||||
requiere `CAMELIA_TEST_DSN` y se **salta** si falta.
|
requiere `CAMELIA_TEST_DSN` y se **salta** si falta.
|
||||||
@@ -44,8 +44,10 @@ Nunca mergees con uno en rojo. Orden obligatorio.
|
|||||||
|
|
||||||
`mago.toml` configura formatter, linter y analyzer. Notas que ahorran tiempo:
|
`mago.toml` configura formatter, linter y analyzer. Notas que ahorran tiempo:
|
||||||
|
|
||||||
- **`php-version = "8.2"` en `mago.toml` es obligatorio.** Si se sube a 8.4, `mago fmt` reescribe
|
- **`php-version = "8.4"` en `mago.toml` debe coincidir con el mínimo declarado.** El paquete
|
||||||
`(new X())->m()` como `new X()->m()`, que rompe el soporte declarado de 8.2.
|
promete `>=8.4`, así que `mago fmt` puede emitir `new X()->m()`. Si el soporte mínimo bajara,
|
||||||
|
`php-version` tendría que bajar con él: con 8.4 el formatter elimina los paréntesis de
|
||||||
|
`(new X())->m()`, sintaxis que no parsea en 8.3 ni inferiores.
|
||||||
- `mago analyze` excluye `tests/`: no carga el autoloader de Composer, así que reportaría
|
- `mago analyze` excluye `tests/`: no carga el autoloader de Composer, así que reportaría
|
||||||
`PHPUnit\Framework\TestCase` como clase inexistente. PHPStan sí cubre los tests.
|
`PHPUnit\Framework\TestCase` como clase inexistente. PHPStan sí cubre los tests.
|
||||||
- `mago-baseline.toml` acepta los hallazgos de `mixed` inherentes a valores que vienen de PDO.
|
- `mago-baseline.toml` acepta los hallazgos de `mixed` inherentes a valores que vienen de PDO.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
Lightweight attribute-mapped Active Record ORM for MariaDB/MySQL over PDO.
|
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.4`, extensions `pdo_mysql` and `mbstring`
|
||||||
- **Runtime dependencies:** `psr/log` (PSR-3, optional usage). `brick/math` is a suggestion for
|
- **Runtime dependencies:** `psr/log` (PSR-3, optional usage). `brick/math` is a suggestion for
|
||||||
`BigDecimal` properties.
|
`BigDecimal` properties.
|
||||||
|
|
||||||
@@ -140,12 +140,12 @@ Configuration:
|
|||||||
|---|---|
|
|---|---|
|
||||||
| `mago.toml` | formatter, linter, analyzer |
|
| `mago.toml` | formatter, linter, analyzer |
|
||||||
| `mago-baseline.toml` | accepted analyzer findings (values coming from PDO) |
|
| `mago-baseline.toml` | accepted analyzer findings (values coming from PDO) |
|
||||||
| `phpstan.neon` | level 8, `phpVersion: 80300` |
|
| `phpstan.neon` | level 8, `phpVersion: 80400` |
|
||||||
| `phpunit.xml.dist` | unit suite |
|
| `phpunit.xml.dist` | unit suite |
|
||||||
| `phpunit.integration.xml.dist` | integration suite, skipped without `CAMELIA_TEST_DSN` |
|
| `phpunit.integration.xml.dist` | integration suite, skipped without `CAMELIA_TEST_DSN` |
|
||||||
|
|
||||||
`mago.toml` pins `php-version = "8.3"`. Do not raise it to 8.4: with 8.4 the formatter emits
|
`mago.toml` pins `php-version = "8.4"`, matching the minimum supported version, so `mago fmt` and
|
||||||
`new Foo()->bar()`, which the package cannot ship because it promises PHP 8.3 support.
|
the runtime agree on which syntax the package may ship.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -11,14 +11,14 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.3",
|
"php": ">=8.4",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
"psr/log": "^3.0"
|
"psr/log": "^3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"carthage-software/mago": "^1.60",
|
"carthage-software/mago": "^1.60",
|
||||||
"phpstan/phpstan": "^1.11",
|
"phpstan/phpstan": "2.3",
|
||||||
"phpunit/phpunit": "^10.5 || ^11.0"
|
"phpunit/phpunit": "^10.5 || ^11.0"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
|
|||||||
Generated
+18
-7
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "995f47882c4069e4904f4637e3219078",
|
"content-hash": "d7369cefc9ff778b213f99238b1f8f2d",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "psr/log",
|
"name": "psr/log",
|
||||||
@@ -359,15 +359,15 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpstan/phpstan",
|
"name": "phpstan/phpstan",
|
||||||
"version": "1.12.34",
|
"version": "2.3.0",
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/4dd89ca7aa30fdc6760be21550d583bcc32e8476",
|
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/b1f9890d9af53a25c58129e78f0aadd31f90d7f4",
|
||||||
"reference": "4dd89ca7aa30fdc6760be21550d583bcc32e8476",
|
"reference": "b1f9890d9af53a25c58129e78f0aadd31f90d7f4",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2|^8.0"
|
"php": "^7.4|^8.0"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"phpstan/phpstan-shim": "*"
|
"phpstan/phpstan-shim": "*"
|
||||||
@@ -386,6 +386,17 @@
|
|||||||
"license": [
|
"license": [
|
||||||
"MIT"
|
"MIT"
|
||||||
],
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Ondřej Mirtes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Markus Staab"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Vincent Langlet"
|
||||||
|
}
|
||||||
|
],
|
||||||
"description": "PHPStan - PHP Static Analysis Tool",
|
"description": "PHPStan - PHP Static Analysis Tool",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"dev",
|
"dev",
|
||||||
@@ -408,7 +419,7 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2026-07-28T10:04:39+00:00"
|
"time": "2026-10-06T06:15:36+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-code-coverage",
|
"name": "phpunit/php-code-coverage",
|
||||||
@@ -2018,7 +2029,7 @@
|
|||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": ">=8.3",
|
"php": ">=8.4",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"ext-pdo": "*"
|
"ext-pdo": "*"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
# Mago toolchain configuration — camelia/orm
|
# Mago toolchain configuration — camelia/orm
|
||||||
# Docs: https://mago.carthage.software
|
# Docs: https://mago.carthage.software
|
||||||
|
|
||||||
# The library promises PHP >= 8.3. Pinning the parser to 8.3 keeps the formatter from emitting
|
# The library promises PHP >= 8.4.
|
||||||
# syntax the package cannot ship (for example `new Foo()->bar()`, which needs 8.4).
|
php-version = "8.4"
|
||||||
php-version = "8.3"
|
|
||||||
|
|
||||||
[source]
|
[source]
|
||||||
paths = ["src", "tests"]
|
paths = ["src", "tests"]
|
||||||
|
|||||||
+2
-3
@@ -1,8 +1,7 @@
|
|||||||
parameters:
|
parameters:
|
||||||
level: 8
|
level: 8
|
||||||
# The library promises PHP >= 8.3, so analysis targets the oldest supported version.
|
# The library promises PHP >= 8.4, so analysis targets the only supported version.
|
||||||
# This is why `(new Foo())->bar()` keeps its parentheses: `new Foo()->bar()` only parses on 8.4+.
|
phpVersion: 80400
|
||||||
phpVersion: 80300
|
|
||||||
paths:
|
paths:
|
||||||
- src
|
- src
|
||||||
- tests
|
- tests
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ final class ConnectionFactory
|
|||||||
|
|
||||||
public static function fromEnvironment(): Connection
|
public static function fromEnvironment(): Connection
|
||||||
{
|
{
|
||||||
|
/** @var array<string, string> $values */
|
||||||
$values = [];
|
$values = [];
|
||||||
$missing = [];
|
$missing = [];
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ final class PdoConnection implements Connection
|
|||||||
/** @var array<string, PDOStatement> */
|
/** @var array<string, PDOStatement> */
|
||||||
private array $statements = [];
|
private array $statements = [];
|
||||||
|
|
||||||
/** @var list<string> LRU order, most recent last */
|
/** @var array<int, string> LRU order, most recent last; reindexed after eviction */
|
||||||
private array $lru = [];
|
private array $lru = [];
|
||||||
|
|
||||||
/** @var list<string> savepoint names for nested transactions */
|
/** @var list<string> savepoint names for nested transactions */
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ final class MetadataFactory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param class-string<\Camelia\Orm\Model> $class
|
* @param class-string<\Camelia\Orm\Model> $class
|
||||||
* @param ReflectionClass<object> $reflection
|
* @param ReflectionClass<\Camelia\Orm\Model> $reflection
|
||||||
*/
|
*/
|
||||||
private function buildProperty(
|
private function buildProperty(
|
||||||
string $class,
|
string $class,
|
||||||
@@ -169,7 +169,7 @@ final class MetadataFactory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param class-string<\Camelia\Orm\Model> $class
|
* @param class-string<\Camelia\Orm\Model> $class
|
||||||
* @param ReflectionClass<object> $reflection
|
* @param ReflectionClass<\Camelia\Orm\Model> $reflection
|
||||||
*/
|
*/
|
||||||
private function buildRelation(
|
private function buildRelation(
|
||||||
string $class,
|
string $class,
|
||||||
@@ -238,7 +238,7 @@ final class MetadataFactory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param class-string<\Camelia\Orm\Model> $class
|
* @param class-string<\Camelia\Orm\Model> $class
|
||||||
* @param ReflectionClass<object> $reflection
|
* @param ReflectionClass<\Camelia\Orm\Model> $reflection
|
||||||
* @return class-string<\Camelia\Orm\Model>
|
* @return class-string<\Camelia\Orm\Model>
|
||||||
*/
|
*/
|
||||||
private function resolveRelatedClass(
|
private function resolveRelatedClass(
|
||||||
|
|||||||
+3
-9
@@ -56,10 +56,7 @@ abstract class Model
|
|||||||
|
|
||||||
public static function metadata(): ClassMetadata
|
public static function metadata(): ClassMetadata
|
||||||
{
|
{
|
||||||
/** @var class-string<\Camelia\Orm\Model> $class */
|
return self::metadataFor(static::class);
|
||||||
$class = static::class;
|
|
||||||
|
|
||||||
return self::metadataFor($class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -193,7 +190,7 @@ abstract class Model
|
|||||||
*/
|
*/
|
||||||
public function validate(): array
|
public function validate(): array
|
||||||
{
|
{
|
||||||
return (new Validator())->validate($this);
|
return new Validator()->validate($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isValid(): bool
|
public function isValid(): bool
|
||||||
@@ -286,10 +283,7 @@ abstract class Model
|
|||||||
$errors = $this->validate();
|
$errors = $this->validate();
|
||||||
|
|
||||||
if ($errors !== []) {
|
if ($errors !== []) {
|
||||||
/** @var class-string<\Camelia\Orm\Model> $class */
|
throw new ValidationException($errors, static::class);
|
||||||
$class = static::class;
|
|
||||||
|
|
||||||
throw new ValidationException($errors, $class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -82,14 +82,17 @@ final class Orm
|
|||||||
*/
|
*/
|
||||||
public function repository(string $class): Repository
|
public function repository(string $class): Repository
|
||||||
{
|
{
|
||||||
/** @var Repository<T> $repository */
|
if (!isset($this->repositories[$class])) {
|
||||||
$repository =
|
$this->repositories[$class] = new Repository(
|
||||||
$this->repositories[$class] ??= new Repository(
|
|
||||||
$this->connection,
|
$this->connection,
|
||||||
$class,
|
$class,
|
||||||
$this->dialect,
|
$this->dialect,
|
||||||
$this->persister(),
|
$this->persister(),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Repository<T> $repository */
|
||||||
|
$repository = $this->repositories[$class];
|
||||||
|
|
||||||
return $repository;
|
return $repository;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,10 +303,7 @@ final class Persister
|
|||||||
private function assertNotPartial(Model $model, string $operation): void
|
private function assertNotPartial(Model $model, string $operation): void
|
||||||
{
|
{
|
||||||
if ($model->isPartial()) {
|
if ($model->isPartial()) {
|
||||||
/** @var class-string<\Camelia\Orm\Model> $class */
|
throw PartialModelException::onWrite($model::class, $operation);
|
||||||
$class = $model::class;
|
|
||||||
|
|
||||||
throw PartialModelException::onWrite($class, $operation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ final class QueryBuilder
|
|||||||
$table = $this->dialect->quoteIdentifier($metadata->table());
|
$table = $this->dialect->quoteIdentifier($metadata->table());
|
||||||
$list = $this->compileSelectList($metadata, $columns);
|
$list = $this->compileSelectList($metadata, $columns);
|
||||||
|
|
||||||
[$where, $params] = (new CriteriaCompiler($this->dialect))->compile($metadata, $criteria);
|
[$where, $params] = new CriteriaCompiler($this->dialect)->compile($metadata, $criteria);
|
||||||
|
|
||||||
$sql = 'SELECT ' . $list . ' FROM ' . $table;
|
$sql = 'SELECT ' . $list . ' FROM ' . $table;
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ final class QueryBuilder
|
|||||||
public function count(ClassMetadata $metadata, array $criteria): array
|
public function count(ClassMetadata $metadata, array $criteria): array
|
||||||
{
|
{
|
||||||
$table = $this->dialect->quoteIdentifier($metadata->table());
|
$table = $this->dialect->quoteIdentifier($metadata->table());
|
||||||
[$where, $params] = (new CriteriaCompiler($this->dialect))->compile($metadata, $criteria);
|
[$where, $params] = new CriteriaCompiler($this->dialect)->compile($metadata, $criteria);
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*) AS aggregate FROM ' . $table;
|
$sql = 'SELECT COUNT(*) AS aggregate FROM ' . $table;
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ final class QueryBuilder
|
|||||||
|
|
||||||
$quoted = $this->dialect->quoteIdentifier($metadata->propertyMetadata($property)->column);
|
$quoted = $this->dialect->quoteIdentifier($metadata->propertyMetadata($property)->column);
|
||||||
$table = $this->dialect->quoteIdentifier($metadata->table());
|
$table = $this->dialect->quoteIdentifier($metadata->table());
|
||||||
[$where, $params] = (new CriteriaCompiler($this->dialect))->compile($metadata, $criteria);
|
[$where, $params] = new CriteriaCompiler($this->dialect)->compile($metadata, $criteria);
|
||||||
|
|
||||||
$sql = 'SELECT ' . $function . '(' . $quoted . ') AS aggregate FROM ' . $table;
|
$sql = 'SELECT ' . $function . '(' . $quoted . ') AS aggregate FROM ' . $table;
|
||||||
|
|
||||||
|
|||||||
+5
-9
@@ -25,7 +25,7 @@ use Camelia\Orm\Support\TypeCaster;
|
|||||||
* Public read and write API for one model class.
|
* Public read and write API for one model class.
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
* @template T of Model
|
* @template-covariant T of Model
|
||||||
*/
|
*/
|
||||||
final class Repository
|
final class Repository
|
||||||
{
|
{
|
||||||
@@ -34,7 +34,7 @@ final class Repository
|
|||||||
private readonly QueryBuilder $builder;
|
private readonly QueryBuilder $builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param class-string<T> $class
|
* @param class-string<T> $class Not a field of the covariant template; kept for IDE inference.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Connection $connection,
|
private readonly Connection $connection,
|
||||||
@@ -726,7 +726,9 @@ final class Repository
|
|||||||
throw ConfigurationException::relationDepthExceeded(self::MAX_RELATION_DEPTH);
|
throw ConfigurationException::relationDepthExceeded(self::MAX_RELATION_DEPTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$metadata->hasProperty($name) || $metadata->properties()[$name]->relation === null) {
|
$relation = $metadata->hasProperty($name) ? $metadata->properties()[$name]->relation : null;
|
||||||
|
|
||||||
|
if ($relation === null) {
|
||||||
throw MetadataException::unknownRelation($metadata->class, $name);
|
throw MetadataException::unknownRelation($metadata->class, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,12 +736,6 @@ final class Repository
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relation = $metadata->properties()[$name]->relation;
|
|
||||||
|
|
||||||
if ($relation === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$next = $this->relatedRepository($relation->relatedClass)->metadata();
|
$next = $this->relatedRepository($relation->relatedClass)->metadata();
|
||||||
|
|
||||||
foreach ($nested as $key => $value) {
|
foreach ($nested as $key => $value) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_reads_table_and_primary_key(): void
|
public function it_reads_table_and_primary_key(): void
|
||||||
{
|
{
|
||||||
$metadata = (new MetadataFactory())->forClass(Usuario::class);
|
$metadata = new MetadataFactory()->forClass(Usuario::class);
|
||||||
|
|
||||||
self::assertSame('usuarios', $metadata->table());
|
self::assertSame('usuarios', $metadata->table());
|
||||||
self::assertSame('codigo', $metadata->primaryKey());
|
self::assertSame('codigo', $metadata->primaryKey());
|
||||||
@@ -33,7 +33,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_converts_property_names_to_columns(): void
|
public function it_converts_property_names_to_columns(): void
|
||||||
{
|
{
|
||||||
$metadata = (new MetadataFactory())->forClass(Usuario::class);
|
$metadata = new MetadataFactory()->forClass(Usuario::class);
|
||||||
|
|
||||||
self::assertSame('password_hash', $metadata->column('passwordHash'));
|
self::assertSame('password_hash', $metadata->column('passwordHash'));
|
||||||
self::assertSame('passwordHash', $metadata->property('password_hash'));
|
self::assertSame('passwordHash', $metadata->property('password_hash'));
|
||||||
@@ -43,7 +43,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_honours_an_explicit_column_name(): void
|
public function it_honours_an_explicit_column_name(): void
|
||||||
{
|
{
|
||||||
$metadata = (new MetadataFactory())->forClass(Factura::class);
|
$metadata = new MetadataFactory()->forClass(Factura::class);
|
||||||
|
|
||||||
self::assertSame('importe_total', $metadata->column('total'));
|
self::assertSame('importe_total', $metadata->column('total'));
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_excludes_relations_from_writable_columns(): void
|
public function it_excludes_relations_from_writable_columns(): void
|
||||||
{
|
{
|
||||||
$metadata = (new MetadataFactory())->forClass(Factura::class);
|
$metadata = new MetadataFactory()->forClass(Factura::class);
|
||||||
|
|
||||||
self::assertSame(['usuarioCodigo', 'total'], $metadata->writable());
|
self::assertSame(['usuarioCodigo', 'total'], $metadata->writable());
|
||||||
self::assertCount(2, $metadata->relations());
|
self::assertCount(2, $metadata->relations());
|
||||||
@@ -60,7 +60,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_resolves_belongs_to_metadata(): void
|
public function it_resolves_belongs_to_metadata(): void
|
||||||
{
|
{
|
||||||
$metadata = (new MetadataFactory())->forClass(Factura::class);
|
$metadata = new MetadataFactory()->forClass(Factura::class);
|
||||||
$relation = $metadata->properties()['usuario']->relation;
|
$relation = $metadata->properties()['usuario']->relation;
|
||||||
|
|
||||||
self::assertNotNull($relation);
|
self::assertNotNull($relation);
|
||||||
@@ -72,7 +72,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_resolves_belongs_to_many_pivot_metadata(): void
|
public function it_resolves_belongs_to_many_pivot_metadata(): void
|
||||||
{
|
{
|
||||||
$metadata = (new MetadataFactory())->forClass(Articulo::class);
|
$metadata = new MetadataFactory()->forClass(Articulo::class);
|
||||||
$relation = $metadata->properties()['etiquetas']->relation;
|
$relation = $metadata->properties()['etiquetas']->relation;
|
||||||
|
|
||||||
self::assertNotNull($relation);
|
self::assertNotNull($relation);
|
||||||
@@ -89,7 +89,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
$this->expectException(MetadataException::class);
|
$this->expectException(MetadataException::class);
|
||||||
$this->expectExceptionMessage('[M2]');
|
$this->expectExceptionMessage('[M2]');
|
||||||
|
|
||||||
(new MetadataFactory())->forClass(SinTableName::class);
|
new MetadataFactory()->forClass(SinTableName::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
@@ -98,7 +98,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
$this->expectException(MetadataException::class);
|
$this->expectException(MetadataException::class);
|
||||||
$this->expectExceptionMessage('[M3]');
|
$this->expectExceptionMessage('[M3]');
|
||||||
|
|
||||||
(new MetadataFactory())->forClass(SinPrimaryKey::class);
|
new MetadataFactory()->forClass(SinPrimaryKey::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
@@ -107,7 +107,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
$this->expectException(MetadataException::class);
|
$this->expectException(MetadataException::class);
|
||||||
$this->expectExceptionMessage('[M3]');
|
$this->expectExceptionMessage('[M3]');
|
||||||
|
|
||||||
(new MetadataFactory())->forClass(DosPrimaryKeys::class);
|
new MetadataFactory()->forClass(DosPrimaryKeys::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
@@ -116,7 +116,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
$this->expectException(MetadataException::class);
|
$this->expectException(MetadataException::class);
|
||||||
$this->expectExceptionMessage('[M4]');
|
$this->expectExceptionMessage('[M4]');
|
||||||
|
|
||||||
(new MetadataFactory())->forClass(SinTipo::class);
|
new MetadataFactory()->forClass(SinTipo::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
@@ -125,7 +125,7 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
$this->expectException(MetadataException::class);
|
$this->expectException(MetadataException::class);
|
||||||
$this->expectExceptionMessage('[M7]');
|
$this->expectExceptionMessage('[M7]');
|
||||||
|
|
||||||
(new MetadataFactory())->forClass(ColumnaDuplicada::class);
|
new MetadataFactory()->forClass(ColumnaDuplicada::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
@@ -134,6 +134,6 @@ final class MetadataFactoryTest extends TestCase
|
|||||||
$this->expectException(MetadataException::class);
|
$this->expectException(MetadataException::class);
|
||||||
$this->expectExceptionMessage('[M5]');
|
$this->expectExceptionMessage('[M5]');
|
||||||
|
|
||||||
(new MetadataFactory())->forClass(RelacionNoNulable::class);
|
new MetadataFactory()->forClass(RelacionNoNulable::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+13
-13
@@ -33,7 +33,7 @@ final class ModelTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_hydrates_by_property_name(): void
|
public function it_hydrates_by_property_name(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['nombre' => 'Ana', 'activo' => false]);
|
$usuario = new Usuario()->hydrate(['nombre' => 'Ana', 'activo' => false]);
|
||||||
|
|
||||||
self::assertSame('Ana', $usuario->nombre);
|
self::assertSame('Ana', $usuario->nombre);
|
||||||
self::assertFalse($usuario->activo);
|
self::assertFalse($usuario->activo);
|
||||||
@@ -42,7 +42,7 @@ final class ModelTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_hydrates_by_column_name(): void
|
public function it_hydrates_by_column_name(): void
|
||||||
{
|
{
|
||||||
$factura = (new Factura())->hydrate(['importe_total' => '12.5']);
|
$factura = new Factura()->hydrate(['importe_total' => '12.5']);
|
||||||
|
|
||||||
self::assertSame(12.5, $factura->total);
|
self::assertSame(12.5, $factura->total);
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ final class ModelTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_prefers_the_property_when_both_forms_are_present(): void
|
public function it_prefers_the_property_when_both_forms_are_present(): void
|
||||||
{
|
{
|
||||||
$factura = (new Factura())->hydrate(['total' => 1.0, 'importe_total' => 2.0]);
|
$factura = new Factura()->hydrate(['total' => 1.0, 'importe_total' => 2.0]);
|
||||||
|
|
||||||
self::assertSame(1.0, $factura->total);
|
self::assertSame(1.0, $factura->total);
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ final class ModelTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_skips_guarded_properties(): void
|
public function it_skips_guarded_properties(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['passwordHash' => 'secreto']);
|
$usuario = new Usuario()->hydrate(['passwordHash' => 'secreto']);
|
||||||
|
|
||||||
self::assertSame('', $usuario->passwordHash);
|
self::assertSame('', $usuario->passwordHash);
|
||||||
}
|
}
|
||||||
@@ -68,13 +68,13 @@ final class ModelTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException(\InvalidArgumentException::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
(new Usuario())->hydrateStrict(['passwordHash' => 'secreto']);
|
new Usuario()->hydrateStrict(['passwordHash' => 'secreto']);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function it_ignores_unknown_keys(): void
|
public function it_ignores_unknown_keys(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['inexistente' => 1, 'nombre' => 'Ana']);
|
$usuario = new Usuario()->hydrate(['inexistente' => 1, 'nombre' => 'Ana']);
|
||||||
|
|
||||||
self::assertSame('Ana', $usuario->nombre);
|
self::assertSame('Ana', $usuario->nombre);
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ final class ModelTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_never_hydrates_the_primary_key(): void
|
public function it_never_hydrates_the_primary_key(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['codigo' => 99]);
|
$usuario = new Usuario()->hydrate(['codigo' => 99]);
|
||||||
|
|
||||||
self::assertNull($usuario->codigo);
|
self::assertNull($usuario->codigo);
|
||||||
}
|
}
|
||||||
@@ -92,13 +92,13 @@ final class ModelTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException(\InvalidArgumentException::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
(new Usuario())->hydrate(['activo' => 'no-es-bool']);
|
new Usuario()->hydrate(['activo' => 'no-es-bool']);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function it_serializes_writable_columns_by_column_name(): void
|
public function it_serializes_writable_columns_by_column_name(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['nombre' => 'Ana']);
|
$usuario = new Usuario()->hydrate(['nombre' => 'Ana']);
|
||||||
$array = $usuario->toArray();
|
$array = $usuario->toArray();
|
||||||
|
|
||||||
self::assertSame('Ana', $array['nombre']);
|
self::assertSame('Ana', $array['nombre']);
|
||||||
@@ -109,7 +109,7 @@ final class ModelTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_serializes_json(): void
|
public function it_serializes_json(): void
|
||||||
{
|
{
|
||||||
$json = (new Usuario())->hydrate(['nombre' => 'Ana'])->toJson();
|
$json = new Usuario()->hydrate(['nombre' => 'Ana'])->toJson();
|
||||||
$decoded = json_decode($json, true);
|
$decoded = json_decode($json, true);
|
||||||
|
|
||||||
self::assertIsArray($decoded);
|
self::assertIsArray($decoded);
|
||||||
@@ -129,7 +129,7 @@ final class ModelTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_reports_a_too_long_value(): void
|
public function it_reports_a_too_long_value(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['clave' => 'supercalifragilistico']);
|
$usuario = new Usuario()->hydrate(['clave' => 'supercalifragilistico']);
|
||||||
|
|
||||||
self::assertStringContainsString('10', $usuario->validate()['clave'][0]);
|
self::assertStringContainsString('10', $usuario->validate()['clave'][0]);
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ final class ModelTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_is_valid_when_no_rule_fails(): void
|
public function it_is_valid_when_no_rule_fails(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['clave' => 'abc']);
|
$usuario = new Usuario()->hydrate(['clave' => 'abc']);
|
||||||
|
|
||||||
self::assertTrue($usuario->isValid());
|
self::assertTrue($usuario->isValid());
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ final class ModelTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_replicates_without_the_primary_key(): void
|
public function it_replicates_without_the_primary_key(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['nombre' => 'Ana']);
|
$usuario = new Usuario()->hydrate(['nombre' => 'Ana']);
|
||||||
$usuario->codigo = 5;
|
$usuario->codigo = 5;
|
||||||
|
|
||||||
$copy = $usuario->replicate();
|
$copy = $usuario->replicate();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ final class PersisterTest extends TestCase
|
|||||||
public function it_inserts_and_assigns_the_generated_key(): void
|
public function it_inserts_and_assigns_the_generated_key(): void
|
||||||
{
|
{
|
||||||
$this->connection->lastInsertId = '42';
|
$this->connection->lastInsertId = '42';
|
||||||
$usuario = (new Usuario())->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
$usuario = new Usuario()->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
||||||
|
|
||||||
$key = $this->persister->insert($usuario);
|
$key = $this->persister->insert($usuario);
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ final class PersisterTest extends TestCase
|
|||||||
public function it_only_writes_writable_columns(): void
|
public function it_only_writes_writable_columns(): void
|
||||||
{
|
{
|
||||||
$this->connection->lastInsertId = '1';
|
$this->connection->lastInsertId = '1';
|
||||||
$usuario = (new Usuario())->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
$usuario = new Usuario()->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
||||||
|
|
||||||
$this->persister->insert($usuario);
|
$this->persister->insert($usuario);
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ final class PersisterTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_saves_as_update_when_the_key_is_present(): void
|
public function it_saves_as_update_when_the_key_is_present(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
$usuario = new Usuario()->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
||||||
$usuario->codigo = 9;
|
$usuario->codigo = 9;
|
||||||
|
|
||||||
$this->persister->save($usuario);
|
$this->persister->save($usuario);
|
||||||
@@ -69,7 +69,7 @@ final class PersisterTest extends TestCase
|
|||||||
public function it_saves_as_insert_when_the_key_is_absent(): void
|
public function it_saves_as_insert_when_the_key_is_absent(): void
|
||||||
{
|
{
|
||||||
$this->connection->lastInsertId = '3';
|
$this->connection->lastInsertId = '3';
|
||||||
$usuario = (new Usuario())->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
$usuario = new Usuario()->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
||||||
|
|
||||||
$this->persister->save($usuario);
|
$this->persister->save($usuario);
|
||||||
|
|
||||||
@@ -81,13 +81,13 @@ final class PersisterTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException(ValidationException::class);
|
$this->expectException(ValidationException::class);
|
||||||
|
|
||||||
$this->persister->insert((new Usuario())->hydrate(['nombre' => 'Ana']));
|
$this->persister->insert(new Usuario()->hydrate(['nombre' => 'Ana']));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function it_refuses_to_write_a_partial_model(): void
|
public function it_refuses_to_write_a_partial_model(): void
|
||||||
{
|
{
|
||||||
$usuario = (new Usuario())->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
$usuario = new Usuario()->hydrate(['nombre' => 'Ana', 'clave' => 'abc']);
|
||||||
$usuario->codigo = 1;
|
$usuario->codigo = 1;
|
||||||
$usuario->markPartial();
|
$usuario->markPartial();
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ final class PersisterTest extends TestCase
|
|||||||
$listener,
|
$listener,
|
||||||
);
|
);
|
||||||
|
|
||||||
$persister->insert((new Usuario())->hydrate(['nombre' => 'Ana', 'clave' => 'abc']));
|
$persister->insert(new Usuario()->hydrate(['nombre' => 'Ana', 'clave' => 'abc']));
|
||||||
|
|
||||||
self::assertSame([['action' => 'insert', 'pk' => 7]], $listener->calls);
|
self::assertSame([['action' => 'insert', 'pk' => 7]], $listener->calls);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,6 +143,6 @@ final class CriteriaCompilerTest extends TestCase
|
|||||||
|
|
||||||
private function metadata(): \Camelia\Orm\Metadata\ClassMetadata
|
private function metadata(): \Camelia\Orm\Metadata\ClassMetadata
|
||||||
{
|
{
|
||||||
return (new MetadataFactory())->forClass(Usuario::class);
|
return new MetadataFactory()->forClass(Usuario::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ final class QueryBuilderTest extends TestCase
|
|||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->builder = new QueryBuilder(new MySqlDialect());
|
$this->builder = new QueryBuilder(new MySqlDialect());
|
||||||
$this->usuarios = (new MetadataFactory())->forClass(Usuario::class);
|
$this->usuarios = new MetadataFactory()->forClass(Usuario::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
@@ -42,7 +42,7 @@ final class QueryBuilderTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function it_excludes_relations_from_the_select_list(): void
|
public function it_excludes_relations_from_the_select_list(): void
|
||||||
{
|
{
|
||||||
$metadata = (new MetadataFactory())->forClass(Factura::class);
|
$metadata = new MetadataFactory()->forClass(Factura::class);
|
||||||
$compiled = $this->builder->select($metadata, []);
|
$compiled = $this->builder->select($metadata, []);
|
||||||
|
|
||||||
self::assertStringNotContainsString('`usuario`', $compiled['sql']);
|
self::assertStringNotContainsString('`usuario`', $compiled['sql']);
|
||||||
|
|||||||
Reference in new issue
Block a user