Completed
Push — master ( fd8ace...dd449b )
by Korotkov
02:45 queued 10s
created

LazyInitializationTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testRegister() 0 4 1
A testLogin() 0 5 1
A getUserService() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Creational\LazyInitialization\Tests;
11
12
use Creational\LazyInitialization\UserService;
13
use Creational\LazyInitialization\ServiceInterface;
14
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
15
16
/**
17
 * Class LazyInitializationTest
18
 */
19
class LazyInitializationTest extends PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * @var ServiceInterface
23
     */
24
    private $userService;
25
26
    protected function setUp(): void
27
    {
28
        $this->userService = new UserService();
29
    }
30
31
    public function testRegister()
32
    {
33
        $this->assertEquals(sprintf("%s has been registered \n", 'John'), $this->getUserService()->register('John'));
34
        $this->assertEquals(sprintf("%s was already registered \n", 'John'), $this->getUserService()->register('John'));
35
    }
36
37
    public function testLogin()
38
    {
39
        $this->getUserService()->register('John');
40
        $this->assertEquals(sprintf("%s is authenticated \n", 'John'), $this->getUserService()->login('John'));
41
        $this->assertEquals(sprintf("%s must be registered \n", 'Bill'), $this->getUserService()->login('Bill'));
42
    }
43
44
    /**
45
     * @return UserService
46
     */
47
    public function getUserService(): ServiceInterface
48
    {
49
        return $this->userService;
50
    }
51
}
52