尝试截断时,Zend Db单元测试失败

时间:2011-05-06 01:05:24

标签: zend-framework phpunit

当尝试以错误的顺序TRUNCATE表时,基本上我的测试因“完整性违规”而失败。

每个Db测试用例都扩展了PHPUnit_DatabaseTestCase_Abstract,它会在测试之前截断表。只要我在Property中有一行,所有测试都会因Error而失败:COMPOSITE [TRUNCATE]操作在查询时失败。

这是我的数据库架构:

-- -----------------------------------------------------
-- 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;


-- -----------------------------------------------------
-- 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;

我测试错了吗?如何在测试之前指定以正确的顺序截断?

Zend Version 1.11.5

错误应该是固定的(检查framework zend forum

1 个答案:

答案 0 :(得分:1)

当你想使用phpunit来测试你的数据库时,我认为扩展和使用ZF的类更好:Zend_Test_PHPUnit_DatabaseTestCase而不是直接扩展PHPUnit_DatabaseTestCase_Abstract。也许这是你问题的一部分。