Completed
Push — master ( 765465...c6a31f )
by Ciaran
02:11 queued 11s
created

ParentClass::addChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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
}