Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
635bc1fa
Commit
635bc1fa
authored
Apr 12, 2007
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved the previous fix for the unique validator.
parent
18766e65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
8 deletions
+36
-8
Unique.php
lib/Doctrine/Validator/Unique.php
+10
-4
ValidatorTestCase.php
tests/ValidatorTestCase.php
+26
-4
No files found.
lib/Doctrine/Validator/Unique.php
View file @
635bc1fa
...
@@ -46,10 +46,16 @@ class Doctrine_Validator_Unique
...
@@ -46,10 +46,16 @@ class Doctrine_Validator_Unique
$values
=
array
();
$values
=
array
();
$values
[]
=
$value
;
$values
[]
=
$value
;
foreach
(
$table
->
getPrimaryKeys
()
as
$pk
)
{
// If the record is not new we need to add primary key checks because its ok if the
$sql
.=
" AND
{
$pk
}
!= ?"
;
// unique value already exists in the database IF the record in the database is the same
$values
[]
=
$record
->
$pk
;
// as the one that is validated here.
$state
=
$record
->
getState
();
if
(
!
(
$state
==
Doctrine_Record
::
STATE_TDIRTY
||
$state
==
Doctrine_Record
::
STATE_TCLEAN
))
{
foreach
(
$table
->
getPrimaryKeys
()
as
$pk
)
{
$sql
.=
" AND
{
$pk
}
!= ?"
;
$values
[]
=
$record
->
$pk
;
}
}
}
$stmt
=
$table
->
getConnection
()
->
getDbh
()
->
prepare
(
$sql
);
$stmt
=
$table
->
getConnection
()
->
getDbh
()
->
prepare
(
$sql
);
...
...
tests/ValidatorTestCase.php
View file @
635bc1fa
...
@@ -40,7 +40,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
...
@@ -40,7 +40,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$this
->
tables
[]
=
'ValidatorTest_FootballPlayer'
;
$this
->
tables
[]
=
'ValidatorTest_FootballPlayer'
;
parent
::
prepareTables
();
parent
::
prepareTables
();
}
}
/**
/**
* Tests correct type detection.
* Tests correct type detection.
*/
*/
...
@@ -333,7 +333,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
...
@@ -333,7 +333,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
*
*
* @todo move to a separate test file (tests/Validator/UniqueTestCase) .
* @todo move to a separate test file (tests/Validator/UniqueTestCase) .
*/
*/
public
function
testSetSameUniqueValueThrowsNoException
()
public
function
testSetSameUniqueValue
OnSameRecord
ThrowsNoException
()
{
{
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
true
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
true
);
...
@@ -346,11 +346,33 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
...
@@ -346,11 +346,33 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
try
{
try
{
$r
->
save
();
$r
->
save
();
}
}
catch
(
Doctrine_Validator_Exception
$e
)
{
catch
(
Doctrine_Validator_Exception
$e
)
{
$this
->
fail
(
"Validator exception raised without reason!"
);
$this
->
fail
(
"Validator exception raised without reason!"
);
var_dump
(
$r
->
getErrorStack
());
}
}
$r
->
delete
();
// clean up
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
false
);
}
public
function
testSetSameUniqueValueOnDifferentRecordThrowsException
()
{
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
true
);
$r
=
new
ValidatorTest_Person
();
$r
->
identifier
=
'1234'
;
$r
->
save
();
$r
=
new
ValidatorTest_Person
();
$r
->
identifier
=
1234
;
try
{
$r
->
save
();
$this
->
fail
(
"No validator exception thrown on unique validation."
);
}
catch
(
Doctrine_Validator_Exception
$e
)
{
$this
->
pass
();
}
$r
->
delete
();
// clean up
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
false
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
false
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment