ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SelectSettingTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\LegalDocuments\test\ContainerMock;
28use PHPUnit\Framework\TestCase;
30use stdClass;
31
32require_once __DIR__ . '/../ContainerMock.php';
33
34class SelectSettingTest extends TestCase
35{
36 use ContainerMock;
37
38 public function testConstruct(): void
39 {
40 $this->assertInstanceOf(SelectSetting::class, new SelectSetting($this->mock(KeyValueStore::class), $this->mock(Marshal::class)));
41 }
42
43 public function testTyped(): void
44 {
45 $read_value = 'a value';
46 $write_value = 'some value';
47 $set_value = new stdClass();
48 $value = new stdClass();
49
50 $marshal = $this->mock(Marshal::class);
51 $convert = $this->mockTree(Convert::class, [
52 'fromString' => $this->mockMethod(Transformation::class, 'transform', [$read_value], $value),
53 'toString' => $this->mockMethod(Transformation::class, 'transform', [$set_value], $write_value),
54 ]);
55
56 $store = $this->mock(KeyValueStore::class);
57 $store->expects(self::once())->method('value')->with('foo')->willReturn($read_value);
58 $store->expects(self::once())->method('update')->with('foo', $write_value);
59
60 $instance = new SelectSetting($store, $marshal);
61 $setting = $instance->typed('foo', function (Marshal $m) use ($marshal, $convert): Convert {
62 $this->assertSame($marshal, $m);
63 return $convert;
64 });
65
66 $this->assertSame($value, $setting->value());
67 $setting->update($set_value);
68 }
69}
ilSetting $setting
Definition: class.ilias.php:68
A transformation is a function from one datatype to another.