ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
MarshalTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 use ILIAS\Refinery\In\Group as In;
32 
33 require_once __DIR__ . '/../ContainerMock.php';
34 
35 class MarshalTest extends TestCase
36 {
37  use ContainerMock;
38 
39  public function testConstruct(): void
40  {
41  $this->assertInstanceOf(Marshal::class, new Marshal($this->mock(Refinery::class)));
42  }
43 
44  public function testDateTime(): void
45  {
46  $from = $this->mock(Transformation::class);
47  $custom = $this->mock(Transformation::class);
48  $date = $this->mock(Transformation::class);
49 
50  $refinery = $this->mockTree(Refinery::class, [
51  'in' => $this->mockMethod(In::class, 'series', [[$custom, $date]], $from),
52  'custom' => ['transformation' => $custom],
53  'to' => ['dateTime' => $date],
54  ]);
55 
56  $convert = (new Marshal($refinery))->dateTime();
57  $this->assertSame($from, $convert->fromString());
58  $this->assertSame($custom, $convert->toString());
59  }
60 
61  public function testBoolean(): void
62  {
63  $from = $this->mock(ByTrying::class);
64  $custom = $this->mock(Transformation::class);
65  $bool = $this->mock(Transformation::class);
66  $to = $this->mock(Transformation::class);
67 
68  $refinery = $this->mockTree(Refinery::class, [
69  'custom' => ['transformation' => $custom],
70  'kindlyTo' => ['string' => $to, 'bool' => $bool],
71  ]);
72  $refinery->expects(self::once())->method('byTrying')->with([$bool, $custom])->willReturn($from);
73 
74  $convert = (new Marshal($refinery))->boolean();
75  $this->assertSame($from, $convert->fromString());
76  $this->assertSame($to, $convert->toString());
77  }
78 
79  public function testNullable(): void
80  {
81  $decorate = $this->mockTree(Convert::class, [
82  'fromString' => $this->mock(Transformation::class),
83  'toString' => $this->mock(Transformation::class),
84  ]);
85 
86  $by_trying = $this->mock(ByTrying::class);
87  $nice_null = $this->mock(Transformation::class);
88  $null = $this->mock(Constraint::class);
89  $always = $this->mock(Transformation::class);
90  $series = $this->mock(Transformation::class);
91 
92  $refinery = $this->mockTree(Refinery::class, [
93  'kindlyTo' => ['null' => $nice_null],
94  'in' => $this->mockMethod(In::class, 'series', [[$null, $always]], $series),
95  'always' => $always,
96  'null' => $null,
97  ]);
98  $consecutive = [[$nice_null, $decorate->fromString()], [$series, $decorate->toString()]];
99  $refinery->expects(self::exactly(2))->method('byTrying')->with(
100  $this->callback(function ($value) use (&$consecutive) {
101  $this->assertSame(array_shift($consecutive), $value);
102  return true;
103  })
104  )->willReturn($by_trying);
105 
106  $convert = (new Marshal($refinery))->nullable($decorate);
107  $this->assertSame($by_trying, $convert->fromString());
108  $this->assertSame($by_trying, $convert->toString());
109  }
110 
111  public function testString(): void
112  {
113  $id = $this->mock(Transformation::class);
114 
115  $convert = (new Marshal($this->mockTree(Refinery::class, ['identity' => $id])))->string();
116  $this->assertSame($id, $convert->fromString());
117  $this->assertSame($id, $convert->toString());
118  }
119 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23