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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Constraint for testing the configuration values
*
*
*/
class EcomDev_PHPUnit_Constraint_Config extends PHPUnit_Framework_Constraint
{
/**
* Configuration instance
*
* @var Varien_Simplexml_Config
*/
protected $config = null;
/**
* Configuration constraint
*
* @var PHPUnit_Framework_Constraint
*/
protected $constraint = null;
/**
* Creates configuration constraint for config object
*
* @param Varien_Simplexml_Config $config
*/
public function __construct($constraint)
{
if (!$constraint instanceof EcomDev_PHPUnit_Constraint_Config_Interface) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(
1, 'EcomDev_PHPUnit_Constraint_Config_Interface'
);
}
$this->constraint = $constraint;
}
/**
*
* @param mixed $other
* @param string $description
* @param boolean $not
*/
public function fail($other, $description, $not)
{
$nodeValue = $this->getNodeValue($other);
return $this->constraint->fail($nodeValue, $description, $not);
}
/**
* Retrives a node value from configuration by child constraint path
*
*
* @param Varien_Simplexml_Config $other
*/
protected function getNodeValue($config)
{
$nodeValue = $config->getNode(
$this->constraint->getNodePath()
);
if ($nodeValue === false) {
throw new EcomDev_PHPUnit_Constraint_Exception(
sprintf('Invalid node path specified for evaluation %s', $this->constraint->getNodePath())
);
}
return $nodeValue;
}
/**
* Evalutes constraint that is passed in the parameter
*
* @param Varien_Simplexml_Config $config
* @see PHPUnit_Framework_Constraint::evaluate()
*/
public function evaluate($config, $description = '', $returnResult = false)
{
$nodeValue = $this->getNodeValue($config);
return $this->constraint->evaluate($nodeValue, $description, $returnResult);
}
/**
* Returns a string representation of the constraint.
*
* @return string
*/
public function toString()
{
return $this->constraint->toString();
}
}