Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 2915d9b

Browse files
committed
Update aliases tests
Alias can be reference to: - service - invokable - factory - delegator - another alias
1 parent 4dca9f7 commit 2915d9b

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

src/AliasTestTrait.php

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,92 @@ trait AliasTestTrait
1515
{
1616
public function alias() : Generator
1717
{
18+
yield 'alias-service' => [
19+
[
20+
'aliases' => ['alias' => 'service'],
21+
'services' => ['service' => new TestAsset\Service()],
22+
],
23+
];
24+
1825
yield 'alias-invokable' => [
1926
[
2027
'aliases' => ['alias' => 'service'],
2128
'invokables' => ['service' => TestAsset\Service::class],
22-
]
29+
],
2330
];
31+
2432
yield 'alias-factory' => [
2533
[
2634
'aliases' => ['alias' => 'service'],
2735
'factories' => ['service' => TestAsset\Factory::class],
28-
]
36+
],
37+
];
38+
39+
yield 'alias-delegator' => [
40+
[
41+
'aliases' => ['alias' => 'service'],
42+
'factories' => [
43+
'service' => TestAsset\Factory::class,
44+
],
45+
'delegators' => [
46+
'service' => [
47+
TestAsset\DelegatorFactory::class,
48+
],
49+
],
50+
],
51+
];
52+
53+
yield 'alias-alias-service' => [
54+
[
55+
'aliases' => [
56+
'alias' => 'alias2',
57+
'alias2' => 'service',
58+
],
59+
'services' => [
60+
'service' => new TestAsset\Service(),
61+
],
62+
],
63+
];
64+
65+
yield 'alias-alias-invokable' => [
66+
[
67+
'aliases' => [
68+
'alias' => 'alias2',
69+
'alias2' => 'service',
70+
],
71+
'invokables' => [
72+
'service' => TestAsset\Service::class,
73+
],
74+
],
75+
];
76+
77+
yield 'alias-alias-factory' => [
78+
[
79+
'aliases' => [
80+
'alias' => 'alias2',
81+
'alias2' => 'service',
82+
],
83+
'factories' => [
84+
'service' => TestAsset\Factory::class,
85+
],
86+
],
87+
];
88+
89+
yield 'alias-alias-delegator' => [
90+
[
91+
'aliases' => [
92+
'alias' => 'alias2',
93+
'alias2' => 'service',
94+
],
95+
'factories' => [
96+
'service' => TestAsset\Factory::class,
97+
],
98+
'delegators' => [
99+
'service' => [
100+
TestAsset\DelegatorFactory::class,
101+
],
102+
],
103+
],
29104
];
30105
}
31106

src/TestAsset/Delegator.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-container-test for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-container-test/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Zend\ContainerTest\TestAsset;
11+
12+
class Delegator
13+
{
14+
public $callback;
15+
16+
public function __construct($name, callable $callback)
17+
{
18+
$this->callback = $callback;
19+
}
20+
}

src/TestAsset/DelegatorFactory.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-container-test for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-container-test/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Zend\ContainerTest\TestAsset;
11+
12+
use Psr\Container\ContainerInterface;
13+
14+
class DelegatorFactory
15+
{
16+
public function __invoke(ContainerInterface $container, $name, callable $callback)
17+
{
18+
return new Delegator($name, $callback);
19+
}
20+
}

0 commit comments

Comments
 (0)