InsertTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Test
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once "Zend/Test/DbAdapter.php";
  23. require_once "Zend/Test/PHPUnit/Db/Operation/Insert.php";
  24. /**
  25. * @category Zend
  26. * @package Zend_Test
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Test
  31. */
  32. class Zend_Test_PHPUnit_Db_Operation_InsertTest extends PHPUnit_Framework_TestCase
  33. {
  34. private $operation = null;
  35. public function setUp()
  36. {
  37. $this->operation = new Zend_Test_PHPUnit_Db_Operation_Insert();
  38. }
  39. public function testInsertDataSetUsingAdapterInsert()
  40. {
  41. $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/insertFixture.xml");
  42. $testAdapter = $this->getMock('Zend_Test_DbAdapter');
  43. $testAdapter->expects($this->at(0))
  44. ->method('insert')
  45. ->with('foo', array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'));
  46. $testAdapter->expects($this->at(1))
  47. ->method('insert')
  48. ->with('foo', array('foo' => 'bar', 'bar' => 'bar', 'baz' => 'bar'));
  49. $testAdapter->expects($this->at(2))
  50. ->method('insert')
  51. ->with('foo', array('foo' => 'baz', 'bar' => 'baz', 'baz' => 'baz'));
  52. $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
  53. $this->operation->execute($connection, $dataSet);
  54. }
  55. public function testInsertExceptionIsTransformed()
  56. {
  57. $this->setExpectedException('PHPUnit_Extensions_Database_Operation_Exception');
  58. $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/insertFixture.xml");
  59. $testAdapter = $this->getMock('Zend_Test_DbAdapter');
  60. $testAdapter->expects($this->any())->method('insert')->will($this->throwException(new Exception()));
  61. $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
  62. $this->operation->execute($connection, $dataSet);
  63. }
  64. public function testInvalidConnectionGivenThrowsException()
  65. {
  66. $this->setExpectedException("Zend_Test_PHPUnit_Db_Exception");
  67. $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet');
  68. $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
  69. $this->operation->execute($connection, $dataSet);
  70. }
  71. }