diff --git a/lib/Doctrine/Record/Filter.php b/lib/Doctrine/Record/Filter.php index b122ff723..d5c9a5612 100644 --- a/lib/Doctrine/Record/Filter.php +++ b/lib/Doctrine/Record/Filter.php @@ -33,6 +33,9 @@ */ abstract class Doctrine_Record_Filter { + /** + * @var Doctrine_Table + */ protected $_table; public function setTable(Doctrine_Table $table) @@ -40,6 +43,9 @@ public function setTable(Doctrine_Table $table) $this->_table = $table; } + /** + * @return Doctrine_Table + */ public function getTable() { return $this->_table; diff --git a/lib/Doctrine/Record/Filter/Compound.php b/lib/Doctrine/Record/Filter/Compound.php index 38e599aec..e7b7798fd 100644 --- a/lib/Doctrine/Record/Filter/Compound.php +++ b/lib/Doctrine/Record/Filter/Compound.php @@ -50,10 +50,7 @@ public function __construct(array $aliases) */ public function init() { - // check that all aliases exist - foreach ($this->_aliases as $alias) { - $this->_table->getRelation($alias); - } + $this->validateAliases(); } /** @@ -67,26 +64,17 @@ public function init() */ public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) { - foreach ($this->_aliases as $alias) { - // The relationship must be fetched in order to check the field existence. - // Related to PHP-7.0 compatibility so an explicit call to method get is required. - $record[$alias]; - - if ( ! $record->exists()) { - if (isset($record[$alias][$propertyOrRelation])) { - $record[$alias][$propertyOrRelation] = $value; - - return $record; - } - } else { - if (isset($record[$alias][$propertyOrRelation])) { - $record[$alias][$propertyOrRelation] = $value; - } + try { + $this->setAliasedRecordPropertyOrRelation($record, $propertyOrRelation, $value); + return $record; + } catch (Doctrine_Record_UnknownPropertyException $e) { + if ($record->exists() && $this->hasAlias()) { return $record; } + + throw $e; } - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); } /** @@ -94,27 +82,96 @@ public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) * * @param string $propertyOrRelation * - * @return mixed + * @return mixed The value of the given property * * @thrown Doctrine_Record_UnknownPropertyException when this way is not available */ public function filterGet(Doctrine_Record $record, $propertyOrRelation) + { + $aliasedRecord = $this->findAliasedRecordForGet($record, $propertyOrRelation); + + return $aliasedRecord->get($propertyOrRelation); + } + + /** + * @throws Doctrine_Table_Exception + */ + private function validateAliases() { foreach ($this->_aliases as $alias) { - // The relationship must be fetched in order to check the field existence. - // Related to PHP-7.0 compatibility so an explicit call to method get is required. - $record[$alias]; - - if ( ! $record->exists()) { - if (isset($record[$alias][$propertyOrRelation])) { - return $record[$alias][$propertyOrRelation]; - } - } else { - if (isset($record[$alias][$propertyOrRelation])) { - return $record[$alias][$propertyOrRelation]; - } + $this->_table->getRelation($alias); + } + } + + private function hasAlias() + { + return (bool) $this->_aliases; + } + + /** + * @param string $propertyOrRelation + * + * @thrown Doctrine_Record_UnknownPropertyException when this way is not available + */ + private function setAliasedRecordPropertyOrRelation(Doctrine_Record $record, $propertyOrRelation, $value) + { + $aliasedRecord = $this->findAliasedRecordForSet($record, $propertyOrRelation); + + $aliasedRecord[$propertyOrRelation] = $value; + } + + /** + * @return Doctrine_Record + * + * @thrown Doctrine_Record_UnknownPropertyException + */ + private function findAliasedRecordForSet(Doctrine_Record $record, $propertyOrRelation) + { + foreach ($this->_aliases as $alias) { + if ($this->recordAliasHasPropertyOrRelation($record, $alias, $propertyOrRelation)) { + return $record->get($alias); } + + $this->stopSearchIfRecordExists($record, $propertyOrRelation); } - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); + + throw Doctrine_Record_UnknownPropertyException::createFromRecordAndProperty($record, $propertyOrRelation); + } + + /** + * @thrown Doctrine_Record_UnknownPropertyException + */ + private function stopSearchIfRecordExists(Doctrine_Record $record, $propertyOrRelation) + { + if ($record->exists()) { + throw Doctrine_Record_UnknownPropertyException::createFromRecordAndProperty($record, $propertyOrRelation); + } + } + + /** + * @return Doctrine_Record + * + * @thrown Doctrine_Record_UnknownPropertyException + */ + private function findAliasedRecordForGet(Doctrine_Record $record, $propertyOrRelation) + { + foreach ($this->_aliases as $alias) { + if ($this->recordAliasHasPropertyOrRelation($record, $alias, $propertyOrRelation)) { + return $record->get($alias); + } + } + + throw Doctrine_Record_UnknownPropertyException::createFromRecordAndProperty($record, $propertyOrRelation); + } + + /** + * @param string $alias + * @param string $propertyOrRelation + */ + private function recordAliasHasPropertyOrRelation(Doctrine_Record $record, $alias, $propertyOrRelation) + { + $aliasedRecord = $record->get($alias); + + return isset($aliasedRecord[$propertyOrRelation]); } } diff --git a/lib/Doctrine/Record/Filter/Standard.php b/lib/Doctrine/Record/Filter/Standard.php index f2a665358..440df0fc1 100644 --- a/lib/Doctrine/Record/Filter/Standard.php +++ b/lib/Doctrine/Record/Filter/Standard.php @@ -40,7 +40,7 @@ class Doctrine_Record_Filter_Standard extends Doctrine_Record_Filter */ public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) { - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); + throw Doctrine_Record_UnknownPropertyException::createFromRecordAndProperty($record, $propertyOrRelation); } /** @@ -50,6 +50,6 @@ public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) */ public function filterGet(Doctrine_Record $record, $propertyOrRelation) { - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); + throw Doctrine_Record_UnknownPropertyException::createFromRecordAndProperty($record, $propertyOrRelation); } } diff --git a/lib/Doctrine/Record/UnknownPropertyException.php b/lib/Doctrine/Record/UnknownPropertyException.php index 389004f89..6064cf6ed 100644 --- a/lib/Doctrine/Record/UnknownPropertyException.php +++ b/lib/Doctrine/Record/UnknownPropertyException.php @@ -31,4 +31,14 @@ * @author Konsta Vesterinen */ class Doctrine_Record_UnknownPropertyException extends Doctrine_Record_Exception -{ } \ No newline at end of file +{ + public static function createFromRecordAndProperty(Doctrine_Record $record, $propertyOrRelation) + { + $message = sprintf('Unknown record property / related component "%s" on "%s"', + $propertyOrRelation, + get_class($record) + ); + + return new Doctrine_Record_UnknownPropertyException($message); + } +} diff --git a/tests/Data/ExportTestCase.php b/tests/Data/ExportTestCase.php index 3c176c3d0..a661d5f24 100644 --- a/tests/Data/ExportTestCase.php +++ b/tests/Data/ExportTestCase.php @@ -30,53 +30,53 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Data_Export_TestCase extends Doctrine_UnitTestCase +class Doctrine_Data_Export_TestCase extends Doctrine_UnitTestCase { + public function tearDown() + { + if (file_exists('test.yml')) { + unlink('test.yml'); + } + + parent::tearDown(); + } + public function prepareTables() { $this->tables[] = 'I18nTestExport'; + parent::prepareTables(); } public function testI18nExport() { - try { - $i = new I18nTestExport(); - $i->Translation['en']->title = 'english test'; - $i->Translation['fr']->title = 'french test'; - $i->test_object = new stdClass(); - $i->save(); + $i = new I18nTestExport(); + $i->Translation['en']->title = 'english test'; + $i->Translation['fr']->title = 'french test'; + $i->test_object = new stdClass(); + $i->save(); - $data = new Doctrine_Data(); - $data->exportData('test.yml', 'yml', array('I18nTestExport', 'I18nTestExportTranslation')); + $data = new Doctrine_Data(); + $data->exportData('test.yml', 'yml', array('I18nTestExport', 'I18nTestExportTranslation')); - $array = Doctrine_Parser::load('test.yml', 'yml'); + $array = Doctrine_Parser::load('test.yml', 'yml'); - $this->assertTrue( ! empty($array)); - $this->assertTrue(isset($array['I18nTestExport']['I18nTestExport_1'])); - $this->assertTrue(isset($array['I18nTestExportTranslation']['I18nTestExportTranslation_1_en'])); - $this->assertTrue(isset($array['I18nTestExportTranslation']['I18nTestExportTranslation_1_fr'])); + $this->assertTrue( ! empty($array)); + $this->assertTrue(isset($array['I18nTestExport']['I18nTestExport_1'])); + $this->assertTrue(isset($array['I18nTestExportTranslation']['I18nTestExportTranslation_1_en'])); + $this->assertTrue(isset($array['I18nTestExportTranslation']['I18nTestExportTranslation_1_fr'])); - $i->Translation->delete(); - $i->delete(); + $i->Translation->delete(); + $i->delete(); - Doctrine_Core::loadData('test.yml'); + Doctrine_Core::loadData('test.yml'); - $q = Doctrine_Query::create() - ->from('I18nTestExport e') - ->leftJoin('e.Translation t'); + $q = Doctrine_Query::create() + ->from('I18nTestExport e') + ->leftJoin('e.Translation t'); - $results = $q->execute(); - $this->assertEqual(get_class($results[0]->test_object), 'stdClass'); - - $this->pass(); - } catch (Exception $e) { - $this->fail($e->getMessage()); - } - - if (file_exists('test.yml')) { - unlink('test.yml'); - } + $results = $q->execute(); + $this->assertEqual(get_class($results[0]->test_object), 'stdClass'); } } @@ -93,4 +93,4 @@ public function setUp() { $this->actAs('I18n', array('fields' => array('name', 'title'))); } -} \ No newline at end of file +} diff --git a/tests/DoctrineTest/UnitTestCase.php b/tests/DoctrineTest/UnitTestCase.php index a2b4193fd..5c6b95197 100644 --- a/tests/DoctrineTest/UnitTestCase.php +++ b/tests/DoctrineTest/UnitTestCase.php @@ -11,6 +11,16 @@ class UnitTestCase protected static $_lastRunsPassesAndFails = array('passes' => array(), 'fails' => array()); + /** + * @var string + */ + private $_expectedExceptionClass; + + /** + * @var string + */ + private $_currentMethod; + public function setUp() { } @@ -19,6 +29,11 @@ public function tearDown() { } + protected function expectException($class) + { + $this->_expectedExceptionClass = $class; + } + public function init() { $tmpFileName = $this->getPassesAndFailsCachePath(); @@ -70,6 +85,15 @@ public function assertIdentical($value, $value2) } } + public function assertNotIdentical($value, $value2) + { + if ($value !== $value2) { + $this->pass(); + } else { + $this->_fail(); + } + } + public function assertNotEqual($value, $value2) { if ($value != $value2) { @@ -126,41 +150,75 @@ public function pass() public function fail($message = "") { - $this->_fail($message); + $this->_fail($message); } public function _fail($message = "") + { + $stack = $this->findTestMethodStack(); + + $this->appendMessage($stack['class'], $stack['method'], $stack['line'], $message); + + $this->_failed++; + + $class = get_class($this); + + if (isset(self::$_passesAndFails['passes'][$class])) { + unset(self::$_passesAndFails['passes'][$class]); + } + + self::$_passesAndFails['fails'][$class] = $class; + } + + private function findTestMethodStack() { $trace = debug_backtrace(); array_shift($trace); - foreach ($trace as $stack) { - if (substr($stack['function'], 0, 4) === 'test') { + if ($this->isTestMethod($stack['function'])) { $class = new ReflectionClass($stack['class']); if ( ! isset($line)) { $line = $stack['line']; } - $errorMessage = $class->getName() . ' : method ' . $stack['function'] . ' failed on line ' . $line; - $this->_messages[] = $errorMessage . " " . $message; - break; + return array( + 'class' => $class->getName(), + 'method' => $stack['function'], + 'line' => $line, + ); } + $line = $stack['line']; } - $this->_failed++; - $class = get_class($this); - if (isset(self::$_passesAndFails['passes'][$class])) { - unset(self::$_passesAndFails['passes'][$class]); + + return array( + 'class' => get_class($this), + 'method' => $this->_currentMethod, + 'line' => null, + ); + } + + private function appendMessage($testCase, $testFuntion, $line = null, $message = "") + { + $lineMessage = ''; + + if (null !== $line) { + $lineMessage = 'on line '.$line; } - self::$_passesAndFails['fails'][$class] = $class; + + $errorMessage = $testCase . ' : method ' . $testFuntion . ' failed '.$lineMessage; + + $this->_messages[] = $errorMessage . " " . $message; } public function run(DoctrineTest_Reporter $reporter = null, $filter = null) { foreach (get_class_methods($this) as $method) { if ($this->isTestMethod($method)) { + $this->_currentMethod = $method; + $this->runTest($method); } } @@ -294,8 +352,49 @@ private function tryFinally(Closure $try, Closure $finally) $finally(); + if (null !== $this->_expectedExceptionClass) { + $this->assertThrownException($thrownException); + + return; + } + if (null !== $thrownException) { throw $thrownException; } } + + private function assertThrownException($thrownException) + { + $expectedExceptionClass = $this->_expectedExceptionClass; + + $this->_expectedExceptionClass = null; + + if (null === $thrownException) { + $message = sprintf('Assert that exception "%s" is thrown.', + $expectedExceptionClass + ); + + $this->fail($message); + + return; + } + + $thrownExceptionClass = get_class($thrownException); + + if ( + $expectedExceptionClass === $thrownExceptionClass + || is_subclass_of($thrownExceptionClass, $expectedExceptionClass) + ) { + $this->pass(); + + return; + } + + $message = sprintf('Assert that exception "%s" is thrown, but was "%s".', + $expectedExceptionClass, + $thrownExceptionClass + ); + + $this->fail($message); + } } diff --git a/tests/Record/FilterTestCase.php b/tests/Record/FilterTestCase.php index 7b82b45f7..10a58b8f6 100644 --- a/tests/Record/FilterTestCase.php +++ b/tests/Record/FilterTestCase.php @@ -30,78 +30,434 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Record_Filter_TestCase extends Doctrine_UnitTestCase +class Doctrine_Record_Filter_TestCase extends Doctrine_UnitTestCase { + public function tearDown() + { + InitTestCompositeRecord::$testHasRelatedRelation = true; + + parent::tearDown(); + } + public function prepareData() - { } + { + } + public function prepareTables() { - $this->tables = array('CompositeRecord', 'RelatedCompositeRecord'); - + $this->tables = array( + 'CompositeRecord', + 'SomeRelatedCompositeRecord', + 'WithTwoCompoundRelationOfDistinctTableCompositeRecord', + 'AnotherRelatedCompositeRecord', + 'WithTwoCompoundRelationOfSameTableCompositeRecord', + 'WithRelationOnCompoundRelationCompositeRecord', + 'WithRelationForPropertyOrRelationCompositeRecord', + 'WithPropertyForPropertyOrRelationCompositeRecord', + 'WithRelationRelatedCompositeRecord', + 'WithoutAliasesCompositeRecord', + 'WithTwoRelationsHavingSameNameForPropertyAndForRelationCompositeRecord', + ); + parent::prepareTables(); } + public function testStandardFiltersThrowsExceptionWhenGettingUnknownProperties() { + $this->expectException('Doctrine_Record_Exception'); + $u = new User(); - - try { - $u->unknown; - - $this->fail(); - } catch (Doctrine_Record_Exception $e) { - $this->pass(); - } + + $u->unknown; } public function testStandardFiltersThrowsExceptionWhenSettingUnknownProperties() { + $this->expectException('Doctrine_Record_Exception'); + $u = new User(); - - try { - $u->unknown = 'something'; - - $this->fail(); - } catch (Doctrine_Record_Exception $e) { - $this->pass(); - } + + $u->unknown = 'something'; } - public function testCompoundFilterSupportsAccessingRelatedComponentProperties() + public function testCompound_willThrowTable_withAliasedRelationIsNotDefined() { - $u = new CompositeRecord(); - - try { - $u->name = 'someone'; - $u->address = 'something'; + InitTestCompositeRecord::$testHasRelatedRelation = false; - $u->save(); + $this->expectException('Doctrine_Table_Exception'); - $this->assertEqual($u->name, 'someone'); - $this->assertEqual($u->address, 'something'); - $this->assertEqual($u->Related->address, 'something'); - } catch (Doctrine_Record_Exception $e) { - $this->fail(); - } + new InitTestCompositeRecord(); + } + + public function testCompoundGet_willThrowUndefinedProperty_withPropertyDoesNotExists() + { + $composite = new CompositeRecord(); + + $this->expectException('Doctrine_Record_UnknownPropertyException'); + + $composite->notExistsProperty; + } + + public function testCompoundSet_willThrowUndefinedProperty_withPropertyDoesNotExists() + { + $composite = new CompositeRecord(); + + $this->expectException('Doctrine_Record_UnknownPropertyException'); + + $composite->notExistsProperty = 'some value'; + } + + public function testCompoundSet_willThrowUndefinedProperty_withoutAliases() + { + $composite = new WithoutAliasesCompositeRecord(); + + $this->expectException('Doctrine_Record_UnknownPropertyException'); + + $composite->notExistsProperty = 'some value'; + } + + public function testCompoundSet_willThrowUndefinedProperty_withoutAliases_andRecordExists() + { + $composite = new WithoutAliasesCompositeRecord(); + $composite->save(); + + $this->expectException('Doctrine_Record_UnknownPropertyException'); + + $composite->notExistsProperty = 'some value'; + } + + public function testCompoundGet_willThrowUndefinedProperty_withoutAliases() + { + $composite = new WithoutAliasesCompositeRecord(); + + $this->expectException('Doctrine_Record_UnknownPropertyException'); + + $composite->notExistsProperty; + } + + public function testCompoundGet_withOneRelation_willReturnRelationPropertyValue() + { + $composite = new CompositeRecord(); + $composite->SomeCompoundRelation->someProperty = 'some value'; + + $actual = $composite->someProperty; + + $this->assertEqual('some value', $actual); + } + + public function testCompoundGet_withTwoDistinctTableRelations_afterGetFromSecondRelation_willReturnRelationPropertyValue() + { + $composite = new WithTwoCompoundRelationOfDistinctTableCompositeRecord(); + $composite->AnotherCompoundRelation->anotherProperty = 'some value'; + + $actual = $composite->anotherProperty; + + $this->assertEqual('some value', $actual); + } + + public function testCompoundGet_withTwoRelationsHavingSameProperty_andFirstIsNull_willReturnFirstPropertyValue() + { + $composite = new WithTwoCompoundRelationOfSameTableCompositeRecord(); + $composite->FirstCompoundRelation->someProperty = null; + $composite->SecondCompoundRelation->someProperty = 'some value'; + + $actual = $composite->someProperty; + + $this->assertNull($actual); + } + + public function testCompoundGet_withNewRecord_andForRelatedComponent() + { + $composite = new WithRelationOnCompoundRelationCompositeRecord(); + $composite->SomeCompoundRelation->SomeRelation->someProperty = 'some value'; + + $actual = $composite->SomeRelation->someProperty; + + $this->assertEqual('some value', $actual); + } + + public function testCompoundSet_willReturnTheGivenRecord_toRespectFluentInterface() + { + $composite = new CompositeRecord(); + + $actual = $composite->set('someProperty', 'some value'); + + $this->assertIdentical($composite, $actual); + } + + public function testCompoundSet_withNewRecord_andForProperty() + { + $composite = new CompositeRecord(); + + $composite->someProperty = 'some value'; + + $this->assertEqual('some value', $composite->SomeCompoundRelation->someProperty); + } + + public function testCompoundSet_withNewRecord_whenSetRelationOnCounpoundRelation_throwsUnknownProperty() + { + $composite = new WithRelationOnCompoundRelationCompositeRecord(); + + $this->expectException('Doctrine_Record_UnknownPropertyException'); + + $composite->SomeRelation = new SomeRelatedCompositeRecord(); + } + + public function testCompoundSet_withNewRecord_andRelationIsSets_whenSetRelationOnCounpoundRelation_willSetRelationThroughCompoundFilter() + { + $composite = new WithRelationOnCompoundRelationCompositeRecord(); + $composite->SomeCompoundRelation->SomeRelation = new SomeRelatedCompositeRecord(); + + $newRelation = new SomeRelatedCompositeRecord(); + $composite->SomeRelation = $newRelation; + + $this->assertIdentical($newRelation, $composite->SomeCompoundRelation->SomeRelation); + } + + public function testCompoundSet_withExistingRecord_whenSetRelationOnCounpoundRelation_doNothing() + { + $composite = new WithRelationOnCompoundRelationCompositeRecord(); + $composite->save(); + + $someRecord = new SomeRelatedCompositeRecord(); + $someRecord->someProperty = 'some value'; + + $composite->SomeRelation = $someRecord; + + $this->assertNull($composite->SomeCompoundRelation->SomeRelation->someProperty); + $this->assertNotIdentical($someRecord, $composite->SomeRelation); + $this->assertNotIdentical($someRecord, $composite->SomeCompoundRelation->SomeRelation); + } + + public function testCompoundSet_withTwoRelationsHavingSameProperty_andFirstIsNull_willSetOnlyFirstRelation() + { + $composite = new WithTwoCompoundRelationOfSameTableCompositeRecord(); + $composite->FirstCompoundRelation->someProperty = null; + $composite->SecondCompoundRelation->someProperty = 'some value'; + + $composite->someProperty = 'new value'; + + $this->assertEqual('new value', $composite->FirstCompoundRelation->someProperty); + $this->assertEqual('some value', $composite->SecondCompoundRelation->someProperty); + } + + public function testCompoundSet_withTwoRelationsHavingDistinctProperty_willCanSetOnSecondRelation() + { + $composite = new WithTwoCompoundRelationOfDistinctTableCompositeRecord(); + $composite->SomeCompoundRelation->someProperty = 'some value'; + $composite->AnotherCompoundRelation->anotherProperty = 'another value'; + + $composite->anotherProperty = 'new value'; + + $this->assertEqual('some value', $composite->SomeCompoundRelation->someProperty); + $this->assertEqual('new value', $composite->AnotherCompoundRelation->anotherProperty); + } + + public function testCompoundSet_withAliasXHavingRelationY_andAliasZHavingColumnY_whenSetY_throwsUnknownProperty() + { + $composite = new WithTwoRelationsHavingSameNameForPropertyAndForRelationCompositeRecord(); + $composite->RelationRelated->somePropertyOrRelation = new SomeRelatedCompositeRecord(); + $composite->PropertyRelated->somePropertyOrRelation = 'some value'; + + $this->expectException('Doctrine_Record_UnknownPropertyException'); + + $composite->somePropertyOrRelation = 'new value'; } } + class CompositeRecord extends Doctrine_Record { public function setTableDefinition() { $this->hasColumn('name', 'string'); } + + public function setUp() + { + $this->hasOne('SomeRelatedCompositeRecord as SomeCompoundRelation', array( + 'foreign' => 'foreign_id', + )); + + $this->unshiftFilter(new Doctrine_Record_Filter_Compound(array( + 'SomeCompoundRelation', + ))); + } +} + +class WithRelationOnCompoundRelationCompositeRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('name', 'string'); + } + + public function setUp() + { + $this->hasOne('WithRelationRelatedCompositeRecord as SomeCompoundRelation', array( + 'foreign' => 'foreign_id', + )); + + $this->unshiftFilter(new Doctrine_Record_Filter_Compound(array( + 'SomeCompoundRelation', + ))); + } +} + +class WithTwoCompoundRelationOfDistinctTableCompositeRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('name', 'string'); + } + + public function setUp() + { + $this->hasOne('SomeRelatedCompositeRecord as SomeCompoundRelation', array( + 'foreign' => 'foreign_id', + )); + $this->hasOne('AnotherRelatedCompositeRecord as AnotherCompoundRelation', array( + 'foreign' => 'foreign_id', + )); + + $this->unshiftFilter(new Doctrine_Record_Filter_Compound(array( + 'SomeCompoundRelation', + 'AnotherCompoundRelation', + ))); + } +} + +class WithTwoCompoundRelationOfSameTableCompositeRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('name', 'string'); + } + + public function setUp() + { + $this->hasOne('SomeRelatedCompositeRecord as FirstCompoundRelation', array( + 'foreign' => 'foreign_id', + )); + $this->hasOne('SomeRelatedCompositeRecord as SecondCompoundRelation', array( + 'foreign' => 'foreign_second_id', + )); + + $this->unshiftFilter(new Doctrine_Record_Filter_Compound(array( + 'FirstCompoundRelation', + 'SecondCompoundRelation', + ))); + } +} + +class WithoutAliasesCompositeRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('name', 'string'); + } + + public function setUp() + { + $this->unshiftFilter(new Doctrine_Record_Filter_Compound(array( + ))); + } +} + +class SomeRelatedCompositeRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('someProperty', 'string'); + $this->hasColumn('foreign_id', 'integer'); + $this->hasColumn('foreign_second_id', 'integer'); + } +} + +class AnotherRelatedCompositeRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('anotherProperty', 'string'); + $this->hasColumn('foreign_id', 'integer'); + } +} + +class WithRelationRelatedCompositeRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('foreign_id', 'integer'); + + $this->hasOne('SomeRelatedCompositeRecord as SomeRelation', array( + 'foreign' => 'foreign_id', + )); + } +} + +class WithTwoRelationsHavingSameNameForPropertyAndForRelationCompositeRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('name', 'string'); + } + public function setUp() { - $this->hasOne('RelatedCompositeRecord as Related', array('foreign' => 'foreign_id')); + $this->hasOne('WithRelationForPropertyOrRelationCompositeRecord as RelationRelated', array( + 'foreign' => 'foreign_id', + )); + $this->hasOne('WithPropertyForPropertyOrRelationCompositeRecord as PropertyRelated', array( + 'foreign' => 'foreign_id', + )); - $this->unshiftFilter(new Doctrine_Record_Filter_Compound(array('Related'))); + $this->unshiftFilter(new Doctrine_Record_Filter_Compound(array( + 'RelationRelated', + 'PropertyRelated', + ))); } } -class RelatedCompositeRecord extends Doctrine_Record + +class WithRelationForPropertyOrRelationCompositeRecord extends Doctrine_Record { public function setTableDefinition() { - $this->hasColumn('address', 'string'); $this->hasColumn('foreign_id', 'integer'); + + $this->hasOne('SomeRelatedCompositeRecord as somePropertyOrRelation', array( + 'foreign' => 'foreign_id', + )); + } +} + +class WithPropertyForPropertyOrRelationCompositeRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('somePropertyOrRelation', 'string'); + $this->hasColumn('foreign_id', 'integer'); + $this->hasColumn('foreign_second_id', 'integer'); + } +} + +class InitTestCompositeRecord extends Doctrine_Record +{ + public static $testHasRelatedRelation = true; + + public function setTableDefinition() + { + $this->hasColumn('name', 'string'); + } + + public function setUp() + { + if (self::$testHasRelatedRelation) { + $this->hasOne('SomeRelatedCompositeRecord as SomeCompoundRelation', array( + 'foreign' => 'foreign_id', + )); + } + + $this->unshiftFilter(new Doctrine_Record_Filter_Compound(array( + 'SomeCompoundRelation', + ))); } } diff --git a/tests/bin/test b/tests/bin/test index 2df829884..4255a1e70 100755 --- a/tests/bin/test +++ b/tests/bin/test @@ -12,7 +12,7 @@ # Configuration # dependencyPreferences='highest' -skipPHPVersions='php8' +skipPHPVersions='php9' # Commands #