From 4ec3be6f10c8594dbff76c8ef4734a67f3a53953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Wed, 15 Aug 2018 11:44:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=AB=E5=90=8D=E9=85=8D=E7=BD=AE=20(https?= =?UTF-8?q?://github.com/swoft-cloud/swoft-component/pull/181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加自定义组件支持别名的单测 * 让组件地址支持别名 --- composer.json | 3 ++- .../Resource/CustomComponentsRegister.php | 2 ++ test/Cases/BeanTest.php | 10 +++++++ test/Testing/Bean/Config.php | 27 +++++++++++++++++++ test/Testing/Bean2/Config.php | 27 +++++++++++++++++++ test/config/properties/app.php | 4 ++- 6 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 test/Testing/Bean/Config.php create mode 100644 test/Testing/Bean2/Config.php diff --git a/composer.json b/composer.json index c659e506..6708017d 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ }, "autoload-dev": { "psr-4": { - "SwoftTest\\": "test/Cases" + "SwoftTest\\": "test/Cases", + "SwoftTest\\Testing\\": "test/Testing/" } }, "repositories": { diff --git a/src/Bean/Resource/CustomComponentsRegister.php b/src/Bean/Resource/CustomComponentsRegister.php index 3c204e9e..d661e23c 100644 --- a/src/Bean/Resource/CustomComponentsRegister.php +++ b/src/Bean/Resource/CustomComponentsRegister.php @@ -20,6 +20,7 @@ public function registerServerNamespace() } $this->componentNamespaces[] = $ns; + $componentDir = alias($componentDir); foreach ($this->serverScan as $dir) { $scanDir = $componentDir . DS . $dir; @@ -48,6 +49,7 @@ public function registerWorkerNamespace() } $this->componentNamespaces[] = $ns; + $componentDir = alias($componentDir); if (!is_dir($componentDir)) { continue; diff --git a/test/Cases/BeanTest.php b/test/Cases/BeanTest.php index f9a98df8..fb444c72 100644 --- a/test/Cases/BeanTest.php +++ b/test/Cases/BeanTest.php @@ -14,6 +14,7 @@ use Swoft\Proxy\Proxy; use SwoftTest\Bean\ProxyTest; use SwoftTest\Bean\TestHandler; +use SwoftTest\Testing\Bean\Config; /** * Class BeanTest @@ -52,4 +53,13 @@ public function testCustomComponentNamespaces() $namespace = $resource->getComponentNamespaces(); $this->assertNotFalse(array_search('SwoftTest', $namespace)); } + + public function testCustomComponentSupportAlias() + { + $config = bean(Config::class); + $this->assertEquals('test', $config->getName()); + + $config = bean(\SwoftTest\Testing\Bean2\Config::class); + $this->assertEquals('test', $config->getName()); + } } diff --git a/test/Testing/Bean/Config.php b/test/Testing/Bean/Config.php new file mode 100644 index 00000000..d0e79911 --- /dev/null +++ b/test/Testing/Bean/Config.php @@ -0,0 +1,27 @@ +name; + } +} \ No newline at end of file diff --git a/test/Testing/Bean2/Config.php b/test/Testing/Bean2/Config.php new file mode 100644 index 00000000..b79fce78 --- /dev/null +++ b/test/Testing/Bean2/Config.php @@ -0,0 +1,27 @@ +name; + } +} \ No newline at end of file diff --git a/test/config/properties/app.php b/test/config/properties/app.php index 2b2cdd17..05b65431 100644 --- a/test/config/properties/app.php +++ b/test/config/properties/app.php @@ -19,7 +19,9 @@ 'env' => 'Base', 'components' => [ 'custom' => [ - 'SwoftTest' + 'SwoftTest', + 'SwoftTest\\Testing\\Bean' => BASE_PATH . '/Testing/Bean', + 'SwoftTest\\Testing\\Bean2' => '@root/Testing/Bean2', ] ], 'provider' => require __DIR__ . DS . 'provider.php',