1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Jared King <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @link http://jaredtking.com |
7
|
|
|
* |
8
|
|
|
* @copyright 2015 Jared King |
9
|
|
|
* @license MIT |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Infuse\Auth\Libs; |
13
|
|
|
|
14
|
|
|
use Exception; |
15
|
|
|
use Infuse\Test; |
16
|
|
|
use PHPUnit\Framework\AssertionFailedError; |
17
|
|
|
use PHPUnit\Framework\Test as PHPUnitTest; |
18
|
|
|
use PHPUnit\Framework\TestListener as PHPUnitTestListener; |
19
|
|
|
use PHPUnit\Framework\TestSuite; |
20
|
|
|
use PHPUnit\Framework\Warning; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @codeCoverageIgnore |
24
|
|
|
*/ |
25
|
|
|
class TestListener implements PHPUnitTestListener |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @staticvar array |
29
|
|
|
*/ |
30
|
|
|
public static $userParams = [ |
31
|
|
|
'email' => '[email protected]', |
32
|
|
|
'password' => ['testpassword', 'testpassword'], |
33
|
|
|
'first_name' => 'Bob', |
34
|
|
|
'ip' => '127.0.0.1', |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
public function __construct() |
38
|
|
|
{ |
39
|
|
|
/* Set up a test user */ |
40
|
|
|
|
41
|
|
|
$userClass = Test::$app['auth']->getUserClass(); |
42
|
|
|
$user = new $userClass(); |
43
|
|
|
|
44
|
|
|
$params = self::$userParams; |
45
|
|
|
if (property_exists($user, 'testUser')) { |
46
|
|
|
$params = array_replace($params, $user::$testUser); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/* Delete any existing test users */ |
50
|
|
|
|
51
|
|
|
$existingUser = $userClass::where('email', $params['email']) |
52
|
|
|
->first(); |
53
|
|
|
if ($existingUser) { |
54
|
|
|
$existingUser->grantAllPermissions()->delete(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/* Create and sign in the test user */ |
58
|
|
|
|
59
|
|
|
$user->create($params); |
60
|
|
|
$user->markSignedIn(); |
61
|
|
|
Test::$app['user'] = $user; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function addError(PHPUnitTest $test, Exception $e, $time) |
65
|
|
|
{ |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function addWarning(PHPUnitTest $test, Warning $e, $time) |
69
|
|
|
{ |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function addFailure(PHPUnitTest $test, AssertionFailedError $e, $time) |
73
|
|
|
{ |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function addIncompleteTest(PHPUnitTest $test, Exception $e, $time) |
77
|
|
|
{ |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function addRiskyTest(PHPUnitTest $test, Exception $e, $time) |
81
|
|
|
{ |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function addSkippedTest(PHPUnitTest $test, Exception $e, $time) |
85
|
|
|
{ |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function startTest(PHPUnitTest $test) |
89
|
|
|
{ |
90
|
|
|
Test::$app['user']->demoteToNormalUser(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function endTest(PHPUnitTest $test, $time) |
94
|
|
|
{ |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function startTestSuite(TestSuite $suite) |
98
|
|
|
{ |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function endTestSuite(TestSuite $suite) |
102
|
|
|
{ |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|