/** * @param Category $category * @param bool $reload * @return bool|Category * @throws ApiException */ public function createCategory(Category $category, $reload = false) { $url = "categories"; $requestBody = $category->toArray(); if ($reload) { $requestBody['reload'] = true; } list($id, $response) = $this->doPost($url, $requestBody); if ($reload) { $categoryData = (array) $response; $categoryData = reset($categoryData); return new Category($categoryData); } else { $category->setId($id); 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); }