mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
#2435 Tests for integrity exception
This commit is contained in:
25
framework/db/IntegrityException.php
Normal file
25
framework/db/IntegrityException.php
Normal 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';
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user