DeleteAll.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 PHPUnit
  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. /**
  23. * @see Zend_Test_PHPUnit_Db_Connection
  24. */
  25. require_once "Zend/Test/PHPUnit/Db/Connection.php";
  26. /**
  27. * Delete All Operation that can be executed on set up or tear down of a database tester.
  28. *
  29. * @uses PHPUnit_Extensions_Database_Operation_IDatabaseOperation
  30. * @category Zend
  31. * @package Zend_Test
  32. * @subpackage PHPUnit
  33. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Test_PHPUnit_Db_Operation_DeleteAll implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
  37. {
  38. /**
  39. * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
  40. * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
  41. */
  42. public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
  43. {
  44. if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
  45. require_once "Zend/Test/PHPUnit/Db/Exception.php";
  46. throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
  47. }
  48. foreach ($dataSet as $table) {
  49. try {
  50. $tableName = $table->getTableMetaData()->getTableName();
  51. $connection->getConnection()->delete($tableName);
  52. } catch (Exception $e) {
  53. throw new PHPUnit_Extensions_Database_Operation_Exception('DELETEALL', 'DELETE FROM '.$tableName.'', array(), $table, $e->getMessage());
  54. }
  55. }
  56. }
  57. }