From 27c763e89bdc33d83907aca15d6ec810b0389911 Mon Sep 17 00:00:00 2001 From: Tr0nYx Date: Fri, 30 Sep 2016 18:30:44 +0200 Subject: [PATCH 1/2] ArrayCollection Fix --- src/Api/Methods/BondController.php | 2 +- src/Api/Methods/CashTransferLogController.php | 2 +- src/Api/Methods/CompanyController.php | 6 +++--- src/Api/Methods/EventController.php | 6 +++--- src/Api/Methods/ListingController.php | 2 +- src/Api/Methods/MainInterestRateController.php | 2 +- src/Api/Methods/NotificationsController.php | 4 ++-- tests/AlphaTraderApiTests/AlphaTraderTest.php | 13 ++++++++----- 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Api/Methods/BondController.php b/src/Api/Methods/BondController.php index b30b18a..5269631 100644 --- a/src/Api/Methods/BondController.php +++ b/src/Api/Methods/BondController.php @@ -98,7 +98,7 @@ public function getBonds() 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', diff --git a/src/Api/Methods/CashTransferLogController.php b/src/Api/Methods/CashTransferLogController.php index 3cd7b98..70e7742 100644 --- a/src/Api/Methods/CashTransferLogController.php +++ b/src/Api/Methods/CashTransferLogController.php @@ -49,7 +49,7 @@ public function getCashTransferLogs( 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', diff --git a/src/Api/Methods/CompanyController.php b/src/Api/Methods/CompanyController.php index a1ab061..eb74227 100644 --- a/src/Api/Methods/CompanyController.php +++ b/src/Api/Methods/CompanyController.php @@ -35,7 +35,7 @@ public function getCompanies($all) 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', @@ -83,7 +83,7 @@ public function getCompanyByUserId(UserAccount $user) 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', @@ -107,7 +107,7 @@ public function getCompanyByUserName($username) 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', diff --git a/src/Api/Methods/EventController.php b/src/Api/Methods/EventController.php index d276919..9655822 100644 --- a/src/Api/Methods/EventController.php +++ b/src/Api/Methods/EventController.php @@ -34,7 +34,7 @@ public function getEvents($afterDate) 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', @@ -59,7 +59,7 @@ public function searchEvents($realms, $afterDate) 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', @@ -85,7 +85,7 @@ public function searchEventsByType($eventtype, $realms, $afterDate) 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', diff --git a/src/Api/Methods/ListingController.php b/src/Api/Methods/ListingController.php index 2bf56cc..1ad29d8 100644 --- a/src/Api/Methods/ListingController.php +++ b/src/Api/Methods/ListingController.php @@ -34,7 +34,7 @@ public function getListing($secIdentPart) 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', diff --git a/src/Api/Methods/MainInterestRateController.php b/src/Api/Methods/MainInterestRateController.php index a2ef0f8..a27ac31 100644 --- a/src/Api/Methods/MainInterestRateController.php +++ b/src/Api/Methods/MainInterestRateController.php @@ -34,7 +34,7 @@ public function getMainInterestRate() 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', diff --git a/src/Api/Methods/NotificationsController.php b/src/Api/Methods/NotificationsController.php index 9912b57..6449ed7 100644 --- a/src/Api/Methods/NotificationsController.php +++ b/src/Api/Methods/NotificationsController.php @@ -31,7 +31,7 @@ public function getNotifications() 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', @@ -53,7 +53,7 @@ public function getUnreadNotifications() 'ArrayCollection', 'json' ); - if (empty($oResult) && !isset($oResult[0])) { + if (!is_array($oResult)) { $oResult = $this->getSerializer()->deserialize( $data, 'Alphatrader\ApiBundle\Model\Error', diff --git a/tests/AlphaTraderApiTests/AlphaTraderTest.php b/tests/AlphaTraderApiTests/AlphaTraderTest.php index 8f0ae38..75b2fc0 100644 --- a/tests/AlphaTraderApiTests/AlphaTraderTest.php +++ b/tests/AlphaTraderApiTests/AlphaTraderTest.php @@ -4,7 +4,6 @@ use Alphatrader\ApiBundle\Api\AlphaTrader; use Alphatrader\ApiBundle\Model\Company; -use Alphatrader\ApiBundle\Model\Useraccount; use JMS\Serializer\Exception\RuntimeException; use Tests\Methods\BaseTestCase; @@ -55,11 +54,15 @@ public function test_getCashTransferLogs() $this->alphatrader->getCashTransferLogs(new \DateTime(),new \DateTime(),$log[0]['senderBankAccount'],$log[0]['receiverBankAccount']); } - /*public function test_generateCash() + public function test_generateCash() { - $this->expectException(RuntimeException::class); - $this->assertNull($this->alphatrader->generateCash(50000)->getMessagePrototype()); - }*/ + $response = ['cash'=>50000]; + $expected = json_encode($response); + $myFactory = $this->getMockBuilder('Alphatrader\ApiBundle\Api\AlphaTrader', array('generateCash'))->disableOriginalConstructor()->getMock(); + $myFactory->expects($this->any())->method('generateCash')->will($this->returnValue($expected)); + $val = $myFactory->generateCash(50000); + $this->assertEquals(json_decode($val)->cash,$response['cash']); + } public function test_getChats() { From a0d12e7631d3240699990827694e3b0cfbc67569 Mon Sep 17 00:00:00 2001 From: Tr0nYx Date: Fri, 30 Sep 2016 18:53:18 +0200 Subject: [PATCH 2/2] Unittest fix --- tests/AlphaTraderApiTests/Methods/BondControllerTest.php | 2 +- .../Methods/CashTransferLogControllerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/AlphaTraderApiTests/Methods/BondControllerTest.php b/tests/AlphaTraderApiTests/Methods/BondControllerTest.php index fdb0403..bb9c41e 100644 --- a/tests/AlphaTraderApiTests/Methods/BondControllerTest.php +++ b/tests/AlphaTraderApiTests/Methods/BondControllerTest.php @@ -78,6 +78,6 @@ public function test_getBonds() $bondcontroller->setClient($this->getClient($expected)); $val = $bondcontroller->getBonds(); - $this->assertInstanceOf('Alphatrader\ApiBundle\Model\Error', $val); + $this->assertTrue(is_array($val)); } } \ No newline at end of file diff --git a/tests/AlphaTraderApiTests/Methods/CashTransferLogControllerTest.php b/tests/AlphaTraderApiTests/Methods/CashTransferLogControllerTest.php index d3f905a..392fede 100644 --- a/tests/AlphaTraderApiTests/Methods/CashTransferLogControllerTest.php +++ b/tests/AlphaTraderApiTests/Methods/CashTransferLogControllerTest.php @@ -28,6 +28,6 @@ public function test_getCashTransferLogs() $bondcontroller->setClient($this->getClient($expected)); $val = $bondcontroller->getCashTransferLogs( new \DateTime(), new \DateTime(),1,1); - $this->assertInstanceOf('Alphatrader\ApiBundle\Model\Error', $val); + $this->assertTrue(is_array($val)); } } \ No newline at end of file