Basically my test failed due to "Integrity Violation" when tries to TRUNCATE the tables in a bad order.
Every Db test case extends PHPUnit_DatabaseTestCase_Abstract which truncates the tables before testing. As soon as I have a row at Property all the tests failed due to Error: COMPOSITE[TRUNCATE] operation failed on query.
This is my database schema:
-- -----------------------------------------------------
-- Table `project`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `project` (
`project_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`project_id`) ,
UNIQUE INDEX `project_id_UNIQUE` (`project_id` ASC) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `customer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `customer` (
`customer_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`firstname` VARCHAR(45) NOT NULL ,
`lastname` VARCHAR(45) NOT NULL ,
`email` VARCHAR(45) NOT NULL ,
`telephone` VARCHAR(45) NULL DEFAULT NULL ,
PRIMARY KEY (`customer_id`) ,
UNIQUE INDEX `customer_id_UNIQUE` (`customer_id` ASC) )
ENGINE = InnoDB;
-- ---------------------------------------------------开发者_如何学Python--
-- Table `property`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `property` (
`property_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`project_id` INT UNSIGNED NOT NULL ,
`customer_id` INT UNSIGNED NULL DEFAULT NULL ,
`name` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`property_id`) ,
UNIQUE INDEX `property_id_UNIQUE` (`property_id` ASC) ,
INDEX `fk_property_project` (`project_id` ASC) ,
INDEX `fk_property_customer1` (`customer_id` ASC) ,
CONSTRAINT `fk_property_project`
FOREIGN KEY (`project_id` )
REFERENCES `project` (`project_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_property_customer1`
FOREIGN KEY (`customer_id` )
REFERENCES `customer` (`customer_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
Am I testing wrong? How could I specify to truncate in a properly order before testing?
Zend Version 1.11.5
The error is supposed to be fixed (check framework zend forum
When you want to use phpunit to test your database, I think it would be better to extend and use ZF's class for this: Zend_Test_PHPUnit_DatabaseTestCase rather than directly extend PHPUnit_DatabaseTestCase_Abstract. Maybe this is a part of your problem.
精彩评论