Skip to content

Commit

Permalink
test(unit) add more coverage for replaceInOrder method
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Apr 24, 2020
1 parent 63e8a13 commit 925d699
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/tad/FunctionMocker/FunctionReplacementInOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function returnValues()
* @test
* @dataProvider returnValues
*/
public function replace_function_should_be_retunr_values_in_order( $values ) {
public function replace_function_should_be_return_values_in_order(array $values) {
$f = 'Some\Name\Space\func' . uniqid(rand(1, 9999));
$spy = FunctionMocker::replaceInOrder( $f, $values );

Expand All @@ -38,4 +38,17 @@ public function replace_function_should_be_retunr_values_in_order( $values ) {
$spy->wasCalledTimes(count($values));
}

/**
* Test replace static methods should replace values in order
* @dataProvider returnValues
*/
public function test_replace_static_methods_should_replace_values_in_order(array $values) {
$f = 'tad\FunctionMocker\Tests\AClass::staticMethod';
$spy = FunctionMocker::replaceInOrder( $f, $values );

foreach ( $values as $value ) {
$this->assertEquals( $value, $f() );
}
$spy->wasCalledTimes(count($values));
}
}
15 changes: 15 additions & 0 deletions tests/tad/FunctionMocker/FunctionReplacementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,19 @@ public function allow_replacing_a_non_defined_namespaced_function()
$this->assertEquals(2324, $f());
$spy->wasCalledOnce();
}

/**
* It should allow replacing a function result w/ an array
*
* @test
*/
public function should_allow_replacing_a_function_result_w_an_array() {
$f = 'Some\Name\Space\func' . uniqid(rand(1, 9999));

$spy = FunctionMocker::replace($f, [23,89,2389]);

$this->assertTrue(function_exists($f));
$this->assertEquals([23,89,2389], $f());
$spy->wasCalledOnce();
}
}

0 comments on commit 925d699

Please sign in to comment.