1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LightSaml\Tests\Builder\Context; |
4
|
|
|
|
5
|
|
|
use LightSaml\Builder\Context\ProfileContextBuilder; |
6
|
|
|
use LightSaml\Context\Profile\ProfileContext; |
7
|
|
|
use LightSaml\Model\Metadata\EntityDescriptor; |
8
|
|
|
use LightSaml\Profile\Profiles; |
9
|
|
|
use LightSaml\Provider\EntityDescriptor\FixedEntityDescriptorProvider; |
10
|
|
|
use LightSaml\Tests\BaseTestCase; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
|
13
|
|
|
class ProfileContextBuilderTest extends BaseTestCase |
14
|
|
|
{ |
15
|
|
|
public function test_constructs_without_arguments() |
16
|
|
|
{ |
17
|
|
|
new ProfileContextBuilder(); |
18
|
|
|
$this->assertTrue(true); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function getters_setters_provider() |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
[new Request(), 'setRequest', 'getRequest'], |
25
|
|
|
[new FixedEntityDescriptorProvider(new EntityDescriptor()), 'setOwnEntityDescriptorProvider', 'getOwnEntityDescriptorProvider'], |
26
|
|
|
[Profiles::METADATA, 'setProfileId', 'getProfileId'], |
27
|
|
|
[ProfileContext::ROLE_IDP, 'setProfileRole', 'getProfileRole'], |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @dataProvider getters_setters_provider |
33
|
|
|
*/ |
34
|
|
|
public function test_getters_setters($value, $setter, $getter) |
35
|
|
|
{ |
36
|
|
|
$builder = new ProfileContextBuilder(); |
37
|
|
|
$builder->{$setter}($value); |
38
|
|
|
$this->assertSame($value, $builder->{$getter}()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function test_build_throws_exception_when_request_not_set() |
42
|
|
|
{ |
43
|
|
|
$this->expectExceptionMessage("HTTP Request not set"); |
44
|
|
|
$this->expectException(\LightSaml\Error\LightSamlBuildException::class); |
45
|
|
|
$builder = new ProfileContextBuilder(); |
46
|
|
|
|
47
|
|
|
$builder->build(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function test_build_throws_exception_when_own_entity_descriptor_not_set() |
51
|
|
|
{ |
52
|
|
|
$this->expectExceptionMessage("Own EntityDescriptor not set"); |
53
|
|
|
$this->expectException(\LightSaml\Error\LightSamlBuildException::class); |
54
|
|
|
$builder = new ProfileContextBuilder(); |
55
|
|
|
$builder->setRequest(new Request()); |
56
|
|
|
|
57
|
|
|
$builder->build(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function test_build_throws_exception_when_profile_id_not_set() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$this->expectExceptionMessage("ProfileID not set"); |
63
|
|
|
$this->expectException(\LightSaml\Error\LightSamlBuildException::class); |
64
|
|
|
$builder = new ProfileContextBuilder(); |
65
|
|
|
$builder->setRequest(new Request()); |
66
|
|
|
$builder->setOwnEntityDescriptorProvider(new FixedEntityDescriptorProvider(new EntityDescriptor())); |
67
|
|
|
|
68
|
|
|
$builder->build(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
public function test_build_throws_exception_when_profile_role_not_set() |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$this->expectExceptionMessage("Profile role not set"); |
74
|
|
|
$this->expectException(\LightSaml\Error\LightSamlBuildException::class); |
75
|
|
|
$builder = new ProfileContextBuilder(); |
76
|
|
|
$builder->setRequest(new Request()); |
77
|
|
|
$builder->setOwnEntityDescriptorProvider(new FixedEntityDescriptorProvider(new EntityDescriptor())); |
78
|
|
|
$builder->setProfileId(Profiles::METADATA); |
79
|
|
|
|
80
|
|
|
$builder->build(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.