ObjectParserTest::testParse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the rafrsr/lib-array2object package.
5
 *
6
 * (c) Rafael SR <https://github.com/rafrsr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Rafrsr\LibArray2Object\Tests\Parser;
12
13
use Rafrsr\LibArray2Object\Array2ObjectContext;
14
use Rafrsr\LibArray2Object\Matcher\CamelizeMatcher;
15
use Rafrsr\LibArray2Object\Parser\ObjectParser;
16
use Rafrsr\LibArray2Object\Parser\StringParser;
17
use Rafrsr\LibArray2Object\Tests\Fixtures\Team;
18
use Rafrsr\LibArray2Object\Writer\AccessorWriter;
19
20
class ObjectParserTest extends \PHPUnit_Framework_TestCase
21
{
22
    public function testParse()
23
    {
24
        $context = new Array2ObjectContext();
25
        $context->setWriter(new AccessorWriter());
26
        $context->setMatcher(new CamelizeMatcher());
27
        $context->setParsers([new StringParser()]);
28
        $parser = new ObjectParser($context);
29
30
        $object = new Team();
31
        $property = new \ReflectionProperty(get_class($object), 'name');
32
33
        /** @var Team $team */
34
        $team = $parser->toObjectValue(['name' => 'New Name'], 'Team', $property, $object);
35
        static::assertInstanceOf(Team::class, $team);
36
        static::assertEquals('New Name', $team->getName());
37
    }
38
}
39