-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCase.php
97 lines (86 loc) · 2.35 KB
/
TestCase.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/*
* This file is part of the Allay package.
*
* (c) Cedric van Putten <me@bycedric.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ByCedric\Allay\Tests;
use Mockery;
use PHPUnit_Framework_TestCase;
abstract class TestCase extends PHPUnit_Framework_TestCase
{
/**
* When a test ends, make sure we remove all mocks.
*
* @return void
*/
public function tearDown()
{
Mockery::close();
}
/**
* Assert if the provided value is a string.
*
* @param mixed $value
* @param string $message (default: '')
* @return void
*/
public function assertString($value, $message = '')
{
$this->assertInternalType('string', $value, $message);
}
/**
* Assert if the provided value is an array.
*
* @param mixed $value
* @param string $message (default: '')
* @return void
*/
public function assertArray($value, $message = '')
{
$this->assertInternalType('array', $value, $message);
}
/**
* Assert if the provided string is a subclass of the expected subclass.
*
* @param string $expected
* @param string $classType
* @param string $message (default: '')
* @return void
*/
public function assertSubclassOf($expected, $classType, $message = '')
{
$this->assertTrue(is_subclass_of($classType, $expected), $message);
}
/**
* Assert if the provided class type exists.
*
* @param string $classType
* @param string $message (default: '')
* @return void
*/
public function assertClassExists($classType, $message = '')
{
$this->assertTrue(class_exists($classType), $message);
}
/**
* Call protected method that can't be called otherwise.
*
* @param object &$instance
* @param string $method
* @param array $params
* @return mixed
*/
public function callProtectedMethod(&$instance, $method, array $params = [])
{
$reflection = new \ReflectionMethod(get_class($instance), $method);
$reflection->setAccessible(true);
if (!empty($params)) {
return $reflection->invokeArgs($instance, $params);
}
return $reflection->invoke($instance);
}
}