mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-24 00:55:35 +08:00
add container independence tests
This commit is contained in:
@@ -13,12 +13,12 @@ use ZM\Container\WorkerContainer;
|
|||||||
*/
|
*/
|
||||||
class ContainerTest extends TestCase
|
class ContainerTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testInherit(): void
|
public function testCanInheritParentBinding(): void
|
||||||
{
|
{
|
||||||
$worker_container = new WorkerContainer();
|
$worker_container = new WorkerContainer();
|
||||||
$worker_container->instance('foo', 'bar');
|
$worker_container->instance('foo', 'bar');
|
||||||
|
|
||||||
$container = new Container($worker_container);
|
$container = new Container();
|
||||||
$container->instance('baz', 'qux');
|
$container->instance('baz', 'qux');
|
||||||
|
|
||||||
// 获取父容器的实例
|
// 获取父容器的实例
|
||||||
@@ -27,4 +27,26 @@ class ContainerTest extends TestCase
|
|||||||
// 获取自身容器的实例
|
// 获取自身容器的实例
|
||||||
$this->assertEquals('qux', $container->get('baz'));
|
$this->assertEquals('qux', $container->get('baz'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanOverrideParentBinding(): void
|
||||||
|
{
|
||||||
|
$worker_container = new WorkerContainer();
|
||||||
|
$worker_container->instance('foo', 'bar');
|
||||||
|
|
||||||
|
$container = new Container();
|
||||||
|
$container->instance('foo', 'qux');
|
||||||
|
|
||||||
|
$this->assertEquals('qux', $container->get('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotModifyParentBinding(): void
|
||||||
|
{
|
||||||
|
$worker_container = new WorkerContainer();
|
||||||
|
$worker_container->instance('foo', 'bar');
|
||||||
|
|
||||||
|
$container = new Container();
|
||||||
|
$container->instance('foo', 'qux');
|
||||||
|
|
||||||
|
$this->assertEquals('bar', $worker_container->get('foo'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user