1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\Tests\Unit\Elements; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use PHPUnit4And6Compat; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Base class for unit tests classes for the Maps\BaseElement deriving objects. |
11
|
|
|
* |
12
|
|
|
* @since 3.0 |
13
|
|
|
* |
14
|
|
|
* @licence GNU GPL v2+ |
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
16
|
|
|
*/ |
17
|
|
|
abstract class BaseElementTest extends TestCase { |
18
|
|
|
use PHPUnit4And6Compat; |
19
|
|
|
|
20
|
|
|
public function invalidConstructorProvider() { |
21
|
|
|
return []; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Creates and returns a new instance of the concrete class. |
26
|
|
|
* |
27
|
|
|
* @since 3.0 |
28
|
|
|
* |
29
|
|
|
* @return mixed |
30
|
|
|
*/ |
31
|
|
|
public function newInstance() { |
32
|
|
|
$reflector = new \ReflectionClass( $this->getClass() ); |
33
|
|
|
$args = func_get_args(); |
34
|
|
|
$instance = $reflector->newInstanceArgs( $args ); |
35
|
|
|
return $instance; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Returns the name of the concrete class tested by this test. |
40
|
|
|
* |
41
|
|
|
* @since 3.0 |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public abstract function getClass(); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @since 3.0 |
49
|
|
|
* |
50
|
|
|
* @return array [instance, constructor args] |
51
|
|
|
*/ |
52
|
|
|
public function instanceProvider() { |
53
|
|
|
$phpFails = [ $this, 'newInstance' ]; |
54
|
|
|
|
55
|
|
|
return array_map( |
56
|
|
|
function ( array $args ) use ( $phpFails ) { |
57
|
|
|
return [ call_user_func_array( $phpFails, $args ), $args ]; |
58
|
|
|
}, |
59
|
|
|
$this->validConstructorProvider() |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public abstract function validConstructorProvider(); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider validConstructorProvider |
67
|
|
|
* |
68
|
|
|
* @since 3.0 |
69
|
|
|
*/ |
70
|
|
|
public function testGivenValidArguments_constructorDoesNotThrowException() { |
71
|
|
|
$instance = call_user_func_array( [ $this, 'newInstance' ], func_get_args() ); |
72
|
|
|
$this->assertInstanceOf( $this->getClass(), $instance ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @dataProvider invalidConstructorProvider |
77
|
|
|
* |
78
|
|
|
* @since 3.0 |
79
|
|
|
*/ |
80
|
|
|
public function testGivenInvalidArguments_constructorThrowsException() { |
81
|
|
|
$this->expectException( InvalidArgumentException::class ); |
82
|
|
|
call_user_func_array( [ $this, 'newInstance' ], func_get_args() ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|