diff --git a/.php_cs.dist b/.php_cs.dist index eb8cce296f..40ab7e9162 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -29,6 +29,7 @@ $finder = PhpCsFixer\Finder::create() 'ext', 'ide', 'templates/ZendEngine3', + 'unit-tests/sharness', ]) ->notPath('#unit-tests/fixtures/stubs/.*#'); diff --git a/Library/Stubs/Generator.php b/Library/Stubs/Generator.php index 611c9b13ef..8fe7ad075c 100644 --- a/Library/Stubs/Generator.php +++ b/Library/Stubs/Generator.php @@ -140,7 +140,10 @@ protected function buildClass(ClassDefinition $class, string $indent): string ); } - $source .= ' extends '.($extendsClassDefinition->isBundled() ? '' : '\\').trim($extendsClassDefinition->getCompleteName(), '\\'); + $hasAliasForExtends = $class->getAliasManager()->isAlias($extendsClassDefinition->getShortName()); + + $source .= ' extends '.($hasAliasForExtends || $extendsClassDefinition->isBundled() ? '' : '\\'); + $source .= $hasAliasForExtends ? $extendsClassDefinition->getShortName() : $extendsClassDefinition->getCompleteName(); } if ($implementedInterfaces = $class->getImplementedInterfaces()) { diff --git a/unit-tests/fixtures/stubs/issue1778/config.json b/unit-tests/fixtures/stubs/issue1778/config.json deleted file mode 100644 index af31a06106..0000000000 --- a/unit-tests/fixtures/stubs/issue1778/config.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "namespace": "stubs", - "name": "issue_1778", - "description": "", - "author": "", - "version": "0.0.1", - "verbose": false, - "requires": { - "extensions": [] - }, - "stubs": { - "path": "ide\/%version%\/%namespace%\/", - "stubs-run-after-generate": false - } -} diff --git a/unit-tests/fixtures/stubs/issue1922/config.json b/unit-tests/fixtures/stubs/issues/config.json similarity index 91% rename from unit-tests/fixtures/stubs/issue1922/config.json rename to unit-tests/fixtures/stubs/issues/config.json index 770a83ad09..ea86433538 100644 --- a/unit-tests/fixtures/stubs/issue1922/config.json +++ b/unit-tests/fixtures/stubs/issues/config.json @@ -1,6 +1,6 @@ { "namespace": "stubs", - "name": "stubs", + "name": "issue_ext", "description": "", "author": "", "version": "0.0.1", diff --git a/unit-tests/fixtures/stubs/issues/expected/Exception.zep.php b/unit-tests/fixtures/stubs/issues/expected/Exception.zep.php new file mode 100644 index 0000000000..802551e399 --- /dev/null +++ b/unit-tests/fixtures/stubs/issues/expected/Exception.zep.php @@ -0,0 +1,16 @@ + 42 * ]; * - * $example = new Test($container, $config); + * $example = new Issue_1778($request, $config); * */ -class Test +class Issue_1778 { const PROPERTY_EXAMPLE = 'test_property'; /** - * @var + * @var */ - private $_container; + private $request; /** * @var array @@ -33,10 +33,10 @@ class Test /** - * @param \Fixtures\Ide_Stubs\Interfaces\DiInterfaceExample $container + * @param \Psr\Http\Message\RequestInterface $request * @param array $config */ - public function __construct(\Fixtures\Ide_Stubs\Interfaces\DiInterfaceExample $container, array $config) {} + public function __construct(\Psr\Http\Message\RequestInterface $request, array $config) {} /** * Some useful description diff --git a/unit-tests/fixtures/stubs/issues/expected/Issue_1907.zep.php b/unit-tests/fixtures/stubs/issues/expected/Issue_1907.zep.php new file mode 100644 index 0000000000..bddf9f98aa --- /dev/null +++ b/unit-tests/fixtures/stubs/issues/expected/Issue_1907.zep.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Stubs; + +use Throwable; + +/** + * Exceptions for the Collection object + */ +class Exception extends \Exception implements Throwable +{ + public function __construct() {} +} diff --git a/unit-tests/fixtures/stubs/issue1778/stubs/test.zep b/unit-tests/fixtures/stubs/issues/stubs/issue_1778.zep similarity index 70% rename from unit-tests/fixtures/stubs/issue1778/stubs/test.zep rename to unit-tests/fixtures/stubs/issues/stubs/issue_1778.zep index fb7f520e4a..96d9ca4e29 100644 --- a/unit-tests/fixtures/stubs/issue1778/stubs/test.zep +++ b/unit-tests/fixtures/stubs/issues/stubs/issue_1778.zep @@ -9,7 +9,7 @@ namespace Stubs; -use Fixtures\Ide_Stubs\Interfaces\DiInterfaceExample; +use Psr\Http\Message\RequestInterface; /** * Test Class Example Description @@ -20,22 +20,22 @@ use Fixtures\Ide_Stubs\Interfaces\DiInterfaceExample; * 'param' => 42 * ]; * - * $example = new Test($container, $config); + * $example = new Issue_1778($request, $config); * */ -class Test +class Issue_1778 { const PROPERTY_EXAMPLE = "test_property"; - /** @var */ - private _container; + /** @var */ + private request; /** @var array */ protected config; - public function __construct( container, array config) + public function __construct( request, array config) { - let this->_container = container; + let this->request = request; let this->config = config; } diff --git a/unit-tests/fixtures/stubs/issues/stubs/issue_1907.zep b/unit-tests/fixtures/stubs/issues/stubs/issue_1907.zep new file mode 100644 index 0000000000..a04ecd468b --- /dev/null +++ b/unit-tests/fixtures/stubs/issues/stubs/issue_1907.zep @@ -0,0 +1,22 @@ +/** + * This file is part of the Zephir. + * + * (c) Zephir Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Stubs; + +use Throwable; +use Stubs\Exception; + +/** + * Generated Stub should have `extends Exception` without slash + * because we using import for this class with FQN + */ +class Issue_1907 extends Exception implements Throwable +{ + public function __construct() {} +} diff --git a/unit-tests/fixtures/stubs/issue1922/stubs/test.zep b/unit-tests/fixtures/stubs/issues/stubs/issue_1922.zep similarity index 86% rename from unit-tests/fixtures/stubs/issue1922/stubs/test.zep rename to unit-tests/fixtures/stubs/issues/stubs/issue_1922.zep index bc2d00e3aa..7293ca6c3a 100644 --- a/unit-tests/fixtures/stubs/issue1922/stubs/test.zep +++ b/unit-tests/fixtures/stubs/issues/stubs/issue_1922.zep @@ -1,6 +1,6 @@ namespace Stubs; -class Test +class Issue_1922 { public function getVar(string! key) -> var | null { diff --git a/unit-tests/sharness/t0005-stubs.sh b/unit-tests/sharness/t0005-stubs.sh index aac5c6ee85..e97dad5fdd 100755 --- a/unit-tests/sharness/t0005-stubs.sh +++ b/unit-tests/sharness/t0005-stubs.sh @@ -7,10 +7,34 @@ source ./setup.sh # See: https://github.com/phalcon/zephir/issues/1922 test_expect_success "Should properly generate type hint" " - cd $FIXTURESDIR/stubs/issue1922 && + cd $FIXTURESDIR/stubs/issues && zephirc generate --no-ansi 2>&1 >/dev/null && zephirc stubs --no-ansi 2>&1 >/dev/null && - test_cmp expected/Test.zep.php ide/0.0.1/Stubs/Test.zep.php + test_cmp expected/Issue_1922.zep.php ide/0.0.1/Stubs/Issue_1922.zep.php +" + +# See: https://github.com/phalcon/zephir/issues/1778 +test_expect_success "Should properly namespace imports (use block)" " + cd $FIXTURESDIR/stubs/issues && + zephirc generate --no-ansi 2>&1 >/dev/null && + zephirc stubs --no-ansi 2>&1 >/dev/null && + test_cmp expected/Issue_1778.zep.php ide/0.0.1/Stubs/Issue_1778.zep.php +" + +# See: https://github.com/phalcon/zephir/issues/1907 +test_expect_success "Should properly generate Namespace for extends" " + cd $FIXTURESDIR/stubs/issues && + zephirc generate --no-ansi 2>&1 >/dev/null && + zephirc stubs --no-ansi 2>&1 >/dev/null && + test_cmp expected/Exception.zep.php ide/0.0.1/Stubs/Exception.zep.php +" + +# See: https://github.com/phalcon/zephir/issues/1907 +test_expect_success "Should properly generate Namespace for extends (slash)" " + cd $FIXTURESDIR/stubs/issues && + zephirc generate --no-ansi 2>&1 >/dev/null && + zephirc stubs --no-ansi 2>&1 >/dev/null && + test_cmp expected/Issue_1907.zep.php ide/0.0.1/Stubs/Issue_1907.zep.php " test_done diff --git a/unit-tests/sharness/t0007-stubs-use-block.sh b/unit-tests/sharness/t0007-stubs-use-block.sh deleted file mode 100755 index c6d0ae5c33..0000000000 --- a/unit-tests/sharness/t0007-stubs-use-block.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -# shellcheck disable=SC2034 -test_description="Test generate IDE stubs with proper namespace imports" - -source ./setup.sh - -# See: https://github.com/phalcon/zephir/issues/1778 -test_expect_success "Should properly namespace imports (use block)" " - cd $FIXTURESDIR/stubs/issue1778 && - zephirc generate --no-ansi 2>&1 >/dev/null && - zephirc stubs --no-ansi 2>&1 >/dev/null && - test_cmp expected/Test.zep.php ide/0.0.1/Stubs/Test.zep.php -" - -test_done