Files
dgarcia 807992ecab
Tests / PHP 8.4 (push) Failing after 1m26s
refactor!: require PHP 8.4
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.
- Narrow ArrayGateway::count() to int, matching what the fixture actually returns.
- 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:17 -03:00

69 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Camelia\Controllers\Tests\Fixture;
use Camelia\Controllers\ResourceGateway;
/**
* In-memory gateway: the library's contract is testable without a database.
*/
final class ArrayGateway implements ResourceGateway
{
/** @param array<int|string, array<string, mixed>> $records */
public function __construct(
private array $records = [],
) {}
/** @return list<array<string, mixed>> */
public function findAll(array $query = []): array
{
return array_values($this->records);
}
/** @return array<string, mixed>|null */
public function find(int|string $id): ?array
{
return $this->records[$id] ?? null;
}
/** @return array<string, mixed> */
public function create(array $values): array
{
$id = count($this->records) + 1;
$record = ['id' => $id] + $values;
$this->records[$id] = $record;
return $record;
}
/** @return array<string, mixed>|null */
public function update(int|string $id, array $values): ?array
{
if (!isset($this->records[$id])) {
return null;
}
$this->records[$id] = ['id' => $id] + $values;
return $this->records[$id];
}
public function delete(int|string $id): bool
{
if (!isset($this->records[$id])) {
return false;
}
unset($this->records[$id]);
return true;
}
public function count(array $query = []): int
{
return count($this->records);
}
}