Files
FOSSBilling/tests/modules/Servicehosting/Api/GuestTest.php
T
Belle Aerni 50043e6211 Run Rector against our tests (#1761)
* Update rector config to include tests

* Run Rector against the tests

* Delete test-results

* Update .gitignore

* Correctly set the PHP min to 8.1, split the configs

* Corrected PHPDoc

* Deleted tests we can't really get to pass

PHPunit is hard-coded to fail when a class has a return type of `never`, which is the correct return type of our redirect function (and rightfully so).

No way to disable the exception as far as we can tell
2023-11-11 18:41:09 +00:00

81 lines
2.6 KiB
PHP

<?php
namespace Box\Mod\Servicehosting\Api;
class GuestTest extends \BBTestCase
{
/**
* @var \Box\Mod\Servicehosting\Api\Guest
*/
protected $api = null;
public function setup(): void
{
$this->api = new \Box\Mod\Servicehosting\Api\Guest();
}
public function testfree_tlds()
{
$di = new \Pimple\Container();
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->will($this->returnValue(null));
$di['validator'] = $validatorMock;
$model = new \Model_Product();
$model->loadBean(new \DummyBean());
$model->type = \Model_Product::HOSTING;
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->atLeastOnce())
->method('getExistingModelById')
->will($this->returnValue($model));
$di['db'] = $dbMock;
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\Servicehosting\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('getFreeTlds')
->with($model)
->willReturn(array());
$this->api->setService($serviceMock);
$this->api->setDi($di);
$result = $this->api->free_tlds(array('product_id' => 1));
$this->assertIsArray($result);
}
public function testfree_tlds_ProductTypeIsNotHosting()
{
$di = new \Pimple\Container();
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->will($this->returnValue(null));
$di['validator'] = $validatorMock;
$model = new \Model_Product();
$model->loadBean(new \DummyBean());
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->atLeastOnce())
->method('getExistingModelById')
->will($this->returnValue($model));
$di['db'] = $dbMock;
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\Servicehosting\Service::class)->getMock();
$serviceMock->expects($this->never())->method('getFreeTlds');
$this->api->setService($serviceMock);
$this->api->setDi($di);
$this->expectException(\FOSSBilling\Exception::class);
$this->expectExceptionMessage('Product type is invalid');
$this->api->free_tlds(array('product_id' => 1));
}
}