public function testStockHistory() { $client = static::makeClient(true); /** * @var $part1 Part */ $part1 = $this->fixtures->getReference("part.1"); $stockLevel = new StockEntry(); $stockLevel->setPart($part1); $stockLevel->setStockLevel(5); $fosUser = $this->fixtures->getReference("user.admin"); $userService = $this->getContainer()->get("partkeepr.userservice"); $user = $userService->getProxyUser($fosUser->getUsername(), $userService->getBuiltinProvider(), true); $stockLevel->setUser($user); $part1->addStockLevel($stockLevel); $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush(); $iriCoverter = $this->getContainer()->get("api.iri_converter"); $iri = $iriCoverter->getIriFromItem($part1); $client->request("GET", $iri); $response = $client->getResponse()->getContent(); $responseObj = json_decode($response, true); $responseObj["stockLevels"] = array(); $client->request("PUT", $iri, array(), array(), array(), json_encode($responseObj)); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->getContainer()->get("doctrine.orm.default_entity_manager")->refresh($part1); $this->assertEquals(1, count($part1->getStockLevels())); }
/** * Adds a new stock entry to this part * * @param StockEntry $stockEntry */ public function addStockEntry(StockEntry $stockEntry) { $this->executeSaveListener(); $stockEntry->setPart($this); $this->getStockLevels()->add($stockEntry); }
/** * Removes a stock entry from this part * * @param StockEntry $stockEntry */ public function removeStockLevel($stockEntry) { $stockEntry->setPart(null); $this->stockLevels->removeElement($stockEntry); }