Test Failed
Push — master ( a4091f...776eb4 )
by Joao
07:11
created

SingletonTest::testClone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
require_once __DIR__ . "/../vendor/autoload.php";
4
require_once "Sample1.php";
5
require_once "Sample2.php";
6
7
class SingletonTest extends \PHPUnit\Framework\TestCase
8
{
9
    public function testSingleton()
10
    {
11
        $sample1 = Sample1::getInstance();
12
        $this->assertEquals(10, $sample1->property);
13
        $sample1->property = 20;
14
        $this->assertEquals(20, $sample1->property);
15
16
        $sample1Other = Sample1::getInstance();
17
        $this->assertEquals(20, $sample1Other->property);
18
        $sample1->property = 40;
19
        $this->assertEquals(40, $sample1Other->property);
20
        $this->assertEquals(40, $sample1->property);
21
22
        //
23
24
        $sample2 = Sample2::getInstance();
25
        $sample2->property2 = 50;
26
        $this->assertEquals(50, $sample2->property2);
27
28
        $sample2Other = Sample2::getInstance();
29
        $this->assertEquals(50, $sample2Other->property2);
30
        $sample2->property2 = 90;
31
        $this->assertEquals(90, $sample2Other->property2);
32
        $this->assertEquals(90, $sample2->property2);
33
34
        //
35
36
        $this->assertEquals(40, $sample1->property);
37
    }
38
39
    /**
40
     * @expectedException \ByJG\DesignPattern\SingletonException
41
     */
42
    public function testClone()
43
    {
44
        $sample1 = Sample1::getInstance();
45
        $sample2 = clone $sample1;
46
    }
47
48
    /**
49
     * @expectedException \ByJG\DesignPattern\SingletonException
50
     */
51
    public function testSerialize()
52
    {
53
        $sample1 = Sample1::getInstance();
54
        $serialize = serialize($sample1);
55
    }
56
}
57