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