]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Core/InstallerTest.php
Merge pull request #11195 from annando/issue-10966
[friendica.git] / tests / src / Core / InstallerTest.php
index 68af5ff37f9bf068c25eee08a28dfc248c7d5058..9256581b16ce8e8031a5a356a5b7aa68740c4a60 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
  *
  */
 
-// this is in the same namespace as Install for mocking 'function_exists'
+/// @todo this is in the same namespace as Install for mocking 'function_exists'
 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;
 use Mockery\MockInterface;
 
 class InstallerTest extends MockedTest
 {
        use VFSTrait;
+       use ArraySubsetAsserts;
 
        /**
-        * @var \Friendica\Core\L10n|MockInterface
+        * @var L10n|MockInterface
         */
        private $l10nMock;
        /**
@@ -44,25 +47,34 @@ class InstallerTest extends MockedTest
         */
        private $dice;
 
-       public function setUp()
+       protected function setUp(): void
        {
                parent::setUp();
 
                $this->setUpVfsDir();
 
-               $this->l10nMock = \Mockery::mock(\Friendica\Core\L10n::class);
+               $this->l10nMock = Mockery::mock(L10n::class);
 
                /** @var Dice|MockInterface $dice */
-               $this->dice = \Mockery::mock(Dice::class)->makePartial();
+               $this->dice = Mockery::mock(Dice::class)->makePartial();
                $this->dice = $this->dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
 
                $this->dice->shouldReceive('create')
-                          ->with(\Friendica\Core\L10n::class)
+                          ->with(L10n::class)
                           ->andReturn($this->l10nMock);
 
                DI::init($this->dice);
        }
 
+       public static function tearDownAfterClass(): void
+       {
+               // Reset mocking
+               global $phpMock;
+               $phpMock = [];
+
+               parent::tearDownAfterClass();
+       }
+
        private function mockL10nT(string $text, $times = null)
        {
                $this->l10nMock->shouldReceive('t')->with($text)->andReturn($text)->times($times);
@@ -92,6 +104,8 @@ 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('Program execution functions', 1);
+               $this->mockL10nT('Error: Program execution functions (proc_open) required but not enabled.', 1);
        }
 
        private function assertCheckExist($position, $title, $help, $status, $required, $assertionArray)
@@ -112,7 +126,7 @@ class InstallerTest extends MockedTest
         *
         * @param array $functions a list from function names and their result
         */
-       private function setFunctions($functions)
+       private function setFunctions(array $functions)
        {
                global $phpMock;
                $phpMock['function_exists'] = function($function) use ($functions) {
@@ -130,7 +144,7 @@ class InstallerTest extends MockedTest
         *
         * @param array $classes a list from class names and their results
         */
-       private function setClasses($classes)
+       private function setClasses(array $classes)
        {
                global $phpMock;
                $phpMock['class_exists'] = function($class) use ($classes) {
@@ -231,10 +245,20 @@ class InstallerTest extends MockedTest
                        $install->getChecks());
 
                $this->mockFunctionL10TCalls();
-               $this->setFunctions(['json_encode' => false]);
+               $this->setFunctions(['proc_open' => false]);
                $install = new Installer();
                self::assertFalse($install->checkFunctions());
                self::assertCheckExist(9,
+                       'Program execution functions',
+                       'Error: Program execution functions (proc_open) required but not enabled.',
+                       false,
+                       true,
+                       $install->getChecks());
+               $this->mockFunctionL10TCalls();
+               $this->setFunctions(['json_encode' => false]);
+               $install = new Installer();
+               self::assertFalse($install->checkFunctions());
+               self::assertCheckExist(10,
                        'JSON PHP module',
                        'Error: JSON PHP module required but not installed.',
                        false,
@@ -245,7 +269,7 @@ class InstallerTest extends MockedTest
                $this->setFunctions(['finfo_open' => false]);
                $install = new Installer();
                self::assertFalse($install->checkFunctions());
-               self::assertCheckExist(10,
+               self::assertCheckExist(11,
                        'File Information PHP module',
                        'Error: File Information PHP module required but not installed.',
                        false,
@@ -297,30 +321,30 @@ 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);
@@ -344,30 +368,30 @@ 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);
@@ -387,7 +411,7 @@ class InstallerTest extends MockedTest
         */
        public function testImagick()
        {
-               $this->markTestIncomplete('needs adapted class_exists() mock');
+               static::markTestIncomplete('needs adapted class_exists() mock');
 
                $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
 
@@ -413,7 +437,7 @@ class InstallerTest extends MockedTest
         */
        public function testImagickNotFound()
        {
-               $this->markTestIncomplete('Disabled due not working/difficult mocking global functions - needs more care!');
+               static::markTestIncomplete('Disabled due not working/difficult mocking global functions - needs more care!');
 
                $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
 
@@ -450,14 +474,15 @@ class InstallerTest extends MockedTest
 
        /**
         * Test the setup of the config cache for installation
+        * @doesNotPerformAssertions
         */
        public function testSetUpCache()
        {
                $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
 
                $install = new Installer();
-               $configCache = \Mockery::mock(Cache::class);
-               $configCache->shouldReceive('set')->with('config', 'php_path', \Mockery::any())->once();
+               $configCache = Mockery::mock(Cache::class);
+               $configCache->shouldReceive('set')->with('config', 'php_path', Mockery::any())->once();
                $configCache->shouldReceive('set')->with('system', 'basepath', '/test/')->once();
 
                $install->setUpCache($configCache, '/test/');
@@ -471,7 +496,7 @@ class InstallerTest extends MockedTest
  *
  * @return bool true or false
  */
-function function_exists($function_name)
+function function_exists(string $function_name)
 {
        global $phpMock;
        if (isset($phpMock['function_exists'])) {