Skip to content

Commit

Permalink
Add test for #1751
Browse files Browse the repository at this point in the history
See: #1812
  • Loading branch information
sergeyklay committed Feb 21, 2019
1 parent fb6d407 commit a721542
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[#1758](https://github.com/phalcon/zephir/issues/1758)
- Fixed compilation error when a new file is added or removed to the project
[#1776](https://github.com/phalcon/zephir/issues/1776)
- Fixed calling anonymous functions by resolving context [#1751](https://github.com/phalcon/zephir/issues/1751)

## [0.11.7] - 2018-11-27
### Changed
Expand Down
4 changes: 3 additions & 1 deletion ext/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ if test "$PHP_TEST" = "yes"; then
test/json.zep.c
test/logical.zep.c
test/mcall.zep.c
test/mcall/caller.zep.c
test/mcallchained.zep.c
test/mcalldynamic.zep.c
test/mcallinternal.zep.c
Expand Down Expand Up @@ -186,7 +187,8 @@ if test "$PHP_TEST" = "yes"; then
test/6__closure.zep.c
test/7__closure.zep.c
test/8__closure.zep.c
test/9__closure.zep.c "
test/9__closure.zep.c
test/10__closure.zep.c "
PHP_NEW_EXTENSION(test, $test_sources, $ext_shared,, )
PHP_SUBST(TEST_SHARED_LIBADD)

Expand Down
3 changes: 2 additions & 1 deletion ext/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (PHP_TEST != "no") {
AC_DEFINE("ZEPHIR_USE_PHP_JSON", 1, "Whether PHP json extension is present at compile time");
}

ADD_SOURCES(configure_module_dirname + "/test", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1404.zep.c issue1521.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1404.zep.c issue1521.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c 10__closure.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/oo/extend", "exception.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/oo/extend/db", "exception.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/globals/session", "base.zep.c child.zep.c", "test");
Expand All @@ -24,6 +24,7 @@ if (PHP_TEST != "no") {
ADD_SOURCES(configure_module_dirname + "/test/flow", "switchflow.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/globals", "env.zep.c post.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/integration/psr/http/message", "messageinterfaceex.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/mcall", "caller.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/oo/extend/db/query/placeholder", "exception.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/oo/extend/spl", "arrayobject.zep.c directoryiterator.zep.c doublylinkedlist.zep.c fileinfo.zep.c fileobject.zep.c filesystemiterator.zep.c fixedarray.zep.c globiterator.zep.c heap.zep.c maxheap.zep.c minheap.zep.c priorityqueue.zep.c queue.zep.c recursivedirectoryiterator.zep.c stack.zep.c tempfileobject.zep.c", "test");
ADD_SOURCES(configure_module_dirname + "/test/optimizers", "isscalar.zep.c acos.zep.c arraymerge.zep.c asin.zep.c cos.zep.c createarray.zep.c ldexp.zep.c sin.zep.c sqrt.zep.c strreplace.zep.c substr.zep.c tan.zep.c", "test");
Expand Down
4 changes: 4 additions & 0 deletions ext/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ zend_class_entry *test_oo_oodynamica_ce;
zend_class_entry *test_oo_scopes_hasprivatemethod_ce;
zend_class_entry *test_properties_publicproperties_ce;
zend_class_entry *test_0__closure_ce;
zend_class_entry *test_10__closure_ce;
zend_class_entry *test_1__closure_ce;
zend_class_entry *test_2__closure_ce;
zend_class_entry *test_3__closure_ce;
Expand Down Expand Up @@ -107,6 +108,7 @@ zend_class_entry *test_issue1521_ce;
zend_class_entry *test_issues_ce;
zend_class_entry *test_json_ce;
zend_class_entry *test_logical_ce;
zend_class_entry *test_mcall_caller_ce;
zend_class_entry *test_mcall_ce;
zend_class_entry *test_mcallchained_ce;
zend_class_entry *test_mcalldynamic_ce;
Expand Down Expand Up @@ -297,6 +299,7 @@ static PHP_MINIT_FUNCTION(test)
ZEPHIR_INIT(Test_McallChained);
ZEPHIR_INIT(Test_McallDynamic);
ZEPHIR_INIT(Test_McallInternal);
ZEPHIR_INIT(Test_Mcall_Caller);
ZEPHIR_INIT(Test_MethodAbstract);
ZEPHIR_INIT(Test_MethodArgs);
ZEPHIR_INIT(Test_NativeArray);
Expand Down Expand Up @@ -388,6 +391,7 @@ static PHP_MINIT_FUNCTION(test)
ZEPHIR_INIT(Test_UseTest);
ZEPHIR_INIT(Test_Vars);
ZEPHIR_INIT(test_0__closure);
ZEPHIR_INIT(test_10__closure);
ZEPHIR_INIT(test_1__closure);
ZEPHIR_INIT(test_2__closure);
ZEPHIR_INIT(test_3__closure);
Expand Down
2 changes: 2 additions & 0 deletions ext/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include "test/json.zep.h"
#include "test/logical.zep.h"
#include "test/mcall.zep.h"
#include "test/mcall/caller.zep.h"
#include "test/mcallchained.zep.h"
#include "test/mcalldynamic.zep.h"
#include "test/mcallinternal.zep.h"
Expand Down Expand Up @@ -182,5 +183,6 @@
#include "test/7__closure.zep.h"
#include "test/8__closure.zep.h"
#include "test/9__closure.zep.h"
#include "test/10__closure.zep.h"

#endif
41 changes: 41 additions & 0 deletions ext/test/10__closure.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions ext/test/10__closure.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions ext/test/mcall/caller.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions ext/test/mcall/caller.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions ext/test/mcalldynamic.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ext/test/mcalldynamic.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/mcall/caller.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Test\Mcall;

class Caller
{
public static function start(callable f) -> var
{
return {f}();
}

public static function perform() -> string
{
return __METHOD__;
}
}
17 changes: 17 additions & 0 deletions test/mcalldynamic.zep
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Test;


use Test\Mcall\Caller;

class McallDynamic
{
public function testMethod1()
Expand All @@ -23,4 +26,18 @@ class McallDynamic
let realMethod = "test" . method;
return this->{realMethod}();
}

/**
* @link https://github.com/phalcon/zephir/issues/1751
*/
public function testCallAnonymousFunctionWithContext() -> var
{
var result;

let result = Caller::start(function () {
return Caller::perform();
});

return result;
}
}
18 changes: 15 additions & 3 deletions unit-tests/Extension/MCallDynamicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@

class MCallDynamicTest extends TestCase
{
public function testCallDynamic()
/** @test */
public function callDynamic()
{
$a = new McallDynamic();
$this->assertSame($a->method1(), 1);
$this->assertSame($a->testMagicCall1(), 2);
$this->assertSame(1, $a->method1());
$this->assertSame(2, $a->testMagicCall1());
}

/**
* @test
* @link https://github.com/phalcon/zephir/issues/1751
*/
public function callAnonymousFunctionWithContext()
{
$t = new McallDynamic();

$this->assertSame('Caller:perform', $t->testCallAnonymousFunctionWithContext());
}
}

0 comments on commit a721542

Please sign in to comment.