remove unused ApiException, check for non status 200 errors
This commit is contained in:
parent
637ef9669d
commit
0231890129
@ -22,7 +22,6 @@ use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
|
||||
use D3\Linkmobility4OXID\Application\Model\RequestFactory;
|
||||
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\LoggerHandler;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||
@ -144,7 +143,7 @@ class Sms extends AbstractMessage
|
||||
$this->response = $response = $this->submitMessage($recipientsList);
|
||||
|
||||
return $response->isSuccessful();
|
||||
} catch (GuzzleException|ApiException|InvalidArgumentException $e) {
|
||||
} catch (GuzzleException|InvalidArgumentException $e) {
|
||||
$this->getLogger()->error($e->getMessage());
|
||||
// Oxid does not accept throwable interface only exceptions according to definition
|
||||
/** @var UtilsView $utilsView */
|
||||
@ -204,7 +203,6 @@ class Sms extends AbstractMessage
|
||||
/**
|
||||
* @param RecipientsListInterface $recipientsList
|
||||
* @return ResponseInterface
|
||||
* @throws ApiException
|
||||
* @throws GuzzleException
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
|
@ -18,6 +18,7 @@ namespace D3\Linkmobility4OXID\tests\integration;
|
||||
use D3\Linkmobility4OXID\Application\Model\MessageClient;
|
||||
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\LoggerHandler;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
@ -31,9 +32,20 @@ use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
abstract class LMIntegrationTestCase extends LMUnitTestCase
|
||||
{
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
d3GetOxidDIC()->get(LoggerHandler::class)->setLogger(new NullLogger());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userId
|
||||
*
|
||||
|
@ -20,6 +20,7 @@ use D3\Linkmobility4OXID\Application\Model\Configuration;
|
||||
use Doctrine\DBAL\Exception as DoctrineException;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Middleware;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
@ -73,7 +74,7 @@ class adminOrderTest extends LMIntegrationTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @te__st
|
||||
* @test
|
||||
* @throws DoctrineException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@ -139,7 +140,7 @@ class adminOrderTest extends LMIntegrationTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @te__st
|
||||
* @test
|
||||
* @throws DoctrineException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@ -206,7 +207,7 @@ class adminOrderTest extends LMIntegrationTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @te__st
|
||||
* @test
|
||||
* @throws DoctrineException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@ -267,6 +268,75 @@ class adminOrderTest extends LMIntegrationTestCase
|
||||
$this->deleteAllRemarksFrom($this->userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws DoctrineException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function serverError()
|
||||
{
|
||||
$container = [];
|
||||
$history = Middleware::history($container);
|
||||
|
||||
$this->deleteAllRemarksFrom($this->userId);
|
||||
|
||||
$this->setClientResponse(
|
||||
new Response(
|
||||
500,
|
||||
[],
|
||||
'{"statusCode": 4019, "statusMessage": "parameter \"messageContent\" invalid", "clientMessageId": null, "transferId": null, "smsCount": 0}'
|
||||
),
|
||||
$history
|
||||
);
|
||||
|
||||
$_POST['messagebody'] = 'testMessage';
|
||||
$_POST['oxid'] = $this->orderId;
|
||||
|
||||
/** @var AdminOrder $controller */
|
||||
try{
|
||||
$controller = oxNew(AdminOrder::class);
|
||||
$controller->send();
|
||||
|
||||
} catch (Exception $e) {
|
||||
dumpvar(get_class($e));
|
||||
}
|
||||
|
||||
// check requests
|
||||
$this->assertCount(
|
||||
1,
|
||||
$container
|
||||
);
|
||||
/** @var RequestInterface $request */
|
||||
$request = $container[0]['request'];
|
||||
$this->assertTrue(
|
||||
(bool) strpos(serialize($request->getBody()->getContents()), 'testMessage')
|
||||
);
|
||||
|
||||
// check return message
|
||||
$search = 'no response';
|
||||
|
||||
$this->assertTrue(
|
||||
(bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search)
|
||||
);
|
||||
|
||||
// check remark
|
||||
/** @var QueryBuilder $queryBuilder */
|
||||
$queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
|
||||
$queryBuilder->select('oxid')
|
||||
->from(oxNew(Remark::class)->getViewName())
|
||||
->where(
|
||||
$queryBuilder->expr()->eq(
|
||||
'oxparentid',
|
||||
$queryBuilder->createNamedParameter($this->userId)
|
||||
)
|
||||
);
|
||||
$remarkIds = $queryBuilder->execute()->fetchAll();
|
||||
$this->assertEmpty($remarkIds);
|
||||
|
||||
$this->deleteAllRemarksFrom($this->userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws DoctrineException
|
||||
@ -332,7 +402,7 @@ class adminOrderTest extends LMIntegrationTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @te__st
|
||||
* @test
|
||||
* @throws DoctrineException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
|
@ -23,13 +23,13 @@ use D3\Linkmobility4OXID\Application\Model\RequestFactory;
|
||||
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
|
||||
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||
use D3\LinkmobilityClient\SMS\BinaryRequest;
|
||||
use D3\LinkmobilityClient\SMS\Response;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use Monolog\Logger;
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
use OxidEsales\Eshop\Application\Model\Remark;
|
||||
@ -554,6 +554,11 @@ class SmsTest extends LMUnitTestCase
|
||||
$utilsViewMock->expects($this->exactly((int) $throwException))->method('addErrorToDisplay');
|
||||
d3GetOxidDIC()->set('d3ox.linkmobility.'.UtilsView::class, $utilsViewMock);
|
||||
|
||||
/** @var ServerException|MockObject $serverExceptionMock */
|
||||
$serverExceptionMock = $this->getMockBuilder(ServerException::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var Sms|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(Sms::class)
|
||||
->onlyMethods(['submitMessage', 'getLogger'])
|
||||
@ -561,7 +566,7 @@ class SmsTest extends LMUnitTestCase
|
||||
->getMock();
|
||||
$sut->method('submitMessage')->will(
|
||||
$throwException ?
|
||||
$this->throwException(oxNew(ApiException::class)) :
|
||||
$this->throwException($serverExceptionMock) :
|
||||
$this->returnValue($smsResponseMock)
|
||||
);
|
||||
$sut->method('getLogger')->willReturn($loggerMock);
|
||||
|
Loading…
Reference in New Issue
Block a user