Completed
Pull Request — master (#240)
by Beñat
04:56
created

UsernameSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_creates_from_email() 0 9 1
A it_creates() 0 6 1
A it_does_not_creates_with_invalid_username() 0 5 1
A it_does_not_creates_with_less_than_2_length() 0 5 1
A it_does_not_creates_with_more_than_20_length() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Spec\Kreta\IdentityAccess\Domain\Model\User;
14
15
use BenGorUser\User\Domain\Model\UserEmail;
16
use Kreta\IdentityAccess\Domain\Model\User\Username;
17
use Kreta\IdentityAccess\Domain\Model\User\UsernameInvalidException;
18
use PhpSpec\ObjectBehavior;
19
20
class UsernameSpec extends ObjectBehavior
21
{
22
    function it_creates_from_email()
23
    {
24
        $email = new UserEmail('[email protected]');
25
        $this->beConstructedFromEmail($email);
26
        $this->shouldHaveType(Username::class);
27
28
        $this->username()->shouldContain('info');
29
        $this->__toString()->shouldContain('info');
30
    }
31
32
    function it_creates()
33
    {
34
        $this->beConstructedWIth('kreta');
35
        $this->username()->shouldReturn('kreta');
36
        $this->__toString()->shouldReturn('kreta');
37
    }
38
39
    function it_does_not_creates_with_invalid_username()
40
    {
41
        $this->beConstructedWith('kreta=#,');
42
        $this->shouldThrow(UsernameInvalidException::class)->duringInstantiation();
43
    }
44
45
    function it_does_not_creates_with_less_than_2_length()
46
    {
47
        $this->beConstructedWith('k');
48
        $this->shouldThrow(UsernameInvalidException::class)->duringInstantiation();
49
    }
50
51
    function it_does_not_creates_with_more_than_20_length()
52
    {
53
        $this->beConstructedWith('sdskfhsdufhsduifisudfhisudfhisufdhid');
54
        $this->shouldThrow(UsernameInvalidException::class)->duringInstantiation();
55
    }
56
}
57