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\Matcher; |
11
|
|
|
|
12
|
|
|
use Rafrsr\LibArray2Object\Matcher\PropertyMatcherInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class PropertyMatcherTester |
16
|
|
|
*/ |
17
|
|
|
abstract class PropertyMatcherTester extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
public function testMatch() |
21
|
|
|
{ |
22
|
|
|
$matcher = $this->buildMatcher(); |
23
|
|
|
|
24
|
|
View Code Duplication |
foreach ($this->getEquals() as $prop => $given) { |
|
|
|
|
25
|
|
|
$property = static::getMockBuilder(\ReflectionProperty::class)->disableOriginalConstructor()->getMock(); |
26
|
|
|
$property->expects(static::any())->method('getName')->willReturn($prop); |
27
|
|
|
$msg = sprintf("property '%s' not match with '%s'", $prop, $given); |
28
|
|
|
static::assertTrue($matcher->match($property, $given), $msg); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
foreach ($this->getNotEquals() as $prop => $given) { |
|
|
|
|
32
|
|
|
$property = static::getMockBuilder(\ReflectionProperty::class)->disableOriginalConstructor()->getMock(); |
33
|
|
|
$property->expects(static::any())->method('getName')->willReturn($prop); |
34
|
|
|
$msg = sprintf("property '%s' match with '%s'", $prop, $given); |
35
|
|
|
static::assertFalse($matcher->match($property, $given), $msg); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* buildMatcher |
41
|
|
|
* |
42
|
|
|
* @return PropertyMatcherInterface |
43
|
|
|
*/ |
44
|
|
|
abstract public function buildMatcher(); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* getEquals |
48
|
|
|
* |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
abstract public function getEquals(); |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* getNotEquals |
55
|
|
|
* |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
abstract public function getNotEquals(); |
59
|
|
|
} |
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.