|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ownCloud |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Alessandro Cosentino <[email protected]> |
|
9
|
|
|
* @author Bernhard Posselt <[email protected]> |
|
10
|
|
|
* @copyright Alessandro Cosentino 2012 |
|
11
|
|
|
* @copyright Bernhard Posselt 2012, 2014 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace OCA\Music\AppFramework\Utility; |
|
15
|
|
|
|
|
16
|
|
|
use OCP\AppFramework\Http\Response; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Simple utility class for testing controllers |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class ControllerTestUtility extends \PHPUnit_Framework_TestCase { |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Checks if a controllermethod has the expected annotations |
|
25
|
|
|
* @param Controller|string $controller name or instance of the controller |
|
26
|
|
|
* @param array $expected an array containing the expected annotations |
|
27
|
|
|
* @param array $valid if you define your own annotations, pass them here |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function assertAnnotations($controller, $method, array $expected, |
|
30
|
|
|
array $valid=[]) { |
|
31
|
|
|
$standard = [ |
|
32
|
|
|
'PublicPage', |
|
33
|
|
|
'NoAdminRequired', |
|
34
|
|
|
'NoCSRFRequired', |
|
35
|
|
|
'API' |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
$possible = \array_merge($standard, $valid); |
|
39
|
|
|
|
|
40
|
|
|
// check if expected annotations are valid |
|
41
|
|
|
foreach ($expected as $annotation) { |
|
42
|
|
|
$this->assertTrue(\in_array($annotation, $possible)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$reader = new MethodAnnotationReader($controller, $method); |
|
46
|
|
|
foreach ($expected as $annotation) { |
|
47
|
|
|
$this->assertTrue($reader->hasAnnotation($annotation)); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Shortcut for testing expected headers of a response |
|
53
|
|
|
* @param array $expected an array with the expected headers |
|
54
|
|
|
* @param Response $response the response which we want to test for headers |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function assertHeaders(array $expected=[], Response $response) { |
|
57
|
|
|
$headers = $response->getHeaders(); |
|
58
|
|
|
foreach ($expected as $header) { |
|
59
|
|
|
$this->assertTrue(\in_array($header, $headers)); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Instead of using positional parameters this function instantiates |
|
65
|
|
|
* a request by using a hashmap so its easier to only set specific params |
|
66
|
|
|
* @param array $params a hashmap with the parameters for request |
|
67
|
|
|
* @return Request a request instance |
|
|
|
|
|
|
68
|
|
|
*/ |
|
69
|
|
|
protected function getRequest(array $params=[]) { |
|
70
|
|
|
$mock = $this->getMockBuilder('\OCP\IRequest') |
|
71
|
|
|
->getMock(); |
|
72
|
|
|
|
|
73
|
|
|
$merged = []; |
|
74
|
|
|
|
|
75
|
|
|
foreach ($params as $key => $value) { |
|
76
|
|
|
$merged = \array_merge($value, $merged); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$mock->expects($this->any()) |
|
80
|
|
|
->method('getParam') |
|
81
|
|
|
->will($this->returnCallback(function ($index, $default) use ($merged) { |
|
82
|
|
|
if (\array_key_exists($index, $merged)) { |
|
83
|
|
|
return $merged[$index]; |
|
84
|
|
|
} else { |
|
85
|
|
|
return $default; |
|
86
|
|
|
} |
|
87
|
|
|
})); |
|
88
|
|
|
|
|
89
|
|
|
// attribute access |
|
90
|
|
|
if (\array_key_exists('server', $params)) { |
|
91
|
|
|
$mock->server = $params['server']; |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $mock; |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths