ObjectParserTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 7
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testParse() 0 16 1
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