Completed
Pull Request — master (#7)
by Markus
07:32
created

customFailureDescription()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 3
dl 16
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Agavi\Testing\PHPUnit\Constraint;
3
use Agavi\Controller\Controller;
4
use Agavi\Testing\BaseConstraintBecausePhpunitSucksAtBackwardsCompatibility;
5
6
7
8
/**
9
 * Constraint that checks if an Controller handles an expected request method.
10
 * 
11
 * The Controller instance is passed to the constructor.
12
 *
13
 * @package    agavi
14
 * @subpackage testing
15
 *
16
 * @author     Felix Gilcher <[email protected]>
17
 * @copyright  The Agavi Project
18
 *
19
 * @since      1.0.0
20
 *
21
 * @version    $Id$
22
 */
23
class ConstraintControllerHandlesMethod extends BaseConstraintBecausePhpunitSucksAtBackwardsCompatibility
24
{
25
	/**
26
	 * @var        Controller The Controller instance.
27
	 */
28
	protected $controllerInstance;
29
	
30
	/**
31
	 * @var        bool Whether generic 'execute' methods should be accepted.
32
	 */
33
	protected $acceptGeneric;
34
	
35
	/**
36
	 * Class constructor.
37
	 * 
38
	 * @param      Controller $controllerInstance Instance of the Controller to test.
39
	 * @param      bool   $acceptGeneric Whether generic execute methods should be accepted.
40
	 * 
41
	 * @author     Felix Gilcher <[email protected]>
42
	 * @since      1.0.0
43
	 */
44
	public function __construct(Controller $controllerInstance, $acceptGeneric = true)
45
	{
46
		$this->controllerInstance = $controllerInstance;
47
		$this->acceptGeneric = $acceptGeneric;
48
	}
49
	
50
	/**
51
	 * Evaluates the constraint for parameter $other. Returns TRUE if the
52
	 * constraint is met, FALSE otherwise.
53
	 *
54
	 * @param      mixed $other Value or object to evaluate.
55
	 *
56
	 * @return     bool The result of the evaluation.
57
	 * 
58
	 * @author     Felix Gilcher <[email protected]>
59
	 * @since      1.0.7
60
	 */
61 View Code Duplication
	public function matches($other)
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...
62
	{
63
		$executeMethod = 'execute' . $other;
64
		if(is_callable(array($this->controllerInstance, $executeMethod)) || ($this->acceptGeneric && is_callable(array($this->controllerInstance, 'execute')))) {
65
			return true;
66
		}
67
		
68
		return false;
69
	}
70
	
71
	/**
72
	 * Returns a string representation of the constraint.
73
	 *
74
	 * @return     string The string representation.
75
	 * 
76
	 * @author     Felix Gilcher <[email protected]>
77
	 * @since      1.0.0
78
	 */
79
	public function toString()
80
	{
81
		return sprintf(
82
			'%1$s handles method',
83
			get_class($this->controllerInstance)
84
		);
85
	}
86
	
87
	/**
88
	 * Returns a custom error description.
89
	 * 
90
	 * @param      mixed  $other Value or object to evaluate.
91
	 * @param      string $description The original description.
92
	 * @param      bool   $not true if the constraint was negated.
93
	 * 
94
	 * @return     string The error description.
95
	 * 
96
	 * @author     Felix Gilcher <[email protected]>
97
	 * @since      1.0.0
98
	 */
99 View Code Duplication
	protected function customFailureDescription($other, $description, $not)
0 ignored issues
show
Unused Code introduced by
The parameter $description is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
100
	{
101
		if($not) {
102
			return sprintf(
103
				'Failed asserting that %1$s does not handle method "%2$s".',
104
				get_class($this->controllerInstance),
105
				$other
106
			);
107
		} else {
108
			return sprintf(
109
				'Failed asserting that %1$s handles method "%2$s".',
110
				get_class($this->controllerInstance),
111
				$other
112
			);
113
		}
114
	}
115
}
116
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...