testGetSetPropertyMatcher()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
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;
12
13
use Rafrsr\LibArray2Object\Array2ObjectBuilder;
14
use Rafrsr\LibArray2Object\Array2ObjectContext;
15
use Rafrsr\LibArray2Object\Matcher\CamelizeMatcher;
16
use Rafrsr\LibArray2Object\Matcher\LevenshteinMatcher;
17
use Rafrsr\LibArray2Object\Parser\FloatParser;
18
use Rafrsr\LibArray2Object\Parser\IntegerParser;
19
use Rafrsr\LibArray2Object\Parser\StringParser;
20
use Rafrsr\LibArray2Object\Writer\AccessorWriter;
21
use Rafrsr\LibArray2Object\Writer\ReflectionWriter;
22
23
class Array2ObjectBuilderTest extends \PHPUnit_Framework_TestCase
24
{
25
    public function testCreate()
26
    {
27
        static::assertInstanceOf(Array2ObjectBuilder::class, Array2ObjectBuilder::create());
28
    }
29
30
    public function testGetSetContext()
31
    {
32
        $builder = Array2ObjectBuilder::create();
33
        $context = new Array2ObjectContext();
34
        $builder->setContext($context);
35
        static::assertEquals($context, $builder->getContext());
36
    }
37
38
    public function testGetSetParsers()
39
    {
40
        $builder = Array2ObjectBuilder::create();
41
        $parsers = [new StringParser(), new IntegerParser()];
42
        $builder->setParsers($parsers);
43
44
        static::assertEquals(['string' => new StringParser(), 'integer' => new IntegerParser()], $builder->getParsers());
45
46
        static::assertTrue($builder->hasParser('string'));
47
        static::assertTrue($builder->hasParser(new StringParser()));
48
        static::assertFalse($builder->hasParser(new FloatParser()));
49
50
        static::assertTrue($builder->hasParser('string'));
51
        $builder->removeParser('string');
52
        static::assertFalse($builder->hasParser('string'));
53
54
        static::assertTrue($builder->hasParser('integer'));
55
        $builder->removeParser(new IntegerParser());
56
        static::assertFalse($builder->hasParser('integer'));
57
58
        static::assertFalse($builder->hasParser('float'));
59
        $builder->addParser(new FloatParser());
60
        static::assertTrue($builder->hasParser('float'));
61
    }
62
63
    public function testDisableParsers()
64
    {
65
        $builder = Array2ObjectBuilder::create();
66
        $builder->disableParser(new StringParser());
67
        $builder->disableParser('integer');
68
        static::assertEquals(['string', 'integer'], $builder->getDisabledParsers());
69
    }
70
71 View Code Duplication
    public function testGetSetPropertyMatcher()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
    {
73
        $builder = Array2ObjectBuilder::create();
74
        $matcher = new CamelizeMatcher();
75
        $builder->setMatcher($matcher);
76
        static::assertEquals($matcher, $builder->getMatcher());
77
    }
78
79 View Code Duplication
    public function testGetSetPropertyWriter()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $builder = Array2ObjectBuilder::create();
82
        $writer = new AccessorWriter();
83
        $builder->setWriter($writer);
84
        static::assertEquals($writer, $builder->getWriter());
85
    }
86
87
    public function testBuild()
88
    {
89
        //build basic
90
        $builder = Array2ObjectBuilder::create();
91
        $array2Object = $builder->build();
92
93
        static::assertEquals($array2Object->getContext()->getMatcher(), new CamelizeMatcher());
94
        static::assertEquals($array2Object->getContext()->getWriter(), new AccessorWriter());
95
96
        $parsers = $array2Object->getContext()->getParsers();
97
98
        foreach ($parsers as $name => $parser) {
99
            $builder->disableParser($name);
100
        }
101
102
        $builder->setMatcher(new LevenshteinMatcher());
103
        $builder->setWriter(new ReflectionWriter());
104
105
        $array2Object = $builder->build();
106
107
        static::assertEquals($array2Object->getContext()->getMatcher(), new LevenshteinMatcher());
108
        static::assertEquals($array2Object->getContext()->getWriter(), new ReflectionWriter());
109
        static::assertEmpty($array2Object->getContext()->getParsers());
110
    }
111
}
112