PhpObjectDecorationCacheTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 21
c 1
b 0
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testShouldCacheTheDecoratedObjectClassIfCacheIsEnabled() 0 16 1
A testShouldNotCacheTheDecoratedObjectClassIfCacheIsDisabled() 0 14 1
1
<?php
2
3
namespace Exsio\PhpObjectDecorator\Tests;
4
5
use Exsio\PhpObjectDecorator\PhpObjectDecorator;
6
use Exsio\PhpObjectDecorator\Tests\Fixtures\ChildObjectToDecorate;
7
use Exsio\PhpObjectDecorator\Tests\Fixtures\TestCache;
8
use PHPUnit\Framework\TestCase;
9
10
class PhpObjectDecorationCacheTest extends TestCase
11
{
12
13
    public function testShouldCacheTheDecoratedObjectClassIfCacheIsEnabled()
14
    {
15
        //when:
16
        $className = "TestClass_" . uniqid();
17
        $cache     = new TestCache();
18
        $cache->setEnabled(true);
19
        $decorator = PhpObjectDecorator::decorate(new ChildObjectToDecorate())
20
            ->withClassName($className)
21
            ->withCache($cache);
22
        $decorator->get();
23
        $result    = $decorator->get();
24
25
        //then:
26
        $this->assertTrue($cache->contains($className));
27
        $this->assertEquals($cache->get($className, function () {
28
        }), $result->getBody());
29
30
    }
31
32
    public function testShouldNotCacheTheDecoratedObjectClassIfCacheIsDisabled()
33
    {
34
        //when:
35
        $className = "TestClass_" . uniqid();
36
        $cache     = new TestCache();
37
        $cache->setEnabled(false);
38
        $decorator = PhpObjectDecorator::decorate(new ChildObjectToDecorate())
39
            ->withClassName($className)
40
            ->withCache($cache);
41
        $decorator->get();
42
        $decorator->get();
43
44
        //then:
45
        $this->assertFalse($cache->contains($className));
46
47
48
    }
49
}