#2435 Tests for integrity exception

This commit is contained in:
Alexander Makarov
2014-05-06 16:56:51 +04:00
parent d773ce66c2
commit b86f5a14f7
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db;
/**
* Exception represents an exception that is caused by violation of DB constraints.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class IntegrityException extends Exception
{
/**
* @return string the user-friendly name of this exception
*/
public function getName()
{
return 'Integrity constraint violation';
}
}

View File

@ -287,4 +287,16 @@ class CommandTest extends DatabaseTestCase
public function testDropIndex()
{
}
public function testIntegrityViolation()
{
$this->setExpectedException('\yii\db\IntegrityException');
$db = $this->getConnection();
$sql = 'INSERT INTO profile(id, description) VALUES (123, \'duplicate\')';
$command = $db->createCommand($sql);
$command->execute();
$command->execute();
}
}