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; |
11
|
|
|
|
12
|
|
|
use Rafrsr\LibArray2Object\Array2ObjectContext; |
13
|
|
|
use Rafrsr\LibArray2Object\Matcher\CamelizeMatcher; |
14
|
|
|
use Rafrsr\LibArray2Object\Parser\IntegerParser; |
15
|
|
|
use Rafrsr\LibArray2Object\Parser\StringParser; |
16
|
|
|
use Rafrsr\LibArray2Object\Writer\AccessorWriter; |
17
|
|
|
|
18
|
|
|
class Array2ObjectContextTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
View Code Duplication |
public function testGetSetParsers() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$context = new Array2ObjectContext(); |
23
|
|
|
$parsers = [new StringParser(), new IntegerParser()]; |
24
|
|
|
$context->setParsers($parsers); |
25
|
|
|
|
26
|
|
|
static::assertEquals(['string' => new StringParser(), 'integer' => new IntegerParser()], $context->getParsers()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
View Code Duplication |
public function testAppendParsers() |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$context = new Array2ObjectContext(); |
32
|
|
|
$parsers = [new StringParser()]; |
33
|
|
|
$context->setParsers($parsers); |
34
|
|
|
$context->appendParser(new IntegerParser()); |
35
|
|
|
static::assertEquals(['string' => new StringParser(), 'integer' => new IntegerParser()], $context->getParsers()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function testPrependParsers() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$context = new Array2ObjectContext(); |
41
|
|
|
$parsers = [new StringParser(), new IntegerParser()]; |
42
|
|
|
$context->setParsers($parsers); |
43
|
|
|
$context->prependParser(new IntegerParser()); |
44
|
|
|
static::assertEquals(['integer' => new IntegerParser(), 'string' => new StringParser()], $context->getParsers()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testGetSetPropertyMatcher() |
48
|
|
|
{ |
49
|
|
|
$context = new Array2ObjectContext(); |
50
|
|
|
$matcher = new CamelizeMatcher(); |
51
|
|
|
$context->setMatcher($matcher); |
52
|
|
|
static::assertEquals($matcher, $context->getMatcher()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testGetSetPropertyWriter() |
56
|
|
|
{ |
57
|
|
|
$context = new Array2ObjectContext(); |
58
|
|
|
$writer = new AccessorWriter(); |
59
|
|
|
$context->setWriter($writer); |
60
|
|
|
static::assertEquals($writer, $context->getWriter()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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.