1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Prophecy\Argument\Token; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Prophecy\Argument\Token\ExactValueToken; |
7
|
|
|
|
8
|
|
|
class ExactValueTokenTest extends TestCase { |
9
|
|
|
/** |
10
|
|
|
* @test |
11
|
|
|
* @see https://github.com/phpspec/prophecy/issues/268 |
12
|
|
|
* @see https://stackoverflow.com/a/19097159/2424814 |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
public function does_not_trigger_nesting_error() { |
|
|
|
|
15
|
|
|
$child1 = new ChildClass('A', new ParentClass()); |
16
|
|
|
$child2 = new ChildClass('B', new ParentClass()); |
17
|
|
|
|
18
|
|
|
$exactValueToken = new ExactValueToken($child1); |
19
|
|
|
self::assertEquals(false, $exactValueToken->scoreArgument($child2)); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @test |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
public function scores_10_for_objects_with_same_fields() { |
|
|
|
|
26
|
|
|
$child1 = new ChildClass('A', new ParentClass()); |
27
|
|
|
$child2 = new ChildClass('A', new ParentClass()); |
28
|
|
|
|
29
|
|
|
$exactValueToken = new ExactValueToken($child1); |
30
|
|
|
self::assertEquals(10, $exactValueToken->scoreArgument($child2)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function scores_false_for_object_and_string() { |
37
|
|
|
$child1 = new ChildClass('A', new ParentClass()); |
38
|
|
|
|
39
|
|
|
$exactValueToken = new ExactValueToken($child1); |
40
|
|
|
self::assertEquals(false, $exactValueToken->scoreArgument("A")); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
*/ |
46
|
|
|
public function scores_false_for_object_and_int() { |
47
|
|
|
$child1 = new ChildClass('A', new ParentClass()); |
48
|
|
|
|
49
|
|
|
$exactValueToken = new ExactValueToken($child1); |
50
|
|
|
self::assertEquals(false, $exactValueToken->scoreArgument(100)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @test |
55
|
|
|
*/ |
56
|
|
|
public function scores_false_for_object_and_stdclass() { |
57
|
|
|
$child1 = new ChildClass('A', new ParentClass()); |
58
|
|
|
|
59
|
|
|
$exactValueToken = new ExactValueToken($child1); |
60
|
|
|
self::assertEquals(false, $exactValueToken->scoreArgument(new \stdClass())); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @test |
65
|
|
|
*/ |
66
|
|
|
public function scores_false_for_object_and_null() { |
67
|
|
|
$child1 = new ChildClass('A', new ParentClass()); |
68
|
|
|
|
69
|
|
|
$exactValueToken = new ExactValueToken($child1); |
70
|
|
|
self::assertEquals(false, $exactValueToken->scoreArgument(null)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
class ParentClass { |
77
|
|
|
|
78
|
|
|
public $children = array(); |
79
|
|
|
|
80
|
|
|
public function addChild($child) { |
81
|
|
|
$this->children[] = $child; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
class ChildClass { |
86
|
|
|
|
87
|
|
|
public $parent = null; |
88
|
|
|
public $name = null; |
89
|
|
|
|
90
|
|
|
public function __construct($name, $parent) { |
91
|
|
|
$this->name = $name; |
92
|
|
|
$this->parent = $parent; |
93
|
|
|
$this->parent->addChild($this); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
} |
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.