Completed
Push — master ( ceb81d...34dbeb )
by Beñat
07:47
created

it_does_not_creates_with_invalid_username()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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