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