FluentStateTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testWithState() 0 15 1
1
<?php
2
3
namespace TractorCow\Fluent\Tests\State;
4
5
use SilverStripe\Dev\SapphireTest;
6
use TractorCow\Fluent\State\FluentState;
7
use TractorCow\Fluent\View\FluentTemplateGlobalProvider;
8
9
class FluentStateTest extends SapphireTest
10
{
11
    public function testWithState()
12
    {
13
        $original = new FluentState;
14
15
        $original->withState(function ($newState) use ($original) {
16
            $this->assertInstanceOf(FluentState::class, $newState);
17
            $this->assertNotSame($original, $newState);
18
19
            // Tests that the new state is injected
20
            $newState->setLocale('foo');
21
            $this->assertSame('foo', FluentTemplateGlobalProvider::getCurrentLocale());
22
        });
23
24
        // Tests that the original state is restored
25
        $this->assertSame($original, FluentState::singleton());
26
    }
27
}
28