diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 90ac377fb..f4d6d7991 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11,77 +11,7 @@ parameters: path: src/library/Registrar/Adapter/Namecheap.php - - message: "#^Method Registrar_Adapter_Resellerclub\\:\\:_makeRequest\\(\\) should return string but returns array\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Method Registrar_Adapter_Resellerclub\\:\\:addSubReseller\\(\\) should return stdClass but returns string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Method Registrar_Adapter_Resellerclub\\:\\:transferDomain\\(\\) should return bool but returns string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'actionstatus' does not exist on string\\.$#" - count: 3 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'admincontact' does not exist on string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'creationtime' does not exist on string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'currentstatus' does not exist on string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'domsecret' does not exist on string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'endtime' does not exist on string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'isprivacyprotected' does not exist on string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'recsonpage' does not exist on string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'result' does not exist on string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'status' does not exist on non\\-falsy\\-string\\.$#" - count: 1 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'status' does not exist on string\\.$#" - count: 6 - path: src/library/Registrar/Adapter/Resellerclub.php - - - - message: "#^Offset 'version' does not exist on string\\.$#" + message: "#^Method Registrar_Adapter_Resellerclub\\:\\:addSubReseller\\(\\) should return stdClass but returns array\\|string\\.$#" count: 1 path: src/library/Registrar/Adapter/Resellerclub.php @@ -145,11 +75,6 @@ parameters: count: 1 path: src/library/Server/Manager/Plesk.php - - - message: "#^Call to an undefined method PleskX\\\\Api\\\\Operator\\\\Reseller\\:\\:setProperties\\(\\)\\.$#" - count: 4 - path: src/library/Server/Manager/Plesk.php - - message: "#^Call to an undefined method Server_Package\\:\\:getHasAnonymousFtp\\(\\)\\.$#" count: 1 @@ -172,5 +97,5 @@ parameters: - message: "#^Call to an undefined method Server_Package\\:\\:getMaxEmailLists\\(\\)\\.$#" - count: 3 - path: src/library/Server/Manager/Plesk.php + count: 2 + path: src/library/Server/Manager/Plesk.php \ No newline at end of file diff --git a/src/di.php b/src/di.php index 81a940e68..63560b851 100644 --- a/src/di.php +++ b/src/di.php @@ -245,9 +245,9 @@ $di['request'] = fn (): \FOSSBilling\Request => new FOSSBilling\Request(); /* * @param void * - * @return \Symfony\Component\Cache\Adapter\FilesystemAdapter + * @return FilesystemAdapter */ -$di['cache'] = fn (): \Symfony\Component\Cache\Adapter\FilesystemAdapter => +$di['cache'] = fn (): FilesystemAdapter => // Reference: https://symfony.com/doc/current/components/cache/adapters/filesystem_adapter.html new FilesystemAdapter('sf_cache', 24 * 60 * 60, PATH_CACHE); @@ -255,9 +255,9 @@ new FilesystemAdapter('sf_cache', 24 * 60 * 60, PATH_CACHE); * * @param void * - * @return \Box_Authorization + * @return Box_Authorization */ -$di['auth'] = fn (): \Box_Authorization => new Box_Authorization($di); +$di['auth'] = fn (): Box_Authorization => new Box_Authorization($di); /* * Creates a new Twig environment that's configured for FOSSBilling. @@ -624,27 +624,6 @@ $di['updater'] = function () use ($di) { return $updater; }; -/* - * @param void - * - * @return Server_Package - */ -$di['server_package'] = fn (): \Server_Package => new Server_Package(); - -/* - * @param void - * - * @return Server_Client - */ -$di['server_client'] = fn (): \Server_Client => new Server_Client(); - -/* - * @param void - * - * @return Server_Account - */ -$di['server_account'] = fn (): \Server_Account => new Server_Account(); - /* * Creates a new server manager object and returns it. * @@ -662,13 +641,6 @@ $di['server_manager'] = $di->protect(function ($manager, $config) use ($di) { return $s; }); -/* - * @param void - * - * @return \FOSSBilling\Requirements - */ -$di['requirements'] = fn (): \FOSSBilling\Requirements => new FOSSBilling\Requirements(); - /* * Creates a new Box_Period object using the provided period code and returns it. * @@ -763,7 +735,7 @@ $di['password'] = fn (): \FOSSBilling\PasswordManager => new FOSSBilling\Passwor * * @return \Box_Translate The new translation object that was just created. */ -$di['translate'] = $di->protect(function ($textDomain = '') use ($di) { +$di['translate'] = $di->protect(function ($textDomain = '') { $tr = new Box_Translate(); if (!empty($textDomain)) { @@ -772,7 +744,6 @@ $di['translate'] = $di->protect(function ($textDomain = '') use ($di) { $locale = FOSSBilling\i18n::getActiveLocale(); - $tr->setDi($di); $tr->setLocale($locale); $tr->setup(); @@ -829,10 +800,10 @@ $di['parse_markdown'] = $di->protect(function (?string $content, bool $addAttrib // If we are defining the default attributes, build the list and add them to the config if ($addAttributes) { $attributes = $di['mod_service']('theme')->getDefaultMarkdownAttributes(); - foreach ($attributes as $class => $attributes) { + foreach ($attributes as $class => $classAttributes) { $reflectionClass = new ReflectionClass($class); $fqcn = $reflectionClass->getName(); - $defaultAttributes[$fqcn] = $attributes; + $defaultAttributes[$fqcn] = $classAttributes; } } diff --git a/src/library/Box/Log.php b/src/library/Box/Log.php index a2baa37c7..487579059 100644 --- a/src/library/Box/Log.php +++ b/src/library/Box/Log.php @@ -127,7 +127,7 @@ class Box_Log implements FOSSBilling\InjectionAwareInterface } // do not log debug level messages if debug is OFF - if (!DEBUG && $event['priority'] > self::INFO) { + if ($event['priority'] > self::INFO && DEBUG === false) { return; } diff --git a/src/library/Box/Translate.php b/src/library/Box/Translate.php index f627e8bde..f9027d2b1 100644 --- a/src/library/Box/Translate.php +++ b/src/library/Box/Translate.php @@ -7,10 +7,8 @@ * @copyright FOSSBilling (https://www.fossbilling.org) * @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 */ -class Box_Translate implements FOSSBilling\InjectionAwareInterface +class Box_Translate { - protected ?Pimple\Container $di = null; - protected $domain = 'messages'; protected $locale = 'en_US'; @@ -35,16 +33,6 @@ class Box_Translate implements FOSSBilling\InjectionAwareInterface return $this; } - public function setDi(Pimple\Container $di): void - { - $this->di = $di; - } - - public function getDi(): ?Pimple\Container - { - return $this->di; - } - public function setup() { PhpMyAdmin\MoTranslator\Loader::loadFunctions(); @@ -56,8 +44,6 @@ class Box_Translate implements FOSSBilling\InjectionAwareInterface } $codeset = 'UTF-8'; - @putenv('LANG=' . $locale . '.' . $codeset); - @putenv('LANGUAGE=' . $locale . '.' . $codeset); // set locale if (!defined('LC_MESSAGES')) { define('LC_MESSAGES', 5); diff --git a/src/library/FOSSBilling/SentryHelper.php b/src/library/FOSSBilling/SentryHelper.php index c91e7bb2b..608df8896 100644 --- a/src/library/FOSSBilling/SentryHelper.php +++ b/src/library/FOSSBilling/SentryHelper.php @@ -85,7 +85,8 @@ class SentryHelper // Array containing instance IDs that are blacklisted from error reporting and a timestamp of when their blacklist expires. private static array $blacklistedInstances = [ '82766452-ff2f-43ff-953a-3cbe3c3973ea' => '2024-07-01', // Low quality modifications causing lots of errors - 'fd26d5bc-95f4-4c9f-9807-28577f43c811' => '2024-05-01', // Low quality modifications causing lots of errors + 'f7cf66d8-112c-45cd-ae90-21427cc787a3' => '2025-0-1', // Noisy errors that are out of our control + '3ce3f723-c6e0-492c-a4d8-24630ce978b3' => '2025-0-1', // Noisy errors that are out of our control ]; private static string $placeholderFirstHalf = '--replace--this--'; diff --git a/src/library/Registrar/Adapter/Resellerclub.php b/src/library/Registrar/Adapter/Resellerclub.php index 8d2b5d6e5..aee6ab769 100644 --- a/src/library/Registrar/Adapter/Resellerclub.php +++ b/src/library/Registrar/Adapter/Resellerclub.php @@ -54,16 +54,20 @@ class Registrar_Adapter_Resellerclub extends Registrar_AdapterAbstract return [ 'label' => 'Manages domains on ResellerClub via API. ResellerClub requires your server IP in order to work. Login to the ResellerClub control panel (the url will be in the email you received when you signed up with them) and then go to Settings > API and enter the IP address of the server where FOSSBilling is installed to authorize it for API access.', 'form' => [ - 'userid' => ['text', [ - 'label' => 'Reseller ID. You can get this at ResellerClub control panel Settings > Personal information > Primary profile > Reseller ID', - 'description' => 'ResellerClub Reseller ID', - ], - ], - 'api-key' => ['password', [ - 'label' => 'ResellerClub API Key', - 'description' => 'You can get this at ResellerClub control panel, go to Settings -> API', - 'required' => false, + 'userid' => [ + 'text', + [ + 'label' => 'Reseller ID. You can get this at ResellerClub control panel Settings > Personal information > Primary profile > Reseller ID', + 'description' => 'ResellerClub Reseller ID', + ], ], + 'api-key' => [ + 'password', + [ + 'label' => 'ResellerClub API Key', + 'description' => 'You can get this at ResellerClub control panel, go to Settings -> API', + 'required' => false, + ], ], ], ]; @@ -189,7 +193,9 @@ class Registrar_Adapter_Resellerclub extends Registrar_AdapterAbstract $required_params['attr-value1'] = 'default'; } - return $this->_makeRequest('domains/transfer', $required_params, 'POST'); + $result = $this->_makeRequest('domains/transfer', $required_params, 'POST'); + + return $result['status'] == 'Success'; } private function _getDomainOrderId(Registrar_Domain $d) @@ -657,11 +663,9 @@ class Registrar_Adapter_Resellerclub extends Registrar_AdapterAbstract * @param array $params * @param string $method * - * @return string - * * @throws Registrar_Exception */ - protected function _makeRequest($url, $params = [], $method = 'GET', $type = 'json') + protected function _makeRequest($url, $params = [], $method = 'GET', $type = 'json'): array|string { $params = $this->includeAuthorizationParams($params); diff --git a/src/library/Server/Manager/Plesk.php b/src/library/Server/Manager/Plesk.php index a76f18625..84151dd84 100644 --- a/src/library/Server/Manager/Plesk.php +++ b/src/library/Server/Manager/Plesk.php @@ -187,13 +187,7 @@ class Server_Manager_Plesk extends Server_Manager */ public function suspendAccount(Server_Account $account, bool $suspend = true): bool { - if ($account->getReseller()) { - $result = $this->_client->reseller()->setProperties('login', $account->getUsername(), ['status' => 16]); - } else { - $result = $this->_client->customer()->setProperties('login', $account->getUsername(), ['status' => 16]); - } - - return $result; + return $this->_client->customer()->setProperties('login', $account->getUsername(), ['status' => 16]); } /** @@ -206,13 +200,7 @@ class Server_Manager_Plesk extends Server_Manager */ public function unsuspendAccount(Server_Account $account): bool { - if ($account->getReseller()) { - $result = $this->_client->reseller()->setProperties('login', $account->getUsername(), ['status' => 0]); - } else { - $result = $this->_client->customer()->setProperties('login', $account->getUsername(), ['status' => 0]); - } - - return $result; + return $this->_client->customer()->setProperties('login', $account->getUsername(), ['status' => 0]); } /** @@ -292,13 +280,7 @@ class Server_Manager_Plesk extends Server_Manager { $this->getLog()->info('Changing password for account ' . $account->getUsername()); - if ($account->getReseller()) { - $result = $this->_client->reseller()->setProperties('login', $account->getUsername(), ['passwd' => $newPassword]); - } else { - $result = $this->_client->customer()->setProperties('login', $account->getUsername(), ['passwd' => $newPassword]); - } - - return $result; + return $this->_client->customer()->setProperties('login', $account->getUsername(), ['passwd' => $newPassword]); } /** @@ -533,10 +515,6 @@ class Server_Manager_Plesk extends Server_Manager 'name' => 'max_maillists', 'value' => $package->getMaxEmailLists() ?: 0, ], - [ - 'name' => 'max_maillists', - 'value' => $package->getMaxEmailLists() ?: 0, - ], [ 'name' => 'max_box', 'value' => $package->getMaxPop() ?: 0, @@ -632,13 +610,7 @@ class Server_Manager_Plesk extends Server_Manager */ private function modifyClient(Server_Account $account): mixed { - if ($account->getReseller()) { - $result = $this->_client->reseller()->setProperties('login', $account->getUsername(), $this->createClientProps($account)); - } else { - $result = $this->_client->customer()->setProperties('login', $account->getUsername(), $this->createClientProps($account)); - } - - return $result; + return $this->_client->customer()->setProperties('login', $account->getUsername(), $this->createClientProps($account)); } /** diff --git a/src/library/Server/Package.php b/src/library/Server/Package.php index cccdf005b..5366ce75e 100644 --- a/src/library/Server/Package.php +++ b/src/library/Server/Package.php @@ -112,7 +112,7 @@ class Server_Package * * @return string returns the quota */ - public function getQuota(): string + public function getQuota(): ?string { return $this->quota; } @@ -136,7 +136,7 @@ class Server_Package * * @return string returns the bandwidth */ - public function getBandwidth(): string + public function getBandwidth(): ?string { return $this->bandwidth; } @@ -160,7 +160,7 @@ class Server_Package * * @return string returns the maximum number of domains */ - public function getMaxDomains(): string + public function getMaxDomains(): ?string { return $this->maxDomains; } @@ -184,7 +184,7 @@ class Server_Package * * @return string returns the maximum number of subdomains */ - public function getMaxSubdomains(): string + public function getMaxSubdomains(): ?string { return $this->maxSubdomains; } @@ -208,7 +208,7 @@ class Server_Package * * @return string returns the maximum number of parked domains */ - public function getMaxParkedDomains(): string + public function getMaxParkedDomains(): ?string { return $this->maxParkedDomains; } @@ -232,7 +232,7 @@ class Server_Package * * @return string returns the maximum number of FTP accounts */ - public function getMaxFtp(): string + public function getMaxFtp(): ?string { return $this->maxFtp; } @@ -256,7 +256,7 @@ class Server_Package * * @return string returns the maximum number of SQL databases */ - public function getMaxSql(): string + public function getMaxSql(): ?string { return $this->maxSql; } diff --git a/src/load.php b/src/load.php index 2902cb523..47fdc73ae 100644 --- a/src/load.php +++ b/src/load.php @@ -170,7 +170,7 @@ function errorHandler(int $number, string $message, string $file, int $line) */ function exceptionHandler(Exception|Error $e) { - if (getenv('APP_ENV') === 'test') { + if (Environment::isTesting()) { echo $e->getMessage() . PHP_EOL; return; diff --git a/src/modules/Servicehosting/Service.php b/src/modules/Servicehosting/Service.php index 946133033..def4ff67a 100644 --- a/src/modules/Servicehosting/Service.php +++ b/src/modules/Servicehosting/Service.php @@ -450,7 +450,7 @@ class Service implements InjectionAwareInterface $hp_config = $hp->config; - $server_client = $this->di['server_client']; + $server_client = new \Server_Client(); $server_client ->setEmail($client->email) ->setFullName($client->getFullName()) @@ -463,7 +463,7 @@ class Service implements InjectionAwareInterface ->setTelephone($client->phone); $package = $this->getServerPackage($hp); - $server_account = $this->di['server_account']; + $server_account = new \Server_Account(); $server_account ->setClient($server_client) ->setPackage($package) @@ -949,9 +949,8 @@ class Service implements InjectionAwareInterface $config = []; } - $p = $this->di['server_package']; - $p - ->setCustomValues($config) + $p = new \Server_Package(); + $p->setCustomValues($config) ->setMaxFtp($model->max_ftp) ->setMaxSql($model->max_sql) ->setMaxPop($model->max_pop) diff --git a/src/modules/System/Service.php b/src/modules/System/Service.php index 8d3c43bb8..ac46a8589 100644 --- a/src/modules/System/Service.php +++ b/src/modules/System/Service.php @@ -485,7 +485,7 @@ class Service } } - $r = $this->di['requirements']; + $r = new \FOSSBilling\Requirements(); $data = $r->checkCompat(); $data['last_patch'] = $this->getParamValue('last_patch'); diff --git a/tests-legacy/library/Box/Box_TranslateTest.php b/tests-legacy/library/Box/Box_TranslateTest.php index ed472dba3..4b289ac00 100644 --- a/tests-legacy/library/Box/Box_TranslateTest.php +++ b/tests-legacy/library/Box/Box_TranslateTest.php @@ -13,15 +13,6 @@ class Box_TranslateTest extends PHPUnit\Framework\TestCase $this->assertEquals($locale, $result); } - public function testDi(): void - { - $di = new Pimple\Container(); - $translateObj = new Box_Translate(); - $translateObj->setDi($di); - $getDi = $translateObj->getDi(); - $this->assertEquals($di, $getDi); - } - public function testDomainSetterAndGetter(): void { $translateObj = new Box_Translate(); diff --git a/tests-legacy/library/Registrar/Adapter/Registrar_Adapter_ResellerclubTest.php b/tests-legacy/library/Registrar/Adapter/Registrar_Adapter_ResellerclubTest.php deleted file mode 100644 index f2e3987c3..000000000 --- a/tests-legacy/library/Registrar/Adapter/Registrar_Adapter_ResellerclubTest.php +++ /dev/null @@ -1,291 +0,0 @@ - '12345', - 'api-key' => 'api-token', - ]; - - return new Registrar_Adapter_Resellerclub($options); - } - - public function testConstructionMissingUserId(): void - { - $options = []; - - $this->expectException(Registrar_Exception::class); - $this->expectExceptionMessage('ResellerClub" domain registrar is not fully configured. Please configure the ResellerClub Reseller ID'); - - $adapter = new Registrar_Adapter_Resellerclub($options); - } - - public function testConstructionMissingApiKey(): void - { - $options = [ - 'userid' => '12345', - ]; - - $this->expectException(Registrar_Exception::class); - $this->expectExceptionMessage('The "ResellerClub" domain registrar is not fully configured. Please configure the ResellerClub API Key'); - - new Registrar_Adapter_Resellerclub($options); - } - - public function testConstruction(): void - { - $options = [ - 'userid' => '12345', - 'api-key' => 'api-key Token', - ]; - $adapter = new Registrar_Adapter_Resellerclub($options); - - $this->assertEquals($options['userid'], $adapter->config['userid']); - $this->assertEquals($options['api-key'], $adapter->config['api-key']); - $this->assertNull($adapter->config['password']); - } - - public function testgetConfig(): void - { - $adapter = $this->getAdapter(); - $result = $adapter->getConfig(); - - $this->assertNotEmpty($result); - $this->assertIsArray($result); - $this->assertArrayHasKey('label', $result); - $this->assertArrayHasKey('form', $result); - } - - public function testisDomainAvailableFoundInArray(): void - { - $adapterMock = $this->getMockBuilder('Registrar_Adapter_Resellerclub')->disableOriginalConstructor() - ->onlyMethods(['_makeRequest']) - ->getMock(); - - $registrarDomain = new Registrar_Domain(); - $registrarDomain->setSld('example')->setTld('.com'); - - $requestResult = []; - $adapterMock->expects($this->atLeastOnce()) - ->method('_makeRequest') - ->with('domains/available') - ->willReturn($requestResult); - - $result = $adapterMock->isDomainAvailable($registrarDomain); - $this->assertTrue($result); - } - - public function testisDomainAvailableStatusAvailable(): void - { - $adapterMock = $this->getMockBuilder('Registrar_Adapter_Resellerclub')->disableOriginalConstructor() - ->onlyMethods(['_makeRequest']) - ->getMock(); - - $registrarDomain = new Registrar_Domain(); - $registrarDomain->setSld('example')->setTld('.com'); - - $requestResult = [$registrarDomain->getName() => ['status' => 'available']]; - $adapterMock->expects($this->atLeastOnce()) - ->method('_makeRequest') - ->with('domains/available') - ->willReturn($requestResult); - - $result = $adapterMock->isDomainAvailable($registrarDomain); - $this->assertTrue($result); - } - - public function testisDomainAvailableIsNotAvailable(): void - { - $adapterMock = $this->getMockBuilder('Registrar_Adapter_Resellerclub')->disableOriginalConstructor() - ->onlyMethods(['_makeRequest']) - ->getMock(); - - $registrarDomain = new Registrar_Domain(); - $registrarDomain->setSld('example')->setTld('.com'); - - $requestResult = [$registrarDomain->getName() => []]; - $adapterMock->expects($this->atLeastOnce()) - ->method('_makeRequest') - ->with('domains/available') - ->willReturn($requestResult); - - $result = $adapterMock->isDomainAvailable($registrarDomain); - $this->assertFalse($result); - } - - public function testisDomaincanBeTransferred(): void - { - $adapterMock = $this->getMockBuilder('Registrar_Adapter_Resellerclub')->disableOriginalConstructor() - ->onlyMethods(['_makeRequest']) - ->getMock(); - - $registrarDomain = new Registrar_Domain(); - $registrarDomain->setSld('example')->setTld('.com'); - - $requestResult = 'true'; - $adapterMock->expects($this->atLeastOnce()) - ->method('_makeRequest') - ->with('domains/validate-transfer') - ->willReturn($requestResult); - - $result = $adapterMock->isDomaincanBeTransferred($registrarDomain); - $this->assertIsBool($result); - $this->assertTrue($result); - } - - public function testmodifyNs(): void - { - $adapterMock = $this->getMockBuilder('Registrar_Adapter_Resellerclub')->disableOriginalConstructor() - ->onlyMethods(['_makeRequest']) - ->getMock(); - - $registrarDomain = new Registrar_Domain(); - $registrarDomain->setSld('example')->setTld('.com'); - - $adapterMock->expects($this->atLeastOnce()) - ->method('_makeRequest') - ->willReturnCallback(fn (...$args) => match ($args[0]) { - 'domains/orderid' => 1, - 'domains/modify-ns' => ['status' => 'Success'] - }); - - $result = $adapterMock->modifyNs($registrarDomain); - $this->assertIsBool($result); - $this->assertTrue($result); - } - - public function testmodifyContact(): void - { - $adapterMock = $this->getMockBuilder('Registrar_Adapter_Resellerclub')->disableOriginalConstructor() - ->onlyMethods(['_makeRequest']) - ->getMock(); - - $registrarDomain = new Registrar_Domain(); - $registrarDomain->setSld('example')->setTld('.com')->setContactRegistrar(new Registrar_Domain_Contact()); - - $adapterMock->expects($this->atLeastOnce()) - ->method('_makeRequest') - ->willReturnCallback(fn (...$args) => match ($args[0]) { - 'customers/details' => ['customerid' => 1], - 'contacts/default' => ['Contact' => ['registrant' => 1]], - 'contacts/modify' => ['status' => 'Success'] - }); - - $result = $adapterMock->modifyContact($registrarDomain); - $this->assertIsBool($result); - $this->assertTrue($result); - } - - public function testtransferDomain(): void - { - $adapterMock = $this->getMockBuilder('Registrar_Adapter_Resellerclub')->disableOriginalConstructor() - ->onlyMethods(['_makeRequest']) - ->getMock(); - - $registrarDomain = new Registrar_Domain(); - $registrarDomain->setSld('example')->setTld('.com')->setContactRegistrar(new Registrar_Domain_Contact()); - - $adapterMock->expects($this->atLeastOnce()) - ->method('_makeRequest') - ->willReturnCallback(fn (...$args) => match ($args[0]) { - 'customers/details' => ['customerid' => 1], - 'contacts/default' => ['Contact' => ['registrant' => 1]], - 'domains/transfer' => ['status' => 'Success'] - }); - - $result = $adapterMock->transferDomain($registrarDomain); - $this->assertIsArray($result); - } - - public function testregisterDomain(): void - { - $adapterMock = $this->getMockBuilder('Registrar_Adapter_Resellerclub')->disableOriginalConstructor() - ->onlyMethods(['_makeRequest']) - ->getMock(); - - $registrarDomain = new Registrar_Domain(); - $registrarDomain->setSld('example')->setTld('.com')->setContactRegistrar(new Registrar_Domain_Contact()); - - $requestResult = ['status' => 'Success']; - $adapterMock->expects($this->atLeastOnce()) - ->method('_makeRequest') - ->willReturnCallback(fn (...$args) => match ($args[0]) { - 'domains/orderid' => 1, - 'domains/details' => ['currentstatus' => ''], - 'customers/details' => ['customerid' => 1], - 'contacts/search' => ['recsonpage' => 1, 'result' => [['entity.entityid' => 2]]], - 'contacts/delete' => [], - 'contacts/add' => 2, - 'domains/register' => ['status' => 'Success'] - }); - - $result = $adapterMock->registerDomain($registrarDomain); - $this->assertIsBool($result); - $this->assertTrue($result); - } - - public function testincludeAuthorizationParamsApiKeyProvided(): void - { - $options = [ - 'userid' => '12345', - 'api-key' => 'password', - ]; - $adapter = new Registrar_Adapter_Resellerclub($options); - - $params = []; - $result = $adapter->includeAuthorizationParams($params); - $this->assertArrayHasKey('auth-userid', $result); - $this->assertArrayHasKey('api-key', $result); - } - - public function testincludeAuthorizationParamsBothProvidedApiKeyIsUsed(): void - { - $options = [ - 'userid' => '12345', - 'password' => 'password', - 'api-key' => 'password', - ]; - $adapter = new Registrar_Adapter_Resellerclub($options); - - $params = []; - $result = $adapter->includeAuthorizationParams($params); - $this->assertArrayHasKey('auth-userid', $result); - $this->assertArrayHasKey('api-key', $result); - $this->assertArrayNotHasKey('auth-password', $result); - } - - public static function providerTestArray() - { - return [ - [ - [], 'NotExistingKey', false, - ], - [ - ['api-key' => ''], 'api-key', false, - ], - [ - ['api-key' => ' '], 'api-key', false, - ], - [ - ['api-key' => '123'], 'api-key', true, - ], - ]; - } - - #[PHPUnit\Framework\Attributes\DataProvider('providerTestArray')] - public function testisKeyValueNotEmpty($array, $key, $expected): void - { - $options = [ - 'userid' => 'TEST', - 'api-key' => 'TEST', - ]; - - $regAdapter = new Registrar_Adapter_Resellerclub($options); - $result = $regAdapter->isKeyValueNotEmpty($array, $key); - - $this->assertEquals($expected, $result); - } -} diff --git a/tests-legacy/modules/Servicehosting/ServiceTest.php b/tests-legacy/modules/Servicehosting/ServiceTest.php index 6506844c1..f44543968 100644 --- a/tests-legacy/modules/Servicehosting/ServiceTest.php +++ b/tests-legacy/modules/Servicehosting/ServiceTest.php @@ -1151,7 +1151,6 @@ class ServiceTest extends \BBTestCase $model->config = '{}'; $di = new \Pimple\Container(); - $di['server_package'] = new \Server_Package(); $this->service->setDi($di); $result = $this->service->getServerPackage($model);