Browse Source

#2435 Tests for integrity exception

tags/2.0.0-rc
Alexander Makarov 11 years ago
parent
commit
b86f5a14f7
  1. 25
      framework/db/IntegrityException.php
  2. 12
      tests/unit/framework/db/CommandTest.php

25
framework/db/IntegrityException.php

@ -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';
}
}

12
tests/unit/framework/db/CommandTest.php

@ -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();
}
}

Loading…
Cancel
Save