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

ManagerTestCase::testResolverByName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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