-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from mehamasum/fix/infinite-loop-on-restub-invoke
Fix/infinite loop on restub invoke
- Loading branch information
Showing
2 changed files
with
79 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
|
||
function global_function_bar() { | ||
return - 1; | ||
} | ||
|
||
class ConsecutiveExecutionTest extends \Spies\TestCase { | ||
function tearDown() { | ||
\Spies\finish_spying(); | ||
} | ||
|
||
public function test__undefined_function___can_be_stubbed() { | ||
$foo_spy = \Spies\get_spy_for( 'undefined_function' )->and_return( 4 ); | ||
$ret = undefined_function(); | ||
$this->assertEquals( 1, $foo_spy->get_times_called() ); | ||
$this->assertEquals( 4, $ret ); | ||
} | ||
|
||
public function test__undefined_function___can_be_restubbed() { | ||
$foo_spy = \Spies\get_spy_for( 'undefined_function' ); | ||
$ret = undefined_function(); | ||
$this->assertEquals( 1, $foo_spy->get_times_called() ); | ||
$this->assertEquals( null, $ret ); | ||
} | ||
|
||
public function test__undefined_function___can_be_restubbed_again() { | ||
$foo_spy = \Spies\get_spy_for( 'undefined_function' ); | ||
$ret = undefined_function(); | ||
$this->assertEquals( 1, $foo_spy->get_times_called() ); | ||
$this->assertEquals( null, $ret ); | ||
} | ||
|
||
public function test__undefined_function___can_be_restubbed_again_with_new_return() { | ||
$foo_spy = \Spies\get_spy_for( 'undefined_function' )->and_return( 3 ); | ||
$ret = undefined_function(); | ||
$this->assertEquals( 1, $foo_spy->get_times_called() ); | ||
$this->assertEquals( 3, $ret ); | ||
} | ||
|
||
public function test__global_function__can_be_stubbed() { | ||
$bar_spy = \Spies\get_spy_for( 'global_function_bar' )->and_return( 0 ); | ||
$ret = global_function_bar(); | ||
$this->assertEquals( 1, $bar_spy->get_times_called() ); | ||
$this->assertEquals( 0, $ret ); | ||
} | ||
|
||
public function test__global_function__can_be_restubbed() { | ||
$bar_spy = \Spies\get_spy_for( 'global_function_bar' ); | ||
$ret = global_function_bar(); | ||
$this->assertEquals( 1, $bar_spy->get_times_called() ); | ||
$this->assertEquals( - 1, $ret ); | ||
} | ||
|
||
public function test__global_function__can_be_restubbed_again() { | ||
$bar_spy = \Spies\get_spy_for( 'global_function_bar' ); | ||
$ret = global_function_bar(); | ||
$this->assertEquals( 1, $bar_spy->get_times_called() ); | ||
$this->assertEquals( - 1, $ret ); | ||
} | ||
|
||
public function test__global_function__can_be_restubbed_again_with_new_return() { | ||
$bar_spy = \Spies\get_spy_for( 'global_function_bar' )->and_return( 3 ); | ||
$ret = global_function_bar(); | ||
$this->assertEquals( 1, $bar_spy->get_times_called() ); | ||
$this->assertEquals( 3, $ret ); | ||
} | ||
} |