19declare(strict_types=1);
25use ILIAS\Tests\KeyValueStorage\RefineryHelper;
26use PHPUnit\Framework\Attributes\DataProvider;
27use PHPUnit\Framework\TestCase;
35 protected function setUp(): void
40 #[DataProvider('roundTrippableValues')]
43 $this->assertSame($value, $this->values->decode($this->values->encode($value)));
57 'string' => [
'title'],
58 'empty string' => [
''],
59 'list' => [[
'a',
'b']],
60 'map' => [[
'sort' =>
'title',
'direction' =>
'asc']],
61 'nested' => [[
'filter' => [
'status' => [
'open',
'closed'],
'limit' => 10]]],
62 'empty array' => [[]],
68 $value =
new class () implements \JsonSerializable {
72 public function jsonSerialize(): array
78 $this->assertSame(
'{"a":1}', $this->values->encode($value));
79 $this->assertSame([
'a' => 1], $this->values->decode($this->values->encode($value)));
84 $value =
new class () implements \JsonSerializable {
85 public function jsonSerialize():
string
91 $this->assertSame(
'title', $this->values->decode($this->values->encode($value)));
96 $inner =
new class () implements \JsonSerializable {
100 public function jsonSerialize(): array
107 [
'wrapped' => [
'a' => 1]],
108 $this->values->decode($this->values->encode([
'wrapped' => $inner]))
114 $value =
new class () implements \JsonSerializable {
118 public function jsonSerialize(): array
120 return [
'bad' => new \stdClass()];
124 $this->expectException(\InvalidArgumentException::class);
126 $this->values->encode($value);
129 #[DataProvider('unstorableValues')]
132 $this->expectException(\InvalidArgumentException::class);
134 $this->values->encode($value);
143 'plain object' => [new \stdClass()],
144 'object in array' => [[
'a' => new \stdClass()]],
145 'closure' => [
static fn() =>
null],
146 'not a number' => [NAN],
152 $this->expectException(InvalidStoredValueException::class);
154 $this->values->decode(
'{not json');
A stored value could not be read back, e.g.
Translates between the values a consumer works with and the strings a repository stores.
testUnstorableValuesAreRejected(mixed $value)
testAJsonSerializableMayReturnAScalar()
testAJsonSerializableInsideAnArrayIsAccepted()
testJsonSerializableIsStoredAsItsJsonForm()
static unstorableValues()
testAJsonSerializableReturningSomethingUnstorableIsRejected()
static roundTrippableValues()
testValuesSurviveARoundTrip(mixed $value)
testStoredGarbageIsReported()