-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDomainRule.php
More file actions
90 lines (76 loc) · 2.02 KB
/
Copy pathDomainRule.php
File metadata and controls
90 lines (76 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Codeception;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
class DomainRule extends Constraint
{
/**
* @var string rule
*/
protected $rule;
/**
* @var ExpressionLanguage
*/
protected $language;
/**
* @var array
*/
protected $values = [];
public function __construct($rule, array $values = array())
{
if (method_exists(Constraint::class, '__construct')) {
//PHPUnit 7 compatibility
parent::__construct();
}
$this->language = new ExpressionLanguage();
$this->rule = $rule;
$this->values = $values;
}
/**
* @return ExpressionLanguage
*/
public function getLanguage(): ExpressionLanguage
{
return $this->language;
}
private function convertOtherToArray($other)
{
if ($other == null) {
return $this->values;
}
if (!is_array($other)) {
return $this->values['expected'] = $other;
}
return array_merge($other, $this->values);
}
protected function matches($other): bool
{
return $this->language->evaluate($this->rule, $this->convertOtherToArray($other));
}
protected function failureDescription($other): string
{
return '`' . $this->rule . '`';
}
protected function additionalFailureDescription($other): string
{
$values = $this->convertOtherToArray($other);
if (empty($values)) {
return '';
}
$varString = '';
if (isset($this->exporter)) {
//PHPUnit 7 compatibility
$exporter = $this->exporter;
} else {
$exporter = $this->exporter();
}
foreach ($values as $key => $value) {
$varString .= "[$key]: " . $exporter->export($value) . "\n";
}
return $varString;
}
public function toString(): string
{
return "Expression " . $this->rule;
}
}