public function testInputFiltersAreSetCorrectly()
 {
     $supplier = new Supplier();
     $inputFilter = $supplier->getInputFilter();
     $this->assertSame(2, $inputFilter->count());
     $this->assertTrue($inputFilter->has('supplier_name'));
     $this->assertTrue($inputFilter->has('id'));
 }
 public function testSaveSupplierWillUpdateExistingSupplierIfTheyAlreadyHaveAnId()
 {
     $supplierData = array('id' => 123, 'supplier_name' => 'My Supplier');
     $supplier = new Supplier();
     $supplier->exchangeArray($supplierData);
     $resultSet = new ResultSet();
     $resultSet->setArrayObjectPrototype(new Supplier());
     $resultSet->initialize(array($supplier));
     $mockTableGateway = $this->getMock('Zend\\Db\\TableGateway\\TableGateway', array('select', 'update'), array(), '', false);
     $mockTableGateway->expects($this->once())->method('select')->with(array('id' => 123))->will($this->returnValue($resultSet));
     $mockTableGateway->expects($this->once())->method('update')->with(array('supplier_name' => 'My Supplier'), array('id' => 123));
     $supplierTable = new SupplierTable($mockTableGateway);
     $supplierTable->saveSupplier($supplier);
 }
 public function create($data)
 {
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $supplier = new Supplier();
     $supplier->setSupplierName($data['supplier_name']);
     $em->persist($supplier);
     foreach ($data['addresses'] as $address) {
         $newAddress = new Address();
         $newAddress->setAddress_line_1($address['address_line_1']);
         $newAddress->setAddress_line_2($address['address_line_2']);
         $newAddress->setEmail($address['email']);
         $newAddress->setPost_code($address['post_code']);
         $newAddress->setFax($address['fax']);
         $newAddress->setTelephone($address['telephone']);
         $newAddress->setTown($address['town']);
         $supplier->getAddresses()->add($newAddress);
         $em->persist($newAddress);
     }
     $em->flush();
     return new JsonModel(array('data' => $supplier->getId()));
 }