ProfileContextBuilderTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 30 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 21
loc 70
c 0
b 0
f 0
wmc 7
lcom 1
cbo 5
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A test_constructs_without_arguments() 0 5 1
A getters_setters_provider() 0 9 1
A test_getters_setters() 0 6 1
A test_build_throws_exception_when_request_not_set() 0 8 1
A test_build_throws_exception_when_own_entity_descriptor_not_set() 0 9 1
A test_build_throws_exception_when_profile_id_not_set() 10 10 1
A test_build_throws_exception_when_profile_role_not_set() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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