Failed Conditions
Push — v7 ( 809898...b3c0a6 )
by Florent
05:05
created

theResponseShouldContainAKeySetInJwksetFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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