Commit 34f4ee71 authored by romanb's avatar romanb

First tests for basic collection implementation. First experimental use of...

First tests for basic collection implementation. First experimental use of closures (Currently commented out, because the svn server makes a syntax check against 5.2.x).
parent 73ad0ac4
......@@ -30,7 +30,7 @@ interface Doctrine_DBAL_Driver
* Gets the SchemaManager that can be used to inspect and change the underlying
* database schema of the platform this driver connects to.
*
* @return Doctrine::DBAL::SchemaManager
* @return Doctrine\DBAL\SchemaManager
*/
public function getSchemaManager(Doctrine_DBAL_Connection $conn);
}
......
......@@ -44,12 +44,12 @@ class Doctrine_DBAL_Driver_PDOMySql_Driver implements Doctrine_DBAL_Driver
public function getDatabasePlatform()
{
return new Doctrine_DatabasePlatform_MySqlPlatform();
return new Doctrine_DBAL_Platforms_MySqlPlatform();
}
public function getSchemaManager(Doctrine_Connection $conn)
public function getSchemaManager(Doctrine_DBAL_Connection $conn)
{
return new Doctrine_Schema_MySqlSchemaManager($conn);
return new Doctrine_DBAL_Schema_MySqlSchemaManager($conn);
}
}
......
......@@ -31,12 +31,12 @@ class Doctrine_DBAL_Driver_PDOPgSql_Driver implements Doctrine_DBAL_Driver
public function getDatabasePlatform()
{
return new Doctrine_DatabasePlatform_PostgreSqlPlatform();
return new Doctrine_DBAL_Platforms_PostgreSqlPlatform();
}
public function getSchemaManager(Doctrine_Connection $conn)
public function getSchemaManager(Doctrine_DBAL_Connection $conn)
{
return new Doctrine_Schema_PostgreSqlSchemaManager($conn);
return new Doctrine_DBAL_Schema_PostgreSqlSchemaManager($conn);
}
}
......
......@@ -724,7 +724,7 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
// attach all primary keys
if (isset($options['primary']) && ! empty($options['primary'])) {
$keyColumns = array_values($options['primary']);
$keyColumns = array_map(array($this->_conn, 'quoteIdentifier'), $keyColumns);
$keyColumns = array_map(array($this, 'quoteIdentifier'), $keyColumns);
$queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')';
}
......@@ -751,9 +751,9 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
// get the type of the table
if (isset($options['type'])) {
$type = $options['type'];
} else {
}/* else {
$type = $this->getAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE);
}
}*/
if ($type) {
$optionStrings[] = 'ENGINE = ' . $type;
......@@ -1057,13 +1057,13 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
}
/** @override */
public function getSmallIntDeclarationSql(array $field)
public function getSmallIntTypeDeclarationSql(array $field)
{
return 'SMALLINT ' . $this->_getCommonIntegerTypeDeclarationSql($field);
}
/** @override */
public function getMediumIntDeclarationSql(array $field)
public function getMediumIntTypeDeclarationSql(array $field)
{
return 'MEDIUMINT ' . $this->_getCommonIntegerTypeDeclarationSql($field);
}
......@@ -1072,23 +1072,23 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
{
$default = $autoinc = '';
if ( ! empty($field['autoincrement'])) {
if ( ! empty($columnDef['autoincrement'])) {
$autoinc = ' AUTO_INCREMENT';
} elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
} elseif (array_key_exists('default', $columnDef)) {
if ($columnDef['default'] === '') {
$columnDef['default'] = empty($columnDef['notnull']) ? null : 0;
}
if (is_null($field['default'])) {
if (is_null($columnDef['default'])) {
$default = ' DEFAULT NULL';
} else {
$default = ' DEFAULT '.$this->quote($field['default']);
$default = ' DEFAULT '.$this->quote($columnDef['default']);
}
} elseif (empty($field['notnull'])) {
} elseif (empty($columnDef['notnull'])) {
$default = ' DEFAULT NULL';
}
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
$notnull = (isset($columnDef['notnull']) && $columnDef['notnull']) ? ' NOT NULL' : '';
$unsigned = (isset($columnDef['unsigned']) && $columnDef['unsigned']) ? ' UNSIGNED' : '';
return $unsigned . $default . $notnull . $autoinc;
}
......
......@@ -172,7 +172,6 @@ abstract class Doctrine_DBAL_Schema_AbstractSchemaManager
}
/**
* dropTable
* drop an existing table
*
* @param string $table name of table that should be dropped from the database
......
......@@ -65,7 +65,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
// check needed because of mixed results.
// is_object instead of is_array because is_array is slow on large arrays.
if (is_object($coll)) {
$coll->end();
$coll->last();
return $coll->key();
} else {
end($coll);
......@@ -121,7 +121,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
$classMetadata1 = $this->_metadataMap[spl_object_hash($entity1)];
$classMetadata2 = $this->_metadataMap[spl_object_hash($entity2)];
$indexValue = $classMetadata2->getReflectionProperty($indexField)->getValue($entity2);
$classMetadata1->getReflectionProperty($property)->getValue($entity1)->add($entity2, $indexValue);
$classMetadata1->getReflectionProperty($property)->getValue($entity1)->set($indexValue, $entity2);
}
/**
......@@ -196,7 +196,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
public function addElementToIndexedCollection($coll, $entity, $keyField)
{
$coll->add($entity, $this->getFieldValue($entity, $keyField));
$coll->set($entity, $this->getFieldValue($keyField, $entity));
}
public function addElementToCollection($coll, $entity)
......@@ -216,7 +216,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
*/
public function updateResultPointer(&$resultPointers, &$coll, $index, $dqlAlias, $oneToOne)
{
if ($coll === /*$this->_nullObject*/null) {
if ($coll === null) {
echo "HERE!";
unset($resultPointers[$dqlAlias]); // Ticket #1228
return;
......@@ -232,7 +232,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
$resultPointers[$dqlAlias] =& $coll[key($coll)];
} else if ($coll instanceof Doctrine_ORM_Collection) {
if (count($coll) > 0) {
$resultPointers[$dqlAlias] = $coll->getLast();
$resultPointers[$dqlAlias] = $coll->last();
}
} else {
$resultPointers[$dqlAlias] = $coll;
......
......@@ -105,19 +105,18 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
$rootEntityName = $this->_queryComponents[$rootAlias]['metadata']->getClassName();
// if only one class is involved we can make our lives easier
$isSimpleQuery = count($this->_queryComponents) <= 1;
// Lookup map to quickly discover/lookup existing records in the result
// Lookup map to quickly discover/lookup existing entities in the result
// It's the identifier "memory"
$identifierMap = array();
// Holds for each class a pointer to the last previously seen element in the result set
$resultPointers = array();
// holds the values of the identifier/primary key fields of components,
// separated by a pipe '|' and grouped by component alias (r, u, i, ... whatever)
// the $idTemplate is a prepared template. $id is set to a fresh template when
// Holds the values of the identifier/primary key fields of entities,
// separated by a pipe '|' and grouped by DQL class alias (r, u, i, ... whatever)
// The $idTemplate is a prepared template. $id is set to a fresh template when
// starting to process a row.
$id = array();
$idTemplate = array();
// Holds the resulting hydrated data structure
if ($parserResult->isMixedQuery() || $hydrationMode == Doctrine_ORM_Query::HYDRATE_SCALAR) {
$result = array();
} else {
......
......@@ -343,11 +343,6 @@ class Doctrine_ORM_Mapping_ClassMetadata
$this->_tableName = $this->_entityName;
$this->_rootEntityName = $entityName;
$this->_reflectionClass = new ReflectionClass($entityName);
$reflectionProps = $this->_reflectionClass->getProperties();
foreach ($reflectionProps as $prop) {
$prop->setAccessible(true);
$this->_reflectionProperties[$prop->getName()] = $prop;
}
}
/**
......@@ -652,6 +647,11 @@ class Doctrine_ORM_Mapping_ClassMetadata
$this->_isIdentifierComposite = true;
}
}
// Store ReflectionProperty of mapped field
$refProp = $this->_reflectionClass->getProperty($mapping['fieldName']);
$refProp->setAccessible(true);
$this->_reflectionProperties[$mapping['fieldName']] = $refProp;
}
private function _validateAndCompleteClassMapping(array &$mapping)
......@@ -1270,6 +1270,11 @@ class Doctrine_ORM_Mapping_ClassMetadata
}
$this->_associationMappings[$sourceFieldName] = $assocMapping;
$this->_registerMappingIfInverse($assocMapping);
// Store ReflectionProperty of mapped field
$refProp = $this->_reflectionClass->getProperty($sourceFieldName);
$refProp->setAccessible(true);
$this->_reflectionProperties[$sourceFieldName] = $refProp;
}
/**
......
......@@ -50,9 +50,6 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver {
}
foreach ($annotClass->getProperties() as $property) {
if ($property->hasAnnotation('DoctrineTransient')) {
continue;
}
$mapping = array();
$mapping['fieldName'] = $property->getName();
if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) {
......@@ -90,8 +87,6 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver {
$mapping['joinTable'] = $manyToManyAnnot->joinTable;
$mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
$metadata->mapManyToMany($mapping);
} else {
throw new Doctrine_ORM_Exceptions_MappingException($className);
}
}
}
......@@ -112,9 +107,16 @@ final class DoctrineDiscriminatorColumn extends Annotation {
}
final class DoctrineDiscriminatorMap extends Annotation {}
final class DoctrineSubClasses extends Annotation {}
final class DoctrineTransient extends Annotation {}
final class DoctrineId extends Annotation {}
final class DoctrineIdGenerator extends Annotation {}
final class DoctrineVersion extends Annotation {}
final class DoctrineJoinColumn extends Annotation {
public $name;
public $type;
public $length;
public $onDelete;
public $onUpdate;
}
final class DoctrineColumn extends Annotation {
public $type;
public $length;
......
......@@ -101,7 +101,6 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
* Updates an entity.
*
* @param object $entity The entity to update.
* @return void
*/
public function update($entity)
{
......@@ -110,30 +109,12 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
$id = array_combine($this->_classMetadata->getIdentifierFieldNames(),
$this->_em->getUnitOfWork()->getEntityIdentifier($entity));
$this->_conn->update($this->_classMetadata->getTableName(), $updateData, $id);
/*$dataChangeSet = $entity->_getDataChangeSet();
$referenceChangeSet = $entity->_getReferenceChangeSet();
foreach ($referenceChangeSet as $field => $change) {
$assocMapping = $entity->getClass()->getAssociationMapping($field);
if ($assocMapping instanceof Doctrine_Association_OneToOneMapping) {
if ($assocMapping->isInverseSide()) {
continue; // ignore inverse side
}
// ... null out the foreign key
}
//...
}
*/
//TODO: perform update
}
/**
* Deletes an entity.
*
* @param object $entity The entity to delete.
* @return void
*/
public function delete($entity)
{
......@@ -141,40 +122,11 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
$this->_em->getUnitOfWork()->getEntityIdentifier($entity));
$this->_conn->delete($this->_classMetadata->getTableName(), $id);
}
/**
* Inserts a row into a table.
*
* @todo This method could be used to allow mapping to secondary table(s).
* @see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SecondaryTable
*/
protected function _insertRow($tableName, array $data)
{
$this->_conn->insert($tableName, $data);
}
/**
* Deletes rows of a table.
*
* @todo This method could be used to allow mapping to secondary table(s).
* @see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SecondaryTable
*/
protected function _deleteRow($tableName, array $identifierToMatch)
{
$this->_conn->delete($tableName, $identifierToMatch);
}
/**
* Deletes rows of a table.
*
* @todo This method could be used to allow mapping to secondary table(s).
* @see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SecondaryTable
* @return <type>
*/
protected function _updateRow($tableName, array $data, array $identifierToMatch)
{
$this->_conn->update($tableName, $data, $identifierToMatch);
}
public function getClassMetadata()
{
return $this->_classMetadata;
......@@ -258,7 +210,6 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
//echo "NOT TO-ONE OR INVERSE!";
continue;
}
//echo "HERE!!!";
foreach ($assocMapping->getSourceToTargetKeyColumns() as $sourceColumn => $targetColumn) {
//TODO: throw exc if field not set
$otherClass = $this->_em->getClassMetadata($assocMapping->getTargetEntityName());
......@@ -283,7 +234,4 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
$result[$discColumn['name']] = array_search($this->_entityName, $discMap);
}
}
abstract protected function _doUpdate(Doctrine_ORM_Entity $entity);
abstract protected function _doInsert(Doctrine_ORM_Entity $entity);
}
......@@ -226,12 +226,12 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract
}
/**
* Executes the query and populates the data set.
* Executes the query.
*
* @param string $params Parameters to be sent to query.
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
* One of the Doctrine::HYDRATE_* constants.
* @return Doctrine_Collection The root collection
* @return mixed
*/
public function execute($params = array(), $hydrationMode = null)
{
......@@ -331,7 +331,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract
// Double the params if we are using limit-subquery algorithm
// We always have an instance of Doctrine_ORM_Query_ParserResult on hands...
if ($this->_parserResult->isLimitSubqueryUsed() &&
$this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') {
$this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') {
$params = array_merge($params, $params);
}
......
......@@ -2,7 +2,7 @@
/**
* This class is just an intermediate implementation for refactoring purposes
* and will be replaced by the ParserResult class of the new DQL parser branch.
* and will be replaced by the ParserResult class of the new DQL parser.
*
*/
class Doctrine_ORM_Query_ParserResultDummy
......
......@@ -57,13 +57,13 @@ abstract class Doctrine_ORM_Query_SqlExecutor_Abstract implements Serializable
* @param Doctrine_Connection $conn The database connection that is used to execute the queries.
* @param array $params The parameters.
*/
abstract public function execute(Doctrine_Connection $conn, array $params);
abstract public function execute(Doctrine_DBAL_Connection $conn, array $params);
/**
* Factory method.
* Creates an appropriate sql executor for the given AST.
*
* @param Doctrine_ORM_Query_Production $AST The root node of the AST.
* @param Doctrine_ORM_Query_AST $AST The root node of the AST.
* @return Doctrine_ORM_Query_SqlExecutor_Abstract The executor that is suitable for the given AST.
*/
public static function create(Doctrine_ORM_Query_AST $AST)
......
......@@ -25,7 +25,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Roman Borschel <roman@code-factory.org>
* @version $Revision$
* @link www.phpdoctrine.org
* @link www.doctrine-project.org
* @since 2.0
*/
class Doctrine_ORM_Query_SqlExecutor_SingleSelect extends Doctrine_ORM_Query_SqlExecutor_Abstract
......@@ -36,7 +36,7 @@ class Doctrine_ORM_Query_SqlExecutor_SingleSelect extends Doctrine_ORM_Query_Sql
$this->_sqlStatements = $AST->buildSql();
}
public function execute(Doctrine_Connection $conn, array $params)
public function execute(Doctrine_DBAL_Connection $conn, array $params)
{
return $conn->execute($this->_sqlStatements, $params);
}
......
......@@ -452,23 +452,21 @@ class Doctrine_ORM_UnitOfWork
* @return array
*/
private function _getCommitOrder(array $entityChangeSet = null)
{
//TODO: Once these 3 arrays are indexed by classname we can do this:
// Either way... do we need to care about duplicates?
/*$classesInChangeSet = array_merge(
array_keys($this->_newEntities),
array_keys($this->_dirtyEntities),
array_keys($this->_deletedEntities)
);*/
{
if (is_null($entityChangeSet)) {
$entityChangeSet = array_merge($this->_newEntities, $this->_dirtyEntities, $this->_deletedEntities);
$entityChangeSet = array_merge(
$this->_newEntities,
$this->_dirtyEntities,
$this->_deletedEntities);
}
/* if (count($entityChangeSet) == 1) {
* return array($entityChangeSet[0]->getClass());
* }
*/
// TODO: We can cache computed commit orders in the metadata cache!
// Check cache at this point here!
// See if there are any new classes in the changeset, that are not in the
// commit order graph yet (dont have a node).
......@@ -1242,6 +1240,17 @@ class Doctrine_ORM_UnitOfWork
}
return false;
}
/**
* Calculates the size of the UnitOfWork. The size of the UnitOfWork is the
* number of entities in the identity map.
*/
public function size()
{
$count = 0;
foreach ($this->_identityMap as $entitySet) $count += count($entitySet);
return $count;
}
}
......
......@@ -7,6 +7,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
require_once 'lib/DoctrineTestInit.php';
// Suites
require_once 'Common/AllTests.php';
require_once 'Dbal/AllTests.php';
require_once 'Orm/AllTests.php';
......@@ -21,6 +22,7 @@ class AllTests
{
$suite = new Doctrine_TestSuite('Doctrine Tests');
$suite->addTest(Common_AllTests::suite());
$suite->addTest(Dbal_AllTests::suite());
$suite->addTest(Orm_AllTests::suite());
......
<?php
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Common_AllTests::main');
}
require_once 'lib/DoctrineTestInit.php';
// Suites
require_once 'Common/Collections/AllTests.php';
class Common_AllTests
{
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new Doctrine_TestSuite('Doctrine Common Tests');
$suite->addTest(Common_Collections_AllTests::suite());
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'Common_AllTests::main') {
Common_AllTests::main();
}
\ No newline at end of file
<?php
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Common_Collections_AllTests::main');
}
require_once 'lib/DoctrineTestInit.php';
// Tests
require_once 'Common/Collections/CollectionTest.php';
class Common_Collections_AllTests
{
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new Doctrine_TestSuite('Doctrine Common Collections Tests');
$suite->addTestSuite('Common_Collections_CollectionTest');
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'Common_Collections_AllTests::main') {
Common_Collections_AllTests::main();
}
\ No newline at end of file
<?php
#namespace Doctrine\Tests\Common\Collections;
require_once 'lib/DoctrineTestInit.php';
/**
* Collection tests.
*
* @author robo
* @since 2.0
*/
class Common_Collections_CollectionTest extends Doctrine_TestCase {
private $_coll;
protected function setUp() {
$this->_coll = new Doctrine_Common_Collections_Collection;
}
/*public function testExists() {
$this->_coll->add("one");
$this->_coll->add("two");
$exists = $this->_coll->exists(function($key, $element) { return $element == "one"; });
$this->assertTrue($exists);
$exists = $this->_coll->exists(function($key, $element) { return $element == "other"; });
$this->assertFalse($exists);
}
public function testMap() {
$this->_coll->add(1);
$this->_coll->add(2);
$res = $this->_coll->map(function ($e) { return $e * 2; });
$this->assertEquals(array(2, 4), $res->unwrap());
}
public function testFilter() {
$this->_coll->add(1);
$this->_coll->add("foo");
$this->_coll->add(3);
$res = $this->_coll->filter(function ($e) { return is_numeric($e); });
$this->assertEquals(array(0 => 1, 2 => 3), $res->unwrap());
}*/
}
......@@ -12,6 +12,7 @@ require_once 'Orm/Ticket/AllTests.php';
require_once 'Orm/Entity/AllTests.php';
require_once 'Orm/Associations/AllTests.php';
require_once 'Orm/Mapping/AllTests.php';
require_once 'Orm/Functional/AllTests.php';
// Tests
require_once 'Orm/UnitOfWorkTest.php';
......@@ -41,6 +42,7 @@ class Orm_AllTests
$suite->addTest(Orm_Ticket_AllTests::suite());
$suite->addTest(Orm_Associations_AllTests::suite());
$suite->addTest(Orm_Mapping_AllTests::suite());
$suite->addTest(Orm_Functional_AllTests::suite());
return $suite;
}
......
......@@ -8,13 +8,14 @@ require_once 'lib/DoctrineTestInit.php';
* @author robo
*/
class Orm_Functional_BasicCRUDTest extends Doctrine_OrmFunctionalTestCase {
public function testSingleEntityCRUD() {
$em = $this->_getEntityManager();
$em = $this->_em;
$exporter = new Doctrine_ORM_Export_ClassExporter($em);
$exporter = new Doctrine_ORM_Export_ClassExporter($this->_em);
$exporter->exportClasses(array(
$em->getClassMetadata('CmsUser'),
$em->getClassMetadata('CmsPhonenumber')
$this->_em->getClassMetadata('CmsUser'),
$this->_em->getClassMetadata('CmsPhonenumber')
));
// Create
......@@ -46,11 +47,20 @@ class Orm_Functional_BasicCRUDTest extends Doctrine_OrmFunctionalTestCase {
$this->assertTrue($em->getUnitOfWork()->isRegisteredRemoved($user));
$em->flush();
$this->assertFalse($em->getUnitOfWork()->isRegisteredRemoved($user));
}
public function testMore() {
echo PHP_EOL . "SECOND" . PHP_EOL;
/*$user = new CmsUser;
$user->name = 'jon';
$user->*/
$ph = new CmsPhonenumber;
$ph->phonenumber = 123456;
$this->_em->save($ph);
$this->_em->flush();
}
}
......@@ -134,7 +134,10 @@ class ClassMetadataFactoryTestSubject extends Doctrine_ORM_Mapping_ClassMetadata
/* Test classes */
class CMFTest_Entity1 {}
class CMFTest_Entity1 {
protected $name;
protected $other;
}
class CMFTest_Entity2 extends CMFTest_Entity1 {}
class CMFTest_Entity3 extends CMFTest_Entity2 {}
......@@ -10,7 +10,7 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase
$cm = new Doctrine_ORM_Mapping_ClassMetadata('CmsUser');
// Test initial state
$this->assertTrue(count($cm->getReflectionProperties()) > 0);
$this->assertTrue(count($cm->getReflectionProperties()) == 0);
$this->assertTrue($cm->getReflectionClass() instanceof ReflectionClass);
$this->assertEquals('CmsUser', $cm->getClassName());
$this->assertEquals('CmsUser', $cm->getRootClassName());
......@@ -22,8 +22,8 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase
$cm->setParentClasses(array("UserParent"));
$cm->setCustomRepositoryClass("UserRepository");
$cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer'));
$cm->mapOneToOne(array('fieldName' => 'foo', 'targetEntity' => 'Bar', 'mappedBy' => 'foo'));
$this->assertTrue($cm->getAssociationMapping('foo') instanceof Doctrine_ORM_Mapping_OneToOneMapping);
$cm->mapOneToOne(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Bar', 'mappedBy' => 'foo'));
$this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof Doctrine_ORM_Mapping_OneToOneMapping);
$this->assertEquals(1, count($cm->getAssociationMappings()));
$serialized = serialize($cm);
......@@ -38,10 +38,10 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase
$this->assertEquals(array('UserParent'), $cm->getParentClasses());
$this->assertEquals('UserRepository', $cm->getCustomRepositoryClass());
$this->assertEquals(array('name' => 'disc', 'type' => 'integer'), $cm->getDiscriminatorColumn());
$this->assertTrue($cm->getAssociationMapping('foo') instanceof Doctrine_ORM_Mapping_OneToOneMapping);
$this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof Doctrine_ORM_Mapping_OneToOneMapping);
$this->assertEquals(1, count($cm->getAssociationMappings()));
$oneOneMapping = $cm->getAssociationMapping('foo');
$this->assertEquals('foo', $oneOneMapping->getSourceFieldName());
$oneOneMapping = $cm->getAssociationMapping('phonenumbers');
$this->assertEquals('phonenumbers', $oneOneMapping->getSourceFieldName());
$this->assertEquals('Bar', $oneOneMapping->getTargetEntityName());
}
......
......@@ -18,5 +18,6 @@
<var name="db_username" value="foo" />
<var name="db_password" value="bar" />
<var name="db_name" value="doctrinetests" />
<var name="db_port" value="3306"/>
</php>
</phpunit>
\ No newline at end of file
......@@ -8,6 +8,8 @@
*/
class Doctrine_OrmFunctionalTestCase extends Doctrine_OrmTestCase
{
protected $_em;
/**
* The currently loaded model names of the fixtures for the testcase.
*/
......@@ -103,13 +105,18 @@ class Doctrine_OrmFunctionalTestCase extends Doctrine_OrmTestCase
foreach (array_reverse($this->_loadedFixtures) as $table) {
$conn->exec("DELETE FROM " . $table);
}
$this->_em->clear();
}
protected function setUp()
{
if ( ! isset($this->sharedFixture['conn'])) {
echo " --- CREATE CONNECTION ----";
$this->sharedFixture['conn'] = Doctrine_TestUtil::getConnection();
}
if ( ! $this->_em) {
$this->_em = $this->_getEntityManager();
}
}
protected function _getEntityManager($config = null, $eventManager = null) {
......
......@@ -13,8 +13,13 @@ class Doctrine_OrmFunctionalTestSuite extends Doctrine_OrmTestSuite
{
protected function setUp()
{
if ( ! isset($this->sharedFixture['conn'])) {
$this->sharedFixture['conn'] = Doctrine_TestUtil::getConnection();
}
}
protected function tearDown()
{}
{
$this->sharedFixture = null;
}
}
\ No newline at end of file
......@@ -7,13 +7,14 @@ class Doctrine_TestUtil
public static function getConnection()
{
if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'],
$GLOBALS['db_host'], $GLOBALS['db_name'])) {
$GLOBALS['db_host'], $GLOBALS['db_name'], $GLOBALS['db_port'])) {
$params = array(
'driver' => $GLOBALS['db_type'],
'user' => $GLOBALS['db_username'],
'password' => $GLOBALS['db_password'],
'host' => $GLOBALS['db_host'],
'database' => $GLOBALS['db_name']
'dbname' => $GLOBALS['db_name'],
'port' => $GLOBALS['db_port']
);
} else {
$params = array(
......
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