mirror of
https://github.com/friendica/friendica
synced 2024-12-22 19:20:17 +00:00
Fix mocking namespace
This commit is contained in:
parent
5ecee2b9f7
commit
04d4c6d8f0
3 changed files with 22 additions and 46 deletions
|
@ -313,6 +313,6 @@ class Crypto
|
|||
$rn .= random_int(0, 9);
|
||||
}
|
||||
|
||||
return $rn;
|
||||
return (int) $rn;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckKeys($function, $expected)
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) use ($function, $expected) {
|
||||
if ($function_name === $function) {
|
||||
return $expected;
|
||||
|
@ -170,7 +170,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutIntlChar()
|
||||
{
|
||||
$class_exists = $this->getFunctionMock(__NAMESPACE__, 'class_exists');
|
||||
$class_exists = $this->getFunctionMock('Friendica\Core', 'class_exists');
|
||||
$class_exists->expects($this->any())->willReturnCallback(function($class_name) {
|
||||
if ($class_name === 'IntlChar') {
|
||||
return false;
|
||||
|
@ -195,7 +195,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutCurlInit()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'curl_init') {
|
||||
return false;
|
||||
|
@ -220,7 +220,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutImagecreateformjpeg()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'imagecreatefromjpeg') {
|
||||
return false;
|
||||
|
@ -245,7 +245,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutOpensslpublicencrypt()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'openssl_public_encrypt') {
|
||||
return false;
|
||||
|
@ -270,7 +270,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutMbStrlen()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'mb_strlen') {
|
||||
return false;
|
||||
|
@ -295,7 +295,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutIconvStrlen()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'iconv_strlen') {
|
||||
return false;
|
||||
|
@ -320,7 +320,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutPosixkill()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'posix_kill') {
|
||||
return false;
|
||||
|
@ -345,7 +345,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutProcOpen()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'proc_open') {
|
||||
return false;
|
||||
|
@ -370,7 +370,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutJsonEncode()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'json_encode') {
|
||||
return false;
|
||||
|
@ -395,7 +395,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutFinfoOpen()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'finfo_open') {
|
||||
return false;
|
||||
|
@ -420,7 +420,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctionsWithoutGmpStrval()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'gmp_strval') {
|
||||
return false;
|
||||
|
@ -445,7 +445,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckFunctions()
|
||||
{
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if (in_array(
|
||||
$function_name,
|
||||
|
@ -500,7 +500,7 @@ class InstallerTest extends MockedTest
|
|||
public function testCheckHtAccessFail()
|
||||
{
|
||||
// Mocking that we can use CURL
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'curl_init') {
|
||||
return true;
|
||||
|
@ -553,7 +553,7 @@ class InstallerTest extends MockedTest
|
|||
public function testCheckHtAccessWork()
|
||||
{
|
||||
// Mocking that we can use CURL
|
||||
$function_exists = $this->getFunctionMock(__NAMESPACE__, 'function_exists');
|
||||
$function_exists = $this->getFunctionMock('Friendica\Core', 'function_exists');
|
||||
$function_exists->expects($this->any())->willReturnCallback(function($function_name) {
|
||||
if ($function_name === 'curl_init') {
|
||||
return true;
|
||||
|
@ -604,7 +604,7 @@ class InstallerTest extends MockedTest
|
|||
*/
|
||||
public function testCheckImagickWithImagick()
|
||||
{
|
||||
$class_exists = $this->getFunctionMock(__NAMESPACE__, 'class_exists');
|
||||
$class_exists = $this->getFunctionMock('Friendica\Core', 'class_exists');
|
||||
$class_exists->expects($this->any())->willReturnCallback(function($class_name) {
|
||||
if ($class_name === 'Imagick') {
|
||||
return true;
|
||||
|
|
|
@ -24,39 +24,15 @@ class CryptoTest extends TestCase
|
|||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces random_int results with given mocks
|
||||
*
|
||||
*/
|
||||
private function assertRandomInt($min, $max)
|
||||
{
|
||||
global $phpMock;
|
||||
$phpMock['random_int'] = function ($mMin, $mMax) use ($min, $max) {
|
||||
self::assertEquals($min, $mMin);
|
||||
self::assertEquals($max, $mMax);
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
|
||||
public function testRandomDigitsRandomInt()
|
||||
{
|
||||
$random_int = $this->getFunctionMock(__NAMESPACE__, 'random_int');
|
||||
$random_int = $this->getFunctionMock('Friendica\Util', '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());
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
|
||||
self::assertRandomInt(0, 9);
|
||||
|
||||
$test = Crypto::randomDigits(1);
|
||||
self::assertEquals(1, strlen($test));
|
||||
self::assertEquals(1, $test);
|
||||
|
||||
$test = Crypto::randomDigits(8);
|
||||
self::assertEquals(8, strlen($test));
|
||||
self::assertEquals(11111111, $test);
|
||||
self::assertSame(1, Crypto::randomDigits(1));
|
||||
self::assertSame(11111111, Crypto::randomDigits(8));
|
||||
}
|
||||
|
||||
public function dataRsa(): array
|
||||
|
@ -74,7 +50,7 @@ class CryptoTest extends TestCase
|
|||
*/
|
||||
public function testPubRsaToMe(string $key, string $expected)
|
||||
{
|
||||
self::assertEquals($expected, Crypto::rsaToPem(base64_decode($key)));
|
||||
self::assertSame($expected, Crypto::rsaToPem(base64_decode($key)));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue