mirror of
https://github.com/friendica/friendica
synced 2024-12-23 01:20:16 +00:00
Fix namespace for CryptoTest
This commit is contained in:
parent
f575f6c94c
commit
7de3b16dc3
1 changed files with 13 additions and 16 deletions
|
@ -6,14 +6,16 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
/// @todo Use right namespace - needs alternative way of mocking random_int()
|
/// @todo Use right namespace - needs alternative way of mocking random_int()
|
||||||
namespace Friendica\Util;
|
namespace Friendica\Test\src\Util;
|
||||||
|
|
||||||
use phpseclib\Crypt\RSA;
|
use Friendica\Util\Crypto;
|
||||||
use phpseclib\Math\BigInteger;
|
use phpmock\phpunit\PHPMock;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class CryptoTest extends TestCase
|
class CryptoTest extends TestCase
|
||||||
{
|
{
|
||||||
|
use PHPMock;
|
||||||
|
|
||||||
public static function tearDownAfterClass(): void
|
public static function tearDownAfterClass(): void
|
||||||
{
|
{
|
||||||
// Reset mocking
|
// Reset mocking
|
||||||
|
@ -39,6 +41,14 @@ class CryptoTest extends TestCase
|
||||||
|
|
||||||
public function testRandomDigitsRandomInt()
|
public function testRandomDigitsRandomInt()
|
||||||
{
|
{
|
||||||
|
$random_int = $this->getFunctionMock(__NAMESPACE__, 'random_int');
|
||||||
|
$random_int->expects($this->any())->willReturnCallback(function($min, $max) {
|
||||||
|
global $phpMock;
|
||||||
|
if (isset($phpMock['random_int'])) {
|
||||||
|
return call_user_func_array($phpMock['random_int'], func_get_args());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
self::assertRandomInt(0, 9);
|
self::assertRandomInt(0, 9);
|
||||||
|
|
||||||
$test = Crypto::randomDigits(1);
|
$test = Crypto::randomDigits(1);
|
||||||
|
@ -78,16 +88,3 @@ class CryptoTest extends TestCase
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A workaround to replace the PHP native random_int() (>= 7.0) with a mocked function
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
function random_int($min, $max)
|
|
||||||
{
|
|
||||||
global $phpMock;
|
|
||||||
if (isset($phpMock['random_int'])) {
|
|
||||||
return call_user_func_array($phpMock['random_int'], func_get_args());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue