public function testToArray() { $data = ['id' => 'item123', 'title' => 'The Item', 'description' => 'The Item\'s description', 'author' => 'john.doe', 'dateCreated' => '2010-01-01 00:00:00']; $this->item->fromArray($data); $itemArray = $this->item->toArray(); $this->assertCount(4, $itemArray); unset($data['dateCreated']); $this->assertEquals($data, $itemArray); }
/** * @return array */ public function toArray() { $actionArray = []; $actionArray['actionCode'] = $this->actionCode; if (isset($this->item)) { $actionArray['item'] = $this->item->toArray(); } if (!empty($this->categories)) { $actionArray['categories'] = $this->categories; } return $actionArray; }
/** * Returns information about the status of an interactionaccording to its limits * * @param User|string $user A User model or userId * @param User|string $targetUser A User model or userId * @param string $interactionCode * @param Item|string $item An Item model or itemId * @return array */ public function getInteractionStatus($user, $targetUser, $interactionCode, $item) { // Prepare request body $requestData = ['user' => $user instanceof User ? $user->getUserId() : $user, 'targetUser' => ['id' => $targetUser instanceof User ? $targetUser->getUserId() : $targetUser], 'interactionCode' => $interactionCode, 'item' => $item instanceof Item ? $item->toArray() : ['id' => $item]]; $response = $this->connect('POST', self::INTERACTION_STATUS_ROUTE, ['json' => $requestData]); $contents = $response->getBody()->getContents(); $responseData = $this->serializer->deserialize($contents, 'array', 'json'); // Process response properties unset($responseData['status']); if (!isset($responseData['score'])) { $responseData['score'] = 0; } return $responseData; }