Passed
Pull Request — master (#407)
by Kirill
05:39
created

ManagerTestCase   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 23
dl 0
loc 68
rs 10
c 1
b 0
f 1
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testResolverByName() 0 3 1
A testIterator() 0 11 1
A testUnknownResolver() 0 5 1
A testDefaultResolver() 0 3 1
A testAddedResolver() 0 5 1
A testCount() 0 9 1
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Distribution;
13
14
use Spiral\Distribution\Manager;
15
use Spiral\Distribution\Resolver\StaticResolver;
16
17
/**
18
 * @group unit
19
 */
20
class ManagerTestCase extends TestCase
21
{
22
    /**
23
     * @var StaticResolver
24
     */
25
    private $resolver;
26
27
    /**
28
     * @var Manager
29
     */
30
    private $manager;
31
32
    public function setUp(): void
33
    {
34
        $this->resolver = new StaticResolver($this->uri('localhost'));
35
36
        $this->manager = new Manager();
37
        $this->manager->add(Manager::DEFAULT_RESOLVER, $this->resolver);
38
39
        parent::setUp();
40
    }
41
42
    public function testDefaultResolver(): void
43
    {
44
        $this->assertSame($this->resolver, $this->manager->resolver());
45
    }
46
47
    public function testResolverByName(): void
48
    {
49
        $this->assertSame($this->resolver, $this->manager->resolver('default'));
50
    }
51
52
    public function testUnknownResolver(): void
53
    {
54
        $this->expectException(\InvalidArgumentException::class);
55
56
        $this->manager->resolver('unknown');
57
    }
58
59
    public function testAddedResolver(): void
60
    {
61
        $this->manager->add('known', $this->resolver);
62
63
        $this->assertSame($this->resolver, $this->manager->resolver('known'));
64
    }
65
66
    public function testIterator(): void
67
    {
68
        $manager = clone $this->manager;
69
70
        $resolvers = \iterator_to_array($manager->getIterator());
71
        $this->assertSame([Manager::DEFAULT_RESOLVER => $this->resolver], $resolvers);
72
73
        $manager->add('example', $this->resolver);
74
75
        $resolvers = \iterator_to_array($manager->getIterator());
76
        $this->assertSame([Manager::DEFAULT_RESOLVER => $this->resolver, 'example' => $this->resolver], $resolvers);
77
    }
78
79
    public function testCount(): void
80
    {
81
        $manager = clone $this->manager;
82
83
        $this->assertSame(1, $manager->count());
84
85
        $manager->add('example', $this->resolver);
86
87
        $this->assertSame(2, $manager->count());
88
    }
89
}
90