/** * @param Category $category * @param bool $reload * @return Category * @throws ApiException */ public function updateCategory(Category $category, $reload = false) { $url = sprintf("categories/%s", $category->getId()); $requestBody = $category->toArray(); if ($reload) { $requestBody['reload'] = true; } $response = $this->doPut($url, $requestBody); if ($reload) { $categoryData = (array) $response; $categoryData = reset($categoryData); return new Category($categoryData); } else { return $category; } }
/** * @test */ public function should_update_category_and_respond_without_new_instance() { $responseMock = $this->createResponseMock(200, null); $apiClient = $this->createTestApiClient($responseMock); $category = new Category(); $category->setCollectionId(uniqid()); $category->setId(uniqid()); $category->setName(uniqid("New Category name ")); $updated = $apiClient->updateCategory($category, false); $this->assertInstanceOf(Category::class, $updated); $this->assertSame($updated, $category); }