Skip to content

Commit

Permalink
Amended tests for array return type
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Dec 1, 2018
1 parent 641bd98 commit 98ef66f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 30 deletions.
10 changes: 0 additions & 10 deletions unit-tests/Zephir/Test/Command/CompileCommandTest.php
Expand Up @@ -11,10 +11,8 @@

namespace Zephir\Test\Command;

use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Zephir\Config;
use Zephir\Console\Application;
use Zephir\FileSystem\FileSystemInterface;
use Zephir\Test\KernelTestCase;
Expand Down Expand Up @@ -118,12 +116,4 @@ public function devModeProvider()
['--dev', '-O0 -g3'],
];
}

/**
* @param ContainerInterface $container
*/
protected function muteOutput(ContainerInterface $container)
{
$container->get(Config::class)->set('silent', true);
}
}
12 changes: 12 additions & 0 deletions unit-tests/Zephir/Test/KernelTestCase.php
Expand Up @@ -12,7 +12,9 @@
namespace Zephir\Test;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase as BaseTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Zephir\Config;
use Zephir\DependencyInjection\ZephirKernel;

class KernelTestCase extends BaseTestCase
Expand Down Expand Up @@ -67,4 +69,14 @@ protected static function createKernel(array $options = [])
return new static::$class($env, $debug);
}
}

/**
* Do not output messages from the Zephir compiler.
*
* @param ContainerInterface $container
*/
protected function muteOutput(ContainerInterface $container)
{
$container->get(Config::class)->set('silent', true);
}
}
10 changes: 0 additions & 10 deletions unit-tests/Zephir/Test/LifeCycleTest.php
Expand Up @@ -11,9 +11,7 @@

namespace Zephir\Test;

use Psr\Container\ContainerInterface;
use Zephir\Compiler;
use Zephir\Config;
use Zephir\FileSystem\FileSystemInterface;
use function Zephir\unlink_recursive;

Expand Down Expand Up @@ -94,12 +92,4 @@ protected function createProject($backend)
$compiler = $container->get(Compiler::class);
$compiler->createProjectFiles('lifecycle');
}

/**
* @param ContainerInterface $container
*/
protected function muteOutput(ContainerInterface $container)
{
$container->get(Config::class)->set('silent', true);
}
}
10 changes: 0 additions & 10 deletions unit-tests/Zephir/Test/TypeHintsTest.php
Expand Up @@ -11,9 +11,7 @@

namespace Zephir\Test;

use Psr\Container\ContainerInterface;
use Zephir\Compiler;
use Zephir\Config;
use Zephir\FileSystem\FileSystemInterface;
use function Zephir\unlink_recursive;

Expand Down Expand Up @@ -130,12 +128,4 @@ protected function generate($backend)
$compiler = $container->get(Compiler::class);
$compiler->generate(true);
}

/**
* @param ContainerInterface $container
*/
protected function muteOutput(ContainerInterface $container)
{
$container->get(Config::class)->set('silent', true);
}
}
4 changes: 4 additions & 0 deletions unit-tests/fixtures/typehints/expected_retval2.h
Expand Up @@ -15,6 +15,7 @@ PHP_METHOD(TypeHints_RetVal, retval_boolean);
PHP_METHOD(TypeHints_RetVal, retval_int);
PHP_METHOD(TypeHints_RetVal, retval_long);
PHP_METHOD(TypeHints_RetVal, retval_double);
PHP_METHOD(TypeHints_RetVal, retval_array);
PHP_METHOD(TypeHints_RetVal, retval_retval);
PHP_METHOD(TypeHints_RetVal, retval_nullable_int);
PHP_METHOD(TypeHints_RetVal, retval_nullable_uint);
Expand All @@ -24,6 +25,7 @@ PHP_METHOD(TypeHints_RetVal, retval_nullable_double);
PHP_METHOD(TypeHints_RetVal, retval_nullable_string);
PHP_METHOD(TypeHints_RetVal, retval_nullable_boolean);
PHP_METHOD(TypeHints_RetVal, retval_nullable_char);
PHP_METHOD(TypeHints_RetVal, retval_nullable_array);
PHP_METHOD(TypeHints_RetVal, retval_object_or_scalar);
PHP_METHOD(TypeHints_RetVal, retval_static_object_or_scalar);

Expand All @@ -40,6 +42,7 @@ ZEPHIR_INIT_FUNCS(typehints_retval_method_entry) {
PHP_ME(TypeHints_RetVal, retval_int, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_long, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_double, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_array, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_retval, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_int, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_uint, NULL, ZEND_ACC_PUBLIC)
Expand All @@ -49,6 +52,7 @@ ZEPHIR_INIT_FUNCS(typehints_retval_method_entry) {
PHP_ME(TypeHints_RetVal, retval_nullable_string, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_boolean, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_char, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_array, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_object_or_scalar, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_static_object_or_scalar, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
Expand Down
18 changes: 18 additions & 0 deletions unit-tests/fixtures/typehints/expected_retval3.h
Expand Up @@ -15,6 +15,7 @@ PHP_METHOD(TypeHints_RetVal, retval_boolean);
PHP_METHOD(TypeHints_RetVal, retval_int);
PHP_METHOD(TypeHints_RetVal, retval_long);
PHP_METHOD(TypeHints_RetVal, retval_double);
PHP_METHOD(TypeHints_RetVal, retval_array);
PHP_METHOD(TypeHints_RetVal, retval_retval);
PHP_METHOD(TypeHints_RetVal, retval_nullable_int);
PHP_METHOD(TypeHints_RetVal, retval_nullable_uint);
Expand All @@ -24,6 +25,7 @@ PHP_METHOD(TypeHints_RetVal, retval_nullable_double);
PHP_METHOD(TypeHints_RetVal, retval_nullable_string);
PHP_METHOD(TypeHints_RetVal, retval_nullable_boolean);
PHP_METHOD(TypeHints_RetVal, retval_nullable_char);
PHP_METHOD(TypeHints_RetVal, retval_nullable_array);
PHP_METHOD(TypeHints_RetVal, retval_object_or_scalar);
PHP_METHOD(TypeHints_RetVal, retval_static_object_or_scalar);

Expand Down Expand Up @@ -76,6 +78,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_double,
#endif
ZEND_END_ARG_INFO()

#if PHP_VERSION_ID >= 70200
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_array, 0, 0, IS_ARRAY, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_array, 0, 0, IS_ARRAY, NULL, 0)
#endif
ZEND_END_ARG_INFO()

#if PHP_VERSION_ID >= 70200
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_typehints_retval_retval_retval, 0, 0, TypeHints\\RetVal, 0)
#else
Expand Down Expand Up @@ -139,6 +148,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_nullable
#endif
ZEND_END_ARG_INFO()

#if PHP_VERSION_ID >= 70200
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_nullable_array, 0, 0, IS_ARRAY, 1)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_nullable_array, 0, 0, IS_ARRAY, NULL, 1)
#endif
ZEND_END_ARG_INFO()

ZEPHIR_INIT_FUNCS(typehints_retval_method_entry) {
PHP_ME(TypeHints_RetVal, getMyVar, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, getMyString, arginfo_typehints_retval_getmystring, ZEND_ACC_PUBLIC)
Expand All @@ -152,6 +168,7 @@ ZEPHIR_INIT_FUNCS(typehints_retval_method_entry) {
PHP_ME(TypeHints_RetVal, retval_int, arginfo_typehints_retval_retval_int, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_long, arginfo_typehints_retval_retval_long, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_double, arginfo_typehints_retval_retval_double, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_array, arginfo_typehints_retval_retval_array, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_retval, arginfo_typehints_retval_retval_retval, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_int, arginfo_typehints_retval_retval_nullable_int, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_uint, arginfo_typehints_retval_retval_nullable_uint, ZEND_ACC_PUBLIC)
Expand All @@ -161,6 +178,7 @@ ZEPHIR_INIT_FUNCS(typehints_retval_method_entry) {
PHP_ME(TypeHints_RetVal, retval_nullable_string, arginfo_typehints_retval_retval_nullable_string, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_boolean, arginfo_typehints_retval_retval_nullable_boolean, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_char, arginfo_typehints_retval_retval_nullable_char, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_array, arginfo_typehints_retval_retval_nullable_array, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_object_or_scalar, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_static_object_or_scalar, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
Expand Down
8 changes: 8 additions & 0 deletions unit-tests/fixtures/typehints/typehints/retval.zep
Expand Up @@ -71,6 +71,10 @@ class RetVal {
return _var;
}

public function retval_array() -> array {
return [];
}

public function retval_retval() -> <RetVal> {
var _var;
let _var = new RetVal;
Expand Down Expand Up @@ -109,6 +113,10 @@ class RetVal {
return null;
}

public function retval_nullable_array() -> array | null {
return null;
}

public function retval_object_or_scalar() -> <\stdClass> | bool {
return false;
}
Expand Down

0 comments on commit 98ef66f

Please sign in to comment.