Commit b86f5a14 by Alexander Makarov

#2435 Tests for integrity exception

parent d773ce66
<?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';
}
}
......@@ -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();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment