Completed
Push — master ( fef923...c0df34 )
by Rafael
03:03
created

ObjectParserTest::testParse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
/**
4
 * LICENSE: This file is subject to the terms and conditions defined in
5
 * file 'LICENSE', which is part of this source code package.
6
 *
7
 * @copyright 2016 Copyright(c) - All rights reserved.
8
 */
9
10
namespace Rafrsr\LibArray2Object\Tests\Parser;
11
12
use Rafrsr\LibArray2Object\Array2ObjectContext;
13
use Rafrsr\LibArray2Object\Matcher\CamelizeMatcher;
14
use Rafrsr\LibArray2Object\Parser\ObjectParser;
15
use Rafrsr\LibArray2Object\Parser\StringParser;
16
use Rafrsr\LibArray2Object\Tests\Fixtures\Team;
17
use Rafrsr\LibArray2Object\Writer\AccessorWriter;
18
19
class ObjectParserTest extends \PHPUnit_Framework_TestCase
20
{
21
    public function testParse()
22
    {
23
        $context = new Array2ObjectContext();
24
        $context->setWriter(new AccessorWriter());
25
        $context->setMatcher(new CamelizeMatcher());
26
        $context->setParsers([new StringParser()]);
27
        $parser = new ObjectParser($context);
28
29
        $object = new Team();
30
        $property = new \ReflectionProperty(get_class($object), 'name');
31
32
        /** @var Team $team */
33
        $team = $parser->parseValue(['name' => 'New Name'], 'Team', $property, $object);
34
        static::assertInstanceOf(Team::class, $team);
35
        static::assertEquals('New Name', $team->getName());
36
    }
37
}
38