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
c1c3f489
Commit
c1c3f489
authored
Feb 23, 2008
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validator refactorings and others
parent
514e17ea
Changes
22
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
417 additions
and
348 deletions
+417
-348
ClassMetadata.php
lib/Doctrine/ClassMetadata.php
+120
-54
Connection.php
lib/Doctrine/Connection.php
+2
-2
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+48
-2
Manager.php
lib/Doctrine/Manager.php
+15
-0
Mapper.php
lib/Doctrine/Mapper.php
+11
-0
Record.php
lib/Doctrine/Record.php
+88
-60
Validator.php
lib/Doctrine/Validator.php
+34
-162
AccessTest.php
tests/Orm/Component/AccessTest.php
+10
-0
Doctrine_OrmTestCase.php
tests/lib/Doctrine_OrmTestCase.php
+0
-20
ForumUser.php
tests/models/forum/ForumUser.php
+7
-1
Doctrine_UnitTestCase.php
tests_old/DoctrineTest/Doctrine_UnitTestCase.php
+9
-0
UnitTestCase.php
tests_old/DoctrineTest/UnitTestCase.php
+5
-1
SingleTableTestCase.php
tests_old/Inheritance/SingleTableTestCase.php
+8
-8
FactoryTestCase.php
tests_old/Metadata/FactoryTestCase.php
+19
-19
381TestCase.php
tests_old/Ticket/381TestCase.php
+1
-0
ValidatorTestCase.php
tests_old/ValidatorTestCase.php
+4
-2
Email.php
tests_old/models/Email.php
+2
-1
Entity.php
tests_old/models/Entity.php
+1
-1
ValidatorTest.php
tests_old/models/ValidatorTest.php
+15
-6
ValidatorTest_AddressModel.php
tests_old/models/ValidatorTest_AddressModel.php
+10
-5
ValidatorTest_DateModel.php
tests_old/models/ValidatorTest_DateModel.php
+4
-2
ValidatorTest_Person.php
tests_old/models/ValidatorTest_Person.php
+4
-2
No files found.
lib/Doctrine/ClassMetadata.php
View file @
c1c3f489
This diff is collapsed.
Click to expand it.
lib/Doctrine/Connection.php
View file @
c1c3f489
...
...
@@ -1047,9 +1047,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
CONN_ERROR
);
$this
->
getListener
()
->
preError
(
$event
);
/*if (strstr($e->getMessage(), 'no such column
')) {
if
(
strstr
(
$e
->
getMessage
(),
'may not be NULL
'
))
{
echo
$e
->
getMessage
()
.
"<br />"
.
$e
->
getTraceAsString
()
.
"<br />"
;
}
*/
}
$name
=
'Doctrine_Connection_'
.
$this
->
driverName
.
'_Exception'
;
...
...
lib/Doctrine/Connection/UnitOfWork.php
View file @
c1c3f489
...
...
@@ -29,15 +29,61 @@ Doctrine::autoload('Doctrine_Connection_Module');
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @todo package:orm. Figure out a useful implementation.
*/
class
Doctrine_Connection_UnitOfWork
extends
Doctrine_Connection_Module
{
/**
* A map of all currently managed entities.
*
* @var array
*/
protected
$_managedEntities
=
array
();
/**
* The identity map that holds references to all managed entities that have
* an identity.
*/
protected
$_identityMap
=
array
();
/**
* Boolean flag that indicates whether the unit of work immediately executes any
* database operations or whether these operations are postponed until the
* unit of work is flushed/committed.
*
* @var boolean
*/
protected
$_autoflush
=
true
;
/**
* A list of all postponed inserts.
*/
protected
$_inserts
=
array
();
/**
* A list of all postponed updates.
*/
protected
$_updates
=
array
();
/**
* A list of all postponed deletes.
*/
protected
$_deletes
=
array
();
/**
* The dbal connection used by the unit of work.
*
* @var Doctrine_Connection
* @todo Allow multiple connections for transparent master-slave replication.
*/
protected
$_conn
;
/**
* Flushes the unit of work, executing all operations that have been postponed
* up to this point.
*
*/
public
function
flush
()
{
// get the flush tree
...
...
@@ -47,7 +93,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
foreach
(
$tree
as
$name
)
{
$mapper
=
$this
->
conn
->
getMapper
(
$name
);
foreach
(
$mapper
->
getRepository
()
as
$record
)
{
//echo $record->getOid() . "<br />";
$mapper
->
saveSingleRecord
(
$record
);
}
}
...
...
@@ -95,7 +140,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
if
(
!
(
$mapper
instanceof
Doctrine_Mapper
))
{
$mapper
=
$this
->
conn
->
getMapper
(
$mapper
);
}
$nm
=
$mapper
->
getComponentName
();
$nm
=
$mapper
->
getComponentName
();
$index
=
array_search
(
$nm
,
$tree
);
...
...
@@ -172,6 +217,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
}
}
return
array_values
(
$tree
);
}
...
...
lib/Doctrine/Manager.php
View file @
c1c3f489
...
...
@@ -497,6 +497,21 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
return
$query
;
}
/**
* Creates a new native query (instance of Doctrine_RawSql).
*
* @return Doctrine_RawSql
*/
public
function
createNativeQuery
(
$sql
=
""
)
{
$nativeQuery
=
new
Doctrine_RawSql
(
$this
->
getCurrentConnection
());
if
(
!
empty
(
$sql
))
{
$nativeQuery
->
parseQuery
(
$sql
);
}
return
$nativeQuery
;
}
/**
* Creates a query object out of a registered, named query.
*
...
...
lib/Doctrine/Mapper.php
View file @
c1c3f489
...
...
@@ -317,6 +317,17 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
return
true
;
}
/**
* Tells the mapper to manage the entity if it's not already managed.
*
* @return boolean TRUE if the entity was previously not managed and is now managed,
* FALSE otherwise (the entity is already managed).
*/
public
function
manage
(
Doctrine_Record
$record
)
{
return
$this
->
getRepository
()
->
add
(
$record
);
}
/**
* removeRecord
...
...
lib/Doctrine/Record.php
View file @
c1c3f489
This diff is collapsed.
Click to expand it.
lib/Doctrine/Validator.php
View file @
c1c3f489
...
...
@@ -67,6 +67,7 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
*/
public
function
validateRecord
(
Doctrine_Record
$record
)
{
$classMetadata
=
$record
->
getTable
();
$columns
=
$record
->
getTable
()
->
getColumns
();
$component
=
$record
->
getTable
()
->
getComponentName
();
...
...
@@ -74,90 +75,49 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
// if record is transient all fields will be validated
// if record is persistent only the modified fields will be validated
$data
=
(
$record
->
exists
())
?
$record
->
getModified
()
:
$record
->
getData
();
$err
=
array
();
foreach
(
$data
as
$key
=>
$value
)
{
$fields
=
(
$record
->
exists
())
?
$record
->
getModified
()
:
$record
->
getData
();
$err
=
array
();
foreach
(
$fields
as
$fieldName
=>
$value
)
{
if
(
$value
===
self
::
$_null
)
{
$value
=
null
;
}
else
if
(
$value
instanceof
Doctrine_Record
)
{
$value
=
$value
->
getIncremented
();
}
$dataType
=
$classMetadata
->
getTypeOf
(
$fieldName
);
$column
=
$columns
[
$record
->
getTable
()
->
getColumnName
(
$key
)];
if
(
$column
[
'type'
]
==
'enum'
)
{
$value
=
$record
->
getTable
()
->
enumIndex
(
$key
,
$value
);
if
(
$value
===
false
)
{
$errorStack
->
add
(
$key
,
'enum'
);
continue
;
// Validate field type, if type validation is enabled
if
(
$classMetadata
->
getAttribute
(
Doctrine
::
ATTR_VALIDATE
)
&
Doctrine
::
VALIDATE_TYPES
)
{
if
(
!
self
::
isValidType
(
$value
,
$dataType
))
{
$errorStack
->
add
(
$fieldName
,
'type'
);
}
if
(
$dataType
==
'enum'
)
{
$enumIndex
=
$classMetadata
->
enumIndex
(
$fieldName
,
$value
);
if
(
$enumIndex
===
false
)
{
$errorStack
->
add
(
$fieldName
,
'enum'
);
}
}
}
// Validate field length, if length validation is enabled
if
(
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_VALIDATE
)
&
Doctrine
::
VALIDATE_LENGTHS
)
{
if
(
!
$this
->
validateLength
(
$column
,
$key
,
$value
))
{
$errorStack
->
add
(
$key
,
'length'
);
continue
;
if
(
!
$this
->
validateLength
(
$value
,
$dataType
,
$classMetadata
->
getFieldLength
(
$fieldName
)))
{
$errorStack
->
add
(
$fieldName
,
'length'
);
}
}
foreach
(
$column
as
$name
=>
$args
)
{
if
(
empty
(
$name
)
||
$name
==
'primary'
||
$name
==
'protected'
||
$name
==
'autoincrement'
||
$name
==
'default'
||
$name
==
'values'
||
$name
==
'sequence'
||
$name
==
'zerofill'
||
$name
==
'scale'
||
$name
==
'inherited'
)
{
continue
;
// Run all custom validators
foreach
(
$classMetadata
->
getFieldValidators
(
$fieldName
)
as
$validatorName
=>
$args
)
{
if
(
!
is_string
(
$validatorName
))
{
$validatorName
=
$args
;
$args
=
array
();
}
if
(
strtolower
(
$name
)
===
'notnull'
&&
isset
(
$column
[
'autoincrement'
]))
{
continue
;
}
if
(
strtolower
(
$name
)
==
'length'
)
{
if
(
!
(
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_VALIDATE
)
&
Doctrine
::
VALIDATE_LENGTHS
))
{
if
(
!
$this
->
validateLength
(
$column
,
$key
,
$value
))
{
$errorStack
->
add
(
$key
,
'length'
);
}
}
continue
;
}
if
(
strtolower
(
$name
)
==
'type'
)
{
if
(
!
(
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_VALIDATE
)
&
Doctrine
::
VALIDATE_TYPES
))
{
if
(
!
self
::
isValidType
(
$value
,
$column
[
'type'
]))
{
$errorStack
->
add
(
$key
,
'type'
);
}
}
continue
;
}
$validator
=
self
::
getValidator
(
$name
);
$validator
=
self
::
getValidator
(
$validatorName
);
$validator
->
invoker
=
$record
;
$validator
->
field
=
$key
;
$validator
->
args
=
$args
;
$validator
->
field
=
$fieldName
;
$validator
->
args
=
$args
;
if
(
!
$validator
->
validate
(
$value
))
{
$errorStack
->
add
(
$key
,
$name
);
//$err[$key] = 'not valid';
// errors found quit validation looping for this column
//break;
}
}
if
(
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_VALIDATE
)
&
Doctrine
::
VALIDATE_TYPES
)
{
if
(
!
self
::
isValidType
(
$value
,
$column
[
'type'
]))
{
$errorStack
->
add
(
$key
,
'type'
);
continue
;
$errorStack
->
add
(
$fieldName
,
$validatorName
);
}
}
}
...
...
@@ -166,18 +126,16 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
/**
* Validates the length of a field.
*/
private
function
validateLength
(
$
column
,
$key
,
$value
)
private
function
validateLength
(
$
value
,
$type
,
$maximumLength
)
{
if
(
$column
[
'type'
]
==
'timestamp'
||
$column
[
'type'
]
==
'integer'
||
$column
[
'type'
]
==
'enum'
)
{
if
(
$type
==
'timestamp'
||
$type
==
'integer'
||
$type
==
'enum'
)
{
return
true
;
}
else
if
(
$
column
[
'type'
]
==
'array'
||
$column
[
'type'
]
==
'object'
)
{
}
else
if
(
$
type
==
'array'
||
$type
==
'object'
)
{
$length
=
strlen
(
serialize
(
$value
));
}
else
{
$length
=
strlen
(
$value
);
}
if
(
$length
>
$column
[
'length'
])
{
if
(
$length
>
$maximumLength
)
{
return
false
;
}
return
true
;
...
...
@@ -191,68 +149,7 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
public
function
hasErrors
()
{
return
(
count
(
$this
->
stack
)
>
0
);
}
/**
* phpType
* converts a doctrine type to native php type
*
* @param $portableType portable doctrine type
* @return string
*/
/*
public static function phpType($portableType)
{
switch ($portableType) {
case 'enum':
return 'integer';
case 'blob':
case 'clob':
case 'mbstring':
case 'timestamp':
case 'date':
case 'gzip':
return 'string';
break;
default:
return $portableType;
}
}*/
/**
* returns whether or not the given variable is
* valid type
*
* @param mixed $var
* @param string $type
* @return boolean
*/
/*
public static function isValidType($var, $type)
{
if ($type == 'boolean') {
return true;
}
$looseType = self::gettype($var);
$type = self::phpType($type);
switch ($looseType) {
case 'float':
case 'double':
case 'integer':
if ($type == 'string' || $type == 'float') {
return true;
}
case 'string':
case 'array':
case 'object':
return ($type === $looseType);
break;
case 'NULL':
return true;
break;
}
}*/
}
/**
* returns whether or not the given variable is
...
...
@@ -300,29 +197,4 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable
return
false
;
}
}
/**
* returns the type of loosely typed variable
*
* @param mixed $var
* @return string
*/
/*
public static function gettype($var)
{
$type = gettype($var);
switch ($type) {
case 'string':
if (preg_match("/^[0-9]+$/",$var)) {
return 'integer';
} elseif (is_numeric($var)) {
return 'float';
} else {
return $type;
}
break;
default:
return $type;
}
}*/
}
tests/Orm/Component/AccessTest.php
View file @
c1c3f489
...
...
@@ -44,6 +44,16 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
$this
->
user
=
new
ForumUser
();
}
public
function
testAccessorOverridePerformance
()
{
$this
->
user
->
username
;
$start
=
microtime
(
true
);
for
(
$i
=
0
;
$i
<
1
;
$i
++
)
{
$this
->
user
->
username
;
}
$end
=
microtime
(
true
);
echo
(
$end
-
$start
)
.
" seconds"
.
PHP_EOL
;
}
/**
* @test
*/
...
...
tests/lib/Doctrine_OrmTestCase.php
View file @
c1c3f489
...
...
@@ -119,24 +119,4 @@ class Doctrine_OrmTestCase extends Doctrine_TestCase
$conn
->
exec
(
"DELETE FROM "
.
$conn
->
getClassMetadata
(
$model
)
->
getTableName
());
}
}
/*
public function loadFixturesPackage($package, $models = array())
{
$packagePath = 'fixtures' . DIRECTORY_SEPARATOR . $package;
if ( ! file_exists($packagePath)) {
throw new Exception("Could not find fixtures package: $package.");
}
$modelsPath = $packagePath . DIRECTORY_SEPARATOR . 'models';
$dataPath = $packagePath . DIRECTORY_SEPARATOR . 'data';
Doctrine::loadModels($modelsPath);
Doctrine::createTablesFromModels($modelsPath);
$data = new Doctrine_Data();
$data->importData($dataPath, 'yml', $models);
}
*/
}
\ No newline at end of file
tests/models/forum/ForumUser.php
View file @
c1c3f489
...
...
@@ -16,11 +16,17 @@ class ForumUser extends Doctrine_Record
// the discriminator column
$class
->
mapColumn
(
'dtype'
,
'string'
,
50
);
//
property
mapping
//
column
mapping
$class
->
mapColumn
(
'id'
,
'integer'
,
4
,
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
));
$class
->
mapColumn
(
'username'
,
'string'
,
50
);
}
/*
public function getUsername()
{
return $this->rawGet('username') . "!";
}
*/
}
\ No newline at end of file
tests_old/DoctrineTest/Doctrine_UnitTestCase.php
View file @
c1c3f489
...
...
@@ -300,4 +300,13 @@ class Doctrine_UnitTestCase extends UnitTestCase
$this
->
init
=
true
;
}
public
function
tearDown
()
{
/*foreach ($this->tables as $table) {
foreach ($this->conn->getMapper($table)->getRepository() as $obj) {
$obj->free();
}
}*/
}
}
tests_old/DoctrineTest/UnitTestCase.php
View file @
c1c3f489
...
...
@@ -116,11 +116,15 @@ class UnitTestCase
foreach
(
get_class_methods
(
$this
)
as
$method
)
{
if
(
substr
(
$method
,
0
,
4
)
===
'test'
)
{
$this
->
setUp
();
$this
->
$method
();
$this
->
tearDown
();
}
}
}
public
function
setUp
()
{}
public
function
tearDown
()
{}
public
function
getMessages
()
{
return
$this
->
_messages
;
...
...
tests_old/Inheritance/SingleTableTestCase.php
View file @
c1c3f489
...
...
@@ -17,20 +17,20 @@ class Doctrine_Inheritance_SingleTable_TestCase extends Doctrine_UnitTestCase
public
function
testMetadataSetup
()
{
$user
Table
=
$this
->
conn
->
get
Metadata
(
'STI_User'
);
$superManager
Table
=
$this
->
conn
->
get
Metadata
(
'STI_SuperManager'
);
$manager
Table
=
$this
->
conn
->
get
Metadata
(
'STI_Manager'
);
$customer
Table
=
$this
->
conn
->
get
Metadata
(
'STI_Customer'
);
$user
Class
=
$this
->
conn
->
getClass
Metadata
(
'STI_User'
);
$superManager
Class
=
$this
->
conn
->
getClass
Metadata
(
'STI_SuperManager'
);
$manager
Class
=
$this
->
conn
->
getClass
Metadata
(
'STI_Manager'
);
$customer
Class
=
$this
->
conn
->
getClass
Metadata
(
'STI_Customer'
);
$this
->
assertEqual
(
4
,
count
(
$user
Table
->
getField
s
()));
$this
->
assertEqual
(
'sti_entity'
,
$user
Table
->
getTableName
());
$this
->
assertEqual
(
'sti_entity'
,
$manager
Table
->
getTableName
());
$this
->
assertEqual
(
4
,
count
(
$user
Class
->
getMappedColumn
s
()));
$this
->
assertEqual
(
'sti_entity'
,
$user
Class
->
getTableName
());
$this
->
assertEqual
(
'sti_entity'
,
$manager
Class
->
getTableName
());
// check inheritance map
$this
->
assertEqual
(
array
(
1
=>
'STI_User'
,
2
=>
'STI_Manager'
,
3
=>
'STI_Customer'
,
4
=>
'STI_SuperManager'
),
$user
Table
->
getInheritanceOption
(
'discriminatorMap'
));
4
=>
'STI_SuperManager'
),
$user
Class
->
getInheritanceOption
(
'discriminatorMap'
));
//var_dump($superManagerTable->getComponentName());
}
...
...
tests_old/Metadata/FactoryTestCase.php
View file @
c1c3f489
...
...
@@ -25,8 +25,8 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
$userClass
=
$this
->
conn
->
getClassMetadata
(
'Metadata_User'
);
$this
->
assertTrue
(
$userClass
instanceof
Doctrine_ClassMetadata
);
$this
->
assertEqual
(
'cti_user'
,
$userClass
->
getTableName
());
$this
->
assertEqual
(
4
,
count
(
$userClass
->
get
Field
s
()));
$this
->
assertIdentical
(
array
(),
$userClass
->
get
Option
(
'parents'
));
$this
->
assertEqual
(
4
,
count
(
$userClass
->
get
MappedColumn
s
()));
$this
->
assertIdentical
(
array
(),
$userClass
->
get
ParentClasses
(
));
$this
->
assertEqual
(
'type'
,
$userClass
->
getInheritanceOption
(
'discriminatorColumn'
));
$this
->
assertIdentical
(
array
(
1
=>
'CTI_User'
,
...
...
@@ -37,9 +37,9 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
$managerClass
=
$this
->
conn
->
getMetadata
(
'Metadata_Manager'
);
$this
->
assertTrue
(
$managerClass
instanceof
Doctrine_ClassMetadata
);
$this
->
assertIdentical
(
array
(
'Metadata_User'
),
$managerClass
->
get
Option
(
'parents'
));
$this
->
assertIdentical
(
array
(
'Metadata_User'
),
$managerClass
->
get
ParentClasses
(
));
$this
->
assertEqual
(
'cti_manager'
,
$managerClass
->
getTableName
());
$this
->
assertEqual
(
5
,
count
(
$managerClass
->
get
Field
s
()));
$this
->
assertEqual
(
5
,
count
(
$managerClass
->
get
MappedColumn
s
()));
$this
->
assertEqual
(
'type'
,
$managerClass
->
getInheritanceOption
(
'discriminatorColumn'
));
$this
->
assertIdentical
(
array
(
1
=>
'CTI_User'
,
...
...
@@ -50,9 +50,9 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
$suManagerClass
=
$this
->
conn
->
getMetadata
(
'Metadata_SuperManager'
);
$this
->
assertTrue
(
$suManagerClass
instanceof
Doctrine_ClassMetadata
);
$this
->
assertIdentical
(
array
(
'Metadata_Manager'
,
'Metadata_User'
),
$suManagerClass
->
get
Option
(
'parents'
));
$this
->
assertIdentical
(
array
(
'Metadata_Manager'
,
'Metadata_User'
),
$suManagerClass
->
get
ParentClasses
(
));
$this
->
assertEqual
(
'cti_supermanager'
,
$suManagerClass
->
getTableName
());
$this
->
assertEqual
(
6
,
count
(
$suManagerClass
->
get
Field
s
()));
$this
->
assertEqual
(
6
,
count
(
$suManagerClass
->
get
MappedColumn
s
()));
$this
->
assertEqual
(
'type'
,
$suManagerClass
->
getInheritanceOption
(
'discriminatorColumn'
));
$this
->
assertIdentical
(
array
(
1
=>
'CTI_User'
,
...
...
@@ -65,7 +65,7 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
public
function
testExportableFormatOfClassInClassTableInheritanceHierarchy
()
{
$userClass
=
$this
->
conn
->
getMetadata
(
'Metadata_User'
);
$userClass
=
$this
->
conn
->
get
Class
Metadata
(
'Metadata_User'
);
$userClassExportableFormat
=
$userClass
->
getExportableFormat
();
$this
->
assertEqual
(
4
,
count
(
$userClassExportableFormat
[
'columns'
]));
$this
->
assertTrue
(
isset
(
$userClassExportableFormat
[
'columns'
][
'cti_id'
]));
...
...
@@ -75,21 +75,21 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
$this
->
assertTrue
(
isset
(
$userClassExportableFormat
[
'columns'
][
'cti_name'
]));
$this
->
assertTrue
(
isset
(
$userClassExportableFormat
[
'columns'
][
'type'
]));
$managerClass
=
$this
->
conn
->
getMetadata
(
'Metadata_Manager'
);
$managerClass
=
$this
->
conn
->
get
Class
Metadata
(
'Metadata_Manager'
);
$managerClassExportableFormat
=
$managerClass
->
getExportableFormat
();
$this
->
assertEqual
(
2
,
count
(
$managerClassExportableFormat
[
'columns'
]));
$this
->
assertTrue
(
isset
(
$managerClassExportableFormat
[
'columns'
][
'cti_id'
]));
$this
->
assertTrue
(
isset
(
$managerClassExportableFormat
[
'columns'
][
'cti_id'
][
'primary'
]));
$this
->
assertFalse
(
isset
(
$managerClassExportableFormat
[
'columns'
][
'cti_id'
][
'autoincrement'
]));
$customerClass
=
$this
->
conn
->
getMetadata
(
'Metadata_Customer'
);
$customerClass
=
$this
->
conn
->
get
Class
Metadata
(
'Metadata_Customer'
);
$customerClassExportableFormat
=
$customerClass
->
getExportableFormat
();
$this
->
assertEqual
(
2
,
count
(
$customerClassExportableFormat
[
'columns'
]));
$this
->
assertTrue
(
isset
(
$customerClassExportableFormat
[
'columns'
][
'cti_id'
]));
$this
->
assertTrue
(
isset
(
$customerClassExportableFormat
[
'columns'
][
'cti_id'
][
'primary'
]));
$this
->
assertFalse
(
isset
(
$customerClassExportableFormat
[
'columns'
][
'cti_id'
][
'autoincrement'
]));
$superManagerClass
=
$this
->
conn
->
getMetadata
(
'Metadata_SuperManager'
);
$superManagerClass
=
$this
->
conn
->
get
Class
Metadata
(
'Metadata_SuperManager'
);
$superManagerClassExportableFormat
=
$superManagerClass
->
getExportableFormat
();
$this
->
assertEqual
(
2
,
count
(
$superManagerClassExportableFormat
[
'columns'
]));
$this
->
assertTrue
(
isset
(
$superManagerClassExportableFormat
[
'columns'
][
'cti_id'
]));
...
...
@@ -99,11 +99,11 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
public
function
testMetadataSetupOnSingleTableInheritanceHierarchy
()
{
$userClass
=
$this
->
conn
->
getMetadata
(
'Metadata_STI_User'
);
$userClass
=
$this
->
conn
->
get
Class
Metadata
(
'Metadata_STI_User'
);
$this
->
assertTrue
(
$userClass
instanceof
Doctrine_ClassMetadata
);
$this
->
assertEqual
(
'cti_user'
,
$userClass
->
getTableName
());
$this
->
assertEqual
(
4
,
count
(
$userClass
->
get
Field
s
()));
$this
->
assertIdentical
(
array
(),
$userClass
->
get
Option
(
'parents'
));
$this
->
assertEqual
(
4
,
count
(
$userClass
->
get
MappedColumn
s
()));
$this
->
assertIdentical
(
array
(),
$userClass
->
get
ParentClasses
(
));
$this
->
assertEqual
(
'type'
,
$userClass
->
getInheritanceOption
(
'discriminatorColumn'
));
$this
->
assertIdentical
(
array
(
1
=>
'CTI_User'
,
...
...
@@ -111,11 +111,11 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
3
=>
'CTI_Customer'
,
4
=>
'CTI_SuperManager'
),
$userClass
->
getInheritanceOption
(
'discriminatorMap'
));
$managerClass
=
$this
->
conn
->
getMetadata
(
'Metadata_STI_Manager'
);
$managerClass
=
$this
->
conn
->
get
Class
Metadata
(
'Metadata_STI_Manager'
);
$this
->
assertTrue
(
$managerClass
instanceof
Doctrine_ClassMetadata
);
$this
->
assertIdentical
(
array
(
'Metadata_STI_User'
),
$managerClass
->
get
Option
(
'parents'
));
$this
->
assertIdentical
(
array
(
'Metadata_STI_User'
),
$managerClass
->
get
ParentClasses
(
));
$this
->
assertEqual
(
'cti_user'
,
$managerClass
->
getTableName
());
$this
->
assertEqual
(
5
,
count
(
$managerClass
->
get
Field
s
()));
$this
->
assertEqual
(
5
,
count
(
$managerClass
->
get
MappedColumn
s
()));
$this
->
assertEqual
(
'type'
,
$managerClass
->
getInheritanceOption
(
'discriminatorColumn'
));
$this
->
assertIdentical
(
array
(
1
=>
'CTI_User'
,
...
...
@@ -124,11 +124,11 @@ class Doctrine_Metadata_Factory_TestCase extends Doctrine_UnitTestCase
4
=>
'CTI_SuperManager'
),
$managerClass
->
getInheritanceOption
(
'discriminatorMap'
));
$suManagerClass
=
$this
->
conn
->
getMetadata
(
'Metadata_STI_SuperManager'
);
$suManagerClass
=
$this
->
conn
->
get
Class
Metadata
(
'Metadata_STI_SuperManager'
);
$this
->
assertTrue
(
$suManagerClass
instanceof
Doctrine_ClassMetadata
);
$this
->
assertIdentical
(
array
(
'Metadata_STI_Manager'
,
'Metadata_STI_User'
),
$suManagerClass
->
get
Option
(
'parents'
));
$this
->
assertIdentical
(
array
(
'Metadata_STI_Manager'
,
'Metadata_STI_User'
),
$suManagerClass
->
get
ParentClasses
(
));
$this
->
assertEqual
(
'cti_user'
,
$suManagerClass
->
getTableName
());
$this
->
assertEqual
(
6
,
count
(
$suManagerClass
->
get
Field
s
()));
$this
->
assertEqual
(
6
,
count
(
$suManagerClass
->
get
MappedColumn
s
()));
$this
->
assertEqual
(
'type'
,
$suManagerClass
->
getInheritanceOption
(
'discriminatorColumn'
));
$this
->
assertIdentical
(
array
(
1
=>
'CTI_User'
,
...
...
tests_old/Ticket/381TestCase.php
View file @
c1c3f489
...
...
@@ -56,4 +56,5 @@ class Doctrine_Ticket_381_TestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$obj
->
get
(
'name'
),
'yes2'
);
$obj
->
save
();
}
}
tests_old/ValidatorTestCase.php
View file @
c1c3f489
...
...
@@ -139,6 +139,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
public
function
testValidate
()
{
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VALIDATE
,
Doctrine
::
VALIDATE_ALL
);
$user
=
$this
->
connection
->
getMapper
(
'User'
)
->
find
(
4
);
$set
=
array
(
'password'
=>
'this is an example of too long password'
,
...
...
@@ -152,11 +153,11 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
$this
->
assertTrue
(
$user
->
getModified
()
==
$set
);
$validator
=
new
Doctrine_Validator
();
$validator
->
validateRecord
(
$user
);
$validator
->
validateRecord
(
$user
);
$stack
=
$user
->
errorStack
();
$this
->
assertTrue
(
$stack
instanceof
Doctrine_Validator_ErrorStack
);
$this
->
assertTrue
(
in_array
(
'length'
,
$stack
[
'loginname'
]));
$this
->
assertTrue
(
in_array
(
'length'
,
$stack
[
'password'
]));
...
...
@@ -171,6 +172,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
$stack
=
$email
->
errorStack
();
$this
->
assertTrue
(
in_array
(
'unique'
,
$stack
[
'address'
]));
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VALIDATE
,
Doctrine
::
VALIDATE_NONE
);
}
/**
...
...
tests_old/models/Email.php
View file @
c1c3f489
...
...
@@ -3,7 +3,8 @@ class Email extends Doctrine_Record
{
public
static
function
initMetadata
(
$class
)
{
$class
->
setColumn
(
'address'
,
'string'
,
150
,
array
(
'email'
,
'unique'
=>
true
));
$class
->
setColumn
(
'address'
,
'string'
,
150
,
array
(
'email'
,
'unique'
=>
true
,
'validators'
=>
array
(
'email'
,
'unique'
)));
}
...
...
tests_old/models/Entity.php
View file @
c1c3f489
...
...
@@ -5,7 +5,7 @@ class Entity extends Doctrine_Record
{
$class
->
setColumn
(
'id'
,
'integer'
,
20
,
array
(
'autoincrement'
=>
true
,
'primary'
=>
true
));
$class
->
setColumn
(
'name'
,
'string'
,
50
);
$class
->
setColumn
(
'loginname'
,
'string'
,
20
,
array
(
'unique'
=>
true
));
$class
->
setColumn
(
'loginname'
,
'string'
,
20
,
array
(
'unique'
=>
true
,
'validators'
=>
array
(
'unique'
)
));
$class
->
setColumn
(
'password'
,
'string'
,
16
);
$class
->
setColumn
(
'type'
,
'integer'
);
$class
->
setColumn
(
'created'
,
'integer'
,
11
);
...
...
tests_old/models/ValidatorTest.php
View file @
c1c3f489
...
...
@@ -2,14 +2,23 @@
class
ValidatorTest
extends
Doctrine_Record
{
public
static
function
initMetadata
(
$class
)
{
$class
->
setColumn
(
'mymixed'
,
'string'
,
100
);
$class
->
setColumn
(
'mystring'
,
'string'
,
100
,
array
(
'notnull'
,
'unique'
));
$class
->
setColumn
(
'mystring'
,
'string'
,
100
,
array
(
'validators'
=>
array
(
'notnull'
,
'unique'
))
);
$class
->
setColumn
(
'myarray'
,
'array'
,
1000
);
$class
->
setColumn
(
'myobject'
,
'object'
,
1000
);
$class
->
setColumn
(
'myinteger'
,
'integer'
,
11
);
$class
->
setColumn
(
'myrange'
,
'integer'
,
11
,
array
(
'range'
=>
array
(
4
,
123
)));
$class
->
setColumn
(
'myregexp'
,
'string'
,
5
,
array
(
'regexp'
=>
'/^[0-9]+$/'
));
$class
->
setColumn
(
'myemail'
,
'string'
,
100
,
array
(
'email'
));
$class
->
setColumn
(
'myemail2'
,
'string'
,
100
,
array
(
'email'
,
'notblank'
));
$class
->
setColumn
(
'myrange'
,
'integer'
,
11
,
array
(
'validators'
=>
array
(
'range'
=>
array
(
4
,
123
)))
);
$class
->
setColumn
(
'myregexp'
,
'string'
,
5
,
array
(
'validators'
=>
array
(
'regexp'
=>
'/^[0-9]+$/'
))
);
$class
->
setColumn
(
'myemail'
,
'string'
,
100
,
array
(
'validators'
=>
array
(
'email'
))
);
$class
->
setColumn
(
'myemail2'
,
'string'
,
100
,
array
(
'validators'
=>
array
(
'email'
,
'notblank'
))
);
}
}
tests_old/models/ValidatorTest_AddressModel.php
View file @
c1c3f489
...
...
@@ -4,11 +4,16 @@ class ValidatorTest_AddressModel extends Doctrine_Record {
$class
->
setColumn
(
"id"
,
"integer"
,
11
,
array
(
'autoincrement'
=>
true
,
'primary'
=>
true
));
$class
->
setColumn
(
'address1'
,
'string'
,
255
,
array
(
'notnull'
=>
true
,
'notblank'
));
$class
->
setColumn
(
'address2'
,
'string'
,
255
,
array
(
'notnull'
=>
true
));
$class
->
setColumn
(
'city'
,
'string'
,
255
,
array
(
'notnull'
=>
true
,
'notblank'
));
$class
->
setColumn
(
'state'
,
'string'
,
10
,
array
(
'notnull'
=>
true
,
'notblank'
,
'usstate'
));
$class
->
setColumn
(
'zip'
,
'string'
,
15
,
array
(
'notnull'
=>
true
,
'notblank'
,
'regexp'
=>
'/^[0-9-]*$/'
));
$class
->
setColumn
(
'address1'
,
'string'
,
255
,
array
(
'notnull'
=>
true
,
'validators'
=>
array
(
'notnull'
,
'notblank'
)));
$class
->
setColumn
(
'address2'
,
'string'
,
255
,
array
(
'notnull'
=>
true
,
'validators'
=>
array
(
'notnull'
)));
$class
->
setColumn
(
'city'
,
'string'
,
255
,
array
(
'notnull'
=>
true
,
'validators'
=>
array
(
'notnull'
,
'notblank'
)));
$class
->
setColumn
(
'state'
,
'string'
,
10
,
array
(
'notnull'
=>
true
,
'validators'
=>
array
(
'notnull'
,
'notblank'
,
'usstate'
)));
$class
->
setColumn
(
'zip'
,
'string'
,
15
,
array
(
'notnull'
=>
true
,
'validators'
=>
array
(
'notnull'
,
'notblank'
,
'regexp'
=>
'/^[0-9-]*$/'
)));
$class
->
hasMany
(
'ValidatorTest_ClientModel'
,
array
(
'local'
=>
'address_id'
,
'foreign'
=>
'client_id'
,
'refClass'
=>
'ValidatorTest_ClientToAddressModel'
));
}
}
tests_old/models/ValidatorTest_DateModel.php
View file @
c1c3f489
<?php
class
ValidatorTest_DateModel
extends
Doctrine_Record
{
public
static
function
initMetadata
(
$class
)
{
$class
->
setColumn
(
'birthday'
,
'date'
,
null
,
array
(
'past'
));
$class
->
setColumn
(
'death'
,
'date'
,
null
,
array
(
'future'
));
$class
->
setColumn
(
'birthday'
,
'date'
,
null
,
array
(
'validators'
=>
array
(
'past'
)));
$class
->
setColumn
(
'death'
,
'date'
,
null
,
array
(
'validators'
=>
array
(
'future'
)));
}
}
tests_old/models/ValidatorTest_Person.php
View file @
c1c3f489
<?php
class
ValidatorTest_Person
extends
Doctrine_Record
{
public
static
function
initMetadata
(
$class
)
{
$class
->
setColumn
(
'identifier'
,
'integer'
,
4
,
array
(
'notblank'
,
'unique'
));
$class
->
setColumn
(
'identifier'
,
'integer'
,
4
,
array
(
'validators'
=>
array
(
'notblank'
,
'unique'
)));
$class
->
setColumn
(
'is_football_player'
,
'boolean'
);
$class
->
hasOne
(
'ValidatorTest_FootballPlayer'
,
array
(
'local'
=>
'id'
,
'foreign'
=>
'person_id'
));
$class
->
hasOne
(
'ValidatorTest_FootballPlayer'
,
array
(
'local'
=>
'id'
,
'foreign'
=>
'person_id'
));
}
}
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