FluentStateTest::testWithState()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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