2
0

DeleteAllTest.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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-2012 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/DeleteAll.php";
  24. require_once "PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php";
  25. /**
  26. * @category Zend
  27. * @package Zend_Test
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Test
  32. */
  33. class Zend_Test_PHPUnit_Db_Operation_DeleteAllTest extends PHPUnit_Framework_TestCase
  34. {
  35. private $operation = null;
  36. public function setUp()
  37. {
  38. $this->operation = new Zend_Test_PHPUnit_Db_Operation_DeleteAll();
  39. }
  40. public function testDeleteAll()
  41. {
  42. $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/truncateFixture.xml");
  43. $testAdapter = $this->getMock('Zend_Test_DbAdapter');
  44. $testAdapter->expects($this->at(0))
  45. ->method('delete')
  46. ->with('foo');
  47. $testAdapter->expects($this->at(1))
  48. ->method('delete')
  49. ->with('bar');
  50. $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
  51. $this->operation->execute($connection, $dataSet);
  52. }
  53. public function testDeleteQueryErrorTransformsException()
  54. {
  55. $this->setExpectedException('PHPUnit_Extensions_Database_Operation_Exception');
  56. $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/truncateFixture.xml");
  57. $testAdapter = $this->getMock('Zend_Test_DbAdapter');
  58. $testAdapter->expects($this->any())
  59. ->method('delete')
  60. ->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. }