Passed
Push — master ( 72c793...7f699f )
by Kirill
03:22
created

GeneratorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testRotateEmpty() 0 8 1
A testRotateMultiValue() 0 12 1
A testRotateSingleValue() 0 11 1
A testRotateMultiple() 0 17 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Views;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Views\Context\ValueDependency;
16
use Spiral\Views\ContextGenerator;
17
use Spiral\Views\ViewContext;
18
19
class GeneratorTest extends TestCase
20
{
21
    public function testRotateSingleValue(): void
22
    {
23
        $context = new ViewContext();
24
        $context = $context->withDependency(new ValueDependency('test', 'value'));
25
26
        $generator = new ContextGenerator($context);
27
        $variants = $generator->generate();
28
29
        $this->assertCount(1, $variants);
30
        $this->assertSame($context->getID(), $variants[0]->getID());
31
        $this->assertSame('value', $variants[0]->resolveValue('test'));
32
    }
33
34
    public function testRotateEmpty(): void
35
    {
36
        $context = new ViewContext();
37
38
        $generator = new ContextGenerator($context);
39
        $variants = $generator->generate();
40
41
        $this->assertCount(0, $variants);
42
    }
43
44
    public function testRotateMultiValue(): void
45
    {
46
        $context = new ViewContext();
47
        $context = $context->withDependency(new ValueDependency('test', 'value', ['value', 'another']));
48
49
        $generator = new ContextGenerator($context);
50
        $variants = $generator->generate();
51
52
        $this->assertCount(2, $variants);
53
        $this->assertSame($context->getID(), $variants[0]->getID());
54
        $this->assertSame('value', $variants[0]->resolveValue('test'));
55
        $this->assertSame('another', $variants[1]->resolveValue('test'));
56
    }
57
58
    public function testRotateMultiple(): void
59
    {
60
        $context = new ViewContext();
61
        $context = $context->withDependency(new ValueDependency('a', 'a', ['a', 'b']));
62
        $context = $context->withDependency(new ValueDependency('b', 'c', ['c', 'e']));
63
        $context = $context->withDependency(new ValueDependency('d', 'f', ['f', 'g']));
64
65
        $generator = new ContextGenerator($context);
66
        $variants = $generator->generate();
67
68
        $this->assertCount(8, $variants);
69
        $this->assertSame($context->getID(), $variants[0]->getID());
70
71
        // ending
72
        $this->assertSame('b', $variants[7]->resolveValue('a'));
73
        $this->assertSame('e', $variants[7]->resolveValue('b'));
74
        $this->assertSame('g', $variants[7]->resolveValue('d'));
75
    }
76
}
77