public function testFetchSingleById()
 {
     $data = array(array('id' => 42, 'firstname' => 'Manfred', 'lastname' => 'Mustermann', 'street' => 'Am Testen 123', 'postcode' => '54321', 'city' => 'Musterhausen', 'country' => 'de'));
     $mockDbStatement = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface');
     $mockDbStatement->expects($this->any())->method('execute')->will($this->returnValue($data));
     $mockDbDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface');
     $mockDbDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockDbStatement));
     $mockDbAdapter = $this->getMock('Zend\\Db\\Adapter\\Adapter', null, array($mockDbDriver));
     $mockCustomerTable = $this->getMock('Customer\\Table\\CustomerTable', null, array($mockDbAdapter));
     $mockCustomerTable->expects($this->any())->method('fetchSingleById')->will($this->returnValue(new CustomerEntity()));
     $customerService = new CustomerService();
     $customerService->setCustomerTable($mockCustomerTable);
     $customerEntity = $customerService->fetchSingleById(42);
     $this->assertTrue($customerEntity instanceof CustomerEntity);
     $this->assertSame($data[0]['id'], $customerEntity->getId());
     $this->assertSame($data[0]['firstname'], $customerEntity->getFirstname());
     $this->assertSame($data[0]['lastname'], $customerEntity->getLastname());
     $this->assertSame($data[0]['street'], $customerEntity->getStreet());
     $this->assertSame($data[0]['postcode'], $customerEntity->getPostcode());
     $this->assertSame($data[0]['city'], $customerEntity->getCity());
     $this->assertSame($data[0]['country'], $customerEntity->getCountry());
 }
 public function testUpdateExistingCustomer()
 {
     $customerFilter = new CustomerInputFilter();
     $customerTable = new CustomerTable($this->adapter);
     $customerHydrator = new CustomerHydrator();
     $customerService = new CustomerService();
     $customerService->setCustomerFilter($customerFilter);
     $customerService->setCustomerTable($customerTable);
     $customerEntity = $customerService->fetchSingleById(42);
     $customerEntity->setFirstname('Monika');
     $customerEntity->setLastname('Musterfrau');
     $data = $customerHydrator->extract($customerEntity);
     $customerEntity = $customerService->save($data, $customerEntity->getId());
     $queryTable = $this->getConnection()->createQueryTable('loadCustomersOrderedByLastname', 'SELECT * FROM customers WHERE id = "42";');
     $expectedRow = $queryTable->getRow(0);
     $customerRow = $customerHydrator->extract($customerEntity);
     $this->assertEquals($expectedRow, $customerRow);
 }