public function testToArray()
 {
     $data = ['actionCode' => 'LOGIN', 'item' => ['id' => 'The Item', 'title' => 'The Item', 'description' => 'The Item\'s description', 'author' => 'john.doe'], 'categories' => ['foo', 'bar']];
     $item = new Item();
     $item->setItemId('The Item')->setTitle('The Item')->setDescription('The Item\'s description')->setAuthor('john.doe');
     $this->action->fromArray($data);
     $this->action->setItem($item);
     $actionArray = $this->action->toArray();
     $this->assertCount(3, $actionArray);
     $this->assertEquals($data, $actionArray);
 }
 public function testNotifySeveralActionsWithCategories()
 {
     $history = new History();
     $this->client->getEmitter()->attach($history);
     $this->subscriber->addResponse(new Response(200, [], new Stream(fopen('data://text/plain,[]', 'r'))));
     $item = new Item();
     $item->setItemId('the-item');
     $actionLogin = new Action();
     $actionLogin->setActionCode('LOGIN')->setItem($item);
     $actionSignup = new Action();
     $actionSignup->setActionCode('SIGNUP')->setCategories(['foo', 'bar']);
     $this->client->notifySeveralActions('12345', [$actionLogin, $actionSignup]);
     $contents = $history->getLastRequest()->getBody()->__toString();
     $request = json_decode($contents, true);
     $this->assertEquals(['userId' => '12345', 'actions' => [['actionCode' => 'LOGIN', 'item' => ['id' => 'the-item', 'title' => null, 'description' => null, 'author' => null]], ['actionCode' => 'SIGNUP', 'categories' => ['foo', 'bar']]]], $request);
 }
 /**
  * Performs an action notification from certain user
  *
  * @param User|string $user A User model or userId
  * @param array $actions array of Action objects or strings
  * @return void
  */
 public function notifySeveralActions($user, array $actions)
 {
     // Prepare request body
     $requestData = ['userId' => $user instanceof User ? $user->getUserId() : $user, 'actions' => []];
     foreach ($actions as $action) {
         if (is_string($action)) {
             $actionCode = $action;
             $action = new Action();
             $action->setActionCode($actionCode);
         }
         if ($action instanceof Action) {
             $requestData['actions'][] = $action->toArray();
         }
     }
     // Perform request
     $this->connect('POST', self::ACTION_NOTIFY_SEVERAL_ROUTE, ['json' => $requestData]);
 }