diff --git a/.gitignore b/.gitignore index 7cdc81d2a..86bb5269c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ tests/DoctrineTest/doctrine_tests/* -*TestCase.php \ No newline at end of file +*TestCase.php +/tests/tmp +/tests/foo.sq3 diff --git a/.travis.yml b/.travis.yml index 1f4ceac7b..70a0ca577 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,14 @@ jobs: - php: 5.6 dist: trusty +services: + - mysql + +before_install: + - mysql -e 'CREATE DATABASE IF NOT EXISTS test;' + install: - - composer install --prefer-dist --no-progress --no-suggest -o + - composer install --prefer-dist --no-progress --no-suggest -o script: - - php -dshort_open_tag=Off -dmagic_quotes_gpc=Off tests/index.php + - "cd tests && php -dshort_open_tag=Off -dmagic_quotes_gpc=Off run.php" diff --git a/composer.json b/composer.json index 9471daa82..053673e5d 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ ], "require": { "php": ">=5.3", + "ext-zlib": "*", "ext-mbstring": "*", "ext-pdo": "*" }, diff --git a/lib/Doctrine/Record/Filter.php b/lib/Doctrine/Record/Filter.php index e1cf85d4a..b122ff723 100644 --- a/lib/Doctrine/Record/Filter.php +++ b/lib/Doctrine/Record/Filter.php @@ -50,18 +50,24 @@ public function init() } /** - * filterSet - * defines an implementation for filtering the set() method of Doctrine_Record + * Provides a way for setting property or relation value to the given record. * - * @param mixed $name name of the property or related component + * @param string $propertyOrRelation + * + * @return Doctrine_Record the given record + * + * @thrown Doctrine_Exception when this way is not available */ - abstract public function filterSet(Doctrine_Record $record, $name, $value); + abstract public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value); /** - * filterGet - * defines an implementation for filtering the get() method of Doctrine_Record + * Provides a way for getting property or relation value from the given record. + * + * @param string $propertyOrRelation + * + * @return mixed * - * @param mixed $name name of the property or related component + * @thrown Doctrine_Exception when this way is not available */ - abstract public function filterGet(Doctrine_Record $record, $name); -} \ No newline at end of file + abstract public function filterGet(Doctrine_Record $record, $propertyOrRelation); +} diff --git a/lib/Doctrine/Record/Filter/Compound.php b/lib/Doctrine/Record/Filter/Compound.php index 98174deeb..38e599aec 100644 --- a/lib/Doctrine/Record/Filter/Compound.php +++ b/lib/Doctrine/Record/Filter/Compound.php @@ -32,66 +32,89 @@ */ class Doctrine_Record_Filter_Compound extends Doctrine_Record_Filter { + /** + * @var string[] + */ protected $_aliases = array(); + /** + * @param string[] $aliases A list of relation name + */ public function __construct(array $aliases) { $this->_aliases = $aliases; } + /** + * @throws Doctrine_Table_Exception when at least one configured alias is not a relation + */ public function init() { - // check that all aliases exist - foreach ($this->_aliases as $alias) { + // check that all aliases exist + foreach ($this->_aliases as $alias) { $this->_table->getRelation($alias); - } + } } /** - * filterSet - * defines an implementation for filtering the set() method of Doctrine_Record + * Provides a way for setting property or relation value to the given record. * - * @param mixed $name name of the property or related component + * @param string $propertyOrRelation + * + * @return Doctrine_Record the given record + * + * @thrown Doctrine_Record_UnknownPropertyException when this way is not available */ - public function filterSet(Doctrine_Record $record, $name, $value) + 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][$name])) { - $record[$alias][$name] = $value; - + if (isset($record[$alias][$propertyOrRelation])) { + $record[$alias][$propertyOrRelation] = $value; + return $record; } } else { - if (isset($record[$alias][$name])) { - $record[$alias][$name] = $value; + if (isset($record[$alias][$propertyOrRelation])) { + $record[$alias][$propertyOrRelation] = $value; } return $record; } } - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record))); + throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); } /** - * filterGet - * defines an implementation for filtering the get() method of Doctrine_Record + * Provides a way for getting property or relation value from the given record. * - * @param mixed $name name of the property or related component + * @param string $propertyOrRelation + * + * @return mixed + * + * @thrown Doctrine_Record_UnknownPropertyException when this way is not available */ - public function filterGet(Doctrine_Record $record, $name) + public function filterGet(Doctrine_Record $record, $propertyOrRelation) { 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][$name])) { - return $record[$alias][$name]; + if (isset($record[$alias][$propertyOrRelation])) { + return $record[$alias][$propertyOrRelation]; } } else { - if (isset($record[$alias][$name])) { - return $record[$alias][$name]; + if (isset($record[$alias][$propertyOrRelation])) { + return $record[$alias][$propertyOrRelation]; } } } - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record))); + throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Record/Filter/Standard.php b/lib/Doctrine/Record/Filter/Standard.php index 7e4572889..f2a665358 100644 --- a/lib/Doctrine/Record/Filter/Standard.php +++ b/lib/Doctrine/Record/Filter/Standard.php @@ -34,24 +34,22 @@ class Doctrine_Record_Filter_Standard extends Doctrine_Record_Filter { /** - * filterSet - * defines an implementation for filtering the set() method of Doctrine_Record + * @param string $propertyOrRelation * - * @param mixed $name name of the property or related component + * @thrown Doctrine_Record_UnknownPropertyException */ - public function filterSet(Doctrine_Record $record, $name, $value) + public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) { - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record))); + throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); } /** - * filterGet - * defines an implementation for filtering the get() method of Doctrine_Record + * @param string $propertyOrRelation * - * @param mixed $name name of the property or related component + * @thrown Doctrine_Record_UnknownPropertyException */ - public function filterGet(Doctrine_Record $record, $name) + public function filterGet(Doctrine_Record $record, $propertyOrRelation) { - throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record))); + throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record))); } } diff --git a/lib/Doctrine/Search/File.php b/lib/Doctrine/Search/File.php index b04b2986c..feff520f4 100644 --- a/lib/Doctrine/Search/File.php +++ b/lib/Doctrine/Search/File.php @@ -77,6 +77,10 @@ public function indexDirectory($dir) continue; } + if ($file->isDir()) { + continue; + } + $this->updateIndex(array('url' => $file->getPathName(), 'content' => file_get_contents($file))); } diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 6a6595cd4..5a865cab2 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Base_TestCase extends Doctrine_UnitTestCase +class Doctrine_Base_TestCase extends Doctrine_UnitTestCase { public function testAggressiveModelLoading() { @@ -92,21 +92,22 @@ public function testModelLoadingCacheInformation() $this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingContact'])); } - public function testGetConnectionByTableName() + public function testGetConnectionByTableNameForTableWithOneModel() { - $connectionBefore = Doctrine_Core::getConnectionByTableName('entity'); + $connectionBefore = Doctrine_Core::getConnectionByTableName('account'); - Doctrine_Manager::connection('sqlite::memory:', 'test_memory'); - Doctrine_Manager::getInstance()->bindComponent('Entity', 'test_memory'); + $this->openAdditionalConnection('sqlite::memory:', 'test_memory'); - $connectionAfter = Doctrine_Core::getConnectionByTableName('entity'); + Doctrine_Manager::getInstance()->bindComponent('Account', 'test_memory'); + + $connectionAfter = Doctrine_Core::getConnectionByTableName('account'); $this->assertEqual($connectionAfter->getName(), 'test_memory'); - Doctrine_Manager::getInstance()->bindComponent('Entity', $connectionBefore->getName()); + Doctrine_Manager::getInstance()->bindComponent('Account', $connectionBefore->getName()); + + $connectionAfter = Doctrine_Core::getConnectionByTableName('account'); - $connectionAfter = Doctrine_Core::getConnectionByTableName('entity'); - $this->assertEqual($connectionBefore->getName(), $connectionAfter->getName()); } -} \ No newline at end of file +} diff --git a/tests/CliTestCase.php b/tests/CliTestCase.php index 681bcb833..967c86c8f 100644 --- a/tests/CliTestCase.php +++ b/tests/CliTestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Cli_TestCase extends Doctrine_UnitTestCase +class Doctrine_Cli_TestCase extends UnitTestCase { /** * @ignore @@ -63,10 +63,6 @@ protected function getFixturesPath() return $this->fixturesPath; } - public function setUp() {} - - public function tearDown() {} - public function testTheNameOfTheTaskBaseClassNameIsStoredInAClassConstant() { $this->assertFalse(is_null(constant('Doctrine_Cli::TASK_BASE_CLASS'))); @@ -446,4 +442,4 @@ protected function _run(array $args) class Doctrine_Cli_TestCase_TestTask01 extends Doctrine_Task { public function execute() {} -} \ No newline at end of file +} diff --git a/tests/Connection/CustomTestCase.php b/tests/Connection/CustomTestCase.php index badb87d77..815599ed9 100644 --- a/tests/Connection/CustomTestCase.php +++ b/tests/Connection/CustomTestCase.php @@ -49,7 +49,10 @@ public function testConnection() class Doctrine_Connection_Test extends Doctrine_Connection_Common { - + /** + * @var string $driverName The name of this connection driver + */ + protected $driverName = 'Mock'; } class Doctrine_Adapter_Test implements Doctrine_Adapter_Interface diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index 15d05f36e..4883d28d7 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -57,6 +57,32 @@ class Doctrine_UnitTestCase extends UnitTestCase protected $init = false; + /** + * @var Doctrine_Connection[] + */ + private $additionalConnections = array(); + + public function setUp() + { + parent::setUp(); + + if ( ! $this->init) { + $this->init(); + } + if (isset($this->objTable)) { + $this->objTable->clear(); + } + + $this->init = true; + } + + public function tearDown() + { + $this->closeAdditionalConnections(); + + parent::tearDown(); + } + public function getName() { return $this->_name; @@ -275,18 +301,20 @@ public function getDeclaration($type) { return $this->dataDict->getPortableDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 1, 'fixed' => true)); } - public function setUp() + + protected function openAdditionalConnection($adapter = null, $name = null) { - if ( ! $this->init) { - $this->init(); - } - if (isset($this->objTable)) { - $this->objTable->clear(); - } + $connection = $this->manager->openConnection($adapter, $name); - $this->init = true; + $this->additionalConnections[] = $connection; + + return $connection; } - public function tearDown() { + private function closeAdditionalConnections() + { + foreach ($this->additionalConnections as $connection) { + $this->manager->closeConnection($connection); + } } } diff --git a/tests/DoctrineTest/UnitTestCase.php b/tests/DoctrineTest/UnitTestCase.php index 681079d03..a2b4193fd 100644 --- a/tests/DoctrineTest/UnitTestCase.php +++ b/tests/DoctrineTest/UnitTestCase.php @@ -11,6 +11,14 @@ class UnitTestCase protected static $_lastRunsPassesAndFails = array('passes' => array(), 'fails' => array()); + public function setUp() + { + } + + public function tearDown() + { + } + public function init() { $tmpFileName = $this->getPassesAndFailsCachePath(); @@ -149,15 +157,11 @@ public function _fail($message = "") self::$_passesAndFails['fails'][$class] = $class; } - public function run(DoctrineTest_Reporter $reporter = null, $filter = null) + public function run(DoctrineTest_Reporter $reporter = null, $filter = null) { foreach (get_class_methods($this) as $method) { - if (substr($method, 0, 4) === 'test') { - $this->setUp(); - - $this->$method(); - - $this->tearDown(); + if ($this->isTestMethod($method)) { + $this->runTest($method); } } } @@ -249,4 +253,49 @@ public function getNumFixedFails() { return count($this->getFixedFails()); } -} \ No newline at end of file + + private function runTest($method) + { + $this->setUp(); + + $this->doRunTestAndTearDown($method); + } + + private function doRunTestAndTearDown($method) + { + $test = $this; + + $this->tryFinally( + function () use ($test, $method) { + $test->$method(); + }, + function () use ($test) { + $test->tearDown(); + } + ); + } + + private function isTestMethod($method) + { + return 'test' === substr($method, 0, 4); + } + + private function tryFinally(Closure $try, Closure $finally) + { + $thrownException = null; + + try { + $try(); + } catch (Throwable $e) { + $thrownException = $e; + } catch (Exception $e) { // for PHP v5.x + $thrownException = $e; + } + + $finally(); + + if (null !== $thrownException) { + throw $thrownException; + } + } +} diff --git a/tests/ExtensionTestCase.php b/tests/ExtensionTestCase.php index 30bf0cf61..c7dd166c8 100755 --- a/tests/ExtensionTestCase.php +++ b/tests/ExtensionTestCase.php @@ -59,6 +59,8 @@ public function testBehaviorExtension() public function tearDown() { spl_autoload_unregister(array('Doctrine_Core', 'extensionsAutoload')); + + parent::tearDown(); } } diff --git a/tests/ManagerTestCase.php b/tests/ManagerTestCase.php index a065db456..780926147 100644 --- a/tests/ManagerTestCase.php +++ b/tests/ManagerTestCase.php @@ -30,7 +30,8 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Manager_TestCase extends Doctrine_UnitTestCase { +class Doctrine_Manager_TestCase extends Doctrine_UnitTestCase +{ public function testGetInstance() { $this->assertTrue(Doctrine_Manager::getInstance() instanceOf Doctrine_Manager); } @@ -166,13 +167,14 @@ public function testConnectionInformationDecoded() { $dsn = 'mysql://' . urlencode('test/t') . ':' . urlencode('p@ssword') . '@localhost/' . urlencode('db/name'); - $conn = Doctrine_Manager::connection($dsn); + $conn = $this->openAdditionalConnection($dsn); $options = $conn->getOptions(); $this->assertEqual($options['username'], 'test/t'); $this->assertEqual($options['password'], 'p@ssword'); $this->assertEqual($options['dsn'], 'mysql:host=localhost;dbname=db/name'); } + public function prepareData() { } public function prepareTables() { } diff --git a/tests/Migration/BaseTestCase.php b/tests/Migration/BaseTestCase.php index 328162327..3a889b0b6 100644 --- a/tests/Migration/BaseTestCase.php +++ b/tests/Migration/BaseTestCase.php @@ -30,9 +30,14 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Migration_Base_TestCase extends Doctrine_UnitTestCase +class Doctrine_Migration_Base_TestCase extends UnitTestCase { - public function setUp() {} + public function tearDown() + { + Doctrine_Migration_Base::setDefaultTableOptions(array()); + + parent::tearDown(); + } public function testIsAbstract() { @@ -59,11 +64,6 @@ public function testGetdefaulttableoptionsReturnsTheOptionsSetWithSetdefaulttabl } } - public function tearDown() - { - Doctrine_Migration_Base::setDefaultTableOptions(array()); - } - public function testCreatetableMergesTheDefaultTableOptionsWithTheSpecifiedOptions() { $fixtures = array( diff --git a/tests/Query/MultiJoinTestCase.php b/tests/Query/MultiJoinTestCase.php index f5b2eb4d3..5f6ef49cd 100644 --- a/tests/Query/MultiJoinTestCase.php +++ b/tests/Query/MultiJoinTestCase.php @@ -22,6 +22,9 @@ /** * Doctrine_Query_MultiJoin_TestCase * + * When the order is not explicit then you must not expect that relationships + * are ordered by the primary key. This test case illustrate this behavior. + * * @package Doctrine * @author Konsta Vesterinen * @license http://www.opensource.org/licenses/lgpl-license.php LGPL @@ -97,26 +100,43 @@ public function testMultipleOneToManyFetching() $this->assertEqual($users[0]->id, 4); + $this->assertEqual($users[0]->Album[0]->id, 1); $this->assertEqual($users[0]->Album[0]->name, 'Damage Done'); + $this->assertEqual($users[0]->Album[0]->Song[0]->id, 1); $this->assertEqual($users[0]->Album[0]->Song[0]->title, 'Damage Done'); - $this->assertEqual($users[0]->Album[0]->Song[1]->title, 'The Treason Wall'); - $this->assertEqual($users[0]->Album[0]->Song[2]->title, 'Monochromatic Stains'); + $this->assertEqual($users[0]->Album[0]->Song[1]->id, 3); + $this->assertEqual($users[0]->Album[0]->Song[1]->title, 'Monochromatic Stains'); + $this->assertEqual($users[0]->Album[0]->Song[2]->id, 2); + $this->assertEqual($users[0]->Album[0]->Song[2]->title, 'The Treason Wall'); + $this->assertEqual($users[0]->Album[1]->id, 2); $this->assertEqual($users[0]->Album[1]->name, 'Haven'); - $this->assertEqual($users[0]->Album[1]->Song[0]->title, 'Not Built To Last'); - $this->assertEqual($users[0]->Album[1]->Song[1]->title, 'The Wonders At Your Feet'); - $this->assertEqual($users[0]->Album[1]->Song[2]->title, 'Feast Of Burden'); - $this->assertEqual($users[0]->Album[1]->Song[3]->title, 'Fabric'); + $this->assertEqual($users[0]->Album[1]->Song[0]->id, 7); + $this->assertEqual($users[0]->Album[1]->Song[0]->title, 'Fabric'); + $this->assertEqual($users[0]->Album[1]->Song[1]->id, 6); + $this->assertEqual($users[0]->Album[1]->Song[1]->title, 'Feast Of Burden'); + $this->assertEqual($users[0]->Album[1]->Song[2]->id, 4); + $this->assertEqual($users[0]->Album[1]->Song[2]->title, 'Not Built To Last'); + $this->assertEqual($users[0]->Album[1]->Song[3]->id, 5); + $this->assertEqual($users[0]->Album[1]->Song[3]->title, 'The Wonders At Your Feet'); + + $this->assertEqual($users[0]->Phonenumber[0]->id, 2); + $this->assertEqual($users[0]->Phonenumber[0]->phonenumber, '123 123'); $this->assertEqual($users[1]->id, 5); + $this->assertEqual($users[1]->Album[0]->id, 3); $this->assertEqual($users[1]->Album[0]->name, 'Clayman'); + $this->assertEqual($users[1]->Album[1]->id, 4); $this->assertEqual($users[1]->Album[1]->name, 'Colony'); + $this->assertEqual($users[1]->Album[1]->Song[0]->id, 8); $this->assertEqual($users[1]->Album[1]->Song[0]->title, 'Colony'); + $this->assertEqual($users[1]->Album[1]->Song[1]->id, 9); $this->assertEqual($users[1]->Album[1]->Song[1]->title, 'Ordinary Story'); - - $this->assertEqual($users[0]->Phonenumber[0]->phonenumber, '123 123'); - + + $this->assertEqual($users[1]->Phonenumber[0]->id, 3); $this->assertEqual($users[1]->Phonenumber[0]->phonenumber, '123 123'); + $this->assertEqual($users[1]->Phonenumber[1]->id, 4); $this->assertEqual($users[1]->Phonenumber[1]->phonenumber, '456 456'); + $this->assertEqual($users[1]->Phonenumber[2]->id, 5); $this->assertEqual($users[1]->Phonenumber[2]->phonenumber, '789 789'); } @@ -153,33 +173,59 @@ public function testMultipleOneToManyFetching2() $this->assertEqual($users->count(), 2); $this->assertEqual($users[0]->id, 4); + $this->assertEqual($users[0]->Album[0]->id, 1); $this->assertEqual($users[0]->Album[0]->name, 'Damage Done'); + $this->assertEqual($users[0]->Album[0]->Song[0]->id, 1); $this->assertEqual($users[0]->Album[0]->Song[0]->title, 'Damage Done'); - $this->assertEqual($users[0]->Album[0]->Song[1]->title, 'The Treason Wall'); - $this->assertEqual($users[0]->Album[0]->Song[2]->title, 'Monochromatic Stains'); + $this->assertEqual($users[0]->Album[0]->Song[1]->id, 3); + $this->assertEqual($users[0]->Album[0]->Song[1]->title, 'Monochromatic Stains'); + $this->assertEqual($users[0]->Album[0]->Song[2]->id, 2); + $this->assertEqual($users[0]->Album[0]->Song[2]->title, 'The Treason Wall'); + $this->assertEqual($users[0]->Album[1]->id, 2); $this->assertEqual($users[0]->Album[1]->name, 'Haven'); - $this->assertEqual($users[0]->Album[1]->Song[0]->title, 'Not Built To Last'); - $this->assertEqual($users[0]->Album[1]->Song[1]->title, 'The Wonders At Your Feet'); - $this->assertEqual($users[0]->Album[1]->Song[2]->title, 'Feast Of Burden'); - $this->assertEqual($users[0]->Album[1]->Song[3]->title, 'Fabric'); - + $this->assertEqual($users[0]->Album[1]->Song[0]->id, 7); + $this->assertEqual($users[0]->Album[1]->Song[0]->title, 'Fabric'); + $this->assertEqual($users[0]->Album[1]->Song[1]->id, 6); + $this->assertEqual($users[0]->Album[1]->Song[1]->title, 'Feast Of Burden'); + $this->assertEqual($users[0]->Album[1]->Song[2]->id, 4); + $this->assertEqual($users[0]->Album[1]->Song[2]->title, 'Not Built To Last'); + $this->assertEqual($users[0]->Album[1]->Song[3]->id, 5); + $this->assertEqual($users[0]->Album[1]->Song[3]->title, 'The Wonders At Your Feet'); + + $this->assertEqual($users[0]->Book[0]->id, 2); + $this->assertEqual($users[0]->Book[0]->name, 'The Art of War'); + $this->assertEqual($users[0]->Book[0]->Author[0]->id, 4); $this->assertEqual($users[0]->Book[0]->Author[0]->name, 'Niccolo Machiavelli'); + $this->assertEqual($users[0]->Book[0]->Author[1]->id, 3); $this->assertEqual($users[0]->Book[0]->Author[1]->name, 'Someone'); - $this->assertEqual($users[0]->Book[1]->name, 'The Art of War'); - $this->assertEqual($users[0]->Book[1]->Author[0]->name, 'Someone'); - $this->assertEqual($users[0]->Book[1]->Author[1]->name, 'Niccolo Machiavelli'); + $this->assertEqual($users[0]->Book[1]->id, 1); + $this->assertEqual($users[0]->Book[1]->name, 'The Prince'); + $this->assertEqual($users[0]->Book[1]->Author[0]->id, 1); + $this->assertEqual($users[0]->Book[1]->Author[0]->name, 'Niccolo Machiavelli'); + $this->assertEqual($users[0]->Book[1]->Author[1]->id, 2); + $this->assertEqual($users[0]->Book[1]->Author[1]->name, 'Someone'); $this->assertEqual($users[1]->id, 5); + $this->assertEqual($users[1]->Album[0]->id, 3); $this->assertEqual($users[1]->Album[0]->name, 'Clayman'); + $this->assertEqual($users[1]->Album[1]->id, 4); $this->assertEqual($users[1]->Album[1]->name, 'Colony'); + $this->assertEqual($users[1]->Album[1]->Song[0]->id, 8); $this->assertEqual($users[1]->Album[1]->Song[0]->title, 'Colony'); + $this->assertEqual($users[1]->Album[1]->Song[1]->id, 9); $this->assertEqual($users[1]->Album[1]->Song[1]->title, 'Ordinary Story'); - $this->assertEqual($users[1]->Book[0]->name, 'Zadig'); - $this->assertEqual($users[1]->Book[0]->Author[0]->name, 'Voltaire'); - $this->assertEqual($users[1]->Book[0]->Author[1]->name, 'Someone'); - $this->assertEqual($users[1]->Book[1]->name, 'Candide'); + $this->assertEqual($users[1]->Book[0]->id, 4); + $this->assertEqual($users[1]->Book[0]->name, 'Candide'); + $this->assertEqual($users[1]->Book[0]->Author[0]->id, 7); + $this->assertEqual($users[1]->Book[0]->Author[0]->name, 'Someone'); + $this->assertEqual($users[1]->Book[0]->Author[1]->id, 8); + $this->assertEqual($users[1]->Book[0]->Author[1]->name, 'Voltaire'); + $this->assertEqual($users[1]->Book[1]->id, 3); + $this->assertEqual($users[1]->Book[1]->name, 'Zadig'); + $this->assertEqual($users[1]->Book[1]->Author[0]->id, 6); $this->assertEqual($users[1]->Book[1]->Author[0]->name, 'Someone'); + $this->assertEqual($users[1]->Book[1]->Author[1]->id, 5); $this->assertEqual($users[1]->Book[1]->Author[1]->name, 'Voltaire'); } @@ -188,5 +234,48 @@ public function testMultipleOneToManyFetchingWithOrderBy() $query = new Doctrine_Query(); $users = $query->query("FROM User.Album.Song WHERE User.id IN (4,5) ORDER BY User.Album.Song.title DESC"); + + $this->assertEqual($users[0]->id, 4); + $this->assertEqual($users[0]->Album[0]->id, 2); + $this->assertEqual($users[0]->Album[0]->name, 'Haven'); + $this->assertEqual($users[0]->Album[0]->Song[0]->title, 'The Wonders At Your Feet'); + $this->assertEqual($users[0]->Album[0]->Song[1]->title, 'Not Built To Last'); + $this->assertEqual($users[0]->Album[0]->Song[2]->title, 'Feast Of Burden'); + $this->assertEqual($users[0]->Album[0]->Song[3]->title, 'Fabric'); + $this->assertEqual($users[0]->Album[1]->id, 1); + $this->assertEqual($users[0]->Album[1]->name, 'Damage Done'); + $this->assertEqual($users[0]->Album[1]->Song[0]->title, 'The Treason Wall'); + $this->assertEqual($users[0]->Album[1]->Song[1]->title, 'Monochromatic Stains'); + $this->assertEqual($users[0]->Album[1]->Song[2]->title, 'Damage Done'); + + $this->assertEqual($users[0]->Book[0]->id, 1); + $this->assertEqual($users[0]->Book[0]->name, 'The Prince'); + $this->assertEqual($users[0]->Book[0]->Author[0]->id, 1); + $this->assertEqual($users[0]->Book[0]->Author[0]->name, 'Niccolo Machiavelli'); + $this->assertEqual($users[0]->Book[0]->Author[1]->id, 2); + $this->assertEqual($users[0]->Book[0]->Author[1]->name, 'Someone'); + $this->assertEqual($users[0]->Book[1]->id, 2); + $this->assertEqual($users[0]->Book[1]->name, 'The Art of War'); + $this->assertEqual($users[0]->Book[1]->Author[0]->id, 4); + $this->assertEqual($users[0]->Book[1]->Author[0]->name, 'Niccolo Machiavelli'); + $this->assertEqual($users[0]->Book[1]->Author[1]->id, 3); + $this->assertEqual($users[0]->Book[1]->Author[1]->name, 'Someone'); + + $this->assertEqual($users[1]->id, 5); + $this->assertEqual($users[1]->Album[0]->id, 4); + $this->assertEqual($users[1]->Album[0]->name, 'Colony'); + $this->assertEqual($users[1]->Album[0]->Song[0]->title, 'Ordinary Story'); + $this->assertEqual($users[1]->Album[0]->Song[1]->title, 'Colony'); + $this->assertEqual($users[1]->Album[1]->id, 3); + $this->assertEqual($users[1]->Album[1]->name, 'Clayman'); + + $this->assertEqual($users[1]->Book[0]->id, 3); + $this->assertEqual($users[1]->Book[0]->name, 'Zadig'); + $this->assertEqual($users[1]->Book[0]->Author[0]->name, 'Someone'); + $this->assertEqual($users[1]->Book[0]->Author[1]->name, 'Voltaire'); + $this->assertEqual($users[1]->Book[1]->id, 4); + $this->assertEqual($users[1]->Book[1]->name, 'Candide'); + $this->assertEqual($users[1]->Book[1]->Author[0]->name, 'Someone'); + $this->assertEqual($users[1]->Book[1]->Author[1]->name, 'Voltaire'); } } diff --git a/tests/Record/FromArrayTestCase.php b/tests/Record/FromArrayTestCase.php index 292ee38c5..bf0617dae 100755 --- a/tests/Record/FromArrayTestCase.php +++ b/tests/Record/FromArrayTestCase.php @@ -78,11 +78,16 @@ public function testFromArrayRecord() public function testFromArrayAfterSaveRecord() { - $user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber, u.Group')->fetchOne(); + $user = Doctrine_Query::create() + ->from('User u, u.Email, u.Phonenumber, u.Group g') + ->addOrderBy('g.id') // The default fetch order is irrelevant here. + ->fetchOne() + ; + $this->assertEqual($user->Phonenumber->count(), 1); $this->assertEqual($user->Phonenumber[0]->phonenumber, '555 321'); $this->assertEqual($user->Email->address, 'johndow@mail.com'); - $this->assertEqual($user->Group[0]->name, 'New Group'); - $this->assertEqual($user->Group[1]->name, 'Group One'); + $this->assertEqual($user->Group[0]->name, 'Group One'); + $this->assertEqual($user->Group[1]->name, 'New Group'); } } \ No newline at end of file diff --git a/tests/Record/SynchronizeTestCase.php b/tests/Record/SynchronizeTestCase.php index 2f1b1628a..67027c15a 100644 --- a/tests/Record/SynchronizeTestCase.php +++ b/tests/Record/SynchronizeTestCase.php @@ -96,12 +96,17 @@ public function testSynchronizeRecord() public function testSynchronizeAfterSaveRecord() { - $user = Doctrine_Query::create()->from('User u, u.Group g, u.Email e, u.Phonenumber p')->fetchOne(); + $user = Doctrine_Query::create() + ->from('User u, u.Group g, u.Email e, u.Phonenumber p') + ->addOrderBy('g.id') // The default fetch order is irrelevant here. + ->fetchOne() + ; + $this->assertEqual($user->Phonenumber->count(), 1); $this->assertEqual($user->Phonenumber[0]->phonenumber, '555 321'); $this->assertEqual($user->Email->address, 'johndow@mail.com'); - $this->assertEqual($user->Group[0]->name, 'New Group'); - $this->assertEqual($user->Group[1]->name, 'Group One'); + $this->assertEqual($user->Group[0]->name, 'Group One'); + $this->assertEqual($user->Group[1]->name, 'New Group'); } public function testSynchronizeAddRecord() @@ -119,9 +124,15 @@ public function testSynchronizeAddRecord() public function testSynchronizeAfterAddRecord() { - $user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber')->fetchOne(); - + $user = Doctrine_Query::create() + ->from('User u, u.Email, u.Phonenumber p') + ->addOrderBy('p.id') // The default fetch order is irrelevant here. + ->fetchOne() + ; + $this->assertEqual($user->Phonenumber->count(), 2); + + $this->assertEqual($user->Phonenumber[0]->phonenumber, '555 321'); $this->assertEqual($user->Phonenumber[1]->phonenumber, '333 238'); } diff --git a/tests/TaskTestCase.php b/tests/TaskTestCase.php index 1ac5d9b37..0c83bf34f 100644 --- a/tests/TaskTestCase.php +++ b/tests/TaskTestCase.php @@ -33,12 +33,8 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Task_TestCase extends Doctrine_UnitTestCase +class Doctrine_Task_TestCase extends UnitTestCase { - public function setUp() {} - - public function tearDown() {} - public function testDerivetasknameReturnsTheNameOfATaskFromItsClassName() { $this->assertEqual('migrate', Doctrine_Task::deriveTaskName('Doctrine_Task_Migrate')); @@ -154,4 +150,4 @@ class Doctrine_Task_TestCase_TestTask003 extends Doctrine_Task public $taskName = 'better-task-name'; public function execute() {} -} \ No newline at end of file +} diff --git a/tests/Ticket/1674TestCase.php b/tests/Ticket/1674TestCase.php index 79a0b6ce2..0edfe8c39 100644 --- a/tests/Ticket/1674TestCase.php +++ b/tests/Ticket/1674TestCase.php @@ -42,7 +42,13 @@ public function testTest() ->limit(1) ->execute(); - $xml = $users->exportTo('xml'); + $xml = $users->exportTo('xml'); + + // Normalize XML documment. + $dom = new DOMDocument('1.0', 'utf-8'); + $dom->loadXML($xml); + $xml = $dom->saveXML(); + $this->assertEqual($xml, ' zYne123 123 '); diff --git a/tests/Ticket/DC521TestCase.php b/tests/Ticket/DC521TestCase.php index 204f984de..4c5dbeef5 100644 --- a/tests/Ticket/DC521TestCase.php +++ b/tests/Ticket/DC521TestCase.php @@ -140,3 +140,4 @@ public function tearDown() $this->driverName = null; parent::tearDown(); } +} diff --git a/tests/run.php b/tests/run.php index d6360a114..2b32582de 100644 --- a/tests/run.php +++ b/tests/run.php @@ -4,20 +4,41 @@ require 'bootstrap.php'; -$test = new DoctrineTest(); - -// Ticket Tests -$tickets = new GroupTest('Tickets Tests', 'tickets'); - $excludeTickets = array( '1830', // MySQL specific error '1876b', '1935', '2015', '2292', + '1783', // Known bug integer validation with numbers greater than PHP_INT_MAX. 'DC521' // PostgreSQL specific error ); +$test = new DoctrineTest(); + +// Search Tests +$search = new GroupTest('Search Tests', 'search'); +$search->addTestCase(new Doctrine_Search_TestCase()); +$search->addTestCase(new Doctrine_Search_Query_TestCase()); +$search->addTestCase(new Doctrine_Search_File_TestCase()); +$test->addTestCase($search); + +// Behaviors Testing +$behaviors = new GroupTest('Behaviors Tests', 'behaviors'); +$behaviors->addTestCase(new Doctrine_I18n_TestCase()); +$behaviors->addTestCase(new Doctrine_Plugin_TestCase()); +$behaviors->addTestCase(new Doctrine_View_TestCase()); +$behaviors->addTestCase(new Doctrine_AuditLog_TestCase()); +$behaviors->addTestCase(new Doctrine_Hook_TestCase()); +$behaviors->addTestCase(new Doctrine_Sluggable_TestCase()); +$behaviors->addTestCase(new Doctrine_Record_Generator_TestCase()); +$behaviors->addTestCase(new Doctrine_SoftDelete_TestCase()); +$behaviors->addTestCase(new Doctrine_SoftDeleteBC_TestCase()); +$test->addTestCase($behaviors); + +// Ticket Tests +$tickets = new GroupTest('Tickets Tests', 'tickets'); + $ticketTestCases = glob(dirname(__FILE__) . '/Ticket/*TestCase.php'); foreach ($ticketTestCases as $testCase) @@ -159,19 +180,6 @@ $data_types->addTestCase(new Doctrine_DataType_Boolean_TestCase()); $test->addTestCase($data_types); -// Behaviors Testing -$behaviors = new GroupTest('Behaviors Tests', 'behaviors'); -$behaviors->addTestCase(new Doctrine_Plugin_TestCase()); -$behaviors->addTestCase(new Doctrine_View_TestCase()); -$behaviors->addTestCase(new Doctrine_AuditLog_TestCase()); -$behaviors->addTestCase(new Doctrine_Hook_TestCase()); -$behaviors->addTestCase(new Doctrine_I18n_TestCase()); -$behaviors->addTestCase(new Doctrine_Sluggable_TestCase()); -$behaviors->addTestCase(new Doctrine_Record_Generator_TestCase()); -$behaviors->addTestCase(new Doctrine_SoftDelete_TestCase()); -$behaviors->addTestCase(new Doctrine_SoftDeleteBC_TestCase()); -$test->addTestCase($behaviors); - // Validator Testing $validators = new GroupTest('Validators Testing', 'validators'); $validators->addTestCase(new Doctrine_Validator_TestCase()); @@ -255,13 +263,6 @@ $inheritance->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase()); $test->addTestCase($inheritance); -// Search Tests -$search = new GroupTest('Search Tests', 'search'); -$search->addTestCase(new Doctrine_Search_TestCase()); -$search->addTestCase(new Doctrine_Search_Query_TestCase()); -$search->addTestCase(new Doctrine_Search_File_TestCase()); -$test->addTestCase($search); - // Cache Tests $cache = new GroupTest('Cache Tests', 'cache'); $cache->addTestCase(new Doctrine_Query_Cache_TestCase()); diff --git a/tests/tmp/Ticket_1527_User.php b/tests/tmp/Ticket_1527_User.php deleted file mode 100644 index 243acef32..000000000 --- a/tests/tmp/Ticket_1527_User.php +++ /dev/null @@ -1,16 +0,0 @@ - - * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $ - */ -class Ticket_1527_User extends BaseTicket_1527_User -{ - -} \ No newline at end of file diff --git a/tests/tmp/generated/BaseTicket_1527_User.php b/tests/tmp/generated/BaseTicket_1527_User.php deleted file mode 100644 index a12f60801..000000000 --- a/tests/tmp/generated/BaseTicket_1527_User.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $ - */ -abstract class BaseTicket_1527_User extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->setTableName('ticket_1527__user'); - $this->hasColumn('username', 'string', 255, array( - 'type' => 'string', - 'extra' => - array( - 'test' => 123, - ), - 'length' => '255', - )); - $this->hasColumn('password', 'string', 255, array( - 'type' => 'string', - 'length' => '255', - )); - } - - public function setUp() - { - parent::setUp(); - - } -} \ No newline at end of file