Files
FOSSBilling/tests/modules/Email/Api/Api_ClientTest.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

246 lines
8.3 KiB
PHP

<?php
namespace Box\Tests\Mod\Email\Api;
class Api_ClientTest extends \BBTestCase
{
public function testGet_list()
{
$clientApi = new \Box\Mod\Email\Api\Client();
$emailService = new \Box\Mod\Email\Service();
$willReturn = array(
"list" => array(
'id' => 1
),
);
$pager = $this->getMockBuilder('Box_Pagination')->getMock();
$pager->expects($this->atLeastOnce())
->method('getSimpleResultSet')
->will($this->returnValue($willReturn));
$di = new \Pimple\Container();
$di['pager'] = $pager;
$clientApi->setDi($di);
$emailService->setDi($di);
$service = $emailService;
$clientApi->setService($service);
$client = new \Model_Client();
$client->loadBean(new \DummyBean());
$client->id = random_int(1, 100);
$clientApi->setIdentity($client);
$result = $clientApi->get_list(array());
$this->assertIsArray($result);
$this->assertArrayHasKey('list', $result);
$this->assertIsArray($result['list']);
}
public function testGet()
{
$clientApi = new \Box\Mod\Email\Api\Client();
$model = new \Model_ActivityClientEmail();
$model->loadBean(new \DummyBean());
$service = $this->getMockBuilder(\Box\Mod\Email\Service::class)->onlyMethods(array('findOneForClientById', 'toApiArray'))->getMock();
$service->expects($this->atLeastOnce())
->method('findOneForClientById')
->will($this->returnValue($model));
$service->expects($this->atLeastOnce())
->method('toApiArray')
->will($this->returnValue(array()));
$clientApi->setService($service);
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->will($this->returnValue(null));
$di = new \Pimple\Container();
$di['validator'] = $validatorMock;
$clientApi->setDi($di);
$client = new \Model_Client();
$client->loadBean(new \DummyBean());
$client->id = random_int(1, 100);
$clientApi->setIdentity($client);
$result = $clientApi->get(array('id' => 1));
$this->assertIsArray($result);
}
public function testGetNotFoundException()
{
$clientApi = new \Box\Mod\Email\Api\Client();
$service = $this->getMockBuilder(\Box\Mod\Email\Service::class)->onlyMethods(array('findOneForClientById'))->getMock();
$service->expects($this->atLeastOnce())
->method('findOneForClientById')
->will($this->returnValue(false));
$client = new \Model_Client();
$client->loadBean(new \DummyBean());
$client->id = 5;
$clientApi->setIdentity($client);
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->will($this->returnValue(null));
$di = new \Pimple\Container();
$di['validator'] = $validatorMock;
$clientApi->setDi($di);
$clientApi->setService($service);
$this->expectException(\FOSSBilling\Exception::class);
$result = $clientApi->get(array('id' => 1));
$this->assertIsArray($result);
}
public function testResend()
{
$clientApi = new \Box\Mod\Email\Api\Client();
$model = new \Model_ActivityClientEmail();
$model->loadBean(new \DummyBean());
$service = $this->getMockBuilder(\Box\Mod\Email\Service::class)->onlyMethods(array('findOneForClientById', 'resend'))->getMock();
$service->expects($this->atLeastOnce())
->method('findOneForClientById')
->will($this->returnValue($model));
$service->expects($this->atLeastOnce())
->method('resend')
->will($this->returnValue(true));
$client = new \Model_Client();
$client->loadBean(new \DummyBean());
$client->id = 5;
$clientApi->setIdentity($client);
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->will($this->returnValue(null));
$di = new \Pimple\Container();
$di['validator'] = $validatorMock;
$clientApi->setDi($di);
$clientApi->setService($service);
$result = $clientApi->resend(array('id' => 1));
$this->assertTrue($result);
}
public function testResendNotFoundException()
{
$clientApi = new \Box\Mod\Email\Api\Client();
$service = $this->getMockBuilder(\Box\Mod\Email\Service::class)->onlyMethods(array('findOneForClientById'))->getMock();
$service->expects($this->atLeastOnce())
->method('findOneForClientById')
->will($this->returnValue(false));
$client = new \Model_Client();
$client->loadBean(new \DummyBean());
$client->id = 5;
$clientApi->setIdentity($client);
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->will($this->returnValue(null));
$di = new \Pimple\Container();
$di['validator'] = $validatorMock;
$clientApi->setDi($di);
$clientApi->setService($service);
$this->expectException(\FOSSBilling\Exception::class);
$result = $clientApi->resend(array('id' => 1));
$this->assertIsArray($result);
}
public function testDelete()
{
$clientApi = new \Box\Mod\Email\Api\Client();
$di = new \Pimple\Container();
$model = new \Model_ActivityClientEmail();
$model->loadBean(new \DummyBean());
$service = $this->getMockBuilder(\Box\Mod\Email\Service::class)->onlyMethods(array('findOneForClientById', 'rm'))->getMock();
$service->expects($this->atLeastOnce())
->method('findOneForClientById')
->will($this->returnValue($model));
$service->expects($this->atLeastOnce())
->method('rm')
->will($this->returnValue(true));
$client = new \Model_Client();
$client->loadBean(new \DummyBean());
$client->id = 5;
$clientApi->setIdentity($client);
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->will($this->returnValue(null));
$di['validator'] = $validatorMock;
$clientApi->setDi($di);
$clientApi->setService($service);
$result = $clientApi->delete(array('id' => 1));
$this->assertTrue($result);
}
public function testDeleteNotFoundException()
{
$clientApi = new \Box\Mod\Email\Api\Client();
$service = $this->getMockBuilder(\Box\Mod\Email\Service::class)->onlyMethods(array('findOneForClientById'))->getMock();
$service->expects($this->atLeastOnce())
->method('findOneForClientById')
->will($this->returnValue(false));
$client = new \Model_Client();
$client->loadBean(new \DummyBean());
$client->id = 5;
$clientApi->setIdentity($client);
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->will($this->returnValue(null));
$di = new \Pimple\Container();
$di['validator'] = $validatorMock;
$clientApi->setDi($di);
$clientApi->setService($service);
$this->expectException(\FOSSBilling\Exception::class);
$result = $clientApi->delete(array('id' => 1));
$this->assertIsArray($result);
}
}