|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Phive Queue package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eugene Leonovich <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Phive\Queue\Tests\Queue; |
|
13
|
|
|
|
|
14
|
|
|
use Phive\Queue\Queue; |
|
15
|
|
|
|
|
16
|
|
|
trait Util |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
|
20
|
|
|
*/ |
|
21
|
|
|
public function getQueueMock() |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->getMock('Phive\Queue\Queue'); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function provideQueueInterfaceMethods() |
|
27
|
|
|
{ |
|
28
|
|
|
return array_chunk(get_class_methods('Phive\Queue\Queue'), 1); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function callQueueMethod(Queue $queue, $method) |
|
32
|
|
|
{ |
|
33
|
|
|
$r = new \ReflectionMethod($queue, $method); |
|
34
|
|
|
|
|
35
|
|
|
if ($num = $r->getNumberOfRequiredParameters()) { |
|
36
|
|
|
return call_user_func_array([$queue, $method], array_fill(0, $num, 'foo')); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $queue->$method(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function provideItemsOfVariousTypes() |
|
43
|
|
|
{ |
|
44
|
|
|
$data = []; |
|
45
|
|
|
|
|
46
|
|
|
foreach (Types::getAll() as $type => $item) { |
|
47
|
|
|
$data[$type] = [$item, $type]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $data; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function provideItemsOfSupportedTypes() |
|
54
|
|
|
{ |
|
55
|
|
|
return array_diff_key( |
|
56
|
|
|
$this->provideItemsOfVariousTypes(), |
|
57
|
|
|
array_fill_keys($this->getUnsupportedItemTypes(), false) |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function provideItemsOfUnsupportedTypes() |
|
62
|
|
|
{ |
|
63
|
|
|
return array_intersect_key( |
|
64
|
|
|
$this->provideItemsOfVariousTypes(), |
|
65
|
|
|
array_fill_keys($this->getUnsupportedItemTypes(), false) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function getUnsupportedItemTypes() |
|
70
|
|
|
{ |
|
71
|
|
|
return []; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.