From 79553e8e7980a35f05b50d663bc7a06cd242547c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Musia=C5=82?= Date: Fri, 7 Jul 2017 14:05:12 +0200 Subject: [PATCH] Fix test. --- Client/YooChooseNotifier.php | 9 ++++++--- Tests/Client/YooChooseNotifierTest.php | 20 +++++++------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Client/YooChooseNotifier.php b/Client/YooChooseNotifier.php index 796eed0..5ca3482 100644 --- a/Client/YooChooseNotifier.php +++ b/Client/YooChooseNotifier.php @@ -9,6 +9,7 @@ use eZ\Publish\API\Repository\ContentService; use eZ\Publish\API\Repository\ContentTypeService; use eZ\Publish\API\Repository\LocationService; +use Guzzle\Http\Message\Response; use GuzzleHttp\ClientInterface as GuzzleClient; use GuzzleHttp\Exception\RequestException; use InvalidArgumentException; @@ -405,9 +406,11 @@ private function notifyGuzzle6(array $events) ) ); - if (isset($this->logger)) { - $this->logger->debug('Got asynchronously ' . $promise->getState() . ' from YooChoose notification POST'); - } + $promise->wait(false); + + $promise->then(function (Response $response) { + $this->log(sprintf('Got asynchronously %s from YooChoose notification POST', $response->getStatusCode()), 'debug'); + }); } /** diff --git a/Tests/Client/YooChooseNotifierTest.php b/Tests/Client/YooChooseNotifierTest.php index 9f7c3a0..157f1f9 100644 --- a/Tests/Client/YooChooseNotifierTest.php +++ b/Tests/Client/YooChooseNotifierTest.php @@ -5,10 +5,9 @@ */ namespace EzSystems\RecommendationBundle\Tests\Client; +use Guzzle\Http\Message\Response; use PHPUnit_Framework_TestCase; -use GuzzleHttp\Message\Response; use GuzzleHttp\Promise\Promise; -use eZ\Publish\Core\Repository\Values\Content\Content; use eZ\Publish\Core\Repository\Values\ContentType\ContentType; use eZ\Publish\API\Repository\Values\Content\ContentInfo; use EzSystems\RecommendationBundle\Client\YooChooseNotifier; @@ -38,11 +37,13 @@ class YooChooseNotifierTest extends PHPUnit_Framework_TestCase */ public function setUp() { - $this->guzzleClientMock = $this->getMock('GuzzleHttp\ClientInterface'); - + $this->guzzleClientMock = $this->getMockBuilder('GuzzleHttp\ClientInterface')->getMock(); $this->notifier = new YooChooseNotifier( $this->guzzleClientMock, $this->getRepositoryServiceMock(self::CONTENT_TYPE_ID), + $this->getContentServiceMock(self::CONTENT_TYPE_ID), + $this->getMockBuilder('eZ\Publish\API\Repository\LocationService')->getMock(), + $this->getMockBuilder('eZ\Publish\API\Repository\ContentTypeService')->getMock(), array( 'customer-id' => self::CUSTOMER_ID, 'license-key' => self::LICENSE_KEY, @@ -181,7 +182,7 @@ protected function setGuzzleExpectations( */ protected function getContentServiceMock($contentTypeId) { - $contentServiceMock = $this->getMock('eZ\Publish\API\Repository\ContentService'); + $contentServiceMock = $this->getMockBuilder('eZ\Publish\API\Repository\ContentService')->getMock(); $contentServiceMock ->expects($this->any()) @@ -202,14 +203,7 @@ protected function getContentServiceMock($contentTypeId) */ protected function getRepositoryServiceMock($identifier) { - $repositoryInterfaceServiceMock = $this->getMock('eZ\Publish\API\Repository\Repository'); - $signalDispatcherServiceMock = $this->getMock('eZ\Publish\Core\SignalSlot\SignalDispatcher'); - - $repositoryServiceMock = $this->getMock( - 'eZ\Publish\Core\SignalSlot\Repository', - array('sudo', 'getContentService', 'getContentTypeService'), - array($repositoryInterfaceServiceMock, $signalDispatcherServiceMock) - ); + $repositoryServiceMock = $this->getMockBuilder('eZ\Publish\Core\SignalSlot\Repository')->disableOriginalConstructor()->getMock(); $repositoryServiceMock ->expects($this->any())