Вопрос по php, mysql – Ошибка усечения PHPUnit и MySQL

14

Error: User Rate Limit ExceededTRUNCATEError: User Rate Limit ExceededwithoutError: User Rate Limit Exceeded

Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint

Error: User Rate Limit ExceededSET FOREIGN_KEY_CHECKS=0;?

Error: User Rate Limit Exceededbugs.mysql.com/bug.php?id=54678Error: User Rate Limit Exceeded jmc

Ваш Ответ

2   ответа
28

Error: User Rate Limit Exceeded

<?php

/**
 * Disables foreign key checks temporarily.
 */
class TruncateOperation extends \PHPUnit_Extensions_Database_Operation_Truncate
{
    public function execute(\PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, \PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
    {
        $connection->getConnection()->query("SET foreign_key_checks = 0");
        parent::execute($connection, $dataSet);
        $connection->getConnection()->query("SET foreign_key_checks = 1");
    }
}

Error: User Rate Limit Exceeded

class FooTest extends \PHPUnit_Extensions_Database_TestCase
{
    public function getSetUpOperation()
    {
        $cascadeTruncates = true; // If you want cascading truncates, false otherwise. If unsure choose false.

        return new \PHPUnit_Extensions_Database_Operation_Composite(array(
            new TruncateOperation($cascadeTruncates),
            \PHPUnit_Extensions_Database_Operation_Factory::INSERT()
        ));
    }
}

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededsetUpError: User Rate Limit Exceededparent::setUpError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededDbUnit GIT
3

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

/**
 * Resets all AUTO_INCREMENT counters on all tables in a dataset.
 * @see PHPUnit_Extensions_Database_Operation_IDatabaseOperation
 */
class ResetAutoincrementOperation implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
{

    /* 
     * @see PHPUnit_Extensions_Database_Operation_IDatabaseOperation::execute()
     */
    public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, 
            PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
    {
        foreach ($dataSet->getReverseIterator() as $table) {
            $query = "ALTER TABLE {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())}"
                . " AUTO_INCREMENT = 1
            ";

            try {
                $connection->getConnection()->query($query);
            } catch (PDOException $e) {
                throw new PHPUnit_Extensions_Database_Operation_Exception('RESET_AUTOINCREMENT', 
                        $query, array(), $table, $e->getMessage());
            }
        }
    }
}

Error: User Rate Limit ExceededgetSetUpOperation()Error: User Rate Limit ExceededgetTearDownOperation()Error: User Rate Limit Exceeded

class FooTest extends PHPUnit_Extensions_Database_TestCase
{
    /**
     * @see PHPUnit_Extensions_Database_TestCase::getTearDownOperation()
     */
    protected function getTearDownOperation ()
    {
        // Clean up after ourselves
        return new PHPUnit_Extensions_Database_Operation_Composite(array(
            PHPUnit_Extensions_Database_Operation_Factory::DELETE_ALL(), // 1. delete all records from table
            new ResetAutoincrementOperation() // 2. reset auto increment value
        ));
    }

    /**
     * @see PHPUnit_Extensions_Database_TestCase::getSetUpOperation ()
     */
    protected function getSetUpOperation ()
    {
        return new PHPUnit_Extensions_Database_Operation_Composite(array(
                PHPUnit_Extensions_Database_Operation_Factory::DELETE_ALL(), // 1. delete all records from table
                new ResetAutoincrementOperation(), // 2. reset auto increment value
                PHPUnit_Extensions_Database_Operation_Factory::INSERT() // 3. insert new records
        ));
    }
}

Error: User Rate Limit Exceeded

Похожие вопросы