11<?php
2-
2+ /**
3+ * This file is part of event-engine/php-data.
4+ * (c) 2018-2020 prooph software GmbH <contact@prooph.de>
5+ *
6+ * For the full copyright and license information, please view the LICENSE
7+ * file that was distributed with this source code.
8+ */
39declare (strict_types=1 );
410
511namespace EventEngineTest \Data ;
612
13+ use EventEngineTest \Data \Stub \ImmutableItem ;
714use EventEngineTest \Data \Stub \ImmutableRecordWithNoTypes ;
815use EventEngineTest \Data \Stub \ImmutableRecordWithTypedGetters ;
916use EventEngineTest \Data \Stub \TypeHintedImmutableRecord ;
17+ use EventEngineTest \Data \Stub \TypeHintedImmutableRecordWithValueObjects ;
18+ use EventEngineTest \Data \Stub \ValueObject \Access ;
19+ use EventEngineTest \Data \Stub \ValueObject \ItemList ;
20+ use EventEngineTest \Data \Stub \ValueObject \Name ;
21+ use EventEngineTest \Data \Stub \ValueObject \Percentage ;
22+ use EventEngineTest \Data \Stub \ValueObject \Type ;
23+ use EventEngineTest \Data \Stub \ValueObject \Version ;
1024use PHPUnit \Framework \TestCase ;
1125
1226final class ImmutableRecordLogicTest extends TestCase
@@ -20,6 +34,8 @@ protected function setUp()
2034 $ this ->data = [
2135 'name ' => 'test ' ,
2236 'version ' => 1 ,
37+ 'itemList ' => [['name ' => 'one ' ]],
38+ 'access ' => true ,
2339 ];
2440 }
2541
@@ -31,6 +47,7 @@ public function it_detects_type_hinted_properties()
3147 $ typeHinted = TypeHintedImmutableRecord::fromArray ($ this ->data );
3248
3349 $ this ->data ['type ' ] = null ;
50+ $ this ->data ['percentage ' ] = 0.5 ;
3451
3552 $ this ->assertEquals (
3653 $ this ->data ,
@@ -46,13 +63,53 @@ public function it_detects_coupled_getters_for_properties()
4663 $ typedGetters = ImmutableRecordWithTypedGetters::fromArray ($ this ->data );
4764
4865 $ this ->data ['type ' ] = null ;
66+ $ this ->data ['percentage ' ] = 0.5 ;
4967
5068 $ this ->assertEquals (
5169 $ this ->data ,
5270 $ typedGetters ->toArray ()
5371 );
5472 }
5573
74+ /**
75+ * @test
76+ */
77+ public function it_can_handle_value_objects ()
78+ {
79+ $ valueObjects = TypeHintedImmutableRecordWithValueObjects::fromArray ($ this ->data );
80+
81+ $ this ->data ['type ' ] = null ;
82+ $ this ->data ['percentage ' ] = 0.5 ;
83+
84+ $ this ->assertEquals (
85+ $ this ->data ,
86+ $ valueObjects ->toArray ()
87+ );
88+ }
89+
90+ /**
91+ * @test
92+ */
93+ public function it_takes_value_object_as_initialization_params ()
94+ {
95+ $ valueObjects = TypeHintedImmutableRecordWithValueObjects::fromRecordData ([
96+ 'name ' => Name::fromString ($ this ->data ['name ' ]),
97+ 'type ' => Type::fromString ('value_object ' ),
98+ 'version ' => Version::fromInt ($ this ->data ['version ' ]),
99+ 'access ' => Access::fromBool ($ this ->data ['access ' ]),
100+ 'percentage ' => Percentage::fromFloat (0.9 ),
101+ 'itemList ' => ItemList::fromItems (ImmutableItem::fromRecordData (['name ' => 'one ' ])),
102+ ]);
103+
104+ $ this ->data ['type ' ] = 'value_object ' ;
105+ $ this ->data ['percentage ' ] = 0.9 ;
106+
107+ $ this ->assertEquals (
108+ $ this ->data ,
109+ $ valueObjects ->toArray ()
110+ );
111+ }
112+
56113 /**
57114 * @test
58115 */
0 commit comments