ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
KeyValueAccessTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Tests\Refinery;
22
24use ILIAS\Refinery\Factory as Refinery;
26use PHPUnit\Framework\TestCase as PHPUnitTestCase;
27use ILIAS\Data\Factory as DataFactory;
28
30{
32
33 protected function setUp(): void
34 {
35 $this->refinery = new Refinery(new DataFactory(), $this->createMock(Language::class));
36 }
37
38 public function testAccess(): void
39 {
40 $array = [
41 'key_one' => '1',
42 'key_two' => '2',
43 'key_three' => '3',
44 ];
45
46 $kv = new KeyValueAccess($array, $this->refinery->kindlyTo()->int());
47
48 $this->assertEquals(3, $kv->count());
49 $this->assertEquals(1, $kv['key_one']);
50 $this->assertEquals(2, $kv['key_two']);
51 $this->assertEquals(3, $kv['key_three']);
52 $this->assertEquals(null, $kv['key_four']);
53 }
54
55 public function testRecursion(): void
56 {
57 $array = [
58 'key_one' => '1',
59 'key_two' => [
60 'sub_key_one' => '1',
61 'sub_key_two' => [
62 'sub_sub_key_one' => '1',
63 ],
64 ]
65 ];
66
67 $kv = new KeyValueAccess($array, $this->refinery->kindlyTo()->int());
68 $this->assertEquals(2, $kv->count());
69 $this->assertEquals(1, $kv['key_two']['sub_key_one']);
70 $this->assertEquals(1, $kv['key_two']['sub_key_two']['sub_sub_key_one']);
71 }
72}
Builds data types.
Definition: Factory.php:36