Skip to content

Commit

Permalink
Improve tests for fixing opis#70
Browse files Browse the repository at this point in the history
Follow-up from opis#71
  • Loading branch information
mnapoli committed Aug 1, 2020
1 parent 9fee604 commit 0818e3d
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions tests/ClosureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@

class ClosureTest extends \PHPUnit\Framework\TestCase
{
public function testClassNameWithUse()
{
$wrapper = new SerializableClosure(
function () {
return new ClosureContext; // new object without `()`
}
);

$code = $wrapper->getReflector()->getCode();
$this->assertStringContainsString('Opis\Closure\ClosureContext', $code);
}

protected function s($closure)
{
if($closure instanceof Closure)
Expand Down Expand Up @@ -364,6 +352,30 @@ public function testClosureScopeRemainsTheSame()
$this->assertNull($ro->getClosureScopeClass());
}

/**
* Covers https://github.com/opis/closure/issues/70
*/
public function testClosureContainingNewWithoutParentheses()
{
$closure = $this->s(function () {
return new A; // new object without `()`
});

$this->assertInstanceOf('Opis\Closure\Test\A', $closure());
}

/**
* Covers https://github.com/opis/closure/pull/71#issuecomment-663766050
*/
public function testClosureContainingNewFromVariable()
{
$closure = $this->s(function () {
$className = 'Opis\Closure\Test\A';
return new $className;
});

$this->assertInstanceOf('Opis\Closure\Test\A', $closure());
}
}

class ObjnObj implements Serializable {
Expand Down

0 comments on commit 0818e3d

Please sign in to comment.