/**
  * @test
  */
 public function hydratorWillReturnCategoryObject()
 {
     $stdClass = new \stdClass();
     $stdClass->id = 10;
     $stdClass->name = 'TestCategory';
     $stdClass->dataProviderId = 10000;
     $stdClass->parentId = 20000;
     $stdClass->createdAt = '2015-10-10';
     $stdClass->updatedAt = '2015-10-10';
     $category = \Audiens\AdForm\Entity\CategoryHydrator::fromStdClass($stdClass);
     $this->assertInstanceOf(\Audiens\AdForm\Entity\Category::class, $category);
 }
 /**
  * Update a category
  *
  * @param Category $category
  *
  * @throws Exception\EntityInvalidException if the API returns a validation error
  * @throws Exception\ApiException if the API call fails
  *
  * @return Category
  */
 public function update(Category $category)
 {
     // Endpoint URI
     $uri = sprintf('v1/categories/%d', $category->getId());
     $options = ['json' => $category];
     try {
         $data = $this->httpClient->put($uri, $options)->getBody()->getContents();
         $category = CategoryHydrator::fromStdClass(json_decode($data));
         if ($this->cache and $data) {
             $this->cache->invalidate($this->cachePrefix);
             $this->cache->put($this->cachePrefix, $uri . '/' . $category->getId(), [], $data);
         }
         return $category;
     } catch (ClientException $e) {
         $response = $e->getResponse();
         $responseBody = $response->getBody()->getContents();
         $responseCode = $response->getStatusCode();
         $error = json_decode($responseBody);
         if (property_exists($error, 'modelState')) {
             // validation error
             throw Exception\EntityInvalidException::invalid($responseBody, $responseCode, $error->modelState);
         } else {
             // general error
             throw Exception\ApiException::translate($responseBody, $responseCode);
         }
     }
 }