-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests and test utils for mocking functions.
- Loading branch information
1 parent
8863235
commit 319ac6b
Showing
8 changed files
with
192 additions
and
33 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,12 @@ | ||
<?php | ||
|
||
namespace League\Flysystem\Local { | ||
function rmdir(...$arguments) | ||
{ | ||
if ( ! is_mocked('rmdir')) { | ||
return \rmdir(...$arguments); | ||
} | ||
|
||
return return_mocked_value('rmdir'); | ||
} | ||
} |
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,5 @@ | ||
<?php | ||
|
||
include __DIR__.'/vendor/autoload.php'; | ||
include __DIR__.'/test-functions.php'; | ||
include __DIR__.'/mocked-functions.php'; |
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
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
function return_mocked_value(string $name) | ||
{ | ||
return array_shift($GLOBALS['__FM:RETURNS:' . $name]); | ||
} | ||
|
||
function reset_function_mocks() | ||
{ | ||
foreach ($GLOBALS as $name) { | ||
if (is_string($name) && substr($name, 0, 5) === '__FM:') { | ||
unset($GLOBALS[$name]); | ||
} | ||
} | ||
} | ||
|
||
function mock_function(string $name, ...$returns) | ||
{ | ||
$GLOBALS['__FM:FUNC_IS_MOCKED:' . $name] = 'yes'; | ||
$GLOBALS['__FM:RETURNS:' . $name] = $returns; | ||
} | ||
|
||
function is_mocked(string $name) | ||
{ | ||
return ($GLOBALS['__FM:FUNC_IS_MOCKED:' . $name] ?? 'no') === 'yes'; | ||
} |