1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Test\Context; |
15
|
|
|
|
16
|
|
|
use Assert\Assertion; |
17
|
|
|
use Behat\MinkExtension\Context\MinkContext; |
18
|
|
|
use Behat\Symfony2Extension\Context\KernelDictionary; |
19
|
|
|
|
20
|
|
|
final class ControllerContext extends MinkContext |
21
|
|
|
{ |
22
|
|
|
use KernelDictionary; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @Then the response content-type should be :content_type |
26
|
|
|
*/ |
27
|
|
|
public function theResponseContentTypeShouldBe($content_type) |
28
|
|
|
{ |
29
|
|
|
$header = $this->getSession()->getResponseHeaders(); |
30
|
|
|
|
31
|
|
|
Assertion::keyExists($header, 'content-type', 'The response header has no content-type.'); |
32
|
|
|
Assertion::inArray($content_type, $header['content-type'], sprintf('The response header content-type does not contain "%s".', $content_type)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @Then the response should contain a key set in JWKSet format |
37
|
|
|
*/ |
38
|
|
|
public function theResponseShouldContainAKeySetInJwksetFormat() |
39
|
|
|
{ |
40
|
|
|
$content = $this->getJsonContent(); |
41
|
|
|
Assertion::keyExists($content, 'keys', 'The response does not contain a key set.'); |
42
|
|
|
Assertion::isArray($content['keys'], 'The response does not contain a valid key set.'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
private function getJsonContent(): array |
49
|
|
|
{ |
50
|
|
|
$content = json_decode($this->getSession()->getPage()->getContent(), true); |
51
|
|
|
|
52
|
|
|
Assertion::notNull($content, 'The response is not a JSON object.'); |
53
|
|
|
Assertion::isArray($content, 'The response is not a JSON object.'); |
54
|
|
|
|
55
|
|
|
return $content; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|