|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of expect package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Noritaka Horio <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace expect\matcher; |
|
12
|
|
|
|
|
13
|
|
|
use expect\FailedMessage; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Verify whether equivalent. |
|
17
|
|
|
* |
|
18
|
|
|
* <code> |
|
19
|
|
|
* $matcher = new ToEqual(100); |
|
20
|
|
|
* $matcher->match(100); //return true |
|
21
|
|
|
* |
|
22
|
|
|
* $matcher = new ToEqual(100); |
|
23
|
|
|
* $matcher->match(99); //return false |
|
24
|
|
|
* <code> |
|
25
|
|
|
* |
|
26
|
|
|
* @author Noritaka Horio <[email protected]> |
|
27
|
|
|
* @copyright Noritaka Horio <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
final class ToEqual implements ReportableMatcher |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @var mixed |
|
33
|
|
|
*/ |
|
34
|
|
|
private $actual; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var mixed |
|
38
|
|
|
*/ |
|
39
|
|
|
private $expected; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param mixed $expected expected value |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct($expected) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->expected = $expected; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function match($actual) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->actual = $actual; |
|
55
|
|
|
|
|
56
|
|
|
return $this->actual === $this->expected; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
View Code Duplication |
public function reportFailed(FailedMessage $message) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
$message->appendText("Expected ") |
|
65
|
|
|
->appendValue($this->actual) |
|
66
|
|
|
->appendText(' to be ') |
|
67
|
|
|
->appendValue($this->expected) |
|
68
|
|
|
->appendText("\n\n") |
|
69
|
|
|
->appendText(' expected: ') |
|
70
|
|
|
->appendValue($this->expected) |
|
71
|
|
|
->appendText("\n") |
|
72
|
|
|
->appendText(' got: ') |
|
73
|
|
|
->appendValue($this->actual); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
|
View Code Duplication |
public function reportNegativeFailed(FailedMessage $message) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
$message->appendText("Expected ") |
|
82
|
|
|
->appendValue($this->actual) |
|
83
|
|
|
->appendText(' not to be ') |
|
84
|
|
|
->appendValue($this->expected) |
|
85
|
|
|
->appendText("\n\n") |
|
86
|
|
|
->appendText(' expected not: ') |
|
87
|
|
|
->appendValue($this->expected) |
|
88
|
|
|
->appendText("\n") |
|
89
|
|
|
->appendText(' got: ') |
|
90
|
|
|
->appendValue($this->actual); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
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.