1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Facile\OpenIDClient\ConformanceTest; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Test; |
8
|
|
|
use PHPUnit\Framework\TestSuite; |
9
|
|
|
use PHPUnit\Framework\TestListenerDefaultImplementation; |
10
|
|
|
use PHPUnit\Framework\TestListener as TestListenerInterface; |
11
|
|
|
use Psr\Container\ContainerInterface; |
12
|
|
|
use ReflectionFunction; |
13
|
|
|
use Facile\OpenIDClient\ConformanceTest\RpTest\ResponseTypeAndResponseMode\RPResponseTypeCodeTest; |
14
|
|
|
use Facile\OpenIDClient\ConformanceTest\RpTest\RpTestInterface; |
15
|
|
|
|
16
|
|
|
class TestListener implements TestListenerInterface |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
use TestListenerDefaultImplementation; |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** @var ContainerInterface */ |
21
|
|
|
private $container; |
22
|
|
|
|
23
|
|
|
/** @var RpTestUtil */ |
24
|
|
|
private $rpTestUtil; |
25
|
|
|
|
26
|
|
|
/** @var null|string */ |
27
|
|
|
private $rpProfile; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** @var null|string */ |
30
|
|
|
private $rpTestId; |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* TestListener constructor. |
34
|
|
|
*/ |
35
|
|
|
public function __construct() |
36
|
|
|
{ |
37
|
|
|
$this->container = require __DIR__ . '/../config/container.php'; |
38
|
|
|
$this->rpTestUtil = $this->container->get(RpTestUtil::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getRoot(): string |
42
|
|
|
{ |
43
|
|
|
return 'https://rp.certification.openid.net:8080/'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getRpId(): string |
47
|
|
|
{ |
48
|
|
|
return 'tmv_php-openid-client'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* A test suite started. |
53
|
|
|
*/ |
54
|
|
|
public function startTestSuite(TestSuite $suite): void |
55
|
|
|
{ |
56
|
|
|
if (0 !== \strpos($suite->getName(), 'rp-')) { |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$profile = \substr($suite->getName(), 3); |
61
|
|
|
|
62
|
|
|
$testMap = [ |
63
|
|
|
'code-basic' => [ |
64
|
|
|
'rp-response_type-code' => new RPResponseTypeCodeTest($this->container) |
65
|
|
|
] |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
$this->rpTestUtil->clearLogs($this->getRoot(), $this->getRpId()); |
69
|
|
|
|
70
|
|
|
$tests = $testMap[$profile] ?? []; |
71
|
|
|
|
72
|
|
|
foreach ($tests as $test) { |
73
|
|
|
$suite->addTest($test); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* A test suite ended. |
79
|
|
|
*/ |
80
|
|
|
public function endTestSuite(TestSuite $suite): void |
81
|
|
|
{ |
82
|
|
|
// TODO: Implement endTestSuite() method. |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* A test started. |
87
|
|
|
*/ |
88
|
|
|
public function startTest(Test $test): void |
89
|
|
|
{ |
90
|
|
|
if (! $test instanceof RpTestInterface) { |
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* A test ended. |
98
|
|
|
*/ |
99
|
|
|
public function endTest(Test $test, float $time): void |
100
|
|
|
{ |
101
|
|
|
if (! $test instanceof RpTestInterface) { |
102
|
|
|
return; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$testUtil = $this->container->get(RpTestUtil::class); |
|
|
|
|
106
|
|
|
|
107
|
|
|
$implementation = $this->getClosureDump([$test, 'execute']); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
protected function getClosureDump(callable $closure, int $indent = 4) { |
111
|
|
|
if (\is_callable($closure)) { |
112
|
|
|
$closure = \Closure::fromCallable($closure); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$r = new ReflectionFunction($closure); |
116
|
|
|
$lines = \file($r->getFileName()); |
117
|
|
|
$lines = \array_slice($lines, $r->getStartLine(), $r->getEndLine() - $r->getStartLine()); |
118
|
|
|
if (\preg_match('/^ *{ *$/', $lines[0] ?? '')) { |
119
|
|
|
unset($lines[0]); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$firstLine = \array_shift($lines) ?: ''; |
123
|
|
|
|
124
|
|
|
if (! \preg_match('/^ *{ *$/', $firstLine)) { |
125
|
|
|
\array_unshift($lines, $firstLine); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$lastLine = \array_pop($lines) ?: ''; |
129
|
|
|
if (! \preg_match('/^ *} *$/', $lastLine)) { |
130
|
|
|
\array_push($lines, $lastLine); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
// remove spaces based on first line |
134
|
|
|
if (\preg_match('/^( +)/', $lines[0] ?? '', $matches)) { |
135
|
|
|
$toTrim = \strlen($matches[1]); |
136
|
|
|
$lines = \array_map(static function (string $line) use ($toTrim) { |
137
|
|
|
return \preg_replace(sprintf('/^ {0,%d}/', $toTrim), '', $line); |
138
|
|
|
}, $lines); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
if ($indent) { |
142
|
|
|
$lines = \array_map(static function (string $line) use ($indent) { |
143
|
|
|
return \str_repeat(' ', $indent) . $line; |
144
|
|
|
}, $lines); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return \implode('', $lines); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.