Failed Conditions
Push — ng ( 625bbc...a06888 )
by Florent
08:03
created

theContactsParameterIsValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 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 OAuth2Framework\Component\ClientRule\Tests;
15
16
use OAuth2Framework\Component\Core\Client\ClientId;
17
use OAuth2Framework\Component\ClientRule;
18
use OAuth2Framework\Component\Core\DataBag\DataBag;
19
use PHPUnit\Framework\TestCase;
20
21
/**
22
 * @group Tests
23
 */
24
class ContactsParametersRuleTest extends TestCase
25
{
26
    /**
27
     * @test
28
     * @expectedException \InvalidArgumentException
29
     * @expectedExceptionMessage The parameter "contacts" must be a list of e-mail addresses.
30
     */
31
    public function theContactsParameterIsNotAnArray()
32
    {
33
        $clientId = ClientId::create('CLIENT_ID');
34
        $commandParameters = DataBag::create([
35
            'contacts' => 123,
36
        ]);
37
        $rule = new ClientRule\ContactsParametersRule();
38
        $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable());
39
    }
40
41
    /**
42
     * @test
43
     * @expectedException \InvalidArgumentException
44
     * @expectedExceptionMessage The parameter "contacts" must be a list of e-mail addresses.
45
     */
46
    public function theContactsParameterIsNotAnArrayOfEmailAddresses()
47
    {
48
        $clientId = ClientId::create('CLIENT_ID');
49
        $commandParameters = DataBag::create([
50
            'contacts' => [123],
51
        ]);
52
        $rule = new ClientRule\ContactsParametersRule();
53
        $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable());
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function theContactsParameterIsValid()
60
    {
61
        $clientId = ClientId::create('CLIENT_ID');
62
        $commandParameters = DataBag::create([
63
            'contacts' => [
64
                '[email protected]',
65
                '[email protected]',
66
            ],
67
        ]);
68
        $rule = new ClientRule\ContactsParametersRule();
69
        $validatedParameters = $rule->handle($clientId, $commandParameters, DataBag::create([]), $this->getCallable());
70
71
        self::assertTrue($validatedParameters->has('contacts'));
72
        self::assertEquals(['[email protected]', '[email protected]'], $validatedParameters->get('contacts'));
73
    }
74
75
    /**
76
     * @return callable
77
     */
78
    private function getCallable(): callable
79
    {
80
        return function (ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters): DataBag {
81
            return $validatedParameters;
82
        };
83
    }
84
}
85