Skip to content

Commit

Permalink
[master]: Merge remote-tracking branch 'origin/PLATFORM-8138_fix_yeld…
Browse files Browse the repository at this point in the history
…ing'

# Conflicts:
#	src/QA/SoftMocks.php
  • Loading branch information
Sannis committed Sep 22, 2017
2 parents 8eb54a3 + c1f1e50 commit 39af1c8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ There are next changes:

- PHP 7.1 support (mostly nullable and void return type declarations);
- update nikic/php-parser to 3.0.6;
- fix bug with throwing from generators;
- added tests for constants redefine.

## v1.2.0
Expand Down
21 changes: 19 additions & 2 deletions src/Badoo/SoftMocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,7 @@ public static function ignoreFunction($function)
private $disable_const_rewrite_level = 0;

private $in_interface = false;
private $in_closure_level = 0;
private $has_yield = false;
private $cur_class = '';

Expand Down Expand Up @@ -1869,17 +1870,33 @@ public function rewriteExpr_Exit(\PhpParser\Node\Expr\Exit_ $Node)

public function beforeStmt_ClassMethod()
{
$this->in_closure_level = 0;
$this->has_yield = false;
}

public function beforeExpr_Closure()
{
$this->in_closure_level++;
}

public function rewriteExpr_Closure(\PhpParser\Node\Expr\Closure $Node)
{
$this->in_closure_level--;
return $Node;
}

public function beforeExpr_Yield()
{
$this->has_yield = true;
if ($this->in_closure_level === 0) {
$this->has_yield = true;
}
}

public function beforeExpr_YieldFrom()
{
$this->has_yield = true;
if ($this->in_closure_level === 0) {
$this->has_yield = true;
}
}

public function beforeStmt_Class(\PhpParser\Node\Stmt\Class_ $Node)
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/Badoo/SoftMocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,22 @@ public function testRewrite($filename)
//file_put_contents(__DIR__ . '/fixtures/expected/' . $filename, file_get_contents($result));
$this->assertEquals(file_get_contents(__DIR__ . '/fixtures/expected/' . $filename), file_get_contents($result));
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage You will never see this message
*/
public function testNotOk()
{
throw new \RuntimeException("You will never see this message");

$Mock = $this->getMock(MyTest::class, ['stubFunction']);
$Mock->expects($this->any())->method('stubFunction')->willReturn(
function () {
yield 10;
}
);
}

public function stubFunction() {}
}

0 comments on commit 39af1c8

Please sign in to comment.