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\Matcher; |
12
|
|
|
|
13
|
|
|
use Rafrsr\LibArray2Object\Matcher\PropertyMatcherInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class PropertyMatcherTester. |
17
|
|
|
*/ |
18
|
|
|
abstract class PropertyMatcherTester extends \PHPUnit_Framework_TestCase |
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
|
|
|
} |
60
|
|
|
|
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.