2
0

InsertTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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-2009 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 dirname(__FILE__)."/../../../../../TestHelper.php";
  23. require_once "Zend/Test/DbAdapter.php";
  24. require_once "Zend/Test/PHPUnit/Db/Operation/Insert.php";
  25. require_once "PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php";
  26. /**
  27. * @category Zend
  28. * @package Zend_Test
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Test
  33. */
  34. class Zend_Test_PHPUnit_Db_Operation_InsertTest extends PHPUnit_Framework_TestCase
  35. {
  36. private $operation = null;
  37. public function setUp()
  38. {
  39. $this->operation = new Zend_Test_PHPUnit_Db_Operation_Insert();
  40. }
  41. public function testInsertDataSetUsingAdapterInsert()
  42. {
  43. $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/insertFixture.xml");
  44. $testAdapter = $this->getMock('Zend_Test_DbAdapter');
  45. $testAdapter->expects($this->at(0))
  46. ->method('insert')
  47. ->with('foo', array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'));
  48. $testAdapter->expects($this->at(1))
  49. ->method('insert')
  50. ->with('foo', array('foo' => 'bar', 'bar' => 'bar', 'baz' => 'bar'));
  51. $testAdapter->expects($this->at(2))
  52. ->method('insert')
  53. ->with('foo', array('foo' => 'baz', 'bar' => 'baz', 'baz' => 'baz'));
  54. $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
  55. $this->operation->execute($connection, $dataSet);
  56. }
  57. public function testInsertExceptionIsTransformed()
  58. {
  59. $this->setExpectedException('PHPUnit_Extensions_Database_Operation_Exception');
  60. $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/insertFixture.xml");
  61. $testAdapter = $this->getMock('Zend_Test_DbAdapter');
  62. $testAdapter->expects($this->any())->method('insert')->will($this->throwException(new Exception()));
  63. $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
  64. $this->operation->execute($connection, $dataSet);
  65. }
  66. public function testInvalidConnectionGivenThrowsException()
  67. {
  68. $this->setExpectedException("Zend_Test_PHPUnit_Db_Exception");
  69. $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet');
  70. $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
  71. $this->operation->execute($connection, $dataSet);
  72. }
  73. }