public function testListProducts()
 {
     $productCollection = new Collection();
     $product = new Product();
     $product->setId(1)->setName('Test')->setDescription('Test descr')->setPrice(99.95)->setUnit('Kg')->setSubjectToVat(true);
     $productCollection[] = $product;
     $productArray = [['id' => 1, 'name' => 'Test', 'description' => 'Test descr', 'price' => 99.95, 'unit' => 'Kg', 'subjectToVat' => true]];
     $headers = ['X-Total-Count' => 1];
     $client = $this->createMock(Client::class);
     $client->expects($this->once())->method('get')->with($this->equalTo('/products'))->will($this->returnValue($productArray));
     $response = $this->createMock(Response::class);
     $response->expects($this->once())->method('getHeaders')->will($this->returnValue($headers));
     $client->expects($this->once())->method('getResponse')->will($this->returnValue($response));
     $hydrator = $this->getMockBuilder(APIHydrator::class)->disableOriginalConstructor()->getMock();
     $hydrator->expects($this->once())->method('hydrate')->with($this->equalTo($productArray[0]), $this->equalTo(null))->will($this->returnValue($productCollection[0]));
     $service = new ProductService($client, $hydrator, new Collection());
     $this->assertEquals($productCollection, $service->listProducts());
 }
Пример #2
0
 public function testExtractWithMissingKey()
 {
     $expData = ['name' => 'A product'];
     $product = new Product();
     $product->setName('A product');
     $hydrator = new APIHydrator(['id', 'name'], new Product());
     $data = $hydrator->extract($product);
     $this->assertSame($expData, $data);
 }