forked from zephir-lang/zephir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix zephir-lang#1885: Check return value before creating dynamic class.
- Loading branch information
1 parent
c893389
commit 8095e19
Showing
6 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Zephir. | ||
* | ||
* (c) Zephir Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Extension; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class NewInstanceOperatorTest extends TestCase | ||
{ | ||
|
||
protected $autoloadMap = [ | ||
'Fixture\ParseErrorClass' => ZEPHIRPATH.'/unit-tests/fixtures/class-parse-error.php', | ||
'Fixture\EmptyClass' => ZEPHIRPATH.'/unit-tests/fixtures/class-empty.php' | ||
]; | ||
|
||
public function setUp() | ||
{ | ||
spl_autoload_register([$this, 'autoload']); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
spl_autoload_unregister([$this, 'autoload']); | ||
} | ||
|
||
public function autoload($className) | ||
{ | ||
if(isset($this->autoloadMap[$className])) { | ||
include $this->autoloadMap[$className]; | ||
} | ||
} | ||
|
||
public function testThrowableException() | ||
{ | ||
$this->expectException(\ParseError::class); | ||
|
||
$t = new \Test\Operator(); | ||
$obj = $t->testNewInstanceOperator('Fixture\ParseErrorClass'); | ||
} | ||
|
||
public function testNewInstance() | ||
{ | ||
$t = new \Test\Operator(); | ||
$object = $t->testNewInstanceOperator('Fixture\EmptyClass'); | ||
|
||
$this->assertInstanceOf('Fixture\EmptyClass', $object); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Zephir. | ||
* | ||
* (c) Zephir Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fixture; | ||
|
||
class EmptyClass | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Zephir. | ||
* | ||
* (c) Zephir Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fixture; | ||
|
||
class ParseErrorClass | ||
{ | ||
|
||
public function __construct() { | ||
|
||
} | ||
|
||
public function syntaxError() { | ||
echo '; | ||
} | ||
|
||
} |