File indexing completed on 2025-02-23 05:32:49

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Test
0017  * @subpackage PHPUnit
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Test_PHPUnit_Db_Connection
0025  */
0026 // require_once "Zend/Test/PHPUnit/Db/Connection.php";
0027 
0028 /**
0029  * Delete All Operation that can be executed on set up or tear down of a database tester.
0030  *
0031  * @uses       PHPUnit_Extensions_Database_Operation_IDatabaseOperation
0032  * @category   Zend
0033  * @package    Zend_Test
0034  * @subpackage PHPUnit
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 class Zend_Test_PHPUnit_Db_Operation_DeleteAll implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
0039 {
0040     /**
0041      * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
0042      * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
0043      */
0044     public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
0045     {
0046         if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
0047             // require_once "Zend/Test/PHPUnit/Db/Exception.php";
0048             throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
0049         }
0050 
0051         foreach ($dataSet as $table) {
0052             try {
0053                 $tableName = $table->getTableMetaData()->getTableName();
0054                 $connection->getConnection()->delete($tableName);
0055             } catch (Exception $e) {
0056                 throw new PHPUnit_Extensions_Database_Operation_Exception('DELETEALL', 'DELETE FROM '.$tableName.'', array(), $table, $e->getMessage());
0057             }
0058         }
0059     }
0060 }