SHARE
TWEET

Unit Test for a CustomerTable

RalfEggert Oct 24th, 2013 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. namespace CustomerTest\Table;
  3.  
  4. use Customer\Entity\CustomerEntity;
  5. use Customer\Hydrator\CustomerHydrator;
  6. use Customer\Table\CustomerTable;
  7. use PHPUnit_Framework_Assert;
  8. use PHPUnit_Framework_TestCase;
  9. use Zend\Db\ResultSet\HydratingResultSet;
  10. use Zend\Db\TableGateway\TableGateway;
  11.  
  12. class CustomerTableTest extends PHPUnit_Framework_TestCase
  13. {
  14.     public function testFetchListResult()
  15.     {
  16.         $data = array(
  17.             array(
  18.                 'id'        => 42,
  19.                 'firstname' => 'Manfred',
  20.                 'lastname'  => 'Mustermann',
  21.                 'street'    => 'Am Testen 123',
  22.                 'postcode'  => '54321',
  23.                 'city'      => 'Musterhausen',
  24.                 'country'   => 'de',
  25.             ),
  26.             array(
  27.                 'id'        => 43,
  28.                 'firstname' => 'Manuela',
  29.                 'lastname'  => 'Musterfrau',
  30.                 'street'    => 'Am Mustern 987',
  31.                 'postcode'  => '98765',
  32.                 'city'      => 'Testhausen',
  33.                 'country'   => 'de',
  34.             )
  35.         );
  36.  
  37.         $mockDbStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
  38.         $mockDbStatement->expects($this->any())->method('execute')->will($this->returnValue($data));
  39.  
  40.         $mockDbDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
  41.         $mockDbDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockDbStatement));
  42.  
  43.         $mockDbAdapter = $this->getMock('Zend\Db\Adapter\Adapter', null, array($mockDbDriver));
  44.  
  45.         $customerTable = new CustomerTable($mockDbAdapter);
  46.         $customerList  = $customerTable->fetchList();
  47.  
  48.         $this->assertEquals($data, $customerList->toArray());
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top