Total Complexity | 5 |
Total Lines | 64 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class Utilities |
||
15 | { |
||
16 | public static function ObtainFrameworkInstance( |
||
17 | TestCase $testCase, |
||
18 | string $implementation, |
||
19 | ...$implementationArgs |
||
20 | ) : Framework { |
||
21 | $testCase->assertTrue( |
||
22 | is_a($implementation, Framework::class, true), |
||
23 | sprintf( |
||
24 | 'Argument %u passed to %s must be an implementation of %s', |
||
25 | 1, |
||
26 | __METHOD__, |
||
27 | Framework::class |
||
28 | ) |
||
29 | ); |
||
30 | |||
31 | return new $implementation(...$implementationArgs); |
||
32 | } |
||
33 | |||
34 | public static function ObtainHttpHandlerInstance( |
||
35 | TestCase $testCase, |
||
36 | string $implementation, |
||
37 | ...$implementationArgs |
||
38 | ) : HttpHandler { |
||
39 | $testCase->assertTrue( |
||
40 | is_a($implementation, HttpHandler::class, true), |
||
41 | sprintf( |
||
42 | 'Argument %u passed to %s must be an implementation of %s', |
||
43 | 1, |
||
44 | __METHOD__, |
||
45 | HttpHandler::class |
||
46 | ) |
||
47 | ); |
||
48 | |||
49 | /** |
||
50 | * @var HttpHandler $instance |
||
51 | */ |
||
52 | $instance = static::ObtainFrameworkInstance( |
||
53 | $testCase, |
||
54 | $implementation, |
||
55 | ...$implementationArgs |
||
56 | ); |
||
57 | |||
58 | return $instance; |
||
59 | } |
||
60 | |||
61 | public static function ConfigureFrameworkInstance( |
||
62 | TestCase $testCase, |
||
63 | Framework $instance, |
||
64 | array $postConstructionCalls |
||
65 | ) : void { |
||
66 | if (count($postConstructionCalls) > 0) { |
||
67 | $reflector = new ReflectionClass($instance); |
||
68 | |||
69 | foreach (array_keys($postConstructionCalls) as $method) { |
||
70 | $testCase->assertTrue(method_exists($instance, $method), sprintf( |
||
71 | 'Argument %u passed to %s must contain keys referring to methods on %s', |
||
72 | 2, |
||
73 | __METHOD__, |
||
74 | get_class($instance) |
||
75 | )); |
||
76 | |||
77 | $instance->$method(...($postConstructionCalls[$method])); |
||
78 | } |
||
82 |