blob: 3781851b271200d41ab7e60dcd937451b800a392 (
plain)
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
|
<?php
namespace Jasny\Router;
use PHPUnit_Framework_MockObject_Matcher_Invocation as Invocation;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
/**
* Helper methods for PHPUnit tests
*/
trait TestHelpers
{
/**
* Create mock for next callback
*
* @param Invocation $matcher
* @param array $with With arguments
* @param mixed $return
* @return MockObject
*/
protected function createCallbackMock(Invocation $matcher, $with = [], $return = null)
{
$callback = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock();
$callback->expects($matcher)->method('__invoke')
->with(...$with)
->willReturn($return);
return $callback;
}
/**
* Assert a non-fatal error
*
* @param int $type
* @param string $message
*/
protected function assertLastError($type, $message)
{
$error = error_get_last();
$expect = compact('type', 'message');
if (is_array($error)) {
$error = array_intersect_key($error, $expect);
}
$this->assertEquals($expect, $error);
}
}
|