public function testPost() { $this->transport->shouldReceive('performRequest')->once()->withArgs(['POST', 'units/', [], ['id_item' => 216221301, 'id_offer' => 'Supa offer'], \Mockery::any()])->andReturn(['headers' => ['Location' => ['/units/123456/']]]); $namespace = new UnitsNamespace($this->transport); $result = $namespace->post(UnitAddTransfer::make(['id_item' => 216221301, 'id_offer' => 'Supa offer'])); $this->assertEquals(123456, $result); }
/** * @param array|UnitAddTransfer $data * @return int */ public function post($data) { if (!$data instanceof UnitAddTransfer) { if (!is_array($data)) { throw new InvalidArgumentException('Data argument should be an array of instance of UnitAddTransfer'); } $data = UnitAddTransfer::make($data); } $endpoint = new Post($this->getTransport()); $endpoint->setTransfer($data); $resultRequest = $endpoint->performRequest(); return Response::extractId($resultRequest, '/units/%d/'); }