ILIAS  trunk Revision v11.0_alpha-2658-ge2404539063
SelectSettingTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 use stdClass;
31 
32 require_once __DIR__ . '/../ContainerMock.php';
33 
34 class 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