Conditions | 1 |
Paths | 1 |
Total Lines | 21 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | public function testShouldMapFromAnotherValue() |
||
12 | { |
||
13 | // arrange |
||
14 | $engine = $this->createEngine(); |
||
15 | $engine->createMap(User::className(), UserDTO::className()) |
||
16 | ->forMember('fullName', new MapFrom(function(User $source) { |
||
17 | return $source->firstName . ' ' . $source->lastName; |
||
18 | })) |
||
19 | ->forMember('numberOfYears', new MapFrom('age')); |
||
20 | |||
21 | $user = new User(); |
||
22 | $user->firstName = 'John'; |
||
23 | $user->lastName = 'Smith'; |
||
24 | $user->age = 26; |
||
25 | // act |
||
26 | /** @var UserDTO $dest */ |
||
27 | $dest = $engine->map($user)->toType(UserDTO::className()); |
||
28 | // assert |
||
29 | $this->assertEquals('John Smith', $dest->fullName); |
||
30 | $this->assertEquals(26, $dest->numberOfYears); |
||
31 | } |
||
32 | } |
||
46 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.