]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Core/InstallerTest.php
Improved logging
[friendica.git] / tests / src / Core / InstallerTest.php
index 365502e4673fef06961cb4986f09352b516d9149..376703a270bf333485e884f8cc05f092bacca03a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 namespace Friendica\Core;
 
 use Dice\Dice;
-use Friendica\Core\Config\Cache;
+use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
+use Friendica\Core\Config\ValueObject\Cache;
 use Friendica\DI;
-use Friendica\Network\CurlResult;
-use Friendica\Network\IHTTPRequest;
+use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
+use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
 use Friendica\Test\MockedTest;
 use Friendica\Test\Util\VFSTrait;
 use Mockery;
@@ -35,6 +36,7 @@ use Mockery\MockInterface;
 class InstallerTest extends MockedTest
 {
        use VFSTrait;
+       use ArraySubsetAsserts;
 
        /**
         * @var L10n|MockInterface
@@ -45,7 +47,7 @@ class InstallerTest extends MockedTest
         */
        private $dice;
 
-       protected function setUp()
+       protected function setUp(): void
        {
                parent::setUp();
 
@@ -61,7 +63,16 @@ class InstallerTest extends MockedTest
                           ->with(L10n::class)
                           ->andReturn($this->l10nMock);
 
-               DI::init($this->dice);
+               DI::init($this->dice, true);
+       }
+
+       public static function tearDownAfterClass(): void
+       {
+               // Reset mocking
+               global $phpMock;
+               $phpMock = [];
+
+               parent::tearDownAfterClass();
        }
 
        private function mockL10nT(string $text, $times = null)
@@ -93,8 +104,10 @@ class InstallerTest extends MockedTest
                $this->mockL10nT('Error: JSON PHP module required but not installed.', 1);
                $this->mockL10nT('File Information PHP module', 1);
                $this->mockL10nT('Error: File Information PHP module required but not installed.', 1);
+               $this->mockL10nT('GNU Multiple Precision PHP module', 1);
+               $this->mockL10nT('Error: GNU Multiple Precision PHP module required but not installed.', 1);
                $this->mockL10nT('Program execution functions', 1);
-               $this->mockL10nT('Error: Program execution functions required but not enabled.', 1);
+               $this->mockL10nT('Error: Program execution functions (proc_open) required but not enabled.', 1);
        }
 
        private function assertCheckExist($position, $title, $help, $status, $required, $assertionArray)
@@ -239,7 +252,7 @@ class InstallerTest extends MockedTest
                self::assertFalse($install->checkFunctions());
                self::assertCheckExist(9,
                        'Program execution functions',
-                       'Error: Program execution functions required but not enabled.',
+                       'Error: Program execution functions (proc_open) required but not enabled.',
                        false,
                        true,
                        $install->getChecks());
@@ -265,6 +278,17 @@ class InstallerTest extends MockedTest
                        true,
                        $install->getChecks());
 
+               $this->mockFunctionL10TCalls();
+               $this->setFunctions(['gmp_strval' => false]);
+               $install = new Installer();
+               self::assertFalse($install->checkFunctions());
+               self::assertCheckExist(12,
+                       'GNU Multiple Precision PHP module',
+                       'Error: GNU Multiple Precision PHP module required but not installed.',
+               false,
+                       true,
+                       $install->getChecks());
+
                $this->mockFunctionL10TCalls();
                $this->setFunctions([
                        'curl_init' => true,
@@ -275,6 +299,7 @@ class InstallerTest extends MockedTest
                        'posix_kill' => true,
                        'json_encode' => true,
                        'finfo_open' => true,
+                       'gmp_strval' => true,
                ]);
                $install = new Installer();
                self::assertTrue($install->checkFunctions());
@@ -310,33 +335,33 @@ class InstallerTest extends MockedTest
                $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
 
                // Mocking the CURL Response
-               $curlResult = Mockery::mock(CurlResult::class);
-               $curlResult
+               $IHTTPResult = Mockery::mock(ICanHandleHttpResponses::class);
+               $IHTTPResult
                        ->shouldReceive('getReturnCode')
                        ->andReturn('404');
-               $curlResult
+               $IHTTPResult
                        ->shouldReceive('getRedirectUrl')
                        ->andReturn('');
-               $curlResult
+               $IHTTPResult
                        ->shouldReceive('getError')
                        ->andReturn('test Error');
 
                // Mocking the CURL Request
-               $networkMock = Mockery::mock(IHTTPRequest::class);
+               $networkMock = Mockery::mock(ICanSendHttpRequests::class);
                $networkMock
                        ->shouldReceive('fetchFull')
                        ->with('https://test/install/testrewrite')
-                       ->andReturn($curlResult);
+                       ->andReturn($IHTTPResult);
                $networkMock
                        ->shouldReceive('fetchFull')
                        ->with('http://test/install/testrewrite')
-                       ->andReturn($curlResult);
+                       ->andReturn($IHTTPResult);
 
                $this->dice->shouldReceive('create')
-                    ->with(IHTTPRequest::class)
+                    ->with(ICanSendHttpRequests::class)
                     ->andReturn($networkMock);
 
-               DI::init($this->dice);
+               DI::init($this->dice, true);
 
                // Mocking that we can use CURL
                $this->setFunctions(['curl_init' => true]);
@@ -357,33 +382,33 @@ class InstallerTest extends MockedTest
                $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
 
                // Mocking the failed CURL Response
-               $curlResultF = Mockery::mock(CurlResult::class);
-               $curlResultF
+               $IHTTPResultF = Mockery::mock(ICanHandleHttpResponses::class);
+               $IHTTPResultF
                        ->shouldReceive('getReturnCode')
                        ->andReturn('404');
 
                // Mocking the working CURL Response
-               $curlResultW = Mockery::mock(CurlResult::class);
-               $curlResultW
+               $IHTTPResultW = Mockery::mock(ICanHandleHttpResponses::class);
+               $IHTTPResultW
                        ->shouldReceive('getReturnCode')
                        ->andReturn('204');
 
                // Mocking the CURL Request
-               $networkMock = Mockery::mock(IHTTPRequest::class);
+               $networkMock = Mockery::mock(ICanSendHttpRequests::class);
                $networkMock
                        ->shouldReceive('fetchFull')
                        ->with('https://test/install/testrewrite')
-                       ->andReturn($curlResultF);
+                       ->andReturn($IHTTPResultF);
                $networkMock
                        ->shouldReceive('fetchFull')
                        ->with('http://test/install/testrewrite')
-                       ->andReturn($curlResultW);
+                       ->andReturn($IHTTPResultW);
 
                $this->dice->shouldReceive('create')
-                          ->with(IHTTPRequest::class)
+                          ->with(ICanSendHttpRequests::class)
                           ->andReturn($networkMock);
 
-               DI::init($this->dice);
+               DI::init($this->dice, true);
 
                // Mocking that we can use CURL
                $this->setFunctions(['curl_init' => true]);
@@ -463,6 +488,7 @@ class InstallerTest extends MockedTest
 
        /**
         * Test the setup of the config cache for installation
+        * @doesNotPerformAssertions
         */
        public function testSetUpCache()
        {