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
|
|
|
|