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

LazyInitializationTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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