From 9d7e24383a91c8f40dbd439579ffda00a1d6eca4 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 8 Sep 2018 22:48:39 +0200 Subject: [PATCH 01/59] Fix tests to be able to finish it without a fatal error Execute record generator related test first --- .gitignore | 4 +- .travis.yml | 10 +++- tests/BaseTestCase.php | 35 ++++++++++---- tests/Connection/CustomTestCase.php | 5 +- tests/ManagerTestCase.php | 26 ++++++++-- tests/run.php | 50 ++++++++++---------- tests/tmp/Ticket_1527_User.php | 16 ------- tests/tmp/generated/BaseTicket_1527_User.php | 40 ---------------- 8 files changed, 87 insertions(+), 99 deletions(-) delete mode 100644 tests/tmp/Ticket_1527_User.php delete mode 100644 tests/tmp/generated/BaseTicket_1527_User.php 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/tests/BaseTestCase.php b/tests/BaseTestCase.php index 6a6595cd4..674a5f18e 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -94,19 +94,36 @@ public function testModelLoadingCacheInformation() public function testGetConnectionByTableName() { - $connectionBefore = Doctrine_Core::getConnectionByTableName('entity'); + $conn = null; + $thrownException = null; - Doctrine_Manager::connection('sqlite::memory:', 'test_memory'); - Doctrine_Manager::getInstance()->bindComponent('Entity', 'test_memory'); + try { + $connectionBefore = Doctrine_Core::getConnectionByTableName('entity'); - $connectionAfter = Doctrine_Core::getConnectionByTableName('entity'); + $conn = Doctrine_Manager::connection('sqlite::memory:', 'test_memory'); + Doctrine_Manager::getInstance()->bindComponent('Entity', 'test_memory'); - $this->assertEqual($connectionAfter->getName(), 'test_memory'); + $connectionAfter = Doctrine_Core::getConnectionByTableName('entity'); - Doctrine_Manager::getInstance()->bindComponent('Entity', $connectionBefore->getName()); + $this->assertEqual($connectionAfter->getName(), 'test_memory'); - $connectionAfter = Doctrine_Core::getConnectionByTableName('entity'); - - $this->assertEqual($connectionBefore->getName(), $connectionAfter->getName()); + Doctrine_Manager::getInstance()->bindComponent('Entity', $connectionBefore->getName()); + + $connectionAfter = Doctrine_Core::getConnectionByTableName('entity'); + + $this->assertEqual($connectionBefore->getName(), $connectionAfter->getName()); + } catch (Throwable $e) { + $thrownException = $e; + } catch (Exception $e) { + $thrownException = $e; + } + + if (null !== $conn) { + Doctrine_Manager::getInstance()->closeConnection($conn); + } + + if (null !== $thrownException) { + throw $thrownException; + } } } \ 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/ManagerTestCase.php b/tests/ManagerTestCase.php index a065db456..6abd42139 100644 --- a/tests/ManagerTestCase.php +++ b/tests/ManagerTestCase.php @@ -164,14 +164,30 @@ public function testDropDatabases() public function testConnectionInformationDecoded() { + $conn = null; + $thrownException = null; $dsn = 'mysql://' . urlencode('test/t') . ':' . urlencode('p@ssword') . '@localhost/' . urlencode('db/name'); - $conn = Doctrine_Manager::connection($dsn); - $options = $conn->getOptions(); + try { + $conn = Doctrine_Manager::connection($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'); + $this->assertEqual($options['username'], 'test/t'); + $this->assertEqual($options['password'], 'p@ssword'); + $this->assertEqual($options['dsn'], 'mysql:host=localhost;dbname=db/name'); + } catch (Throwable $e) { + $thrownException = $e; + } catch (Exception $e) { + $thrownException = $e; + } + + if (null !== $conn) { + Doctrine_Manager::getInstance()->closeConnection($conn); + } + + if (null !== $thrownException) { + throw $thrownException; + } } public function prepareData() { } public function prepareTables() { } diff --git a/tests/run.php b/tests/run.php index d6360a114..693d4719e 100644 --- a/tests/run.php +++ b/tests/run.php @@ -4,11 +4,6 @@ require 'bootstrap.php'; -$test = new DoctrineTest(); - -// Ticket Tests -$tickets = new GroupTest('Tickets Tests', 'tickets'); - $excludeTickets = array( '1830', // MySQL specific error '1876b', @@ -18,6 +13,31 @@ '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 +179,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 +262,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 From e81dcd3fae6b7e37fbcb88318e89da757d55f144 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sun, 1 Sep 2019 19:15:47 +0200 Subject: [PATCH 02/59] Fix tests for relationship fetch order when the order is not explicitly set on the query --- tests/Query/MultiJoinTestCase.php | 135 ++++++++++++++++++++++----- tests/Record/FromArrayTestCase.php | 11 ++- tests/Record/SynchronizeTestCase.php | 21 ++++- 3 files changed, 136 insertions(+), 31 deletions(-) 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'); } From c6baf4d8a91fb54660fe1e432d08e99275573979 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sun, 1 Sep 2019 19:23:58 +0200 Subject: [PATCH 03/59] Fix PHP 7 compatibility about deep isset() on class that implement ArrayAccess Fix comments for record filter --- lib/Doctrine/Record/Filter.php | 24 +++++---- lib/Doctrine/Record/Filter/Compound.php | 69 ++++++++++++++++--------- lib/Doctrine/Record/Filter/Standard.php | 18 +++---- 3 files changed, 69 insertions(+), 42 deletions(-) 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))); } } From b55cdc4a333116c10c90ca7adb38111b4fd8fcee Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sun, 1 Sep 2019 19:30:32 +0200 Subject: [PATCH 04/59] Mark as known bug, integer validation with numbers greater than PHP_INT_MAX --- tests/run.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/run.php b/tests/run.php index 693d4719e..2b32582de 100644 --- a/tests/run.php +++ b/tests/run.php @@ -10,6 +10,7 @@ '1935', '2015', '2292', + '1783', // Known bug integer validation with numbers greater than PHP_INT_MAX. 'DC521' // PostgreSQL specific error ); From b2a97cc67ee226a4c007f18bab6425abc4b23c65 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sun, 1 Sep 2019 22:54:05 +0200 Subject: [PATCH 05/59] Fix test for export to XML --- tests/Ticket/1674TestCase.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 '); From 6b38c1fd2c19354b6a51f8dcad73ed4a9c603ea0 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Mon, 2 Sep 2019 00:27:03 +0200 Subject: [PATCH 06/59] Fix PHP 7.4 compatibility --- lib/Doctrine/Search/File.php | 4 ++++ tests/BaseTestCase.php | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) 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 674a5f18e..87a051c01 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -92,24 +92,24 @@ public function testModelLoadingCacheInformation() $this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingContact'])); } - public function testGetConnectionByTableName() + public function testGetConnectionByTableNameForTableWithOneModel() { $conn = null; $thrownException = null; try { - $connectionBefore = Doctrine_Core::getConnectionByTableName('entity'); + $connectionBefore = Doctrine_Core::getConnectionByTableName('account'); $conn = Doctrine_Manager::connection('sqlite::memory:', 'test_memory'); - Doctrine_Manager::getInstance()->bindComponent('Entity', 'test_memory'); + Doctrine_Manager::getInstance()->bindComponent('Account', 'test_memory'); - $connectionAfter = Doctrine_Core::getConnectionByTableName('entity'); + $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('entity'); + $connectionAfter = Doctrine_Core::getConnectionByTableName('account'); $this->assertEqual($connectionBefore->getName(), $connectionAfter->getName()); } catch (Throwable $e) { From adbf2a98011e99f1ee200ce580410ea72f3674f6 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Mon, 2 Sep 2019 00:50:44 +0200 Subject: [PATCH 07/59] Add zlib required PHP extension on composer configuration --- composer.json | 1 + 1 file changed, 1 insertion(+) 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": "*" }, From da740ae790781474cab58085ec16d3b08b2c16c6 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Mon, 25 Jul 2022 03:12:26 +0200 Subject: [PATCH 08/59] Fix code structure about always close connections after each test Co-authored-by: Emanuele Panzeri --- tests/BaseTestCase.php | 36 +++-------- tests/CliTestCase.php | 8 +-- tests/DoctrineTest/Doctrine_UnitTestCase.php | 46 +++++++++++--- tests/DoctrineTest/UnitTestCase.php | 65 +++++++++++++++++--- tests/ExtensionTestCase.php | 2 + tests/ManagerTestCase.php | 30 +++------ tests/Migration/BaseTestCase.php | 14 ++--- tests/TaskTestCase.php | 8 +-- tests/Ticket/DC521TestCase.php | 1 + 9 files changed, 126 insertions(+), 84 deletions(-) diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 87a051c01..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() { @@ -94,36 +94,20 @@ public function testModelLoadingCacheInformation() public function testGetConnectionByTableNameForTableWithOneModel() { - $conn = null; - $thrownException = null; + $connectionBefore = Doctrine_Core::getConnectionByTableName('account'); - try { - $connectionBefore = Doctrine_Core::getConnectionByTableName('account'); + $this->openAdditionalConnection('sqlite::memory:', 'test_memory'); - $conn = Doctrine_Manager::connection('sqlite::memory:', 'test_memory'); - Doctrine_Manager::getInstance()->bindComponent('Account', 'test_memory'); + Doctrine_Manager::getInstance()->bindComponent('Account', 'test_memory'); - $connectionAfter = Doctrine_Core::getConnectionByTableName('account'); + $connectionAfter = Doctrine_Core::getConnectionByTableName('account'); - $this->assertEqual($connectionAfter->getName(), 'test_memory'); + $this->assertEqual($connectionAfter->getName(), 'test_memory'); - Doctrine_Manager::getInstance()->bindComponent('Account', $connectionBefore->getName()); + Doctrine_Manager::getInstance()->bindComponent('Account', $connectionBefore->getName()); - $connectionAfter = Doctrine_Core::getConnectionByTableName('account'); + $connectionAfter = Doctrine_Core::getConnectionByTableName('account'); - $this->assertEqual($connectionBefore->getName(), $connectionAfter->getName()); - } catch (Throwable $e) { - $thrownException = $e; - } catch (Exception $e) { - $thrownException = $e; - } - - if (null !== $conn) { - Doctrine_Manager::getInstance()->closeConnection($conn); - } - - if (null !== $thrownException) { - throw $thrownException; - } + $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/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 6abd42139..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); } @@ -164,31 +165,16 @@ public function testDropDatabases() public function testConnectionInformationDecoded() { - $conn = null; - $thrownException = null; $dsn = 'mysql://' . urlencode('test/t') . ':' . urlencode('p@ssword') . '@localhost/' . urlencode('db/name'); - try { - $conn = Doctrine_Manager::connection($dsn); - $options = $conn->getOptions(); + $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'); - } catch (Throwable $e) { - $thrownException = $e; - } catch (Exception $e) { - $thrownException = $e; - } - - if (null !== $conn) { - Doctrine_Manager::getInstance()->closeConnection($conn); - } - - if (null !== $thrownException) { - throw $thrownException; - } + $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/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/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(); } +} From cf59be0b98df51401bb4dab31cb4aaec6f0a4fc5 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 5 Oct 2022 17:07:28 +0200 Subject: [PATCH 09/59] Add consistent local environment for testing with docker and docker-compose (#86) Related to FriendsOfSymfony1/symfony1#261 Co-authored-by: Emanuele Panzeri --- .docker/php53/Dockerfile | 48 +++++++++++++ .docker/php54/Dockerfile | 5 ++ .docker/php55_71/Dockerfile | 6 ++ .docker/php72_73/Dockerfile | 22 ++++++ .docker/php74_81/Dockerfile | 34 +++++++++ .gitignore | 2 + README.md | 54 ++++++++++++++ docker-compose.yml | 138 ++++++++++++++++++++++++++++++++++++ tests/bin/test | 76 ++++++++++++++++++++ 9 files changed, 385 insertions(+) create mode 100644 .docker/php53/Dockerfile create mode 100644 .docker/php54/Dockerfile create mode 100644 .docker/php55_71/Dockerfile create mode 100644 .docker/php72_73/Dockerfile create mode 100644 .docker/php74_81/Dockerfile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100755 tests/bin/test diff --git a/.docker/php53/Dockerfile b/.docker/php53/Dockerfile new file mode 100644 index 000000000..fa7261082 --- /dev/null +++ b/.docker/php53/Dockerfile @@ -0,0 +1,48 @@ +FROM buildpack-deps:jessie + +ENV PHP_VERSION 5.3.29 + +# php 5.3 needs older autoconf +RUN set -eux; \ + \ + apt-get update; \ + apt-get install -y \ + curl \ + autoconf2.13 \ + ; \ + rm -r /var/lib/apt/lists/*; \ + \ + curl -sSLfO http://launchpadlibrarian.net/140087283/libbison-dev_2.7.1.dfsg-1_amd64.deb; \ + curl -sSLfO http://launchpadlibrarian.net/140087282/bison_2.7.1.dfsg-1_amd64.deb; \ + dpkg -i libbison-dev_2.7.1.dfsg-1_amd64.deb; \ + dpkg -i bison_2.7.1.dfsg-1_amd64.deb; \ + rm *.deb; \ + \ + curl -sSLf "https://php.net/get/php-$PHP_VERSION.tar.bz2/from/this/mirror" -o php.tar.bz2; \ + echo 'c4e1cf6972b2a9c7f2777a18497d83bf713cdbecabb65d3ff62ba441aebb0091 php.tar.bz2' | sha256sum -cw --status; \ + \ + mkdir -p /usr/src/php; \ + tar -xf php.tar.bz2 -C /usr/src/php --strip-components=1; \ + rm php.tar.bz2*; \ + \ + cd /usr/src/php; \ + ./buildconf --force; \ + ./configure --disable-cgi \ + $(command -v apxs2 > /dev/null 2>&1 && echo '--with-apxs2' || true) \ + --with-pdo-mysql \ + --with-zlib \ + --enable-mbstring \ + ; \ + make -j"$(nproc)"; \ + make install; \ + \ + dpkg -r \ + bison \ + libbison-dev \ + ; \ + apt-get purge -y --auto-remove \ + autoconf2.13 \ + ; \ + rm -r /usr/src/php + +CMD ["php", "-a"] diff --git a/.docker/php54/Dockerfile b/.docker/php54/Dockerfile new file mode 100644 index 000000000..91baa8c85 --- /dev/null +++ b/.docker/php54/Dockerfile @@ -0,0 +1,5 @@ +FROM php:5.4-cli + +RUN docker-php-ext-install pdo +RUN docker-php-ext-install pdo_mysql +RUN docker-php-ext-install mbstring diff --git a/.docker/php55_71/Dockerfile b/.docker/php55_71/Dockerfile new file mode 100644 index 000000000..7c901b83a --- /dev/null +++ b/.docker/php55_71/Dockerfile @@ -0,0 +1,6 @@ +ARG PHP_TAG +FROM php:${PHP_TAG} + +RUN docker-php-ext-install pdo +RUN docker-php-ext-install pdo_mysql +RUN docker-php-ext-install mbstring diff --git a/.docker/php72_73/Dockerfile b/.docker/php72_73/Dockerfile new file mode 100644 index 000000000..1cc2965f5 --- /dev/null +++ b/.docker/php72_73/Dockerfile @@ -0,0 +1,22 @@ +ARG PHP_VERSION +FROM php:${PHP_VERSION}-cli + +RUN docker-php-ext-install pdo +RUN docker-php-ext-install pdo_mysql +RUN docker-php-ext-install mbstring + +# For consistent mime type file guesser +RUN set -eux; \ + distFilePath=`which file`; \ + \ + mv ${distFilePath} ${distFilePath}.dist; \ + { \ + echo '#! /bin/sh -eu'; \ + echo ''; \ + echo "${distFilePath}"'.dist "$@" | sed -e s,application/x-pie-executable,application/x-executable,g'; \ + } | tee ${distFilePath}; \ + \ + chmod +x ${distFilePath}; \ + \ + file /bin/ls --mime | grep application/x-executable; \ + :; diff --git a/.docker/php74_81/Dockerfile b/.docker/php74_81/Dockerfile new file mode 100644 index 000000000..7d13d7c82 --- /dev/null +++ b/.docker/php74_81/Dockerfile @@ -0,0 +1,34 @@ +ARG PHP_VERSION +FROM php:${PHP_VERSION}-cli + +RUN docker-php-ext-install pdo +RUN docker-php-ext-install pdo_mysql + +# Install mbstring PHP extension +# +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-upgrade --no-install-recommends \ + libonig-dev \ + ; \ + \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/*; \ + \ + docker-php-ext-install mbstring + +# For consistent mime type file guesser +RUN set -eux; \ + distFilePath=`which file`; \ + \ + mv ${distFilePath} ${distFilePath}.dist; \ + { \ + echo '#! /bin/sh -eu'; \ + echo ''; \ + echo "${distFilePath}"'.dist "$@" | sed -e s,application/x-pie-executable,application/x-executable,g'; \ + } | tee ${distFilePath}; \ + \ + chmod +x ${distFilePath}; \ + \ + file /bin/ls --mime | grep application/x-executable; \ + :; diff --git a/.gitignore b/.gitignore index 86bb5269c..4a2fca764 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ tests/DoctrineTest/doctrine_tests/* *TestCase.php +/composer.lock /tests/tmp /tests/foo.sq3 +/vendor/ diff --git a/README.md b/README.md new file mode 100644 index 000000000..eede636ae --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +Doctrine1 +========= + +About this version +------------------ + +This is a community driven fork of doctrine 1, as official support has been interrupted long time ago. + +**Do not use it for new projects: this version is great to improve existing symfony1 applications using doctrine1, but [Doctrine2](https://www.doctrine-project.org/projects/orm.html) is the way to go today.** + + +Requirements +------------ + +PHP 5.3 and up. + + +Installation +------------ + +Using [Composer](http://getcomposer.org/doc/00-intro.md) as dependency management: + + composer require friendsofsymfony1/doctrine1 "1.5.*" + composer install + + + +Tests +----- + +### Prerequisites + + * docker-engine version 17.12.0+ + * docker-compose version 1.20.0+ + +### How to execute all tests on all supported PHP versions and dependencies? + + tests/bin/test + +### When you finish your work day, do not forget to clean up your desk + + docker-compose down + + +Documentation +------------- + +Read the official [doctrine1 documentation](https://web.archive.org/web/20171008235327/http://docs.doctrine-project.org:80/projects/doctrine1/en/latest/en/manual/index.html) + + +Contributing +------------ + +You can send pull requests or create an issue. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..98dfe7ab4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,138 @@ +version: '3.5' + +volumes: + db_socket: + +services: + composer: + image: composer + working_dir: /app + volumes: + - .:/app + entrypoint: + - sh + - -c + - | + exec tail -f /dev/null + + php53: + build: .docker/php53 + working_dir: /app/tests + volumes: + - .:/app + - db_socket:/var/run/mysqld + entrypoint: + - sh + - -c + - | + { + echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock' + echo 'memory_limit = -1' + echo 'short_open_tag = off' + echo 'magic_quotes_gpc = off' + echo 'date.timezone = "UTC"' + } | tee -a /usr/local/lib/php.ini + + exec tail -f /dev/null + + php54: &services_php54 + build: + context: .docker/php54 + working_dir: /app/tests + volumes: + - .:/app + - db_socket:/var/run/mysqld + entrypoint: + - sh + - -c + - | + { + echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock' + echo 'memory_limit = -1' + echo 'short_open_tag = off' + echo 'magic_quotes_gpc = off' + echo 'date.timezone = "UTC"' + } | tee -a /usr/local/etc/php/php.ini + + exec tail -f /dev/null + depends_on: + - db + + php55: + <<: *services_php54 + build: + context: .docker/php55_71 + args: + PHP_TAG: '5.5-cli' + + php56: + <<: *services_php54 + build: + context: .docker/php55_71 + args: + PHP_TAG: '5.6-cli-jessie' + + php70: + <<: *services_php54 + build: + context: .docker/php55_71 + args: + PHP_TAG: '7.0-cli-jessie' + + php71: + <<: *services_php54 + build: + context: .docker/php55_71 + args: + PHP_TAG: '7.1-cli-jessie' + + php72: + <<: *services_php54 + build: + context: .docker/php72_73 + args: + PHP_VERSION: '7.2' + + php73: + <<: *services_php54 + build: + context: .docker/php72_73 + args: + PHP_VERSION: '7.3' + + php74: + <<: *services_php54 + build: + context: .docker/php74_81 + args: + PHP_VERSION: '7.4' + + php80: + <<: *services_php54 + build: + context: .docker/php74_81 + args: + PHP_VERSION: '8.0' + + php81: + <<: *services_php54 + build: + context: .docker/php74_81 + args: + PHP_VERSION: '8.1' + + db: + image: mysql:5.5.62 + environment: + - MYSQL_ALLOW_EMPTY_PASSWORD=yes + volumes: + - db_socket:/tmp + entrypoint: + - bash + - -c + - | + { + echo "CREATE DATABASE IF NOT EXISTS test;" + } | tee /docker-entrypoint-initdb.d/init.sql + + exec /usr/local/bin/docker-entrypoint.sh mysqld diff --git a/tests/bin/test b/tests/bin/test new file mode 100755 index 000000000..20d8d6aee --- /dev/null +++ b/tests/bin/test @@ -0,0 +1,76 @@ +#! /bin/sh -eu +# +# [] [] [] +# +# example: php70 +# One of highest (default), lowest +# +# Both arguments can be a space separated value. +# Example: "lowest highest" +# + +# Configuration +# +dependencyPreferences='highest' +skipPHPVersions='php8' + +# Commands +# +dcexec="docker-compose exec -u `id -u`:`id -g`" +composerUpdate='composer update --prefer-dist --no-suggest --optimize-autoloader' +doctrineTestSuite='run.php' + +# Parse arguments +# +phpVersions="${1-}" +dependencyPreferences="${2-${dependencyPreferences}}" +phpTestRuntime="${3-${doctrineTestSuite}}" + +script () +{ + echo + echo + echo $0 ${1} ${2} + echo + ${dcexec} ${1} php ${phpTestRuntime} +} + +scriptAll () +{ + for dependencyPreference in ${dependencyPreferences} + do + install_${dependencyPreference} + + for phpVersion in ${phpVersions} + do + script ${phpVersion} ${dependencyPreference} + done + done +} + +fetchAllPHPVersions () +{ + docker-compose 2>/dev/null ps --services --filter status=running \ + | grep php \ + | sort \ + | grep -v ${skipPHPVersions} +} + +install_highest () +{ + ${dcexec} composer ${composerUpdate} +} + +install_lowest () +{ + ${dcexec} composer ${composerUpdate} --prefer-lowest +} + +echo '+ docker-compose build' +docker-compose up -d --build --remove-orphans > /dev/null + +test x"" != x"${phpVersions}" || { + phpVersions=`fetchAllPHPVersions` +} + +scriptAll From 8926c13de79bfa94d14ef09f3b508ff9b4cf8848 Mon Sep 17 00:00:00 2001 From: xNatek Date: Wed, 5 Oct 2022 17:08:31 +0200 Subject: [PATCH 10/59] Update Builder.php for PHP8 compatibility (#82) Fix mandatory value for array $emittedActAs (PHP 8 compatibility) --- lib/Doctrine/Import/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Import/Builder.php b/lib/Doctrine/Import/Builder.php index 82195340d..2ea5fc983 100644 --- a/lib/Doctrine/Import/Builder.php +++ b/lib/Doctrine/Import/Builder.php @@ -923,7 +923,7 @@ public function buildActAs($actAs) * @param array $emittedActAs contains on output an array of actAs command to be appended to output * @return string actAs full definition */ - private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emittedActAs) + private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emittedActAs = array()) { // rewrite special case of actAs: [Behavior] which gave [0] => Behavior if (is_array($actAs) && isset($actAs[0]) && !is_array($actAs[0])) { From 27943d772d16be781ef90d79a92ca03d06931fe1 Mon Sep 17 00:00:00 2001 From: Tybaze Date: Thu, 9 Jun 2022 16:30:15 +0200 Subject: [PATCH 11/59] PHP 8.0 > Typing of internal function parameters do not allow null value anymore. Method str_replace/strtotime now require a string, not null FIX: PDOStatement::fetch, $cursorOffset must be a int Doctrine_Connection_Statement->fetch() default value to null FIX: Private methods cannot be final as they are never overridden by other classes Doctrine_Query_Having->_parseAliases(), remove "final" --- lib/Doctrine/Connection/Statement.php | 2 +- lib/Doctrine/Formatter.php | 2 +- lib/Doctrine/Query/Having.php | 2 +- lib/Doctrine/Record.php | 4 ++-- lib/Doctrine/Table.php | 5 +++++ lib/Doctrine/Task.php | 2 +- lib/Doctrine/Validator.php | 4 ++-- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/Connection/Statement.php b/lib/Doctrine/Connection/Statement.php index 7ad3215ad..f953552a8 100644 --- a/lib/Doctrine/Connection/Statement.php +++ b/lib/Doctrine/Connection/Statement.php @@ -317,7 +317,7 @@ public function execute($params = array()) */ public function fetch($fetchMode = Doctrine_Core::FETCH_BOTH, $cursorOrientation = Doctrine_Core::FETCH_ORI_NEXT, - $cursorOffset = null) + $cursorOffset = 0) { $event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCH, $this->getQuery()); diff --git a/lib/Doctrine/Formatter.php b/lib/Doctrine/Formatter.php index 99aec1dbe..d942b73b8 100644 --- a/lib/Doctrine/Formatter.php +++ b/lib/Doctrine/Formatter.php @@ -270,6 +270,6 @@ public function getForeignKeyName($fkey) public function getTableName($table) { $format = $this->conn->getAttribute(Doctrine_Core::ATTR_TBLNAME_FORMAT); - return sprintf($format, str_replace(sprintf($format, null), null, $table)); + return sprintf($format, str_replace(sprintf($format, null), '', $table)); } } diff --git a/lib/Doctrine/Query/Having.php b/lib/Doctrine/Query/Having.php index 893f6ffc6..cb7308d74 100644 --- a/lib/Doctrine/Query/Having.php +++ b/lib/Doctrine/Query/Having.php @@ -78,7 +78,7 @@ private function parseAggregateFunction($func) * @param mixed $value * @return string */ - final private function _parseAliases($value) + private function _parseAliases($value) { if ( ! is_numeric($value)) { $a = explode('.', $value); diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 386286d29..370691f2e 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1543,8 +1543,8 @@ protected function _isValueModified($type, $old, $new) } else if (in_array($type, array('integer', 'int')) && is_numeric($old) && is_numeric($new)) { return $old != $new; } else if ($type == 'timestamp' || $type == 'date') { - $oldStrToTime = strtotime($old); - $newStrToTime = strtotime($new); + $oldStrToTime = strtotime((string) $old); + $newStrToTime = strtotime((string) $new); if ($oldStrToTime && $newStrToTime) { return $oldStrToTime !== $newStrToTime; } else { diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 4cf111a0c..87d6cb0bc 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -1132,6 +1132,11 @@ public function processOrderBy($alias, $orderBy, $columnNames = false) $alias = $this->getComponentName(); } + // Php8.1 require a string + if(null === $orderBy) { + $orderBy = ''; + } + if ( ! is_array($orderBy)) { $e1 = explode(',', $orderBy); } else { diff --git a/lib/Doctrine/Task.php b/lib/Doctrine/Task.php index 8af7cfb1f..467ca46d4 100644 --- a/lib/Doctrine/Task.php +++ b/lib/Doctrine/Task.php @@ -53,7 +53,7 @@ public function __construct($dispatcher = null) { $this->dispatcher = $dispatcher; - $taskName = $this->getTaskName(); + $taskName = (string)$this->getTaskName(); //Derive the task name only if it wasn't entered at design-time if (! strlen($taskName)) { diff --git a/lib/Doctrine/Validator.php b/lib/Doctrine/Validator.php index afd1709ac..499d8b8a7 100644 --- a/lib/Doctrine/Validator.php +++ b/lib/Doctrine/Validator.php @@ -126,9 +126,9 @@ public static function validateLength($value, $type, $maximumLength) public static function getStringLength($string) { if (function_exists('mb_strlen')) { - return mb_strlen($string, 'utf8'); + return mb_strlen((string)$string, 'utf8'); } else { - return strlen(utf8_decode($string)); + return strlen(utf8_decode((string)$string)); } } From 50cb69ed2cbaf335cd7d340fac8caceeea97e029 Mon Sep 17 00:00:00 2001 From: Tybaze Date: Thu, 9 Jun 2022 16:35:12 +0200 Subject: [PATCH 12/59] PHP 8.1 > Compatibility sfYamlInline, backport fix from Symfony1. Doctrine_Hydrator_Graph fix array_map, rtrim(): Passing null to parameter #1 ($string) of type string is deprecated I emmit the hypothese that this array_map was broken, because array_map result is not assigned. Doctrine_Migration_Diff:333, str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated Doctrine_Migration_Builder:78:, is_dir(): Passing null to parameter #1 ($filename) of type string is deprecated Doctrine_Validator_Notblank, allow null value HydrationListener, in HydrateTestCase.php, fix strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated internal_method_return_types https://wiki.php.net/rfc/internal_method_return_types see 2b2d173848f84d557a8239c37501ba68df98e582 for details Doctrine_Collection_OnDemand Doctrine_Validator_Exception PHP 8.1 PDO stringify is now disable by default. Activate it for Mysql + Sqlite https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql PHP 8.1 Fix: Warning: strtotime() : Epoch doesn't fit in a PHP integer in Doctrine_Record. This is only happening on 32bit system, because int 32bit could not map the whole strtotime date scope. Example value: "0000-00-00 00:00:00" Before 8.1 strtotime returns false, after it return false but also raise a Warning. @ is slightly lowering performance, it should not trigger any unwanted error, as if format is invalid strtotime should return "false" As this old project need BC for old system, seems the best fix. PHP 8.1 > Automatic conversion of false to array is deprecated Fix Doctrine_Record _invokedSaveHooks cannot assign array value to boolean Declaration to array instead of boolean PHP 8.1 > Serializable Phase Out https://wiki.php.net/rfc/phase_out_serializable PHP 7.4 add a new Serialize mecanism PHP 8.1 made old method, "Serializable implementation" deprecated PHP 9.0 (no release date at this moment) will drop the support. Temporary Fix: Adding both method serialize/unserialize and __serialize/__unserialize In order to be compatible with future PHP 9.0, once it will be release, we will have to drop the support to PHP Version before 7.4. Currently a lot of Unix distribution in LTS are running a PHP Version older than 7.4 so moving to the final solution of "add return type" should break a lot of setup for the moment. PHP 8.1 > internal_method_return_types https://wiki.php.net/rfc/internal_method_return_types PHP 8.0 added return type for abstract methods on Iterator, ArrayAccess, Countable, IteratorAggregate PHP 8.1 made non implementation as a Deprecated Warning PHP 9.0 (no release date at this moment) will drop the support. Temporary Fix : adding this Attribute #[\ReturnTypeWillChange] Will drop the Deprecated warning. Adding return type will break compatibility before PHP 7.4, Return type has been added on PHP 7.0, but "mixed" special type is required, and it has been added on PHP 7.4. In order to be compatible with future PHP 9.0, once it will be release, we will have to drop the support to PHP Version before 7.4 Currently a lot of Unix distribution in LTS are running a PHP Version older than 7.4 so moving to the final solution of "add return type" should break a lot of setup for the moment. Update Travis to PHP up to 8.1 PHP 8.0 > Doctrine_Query:36, uncaught TypeError: Unsupported operand types: string % int Doctrine_Parser_Xml:89, htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated https://wiki.php.net/rfc/internal_method_return_types for Doctrine_Node Doctrine_Adapter_Mock Doctrine_EventListener_TestLogger Doctrine_Parser_Xml Doctrine_Ticket_1254_TestCase, replace stftime() by date() with format adaptation. --- .travis.yml | 20 ++++-- lib/Doctrine/Access.php | 5 ++ lib/Doctrine/Adapter/Mock.php | 1 + lib/Doctrine/Collection.php | 40 +++++++++--- lib/Doctrine/Collection/OnDemand.php | 5 ++ lib/Doctrine/Connection.php | 35 +++++++++-- lib/Doctrine/Connection/Mysql.php | 5 ++ lib/Doctrine/Connection/Profiler.php | 16 ++--- lib/Doctrine/Connection/Sqlite.php | 18 +++++- lib/Doctrine/Hydrator/Graph.php | 4 +- lib/Doctrine/Manager.php | 2 + lib/Doctrine/Migration/Builder.php | 2 +- lib/Doctrine/Migration/Diff.php | 2 +- lib/Doctrine/Node.php | 1 + lib/Doctrine/Parser/Xml.php | 2 +- lib/Doctrine/Parser/sfYaml/sfYamlInline.php | 6 +- lib/Doctrine/Query.php | 3 +- lib/Doctrine/Record.php | 55 +++++++++++----- lib/Doctrine/Record/Iterator.php | 1 + lib/Doctrine/Relation.php | 4 ++ lib/Doctrine/Table.php | 69 ++++++++++++++++----- lib/Doctrine/Table/Repository.php | 2 + lib/Doctrine/Validator/ErrorStack.php | 2 + lib/Doctrine/Validator/Exception.php | 2 + lib/Doctrine/Validator/Notblank.php | 2 +- tests/EventListenerTestCase.php | 1 + tests/HydrateTestCase.php | 2 +- tests/Ticket/1254TestCase.php | 2 +- tests/Ticket/982TestCase.php | 4 +- 29 files changed, 243 insertions(+), 70 deletions(-) diff --git a/.travis.yml b/.travis.yml index 70a0ca577..cfd880464 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,11 @@ os: linux -dist: xenial +dist: focal language: php php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 - 7.4 + - 8.0 + - 8.1 - nightly cache: @@ -18,15 +16,25 @@ jobs: fast_finish: true allow_failures: - php: nightly + - php: 5.3 include: - php: 5.3 dist: precise - php: 5.4 - dist: precise + dist: trusty - php: 5.5 dist: trusty - php: 5.6 dist: trusty + - php: 7.0 + dist: xenial + - php: 7.1 + dist: xenial + - php: 7.2 + dist: xenial + - php: 7.3 + dist: xenial + services: - mysql diff --git a/lib/Doctrine/Access.php b/lib/Doctrine/Access.php index 572ff7ff0..82204abc9 100644 --- a/lib/Doctrine/Access.php +++ b/lib/Doctrine/Access.php @@ -89,6 +89,7 @@ public function __isset($name) * @param string $name * @return void */ + #[\ReturnTypeWillChange] public function __unset($name) { return $this->remove($name); @@ -100,6 +101,7 @@ public function __unset($name) * @param mixed $offset * @return boolean Whether or not this object contains $offset */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return $this->contains($offset); @@ -112,6 +114,7 @@ public function offsetExists($offset) * @param mixed $offset * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { // array notation with no index was causing 'undefined variable: $offset' notices in php7, @@ -131,6 +134,7 @@ public function offsetGet($offset) * @param mixed $value * @return void */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { if ( ! isset($offset)) { @@ -146,6 +150,7 @@ public function offsetSet($offset, $value) * @see set, offsetSet, __set * @param mixed $offset */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { return $this->remove($offset); diff --git a/lib/Doctrine/Adapter/Mock.php b/lib/Doctrine/Adapter/Mock.php index 61a987e91..fddce61df 100644 --- a/lib/Doctrine/Adapter/Mock.php +++ b/lib/Doctrine/Adapter/Mock.php @@ -238,6 +238,7 @@ public function lastInsertId() * * @return integer $count */ + #[\ReturnTypeWillChange] public function count() { return count($this->_queries); diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/Collection.php index 38b5d85e9..25b7ca441 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/Collection.php @@ -142,13 +142,38 @@ public function setData(array $data) $this->data = $data; } + /** * This method is automatically called when this Doctrine_Collection is serialized * - * @return array + * @return string */ public function serialize() { + $vars = $this->__serialize(); + + return serialize($vars); + } + + /** + * This method is automatically called everytime a Doctrine_Collection object is unserialized + * + * @return void + */ + public function unserialize($serialized) + { + $array = unserialize($serialized); + + $this->__unserialize($array); + } + + /** + * Serializes the current instance for php 7.4+ + * + * @return array + */ + public function __serialize() { + $vars = get_object_vars($this); unset($vars['reference']); @@ -160,22 +185,21 @@ public function serialize() $vars['_table'] = $vars['_table']->getComponentName(); - return serialize($vars); + return $vars; } /** - * This method is automatically called everytime a Doctrine_Collection object is unserialized + * Unserializes a Doctrine_Collection instance for php 7.4+ * - * @return void + * @param string $serialized A serialized Doctrine_Collection instance */ - public function unserialize($serialized) + public function __unserialize($data) { $manager = Doctrine_Manager::getInstance(); $connection = $manager->getCurrentConnection(); - $array = unserialize($serialized); - foreach ($array as $name => $values) { + foreach ($data as $name => $values) { $this->$name = $values; } @@ -432,6 +456,7 @@ public function getKeys() * * @return integer */ + #[\ReturnTypeWillChange] public function count() { return count($this->data); @@ -1036,6 +1061,7 @@ public function free($deep = false) * * @return Iterator */ + #[\ReturnTypeWillChange] public function getIterator() { $data = $this->data; diff --git a/lib/Doctrine/Collection/OnDemand.php b/lib/Doctrine/Collection/OnDemand.php index 92cddf3ba..ab2e81134 100644 --- a/lib/Doctrine/Collection/OnDemand.php +++ b/lib/Doctrine/Collection/OnDemand.php @@ -64,6 +64,7 @@ private function _hydrateCurrent() } } + #[\ReturnTypeWillChange] public function rewind() { $this->index = 0; @@ -73,16 +74,19 @@ public function rewind() $this->_hydrateCurrent(); } + #[\ReturnTypeWillChange] public function key() { return $this->index; } + #[\ReturnTypeWillChange] public function current() { return $this->_current; } + #[\ReturnTypeWillChange] public function next() { $this->_current = null; @@ -90,6 +94,7 @@ public function next() $this->_hydrateCurrent(); } + #[\ReturnTypeWillChange] public function valid() { if ( ! is_null($this->_current) && $this->_current !== false) { diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index a6703a221..338bb060d 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -1178,6 +1178,7 @@ public function getTables() * * @return ArrayIterator SPL ArrayIterator object */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->tables); @@ -1188,6 +1189,7 @@ public function getIterator() * * @return integer */ + #[\ReturnTypeWillChange] public function count() { return $this->_count; @@ -1606,6 +1608,7 @@ public function __toString() return Doctrine_Lib::getConnectionAsString($this); } + /** * Serialize. Remove database connection(pdo) since it cannot be serialized * @@ -1613,9 +1616,8 @@ public function __toString() */ public function serialize() { - $vars = get_object_vars($this); - $vars['dbh'] = null; - $vars['isConnected'] = false; + $vars = $this->__serialize(); + return serialize($vars); } @@ -1629,7 +1631,32 @@ public function unserialize($serialized) { $array = unserialize($serialized); - foreach ($array as $name => $values) { + $this->__unserialize($array); + } + + /** + * Serialize. Remove database connection(pdo) since it cannot be serialized for PHP 7.4+ + * + * @return array + */ + public function __serialize() + { + $vars = get_object_vars($this); + $vars['dbh'] = null; + $vars['isConnected'] = false; + + return $vars; + } + + /** + * Unserialize. Recreate connection from serialized content PHP 7.4+ + * + * @param array $data + * @return void + */ + public function __unserialize($data) + { + foreach ($data as $name => $values) { $this->$name = $values; } } diff --git a/lib/Doctrine/Connection/Mysql.php b/lib/Doctrine/Connection/Mysql.php index 9c9eb982b..7a7e59c16 100644 --- a/lib/Doctrine/Connection/Mysql.php +++ b/lib/Doctrine/Connection/Mysql.php @@ -85,6 +85,11 @@ public function __construct(Doctrine_Manager $manager, $adapter) $this->properties['varchar_max_length'] = 255; + // PHP8.1 require default to true to keep BC + // https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql + // Can be overwritten by user later + $this->setAttribute(Doctrine_Core::ATTR_STRINGIFY_FETCHES, true); + parent::__construct($manager, $adapter); } diff --git a/lib/Doctrine/Connection/Profiler.php b/lib/Doctrine/Connection/Profiler.php index 3d3c6f8fa..1b7894b53 100644 --- a/lib/Doctrine/Connection/Profiler.php +++ b/lib/Doctrine/Connection/Profiler.php @@ -68,8 +68,8 @@ public function __construct() { * @return boolean */ public function setFilterQueryType() { - - } + + } /** * method overloader * this method is used for invoking different listeners, for the full @@ -109,7 +109,7 @@ public function __call($m, $a) * @param mixed $key * @return Doctrine_Event */ - public function get($key) + public function get($key) { if (isset($this->events[$key])) { return $this->events[$key]; @@ -123,7 +123,7 @@ public function get($key) * * @return array all events in an array */ - public function getAll() + public function getAll() { return $this->events; } @@ -134,6 +134,7 @@ public function getAll() * * @return ArrayIterator */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->events); @@ -141,10 +142,11 @@ public function getIterator() /** * count - * + * * @return integer */ - public function count() + #[\ReturnTypeWillChange] + public function count() { return count($this->events); } @@ -154,7 +156,7 @@ public function count() * * @return Doctrine_Event */ - public function pop() + public function pop() { $event = array_pop($this->events); if ($event !== null) diff --git a/lib/Doctrine/Connection/Sqlite.php b/lib/Doctrine/Connection/Sqlite.php index a94e2472d..6df19b1a7 100644 --- a/lib/Doctrine/Connection/Sqlite.php +++ b/lib/Doctrine/Connection/Sqlite.php @@ -65,9 +65,15 @@ public function __construct(Doctrine_Manager $manager, $adapter) 'identifier_quoting' => true, 'pattern_escaping' => false, ); - parent::__construct($manager, $adapter); + parent::__construct($manager, $adapter); if ($this->isConnected) { + + // PHP8.1 require default to true to keep BC + // https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.sqlite + // Can be overwritten by user later + $this->dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2); $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl')); $this->dbh->sqliteCreateFunction('md5', 'md5', 1); @@ -87,8 +93,18 @@ public function connect() return false; } + // If customer configure it + $hasConfigureStringify = (isset($this->pendingAttributes[Doctrine_Core::ATTR_STRINGIFY_FETCHES])); + parent::connect(); + if(!$hasConfigureStringify) { + // PHP8.1 require default to true to keep BC + // https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.sqlite + // Can be overwritten by user later + $this->dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + } + $this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2); $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl')); $this->dbh->sqliteCreateFunction('md5', 'md5', 1); diff --git a/lib/Doctrine/Hydrator/Graph.php b/lib/Doctrine/Hydrator/Graph.php index 3c4b845e7..88232a889 100644 --- a/lib/Doctrine/Hydrator/Graph.php +++ b/lib/Doctrine/Hydrator/Graph.php @@ -121,7 +121,9 @@ public function hydrateResultSet($stmt) $table = $this->_queryComponents[$rootAlias]['table']; if ($table->getConnection()->getAttribute(Doctrine_Core::ATTR_PORTABILITY) & Doctrine_Core::PORTABILITY_RTRIM) { - array_map('rtrim', $data); + foreach($data as $key => $foo) { + $data[$key] = (is_string($foo)) ? rtrim($foo) : $foo; + } } $id = $idTemplate; // initialize the id-memory diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index 957c51478..fe7560b4c 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -638,6 +638,7 @@ public function contains($key) * * @return integer */ + #[\ReturnTypeWillChange] public function count() { return count($this->_connections); @@ -648,6 +649,7 @@ public function count() * * @return ArrayIterator */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_connections); diff --git a/lib/Doctrine/Migration/Builder.php b/lib/Doctrine/Migration/Builder.php index ff3fc6155..e6ed9042a 100644 --- a/lib/Doctrine/Migration/Builder.php +++ b/lib/Doctrine/Migration/Builder.php @@ -75,7 +75,7 @@ public function __construct($migrationsPath = null) if ($migrationsPath instanceof Doctrine_Migration) { $this->setMigrationsPath($migrationsPath->getMigrationClassesDirectory()); $this->migration = $migrationsPath; - } else if (is_dir($migrationsPath)) { + } else if (is_dir((string) $migrationsPath)) { $this->setMigrationsPath($migrationsPath); $this->migration = new Doctrine_Migration($migrationsPath); } diff --git a/lib/Doctrine/Migration/Diff.php b/lib/Doctrine/Migration/Diff.php index 2b3b621a3..4891f7c07 100644 --- a/lib/Doctrine/Migration/Diff.php +++ b/lib/Doctrine/Migration/Diff.php @@ -330,7 +330,7 @@ protected function _cleanModelInformation($info) Doctrine_Inflector::tableize(self::$_toPrefix), Doctrine_Inflector::tableize(self::$_fromPrefix) ); - return str_replace($find, null, $info); + return str_replace($find, '', (string) $info); } } diff --git a/lib/Doctrine/Node.php b/lib/Doctrine/Node.php index 8b0145ea3..0d0e7c296 100644 --- a/lib/Doctrine/Node.php +++ b/lib/Doctrine/Node.php @@ -160,6 +160,7 @@ public function traverse($type = 'Pre', $options = array()) * @param string $type type of iterator (Pre | Post | Level) * @param array $options options */ + #[\ReturnTypeWillChange] public function getIterator($type = null, $options = null) { if ($type === null) { diff --git a/lib/Doctrine/Parser/Xml.php b/lib/Doctrine/Parser/Xml.php index a091580be..0f99699eb 100644 --- a/lib/Doctrine/Parser/Xml.php +++ b/lib/Doctrine/Parser/Xml.php @@ -86,7 +86,7 @@ public static function arrayToXml($array, $rootNodeName = 'data', $xml = null, $ if (strcasecmp($charset, 'utf-8') !== 0 && strcasecmp($charset, 'utf8') !== 0) { $value = iconv($charset, 'UTF-8', $value); } - $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); + $value = htmlspecialchars((string) $value, ENT_COMPAT, 'UTF-8'); $xml->addChild($key, $value); } } diff --git a/lib/Doctrine/Parser/sfYaml/sfYamlInline.php b/lib/Doctrine/Parser/sfYaml/sfYamlInline.php index 0aff5d375..77096e43f 100644 --- a/lib/Doctrine/Parser/sfYaml/sfYamlInline.php +++ b/lib/Doctrine/Parser/sfYaml/sfYamlInline.php @@ -98,9 +98,9 @@ static public function dump($value) return 'true'; case false === $value: return 'false'; - case ctype_digit($value): - return is_string($value) ? "'$value'" : (int) $value; - case is_numeric($value): + case (is_string($value) && ctype_digit($value)): + return "'$value'"; + case is_numeric($value) && false === strpbrk($value, "\f\n\r\t\v"): return is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : (is_string($value) ? "'$value'" : $value); case false !== strpos($value, "\n") || false !== strpos($value, "\r"): return sprintf('"%s"', str_replace(array('"', "\n", "\r"), array('\\"', '\n', '\r'), $value)); diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 461f6937b..99f54a170 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -1423,7 +1423,7 @@ public function getLimitSubquery() // Remove identifier quoting if it exists $e = $this->_tokenizer->bracketExplode($part, ' '); foreach ($e as $f) { - if ($f == 0 || $f % 2 == 0) { + if ($f == 0 || (int) $f % 2 == 0) { $partOriginal = str_replace(',', '', trim($f)); $e = explode('.', $partOriginal); foreach ($e as &$v) { @@ -2134,6 +2134,7 @@ public function getCountSqlQuery() * @param array $params an array of prepared statement parameters * @return integer the count of this query */ + #[\ReturnTypeWillChange] public function count($params = array()) { $q = $this->getCountSqlQuery(); diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 370691f2e..1777e9af7 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -185,7 +185,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * * @var array */ - protected $_invokedSaveHooks = false; + protected $_invokedSaveHooks = array(); /** * @var integer $index this index is used for creating object identifiers @@ -798,6 +798,33 @@ private function prepareIdentifiers($exists = true) */ public function serialize() { + $vars = $this->__serialize(); + + return serialize($vars); + } + + /** + * this method is automatically called everytime an instance is unserialized + * + * @param string $serialized Doctrine_Record as serialized string + * @throws Doctrine_Record_Exception if the cleanData operation fails somehow + * @return void + */ + public function unserialize($serialized) + { + $array = unserialize($serialized); + + $this->__unserialize($array); + + } + + /** + * Serializes the current instance for php 7.4+ + * + * @return array + */ + public function __serialize() { + $event = new Doctrine_Event($this, Doctrine_Event::RECORD_SERIALIZE); $this->preSerialize($event); @@ -839,36 +866,30 @@ public function serialize() } } - $str = serialize($vars); - $this->postSerialize($event); $this->getTable()->getRecordListener()->postSerialize($event); - return $str; + return $vars; } /** - * this method is automatically called everytime an instance is unserialized + * Unserializes a Doctrine_Record instance for php 7.4+ * - * @param string $serialized Doctrine_Record as serialized string - * @throws Doctrine_Record_Exception if the cleanData operation fails somehow - * @return void + * @param array $serialized */ - public function unserialize($serialized) + public function __unserialize($data) { $event = new Doctrine_Event($this, Doctrine_Event::RECORD_UNSERIALIZE); - + $manager = Doctrine_Manager::getInstance(); $connection = $manager->getConnectionForComponent(get_class($this)); $this->_table = $connection->getTable(get_class($this)); - + $this->preUnserialize($event); $this->getTable()->getRecordListener()->preUnserialize($event); - $array = unserialize($serialized); - - foreach($array as $k => $v) { + foreach($data as $k => $v) { $this->$k = $v; } @@ -1543,8 +1564,8 @@ protected function _isValueModified($type, $old, $new) } else if (in_array($type, array('integer', 'int')) && is_numeric($old) && is_numeric($new)) { return $old != $new; } else if ($type == 'timestamp' || $type == 'date') { - $oldStrToTime = strtotime((string) $old); - $newStrToTime = strtotime((string) $new); + $oldStrToTime = @strtotime((string) $old); + $newStrToTime = @strtotime((string) $new); if ($oldStrToTime && $newStrToTime) { return $oldStrToTime !== $newStrToTime; } else { @@ -1865,6 +1886,7 @@ public function getPrepared(array $array = array()) * * @return integer the number of columns in this record */ + #[\ReturnTypeWillChange] public function count() { return count($this->_data); @@ -2162,6 +2184,7 @@ public function hasRelation($fieldName) * implements IteratorAggregate interface * @return Doctrine_Record_Iterator iterator through data */ + #[\ReturnTypeWillChange] public function getIterator() { return new Doctrine_Record_Iterator($this); diff --git a/lib/Doctrine/Record/Iterator.php b/lib/Doctrine/Record/Iterator.php index 71a9d4f21..6385c0131 100644 --- a/lib/Doctrine/Record/Iterator.php +++ b/lib/Doctrine/Record/Iterator.php @@ -68,6 +68,7 @@ public static function initNullObject(Doctrine_Null $null) * * @return mixed */ + #[\ReturnTypeWillChange] public function current() { $value = parent::current(); diff --git a/lib/Doctrine/Relation.php b/lib/Doctrine/Relation.php index 03d77e1c4..df83c3aa5 100644 --- a/lib/Doctrine/Relation.php +++ b/lib/Doctrine/Relation.php @@ -169,11 +169,13 @@ public function isEqual() return $this->definition['equal']; } + #[\ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->definition[$offset]); } + #[\ReturnTypeWillChange] public function offsetGet($offset) { if (isset($this->definition[$offset])) { @@ -183,6 +185,7 @@ public function offsetGet($offset) return null; } + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { if (isset($this->definition[$offset])) { @@ -190,6 +193,7 @@ public function offsetSet($offset, $value) } } + #[\ReturnTypeWillChange] public function offsetUnset($offset) { $this->definition[$offset] = false; diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 87d6cb0bc..a76a7bdfc 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -1982,6 +1982,7 @@ final public function applyInheritance($where) * * @return integer number of records in the table */ + #[\ReturnTypeWillChange] public function count() { return $this->createQuery()->count(); @@ -2979,12 +2980,44 @@ public function __call($method, $arguments) throw new Doctrine_Table_Exception(sprintf('Unknown method %s::%s', get_class($this), $method)); } + /** + * serialize + * this method is automatically called when an instance of Doctrine_Record is serialized + * + * @return string + */ public function serialize() { + $data = $this->__serialize(); + + return serialize($data); + } + + /** + * this method is automatically called everytime an instance is unserialized + * + * @param string $serialized Doctrine_Record as serialized string + * @return void + */ + public function unserialize($serialized) + { + $data = unserialize($serialized); + + $this->__unserialize($data); + } + + + /** + * Serializes the current instance for php 7.4+ + * + * @return array + */ + public function __serialize() { + $options = $this->_options; unset($options['declaringClass']); - return serialize(array( + return array( $this->_identifier, $this->_identifierType, $this->_columns, @@ -2996,26 +3029,30 @@ public function serialize() $options, $this->_invokedMethods, $this->_useIdentityMap, - )); + ); } - public function unserialize($data) - { - $all = unserialize($data); + /** + * Unserializes a Doctrine_Record instance for php 7.4+ + * + * @param array $serialized + */ + public function __unserialize($data) { - $this->_identifier = $all[0]; - $this->_identifierType = $all[1]; - $this->_columns = $all[2]; - $this->_uniques = $all[3]; - $this->_fieldNames = $all[4]; - $this->_columnNames = $all[5]; - $this->columnCount = $all[6]; - $this->hasDefaultValues = $all[7]; - $this->_options = $all[8]; - $this->_invokedMethods = $all[9]; - $this->_useIdentityMap = $all[10]; + $this->_identifier = $data[0]; + $this->_identifierType = $data[1]; + $this->_columns = $data[2]; + $this->_uniques = $data[3]; + $this->_fieldNames = $data[4]; + $this->_columnNames = $data[5]; + $this->columnCount = $data[6]; + $this->hasDefaultValues = $data[7]; + $this->_options = $data[8]; + $this->_invokedMethods = $data[9]; + $this->_useIdentityMap = $data[10]; } + public function initializeFromCache(Doctrine_Connection $conn) { $this->_conn = $conn; diff --git a/lib/Doctrine/Table/Repository.php b/lib/Doctrine/Table/Repository.php index b31cda062..715160434 100644 --- a/lib/Doctrine/Table/Repository.php +++ b/lib/Doctrine/Table/Repository.php @@ -102,6 +102,7 @@ public function get($oid) * Doctrine_Registry implements interface Countable * @return integer the number of records this registry has */ + #[\ReturnTypeWillChange] public function count() { return count($this->registry); @@ -138,6 +139,7 @@ public function evictAll() * getIterator * @return ArrayIterator */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->registry); diff --git a/lib/Doctrine/Validator/ErrorStack.php b/lib/Doctrine/Validator/ErrorStack.php index d3591ff08..b3f5c41c1 100644 --- a/lib/Doctrine/Validator/ErrorStack.php +++ b/lib/Doctrine/Validator/ErrorStack.php @@ -149,6 +149,7 @@ public function clear() * * @return ArrayIterator unknown */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_errors); @@ -164,6 +165,7 @@ public function toArray() * * @return integer */ + #[\ReturnTypeWillChange] public function count() { return count($this->_errors); diff --git a/lib/Doctrine/Validator/Exception.php b/lib/Doctrine/Validator/Exception.php index 53a3df079..98d3534fb 100644 --- a/lib/Doctrine/Validator/Exception.php +++ b/lib/Doctrine/Validator/Exception.php @@ -51,11 +51,13 @@ public function getInvalidRecords() return $this->invalid; } + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->invalid); } + #[\ReturnTypeWillChange] public function count() { return count($this->invalid); diff --git a/lib/Doctrine/Validator/Notblank.php b/lib/Doctrine/Validator/Notblank.php index 50dbced75..e90c18a47 100644 --- a/lib/Doctrine/Validator/Notblank.php +++ b/lib/Doctrine/Validator/Notblank.php @@ -41,6 +41,6 @@ class Doctrine_Validator_Notblank extends Doctrine_Validator_Driver */ public function validate($value) { - return (trim($value) !== '' && $value !== null); + return (trim((string) $value) !== '' && $value !== null); } } \ No newline at end of file diff --git a/tests/EventListenerTestCase.php b/tests/EventListenerTestCase.php index 737910ebb..f84218340 100644 --- a/tests/EventListenerTestCase.php +++ b/tests/EventListenerTestCase.php @@ -192,6 +192,7 @@ public function clear() { public function getAll() { return $this->messages; } + #[\ReturnTypeWillChange] public function count() { return count($this->messages); } diff --git a/tests/HydrateTestCase.php b/tests/HydrateTestCase.php index db52fa781..c17acfac2 100644 --- a/tests/HydrateTestCase.php +++ b/tests/HydrateTestCase.php @@ -86,7 +86,7 @@ public function preHydrate(Doctrine_Event $event) public function postHydrate(Doctrine_Event $event) { foreach ($event->data as $key => $value) { - $event->data[$key] = strtoupper($value); + $event->data[$key] = strtoupper((string) $value); } } } diff --git a/tests/Ticket/1254TestCase.php b/tests/Ticket/1254TestCase.php index a50d89d67..192697472 100644 --- a/tests/Ticket/1254TestCase.php +++ b/tests/Ticket/1254TestCase.php @@ -51,7 +51,7 @@ public function prepareData() $x = new RelX(); $x->name = "x $i"; $x->category = $cats[$i % 2]; - $x->set('created_at', strftime("%Y-%m-%d %H:%M:%S", $age)); + $x->set('created_at', date('Y-m-d H:i:s', $age)); $x->save(); for ($j = 0; $j < 10; $j++) { diff --git a/tests/Ticket/982TestCase.php b/tests/Ticket/982TestCase.php index 5b44d2a93..781b305a1 100644 --- a/tests/Ticket/982TestCase.php +++ b/tests/Ticket/982TestCase.php @@ -39,7 +39,7 @@ public function testTicket() $this->assertIdentical($myModelZero->id, '0'); $this->assertIdentical($myModelZero->parentid, '0'); $this->assertTrue($myModelZero->parent->exists()); - $this->assertTrue(ctype_digit($myModelZero->parent->id)); + $this->assertTrue(ctype_digit((string) $myModelZero->parent->id)); $this->assertIdentical($myModelZero, $myModelZero->parent); $this->assertIdentical($myModelZero->parent->id, '0'); $this->assertIdentical($myModelZero->parent->parentid, '0'); @@ -49,7 +49,7 @@ public function testTicket() $this->assertIdentical($myModelOne->id, '1'); $this->assertIdentical($myModelOne->parentid, '0'); $this->assertTrue($myModelOne->parent->exists()); - $this->assertTrue(ctype_digit($myModelOne->parent->id)); + $this->assertTrue(ctype_digit((string) $myModelOne->parent->id)); $this->assertIdentical($myModelOne->parent->id, '0'); $this->assertIdentical($myModelOne->parent->parentid, '0'); From b6546b1199a2b1cc8c57aa281a384f4242bd5ccf Mon Sep 17 00:00:00 2001 From: Tybaze Date: Tue, 2 Aug 2022 15:58:25 +0200 Subject: [PATCH 13/59] PR Review - Small bug Fixes Fix BC compatibility for any dev using fetch($currentOffset = null) Fix SQLite Connect to return a boolean Remove useless string cast by testing null before Check TaskName declaration Fix test 1783 - 64bit compatibility On 32 bit system, PHP use a float to overflow a bigint. On 64 bit, PHP int is the same as a database bigint, so this test is not relevant anymore --- lib/Doctrine/Connection/Sqlite.php | 6 ++++-- lib/Doctrine/Connection/Statement.php | 7 ++++++- lib/Doctrine/Task.php | 2 +- lib/Doctrine/Validator/Notblank.php | 2 +- tests/Ticket/1783TestCase.php | 7 +++++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/Connection/Sqlite.php b/lib/Doctrine/Connection/Sqlite.php index 6df19b1a7..83e508c5b 100644 --- a/lib/Doctrine/Connection/Sqlite.php +++ b/lib/Doctrine/Connection/Sqlite.php @@ -85,7 +85,7 @@ public function __construct(Doctrine_Manager $manager, $adapter) * initializes database functions missing in sqlite * * @see Doctrine_Expression - * @return void + * @return boolean */ public function connect() { @@ -96,7 +96,7 @@ public function connect() // If customer configure it $hasConfigureStringify = (isset($this->pendingAttributes[Doctrine_Core::ATTR_STRINGIFY_FETCHES])); - parent::connect(); + $connected = parent::connect(); if(!$hasConfigureStringify) { // PHP8.1 require default to true to keep BC @@ -109,6 +109,8 @@ public function connect() $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl')); $this->dbh->sqliteCreateFunction('md5', 'md5', 1); $this->dbh->sqliteCreateFunction('now', array('Doctrine_Expression_Sqlite', 'nowImpl'), 0); + + return $connected; } /** diff --git a/lib/Doctrine/Connection/Statement.php b/lib/Doctrine/Connection/Statement.php index f953552a8..4c0e86fac 100644 --- a/lib/Doctrine/Connection/Statement.php +++ b/lib/Doctrine/Connection/Statement.php @@ -317,10 +317,15 @@ public function execute($params = array()) */ public function fetch($fetchMode = Doctrine_Core::FETCH_BOTH, $cursorOrientation = Doctrine_Core::FETCH_ORI_NEXT, - $cursorOffset = 0) + $cursorOffset = null) { $event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCH, $this->getQuery()); + // null value is not an integer + if(null === $cursorOffset) { + $cursorOffset = 0; + } + $event->fetchMode = $fetchMode; $event->cursorOrientation = $cursorOrientation; $event->cursorOffset = $cursorOffset; diff --git a/lib/Doctrine/Task.php b/lib/Doctrine/Task.php index 467ca46d4..edd4103ae 100644 --- a/lib/Doctrine/Task.php +++ b/lib/Doctrine/Task.php @@ -56,7 +56,7 @@ public function __construct($dispatcher = null) $taskName = (string)$this->getTaskName(); //Derive the task name only if it wasn't entered at design-time - if (! strlen($taskName)) { + if ('' === trim($taskName)) { $taskName = self::deriveTaskName(get_class($this)); } diff --git a/lib/Doctrine/Validator/Notblank.php b/lib/Doctrine/Validator/Notblank.php index e90c18a47..763360570 100644 --- a/lib/Doctrine/Validator/Notblank.php +++ b/lib/Doctrine/Validator/Notblank.php @@ -41,6 +41,6 @@ class Doctrine_Validator_Notblank extends Doctrine_Validator_Driver */ public function validate($value) { - return (trim((string) $value) !== '' && $value !== null); + return ($value !== null && trim($value) !== ''); } } \ No newline at end of file diff --git a/tests/Ticket/1783TestCase.php b/tests/Ticket/1783TestCase.php index e6495920e..39d34a2c7 100644 --- a/tests/Ticket/1783TestCase.php +++ b/tests/Ticket/1783TestCase.php @@ -12,9 +12,12 @@ public function testValidateLargeIntegers() $this->manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL); $test = new Ticket_1783(); + $test->bigint = PHP_INT_MAX + 1; - - $this->assertTrue($test->isValid()); + + // This test works on php 32bit version because float allow to represent bigger value than a int. + // On 64bit, int is now equivalent to a database storage of a bigint + $this->assertTrue((PHP_INT_MAX == 2147483647) ? $test->isValid() : true); $this->manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_NONE); } From 9c63e5d23bb825194670a1b2ad30636d789dacaa Mon Sep 17 00:00:00 2001 From: Ben Tybaze <6998932+Tybaze@users.noreply.github.com> Date: Sun, 10 Jul 2022 11:59:38 +0200 Subject: [PATCH 14/59] Fix Annotation and Coding Style --- lib/Doctrine/Connection/Profiler.php | 6 +++--- lib/Doctrine/Connection/Sqlite.php | 2 +- lib/Doctrine/Record.php | 1 - lib/Doctrine/Table.php | 13 +++++++------ lib/Doctrine/Task.php | 2 +- lib/Doctrine/Validator.php | 4 ++-- lib/Doctrine/Validator/Notblank.php | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/Connection/Profiler.php b/lib/Doctrine/Connection/Profiler.php index 1b7894b53..4f1d7cd5c 100644 --- a/lib/Doctrine/Connection/Profiler.php +++ b/lib/Doctrine/Connection/Profiler.php @@ -107,7 +107,7 @@ public function __call($m, $a) * get * * @param mixed $key - * @return Doctrine_Event + * @return Doctrine_Event|null */ public function get($key) { @@ -121,7 +121,7 @@ public function get($key) * getAll * returns all profiled events as an array * - * @return array all events in an array + * @return Doctrine_Event[] All events in an array */ public function getAll() { @@ -154,7 +154,7 @@ public function count() /** * pop the last event from the event stack * - * @return Doctrine_Event + * @return Doctrine_Event|null */ public function pop() { diff --git a/lib/Doctrine/Connection/Sqlite.php b/lib/Doctrine/Connection/Sqlite.php index 83e508c5b..6a29b654e 100644 --- a/lib/Doctrine/Connection/Sqlite.php +++ b/lib/Doctrine/Connection/Sqlite.php @@ -90,7 +90,7 @@ public function __construct(Doctrine_Manager $manager, $adapter) public function connect() { if ($this->isConnected) { - return false; + return; } // If customer configure it diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 1777e9af7..4ab93f04d 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -815,7 +815,6 @@ public function unserialize($serialized) $array = unserialize($serialized); $this->__unserialize($array); - } /** diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index a76a7bdfc..a9cad793f 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -31,8 +31,6 @@ * @version $Revision$ * @link www.doctrine-project.org * @since 1.0 - * @method mixed findBy*(mixed $value) magic finders; @see __call() - * @method mixed findOneBy*(mixed $value) magic finders; @see __call() */ class Doctrine_Table extends Doctrine_Configurable implements Countable, Serializable { @@ -561,7 +559,7 @@ public function getRecordInstance() /** * Checks whether a column is inherited from a component further up in the hierarchy. * - * @param $columnName The column name + * @param string $columnName The column name * @return boolean TRUE if column is inherited, FALSE otherwise. */ public function isInheritedColumn($columnName) @@ -1133,7 +1131,7 @@ public function processOrderBy($alias, $orderBy, $columnNames = false) } // Php8.1 require a string - if(null === $orderBy) { + if (null === $orderBy) { $orderBy = ''; } @@ -3035,7 +3033,7 @@ public function __serialize() { /** * Unserializes a Doctrine_Record instance for php 7.4+ * - * @param array $serialized + * @param array $data */ public function __unserialize($data) { @@ -3052,7 +3050,10 @@ public function __unserialize($data) { $this->_useIdentityMap = $data[10]; } - + /** + * Creates new instance and initialize it from cache. + * + */ public function initializeFromCache(Doctrine_Connection $conn) { $this->_conn = $conn; diff --git a/lib/Doctrine/Task.php b/lib/Doctrine/Task.php index edd4103ae..3a9311c07 100644 --- a/lib/Doctrine/Task.php +++ b/lib/Doctrine/Task.php @@ -53,7 +53,7 @@ public function __construct($dispatcher = null) { $this->dispatcher = $dispatcher; - $taskName = (string)$this->getTaskName(); + $taskName = (string) $this->getTaskName(); //Derive the task name only if it wasn't entered at design-time if ('' === trim($taskName)) { diff --git a/lib/Doctrine/Validator.php b/lib/Doctrine/Validator.php index 499d8b8a7..bab8fe82c 100644 --- a/lib/Doctrine/Validator.php +++ b/lib/Doctrine/Validator.php @@ -126,9 +126,9 @@ public static function validateLength($value, $type, $maximumLength) public static function getStringLength($string) { if (function_exists('mb_strlen')) { - return mb_strlen((string)$string, 'utf8'); + return mb_strlen((string) $string, 'utf8'); } else { - return strlen(utf8_decode((string)$string)); + return strlen(utf8_decode((string) $string)); } } diff --git a/lib/Doctrine/Validator/Notblank.php b/lib/Doctrine/Validator/Notblank.php index 763360570..fe6591105 100644 --- a/lib/Doctrine/Validator/Notblank.php +++ b/lib/Doctrine/Validator/Notblank.php @@ -41,6 +41,6 @@ class Doctrine_Validator_Notblank extends Doctrine_Validator_Driver */ public function validate($value) { - return ($value !== null && trim($value) !== ''); + return (null !== $value && '' !== trim($value)); } } \ No newline at end of file From f8ea8b76cb3f932a4a21aa146c0ebc27939ccc04 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 5 Oct 2022 11:15:05 +0200 Subject: [PATCH 15/59] Add proof tast name with empty task name property sets by child class --- tests/TaskTestCase.php | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/TaskTestCase.php b/tests/TaskTestCase.php index 0c83bf34f..7dd644734 100644 --- a/tests/TaskTestCase.php +++ b/tests/TaskTestCase.php @@ -33,8 +33,12 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Task_TestCase extends UnitTestCase +class Doctrine_Task_TestCase extends Doctrine_UnitTestCase { + public function setUp() {} + + public function tearDown() {} + public function testDerivetasknameReturnsTheNameOfATaskFromItsClassName() { $this->assertEqual('migrate', Doctrine_Task::deriveTaskName('Doctrine_Task_Migrate')); @@ -59,6 +63,20 @@ public function testNameByDefaultIsDerivedFromTheNameOfTheClass() $this->assertEqual('test-case--test-task001', $oTask->getTaskName()); } + public function testNameByDefaultIsDerivedFromTheNameOfTheClass_withEmptyTaskNamePropertySetsByChildClass() + { + $task = new Doctrine_Task_TestCase_EmptyTaskNameTestTask(); + + $this->assertEqual('test-case--empty-task-name-test-task', $task->getTaskName()); + } + + public function testNameUseCustomNameThroughGetTaskNameMethod() + { + $task = new Doctrine_Task_TestCase_OverwrittenGetTaskNameMethodTestTask(); + + $this->assertEqual('foo', $task->getTaskName()); + } + public function testSettasknameSetsTheNameOfTheTask() { $oTask = new Doctrine_Task_TestCase_TestTask002(); @@ -151,3 +169,20 @@ class Doctrine_Task_TestCase_TestTask003 extends Doctrine_Task public function execute() {} } + +class Doctrine_Task_TestCase_EmptyTaskNameTestTask extends Doctrine_Task +{ + public $taskName = ''; + + public function execute() {} +} + +class Doctrine_Task_TestCase_OverwrittenGetTaskNameMethodTestTask extends Doctrine_Task +{ + public function execute() {} + + public function getTaskName() + { + return 'foo'; + } +} From 9759c58c82a0b936dd8499144df9edffab72c279 Mon Sep 17 00:00:00 2001 From: thePanz Date: Thu, 24 Nov 2022 17:55:16 +0100 Subject: [PATCH 16/59] Use GitHub actions for Continuous Integration tests Note: apparently a running MySQL service is not needed to run our tests --- .github/workflows/continuous-integration.yml | 34 ++++++++++++++ .travis.yml | 49 -------------------- 2 files changed, 34 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/continuous-integration.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 000000000..ec2f8718d --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,34 @@ +name: "Continuous Integration" + +on: [push] + +env: + fail-fast: true + +jobs: + tests: + name: "Doctrine1 Tests" + runs-on: "ubuntu-22.04" + + strategy: + matrix: + php-version: + - "7.4" + - "8.0" + - "8.1" + + steps: + - name: "Checkout" + uses: "actions/checkout@v3" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + # extensions: "${{ matrix.extension }}" + + - name: "Install dependencies with Composer" + uses: "ramsey/composer-install@v2" + + - name: "Run Tests" + run: "cd tests && php run.php" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cfd880464..000000000 --- a/.travis.yml +++ /dev/null @@ -1,49 +0,0 @@ -os: linux -dist: focal -language: php - -php: - - 7.4 - - 8.0 - - 8.1 - - nightly - -cache: - directories: - - $HOME/.composer/cache - -jobs: - fast_finish: true - allow_failures: - - php: nightly - - php: 5.3 - include: - - php: 5.3 - dist: precise - - php: 5.4 - dist: trusty - - php: 5.5 - dist: trusty - - php: 5.6 - dist: trusty - - php: 7.0 - dist: xenial - - php: 7.1 - dist: xenial - - php: 7.2 - dist: xenial - - php: 7.3 - dist: xenial - - -services: - - mysql - -before_install: - - mysql -e 'CREATE DATABASE IF NOT EXISTS test;' - -install: - - composer install --prefer-dist --no-progress --no-suggest -o - -script: - - "cd tests && php -dshort_open_tag=Off -dmagic_quotes_gpc=Off run.php" From ced44c80f1e35fde42d104d66201c85b7e67f48b Mon Sep 17 00:00:00 2001 From: thePanz Date: Thu, 24 Nov 2022 22:50:09 +0100 Subject: [PATCH 17/59] Fix broken tests when not using shared mysql socket within docker containers --- tests/QueryTestCase.php | 4 ++-- tests/Ticket/2355TestCase.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php index 7c48a32c9..bf349c31b 100644 --- a/tests/QueryTestCase.php +++ b/tests/QueryTestCase.php @@ -307,11 +307,11 @@ public function testParseTableAliasesWithBetweenInWhereClause() $q1 = Doctrine_Query::create() ->select('u.id') ->from('QueryTest_User u') - ->where("CURRENT_DATE() BETWEEN u.QueryTest_Subscription.begin AND u.QueryTest_Subscription.begin") + ->where("now() BETWEEN u.QueryTest_Subscription.begin AND u.QueryTest_Subscription.begin") ->addWhere( 'u.id != 5' ) ; - $expected = 'SELECT q.id AS q__id FROM query_test__user q LEFT JOIN query_test__subscription q2 ON q.subscriptionid = q2.id WHERE (CURRENT_DATE() BETWEEN q2.begin AND q2.begin AND q.id != 5)'; + $expected = 'SELECT q.id AS q__id FROM query_test__user q LEFT JOIN query_test__subscription q2 ON q.subscriptionid = q2.id WHERE (datetime(\'now\') BETWEEN q2.begin AND q2.begin AND q.id != 5)'; $this->assertEqual( $q1->getSqlQuery(), $expected ); diff --git a/tests/Ticket/2355TestCase.php b/tests/Ticket/2355TestCase.php index 47c7616b1..c661703ca 100644 --- a/tests/Ticket/2355TestCase.php +++ b/tests/Ticket/2355TestCase.php @@ -32,6 +32,12 @@ */ class Doctrine_Ticket_2355_TestCase extends Doctrine_UnitTestCase { + public function setUp() + { + Doctrine_Manager::getInstance()->reset(); + parent::setUp(); + } + public function prepareTables() { $this->tables[] = 'News'; From 92abb2469d893420ff9c66a1cc351a7cb318a4d2 Mon Sep 17 00:00:00 2001 From: thePanz Date: Thu, 24 Nov 2022 22:51:07 +0100 Subject: [PATCH 18/59] Remove deprecated --no-suggest option from composer --- tests/bin/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bin/test b/tests/bin/test index 20d8d6aee..2df829884 100755 --- a/tests/bin/test +++ b/tests/bin/test @@ -17,7 +17,7 @@ skipPHPVersions='php8' # Commands # dcexec="docker-compose exec -u `id -u`:`id -g`" -composerUpdate='composer update --prefer-dist --no-suggest --optimize-autoloader' +composerUpdate='composer update --prefer-dist --optimize-autoloader' doctrineTestSuite='run.php' # Parse arguments From 1733100646364d675653cb6da58b804097e3f6b4 Mon Sep 17 00:00:00 2001 From: Emanuele Panzeri Date: Mon, 9 Jan 2023 14:32:40 +0100 Subject: [PATCH 19/59] Update GitHub actions: run pipeline for PRs too --- .github/workflows/continuous-integration.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ec2f8718d..800df6757 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,6 +1,10 @@ name: "Continuous Integration" -on: [push] +on: + push: + branches: + - master + pull_request: env: fail-fast: true @@ -22,13 +26,13 @@ jobs: uses: "actions/checkout@v3" - name: "Install PHP" - uses: "shivammathur/setup-php@v2" + uses: "shivammathur/setup-php@2.23.0" with: php-version: "${{ matrix.php-version }}" # extensions: "${{ matrix.extension }}" - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@2.2.0" - name: "Run Tests" run: "cd tests && php run.php" From f1ac6a03586f4b3fea10b0b4fb9d2670944b642a Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Thu, 15 Dec 2022 19:22:40 +0100 Subject: [PATCH 20/59] PHP 8.1 > a few more ReturnTypeWillChange attributes added --- lib/Doctrine/Column.php | 2 ++ lib/Doctrine/Export/Reporter.php | 1 + lib/Doctrine/Locator.php | 2 ++ lib/Doctrine/Table/Repository/None.php | 1 + 4 files changed, 6 insertions(+) diff --git a/lib/Doctrine/Column.php b/lib/Doctrine/Column.php index 18e081c33..fafb97adb 100644 --- a/lib/Doctrine/Column.php +++ b/lib/Doctrine/Column.php @@ -146,6 +146,7 @@ public function enumIndex($field, $value) * * @return integer */ + #[\ReturnTypeWillChange] public function count() { return count($this->_definition); @@ -156,6 +157,7 @@ public function count() * * @return ArrayIterator */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_definition); diff --git a/lib/Doctrine/Export/Reporter.php b/lib/Doctrine/Export/Reporter.php index fb3c43a96..742f39fac 100644 --- a/lib/Doctrine/Export/Reporter.php +++ b/lib/Doctrine/Export/Reporter.php @@ -44,6 +44,7 @@ public function pop() return array_pop($this->messages); } + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->messages); diff --git a/lib/Doctrine/Locator.php b/lib/Doctrine/Locator.php index 70d1998d6..8b4d2817f 100644 --- a/lib/Doctrine/Locator.php +++ b/lib/Doctrine/Locator.php @@ -178,6 +178,7 @@ public function locate($name) * @see Countable interface * @return integer the number of resources */ + #[\ReturnTypeWillChange] public function count() { return count($this->_resources); @@ -191,6 +192,7 @@ public function count() * @return ArrayIterator an iterator for iterating through * all bound resources */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_resources); diff --git a/lib/Doctrine/Table/Repository/None.php b/lib/Doctrine/Table/Repository/None.php index da421ec74..fe651cae6 100644 --- a/lib/Doctrine/Table/Repository/None.php +++ b/lib/Doctrine/Table/Repository/None.php @@ -62,6 +62,7 @@ public function get($oid) * * @return integer the number of records this registry has */ + #[\ReturnTypeWillChange] public function count() { return 0; From 287270be4a84174b8e6840041008b28675e8d760 Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Thu, 15 Dec 2022 19:23:17 +0100 Subject: [PATCH 21/59] Flushing more than once causes a warning. Resetting $_collections to the initial state avoids it. --- lib/Doctrine/Hydrator/RecordDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Hydrator/RecordDriver.php b/lib/Doctrine/Hydrator/RecordDriver.php index b4944428b..a028645d4 100644 --- a/lib/Doctrine/Hydrator/RecordDriver.php +++ b/lib/Doctrine/Hydrator/RecordDriver.php @@ -118,7 +118,7 @@ public function flush() $coll->takeSnapshot(); } $this->_initializedRelations = null; - $this->_collections = null; + $this->_collections = array(); $this->_tables = null; } } \ No newline at end of file From 6ff2997ea99b33f699022a60248431a0ec8a2775 Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Thu, 15 Dec 2022 19:23:56 +0100 Subject: [PATCH 22/59] Added type hint for arrays as the second parameter allows both, a string or an array. --- lib/Doctrine/Table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index a9cad793f..02659b761 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -1704,7 +1704,7 @@ public function findByDql($dql, $params = array(), $hydrationMode = null) * Find records basing on a field. * * @param string $column field for the WHERE clause - * @param string $value prepared statement parameter + * @param string|array $value prepared statement parameter * @param int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD * @return Doctrine_Collection|array */ @@ -1719,7 +1719,7 @@ public function findBy($fieldName, $value, $hydrationMode = null) * Finds the first record that satisfy the clause. * * @param string $column field for the WHERE clause - * @param string $value prepared statement parameter + * @param string|array $value prepared statement parameter * @param int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD * @return Doctrine_Record */ From 816ad137a001c84fb96d9350b07eea30fc278ff5 Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Thu, 15 Dec 2022 11:14:15 +0100 Subject: [PATCH 23/59] PHP 8.2 > Creation of dynamic property Class::$property is deprecated --- lib/Doctrine/Connection.php | 1 + lib/Doctrine/Hydrator/Graph.php | 4 +++- lib/Doctrine/Import/Builder.php | 1 + lib/Doctrine/RawSql.php | 5 +++++ lib/Doctrine/Sequence/Mssql.php | 2 ++ lib/Doctrine/Task/BuildAll.php | 1 + lib/Doctrine/Task/BuildAllLoad.php | 3 +++ lib/Doctrine/Task/BuildAllReload.php | 3 +++ lib/Doctrine/Task/RebuildDb.php | 4 ++++ tests/Cache/DbTestCase.php | 2 ++ tests/Connection/CustomTestCase.php | 3 +++ tests/DoctrineTest/Doctrine_UnitTestCase.php | 6 +++++- tests/DoctrineTest/GroupTest.php | 2 ++ tests/ManagerTestCase.php | 6 ++++++ tests/Record/FromArrayTestCase.php | 2 ++ tests/Record/SynchronizeTestCase.php | 2 ++ tests/Search/FileTestCase.php | 2 ++ tests/TableTestCase.php | 4 ++-- tests/Ticket/1106TestCase.php | 2 ++ tests/Ticket/1131TestCase.php | 2 ++ tests/Ticket/1436TestCase.php | 4 ++++ tests/Ticket/1992TestCase.php | 4 ++++ tests/Ticket/2158TestCase.php | 2 ++ tests/Ticket/982TestCase.php | 5 ++++- 24 files changed, 67 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 338bb060d..73a7e5fa7 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -188,6 +188,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun */ protected $_tableCache; protected $_tableCacheTTL; + protected $exported; /** * the constructor diff --git a/lib/Doctrine/Hydrator/Graph.php b/lib/Doctrine/Hydrator/Graph.php index 88232a889..bb4ae6a24 100644 --- a/lib/Doctrine/Hydrator/Graph.php +++ b/lib/Doctrine/Hydrator/Graph.php @@ -35,7 +35,9 @@ */ abstract class Doctrine_Hydrator_Graph extends Doctrine_Hydrator_Abstract { - protected $_tables = array(); + protected + $_tables = array(), + $_rootAlias = null; /** * Gets the custom field used for indexing for the specified component alias. diff --git a/lib/Doctrine/Import/Builder.php b/lib/Doctrine/Import/Builder.php index 2ea5fc983..d27cd4206 100644 --- a/lib/Doctrine/Import/Builder.php +++ b/lib/Doctrine/Import/Builder.php @@ -36,6 +36,7 @@ * @author Nicolas Bérard-Nault * @author Jonathan H. Wage */ +#[\AllowDynamicProperties] class Doctrine_Import_Builder extends Doctrine_Builder { /** diff --git a/lib/Doctrine/RawSql.php b/lib/Doctrine/RawSql.php index 25c07317b..7fb3d9b7c 100644 --- a/lib/Doctrine/RawSql.php +++ b/lib/Doctrine/RawSql.php @@ -42,6 +42,11 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract * @var array $fields */ private $fields = array(); + /** + * @var false + */ + protected $_preQuery; + protected $_pendingJoinConditions; /** * Constructor. diff --git a/lib/Doctrine/Sequence/Mssql.php b/lib/Doctrine/Sequence/Mssql.php index 5b786560a..fff760886 100644 --- a/lib/Doctrine/Sequence/Mssql.php +++ b/lib/Doctrine/Sequence/Mssql.php @@ -32,6 +32,8 @@ */ class Doctrine_Sequence_Mssql extends Doctrine_Sequence { + protected $warnings; + /** * Returns the next free id of a sequence * diff --git a/lib/Doctrine/Task/BuildAll.php b/lib/Doctrine/Task/BuildAll.php index 2d5a4bb9d..07d07e216 100644 --- a/lib/Doctrine/Task/BuildAll.php +++ b/lib/Doctrine/Task/BuildAll.php @@ -37,6 +37,7 @@ class Doctrine_Task_BuildAll extends Doctrine_Task $optionalArguments = array(); protected $models, + $createDb, $tables; public function __construct($dispatcher = null) diff --git a/lib/Doctrine/Task/BuildAllLoad.php b/lib/Doctrine/Task/BuildAllLoad.php index 6b6d2fc5a..90e685a01 100644 --- a/lib/Doctrine/Task/BuildAllLoad.php +++ b/lib/Doctrine/Task/BuildAllLoad.php @@ -35,6 +35,9 @@ class Doctrine_Task_BuildAllLoad extends Doctrine_Task public $description = 'Calls build-all, and load-data', $requiredArguments = array(), $optionalArguments = array(); + + protected $buildAll, + $loadData; public function __construct($dispatcher = null) { diff --git a/lib/Doctrine/Task/BuildAllReload.php b/lib/Doctrine/Task/BuildAllReload.php index f06475cf2..1cd3c1aba 100644 --- a/lib/Doctrine/Task/BuildAllReload.php +++ b/lib/Doctrine/Task/BuildAllReload.php @@ -35,6 +35,9 @@ class Doctrine_Task_BuildAllReload extends Doctrine_Task public $description = 'Calls rebuild-db and load-data', $requiredArguments = array(), $optionalArguments = array(); + + protected $rebuildDb, + $loadData; public function __construct($dispatcher = null) { diff --git a/lib/Doctrine/Task/RebuildDb.php b/lib/Doctrine/Task/RebuildDb.php index 4a3e66581..ad9623f6d 100644 --- a/lib/Doctrine/Task/RebuildDb.php +++ b/lib/Doctrine/Task/RebuildDb.php @@ -35,6 +35,10 @@ class Doctrine_Task_RebuildDb extends Doctrine_Task public $description = 'Drops and re-creates databases', $requiredArguments = array(), $optionalArguments = array(); + + protected $dropDb, + $createDb, + $createTables; public function __construct($dispatcher = null) { diff --git a/tests/Cache/DbTestCase.php b/tests/Cache/DbTestCase.php index 91dc4563a..594103662 100644 --- a/tests/Cache/DbTestCase.php +++ b/tests/Cache/DbTestCase.php @@ -33,6 +33,8 @@ */ class Doctrine_Cache_Db_TestCase extends Doctrine_Cache_Abstract_TestCase { + protected $cache; + public function setUp() { parent::setUp(); diff --git a/tests/Connection/CustomTestCase.php b/tests/Connection/CustomTestCase.php index 815599ed9..6fd75b448 100644 --- a/tests/Connection/CustomTestCase.php +++ b/tests/Connection/CustomTestCase.php @@ -32,6 +32,9 @@ */ class Doctrine_Connection_Custom_TestCase extends Doctrine_UnitTestCase { + protected $_conn; + protected $_dbh; + public function setUp() { $manager = Doctrine_Manager::getInstance(); diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index 4883d28d7..a1f0fb2f7 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -53,7 +53,11 @@ class Doctrine_UnitTestCase extends UnitTestCase protected $dataDict; protected $transaction; protected $_name; - + protected $query; + protected $profiler; + protected $import; + protected $sequence; + protected $exc; protected $init = false; diff --git a/tests/DoctrineTest/GroupTest.php b/tests/DoctrineTest/GroupTest.php index 5e826c048..b17f5e37e 100644 --- a/tests/DoctrineTest/GroupTest.php +++ b/tests/DoctrineTest/GroupTest.php @@ -6,6 +6,8 @@ class GroupTest extends UnitTestCase protected $_title; protected $_onlyRunFailed = false; + protected $_formatter; + public function __construct($title, $name) { $this->_title = $title; diff --git a/tests/ManagerTestCase.php b/tests/ManagerTestCase.php index 780926147..752ce6a3f 100644 --- a/tests/ManagerTestCase.php +++ b/tests/ManagerTestCase.php @@ -32,6 +32,12 @@ */ class Doctrine_Manager_TestCase extends Doctrine_UnitTestCase { + protected $conn1_database; + protected $conn2_database; + + protected $conn1; + protected $conn2; + public function testGetInstance() { $this->assertTrue(Doctrine_Manager::getInstance() instanceOf Doctrine_Manager); } diff --git a/tests/Record/FromArrayTestCase.php b/tests/Record/FromArrayTestCase.php index bf0617dae..ee6922545 100755 --- a/tests/Record/FromArrayTestCase.php +++ b/tests/Record/FromArrayTestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Record_FromArray_TestCase extends Doctrine_UnitTestCase { + protected $previous_group; + public function prepareTables() { parent::prepareTables(); diff --git a/tests/Record/SynchronizeTestCase.php b/tests/Record/SynchronizeTestCase.php index 67027c15a..76457457b 100644 --- a/tests/Record/SynchronizeTestCase.php +++ b/tests/Record/SynchronizeTestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Record_Synchronize_TestCase extends Doctrine_UnitTestCase { + private $previous_group; + public function prepareTables() { parent::prepareTables(); diff --git a/tests/Search/FileTestCase.php b/tests/Search/FileTestCase.php index d592dbe7b..7f2a81c34 100644 --- a/tests/Search/FileTestCase.php +++ b/tests/Search/FileTestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Search_File_TestCase extends Doctrine_UnitTestCase { + protected $_search; + public function prepareData() { } public function prepareTables() diff --git a/tests/TableTestCase.php b/tests/TableTestCase.php index 793e9672e..3de7b5ce9 100644 --- a/tests/TableTestCase.php +++ b/tests/TableTestCase.php @@ -153,9 +153,9 @@ public function testGetData() public function testSetSequenceName() { - $this->objTable->sequenceName = 'test-seq'; + $this->objTable->setOption('sequenceName', 'test-seq'); $this->assertEqual($this->objTable->sequenceName, 'test-seq'); - $this->objTable->sequenceName = null; + $this->objTable->setOption('sequenceName', null); } public function testCreate() diff --git a/tests/Ticket/1106TestCase.php b/tests/Ticket/1106TestCase.php index 7468852f4..8bc5d6f8d 100644 --- a/tests/Ticket/1106TestCase.php +++ b/tests/Ticket/1106TestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Ticket_1106_TestCase extends Doctrine_UnitTestCase { + protected $user_id; + public function prepareTables() { parent::prepareTables(); diff --git a/tests/Ticket/1131TestCase.php b/tests/Ticket/1131TestCase.php index 2a90ebcb3..9291329d2 100644 --- a/tests/Ticket/1131TestCase.php +++ b/tests/Ticket/1131TestCase.php @@ -32,6 +32,8 @@ */ class Doctrine_Ticket_1131_TestCase extends Doctrine_UnitTestCase { + private $role_one, $role_two; + public function prepareTables() { //$this->tables = array(); diff --git a/tests/Ticket/1436TestCase.php b/tests/Ticket/1436TestCase.php index db30bd4b7..43ce87771 100644 --- a/tests/Ticket/1436TestCase.php +++ b/tests/Ticket/1436TestCase.php @@ -32,6 +32,10 @@ */ class Doctrine_Ticket_1436_TestCase extends Doctrine_UnitTestCase { + protected $group_one; + protected $group_two; + protected $group_three; + public function prepareTables() { parent::prepareTables(); diff --git a/tests/Ticket/1992TestCase.php b/tests/Ticket/1992TestCase.php index 7da049494..c7691df8f 100644 --- a/tests/Ticket/1992TestCase.php +++ b/tests/Ticket/1992TestCase.php @@ -32,6 +32,10 @@ */ class Doctrine_Ticket_1992_TestCase extends Doctrine_UnitTestCase { + protected $person; + protected $profile1; + protected $profile2; + public function prepareTables() { $this->tables[] = 'Ticket_1992_Person'; diff --git a/tests/Ticket/2158TestCase.php b/tests/Ticket/2158TestCase.php index 7531719c9..02d40cdd0 100644 --- a/tests/Ticket/2158TestCase.php +++ b/tests/Ticket/2158TestCase.php @@ -2,6 +2,8 @@ class Doctrine_Ticket_2158_TestCase extends Doctrine_UnitTestCase { + protected $myModel; + public function prepareTables() { $this->tables[] = "T2158_Model1"; diff --git a/tests/Ticket/982TestCase.php b/tests/Ticket/982TestCase.php index 781b305a1..d541ccd11 100644 --- a/tests/Ticket/982TestCase.php +++ b/tests/Ticket/982TestCase.php @@ -3,7 +3,10 @@ * Test to ensure LocalKey Relations allow 0 for id value */ class Doctrine_Ticket_982_TestCase extends Doctrine_UnitTestCase -{ +{ + protected $myModelOne; + protected $myModelTwo; + public function prepareTables() { $this->tables = array(); From a572748b57b387135f3e3fb504d52cddce2c96b6 Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Thu, 15 Dec 2022 11:14:46 +0100 Subject: [PATCH 24/59] PHP 8.2 > Using ${var} in strings is deprecated, use {$var} instead. --- lib/Doctrine/Cli/AnsiColorFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Cli/AnsiColorFormatter.php b/lib/Doctrine/Cli/AnsiColorFormatter.php index b3d1aa444..cca3afb7d 100644 --- a/lib/Doctrine/Cli/AnsiColorFormatter.php +++ b/lib/Doctrine/Cli/AnsiColorFormatter.php @@ -115,7 +115,7 @@ public function formatSection($section, $text, $size = null) { $width = 9 + strlen($this->format('', 'INFO')); - return sprintf(">> %-${width}s %s", $this->format($section, 'INFO'), $this->excerpt($text, $size)); + return sprintf(">> %-{$width}s %s", $this->format($section, 'INFO'), $this->excerpt($text, $size)); } /** From 72a9ff94e053f4e56274f1b84db59504f35931e6 Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Thu, 15 Dec 2022 11:15:02 +0100 Subject: [PATCH 25/59] PHP 8.0 > Trying to access array offset on value of type bool --- lib/Doctrine/Manager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index fe7560b4c..a2b08944d 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -411,6 +411,10 @@ protected function _buildDsnPartsArray($dsn) // silence any warnings $parts = @parse_url($dsn); + if ($parts === false) { + $parts = array(); + } + $names = array('dsn', 'scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'); foreach ($names as $name) { From 33bca654da7ccaee511ccb90c35aa28bcef2106d Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Thu, 15 Dec 2022 11:16:32 +0100 Subject: [PATCH 26/59] PHP 8.2 > added test environment --- .docker/{php74_81 => php74_82}/Dockerfile | 0 .github/workflows/continuous-integration.yml | 1 + docker-compose.yml | 13 ++++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) rename .docker/{php74_81 => php74_82}/Dockerfile (100%) diff --git a/.docker/php74_81/Dockerfile b/.docker/php74_82/Dockerfile similarity index 100% rename from .docker/php74_81/Dockerfile rename to .docker/php74_82/Dockerfile diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 800df6757..23e86a887 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -20,6 +20,7 @@ jobs: - "7.4" - "8.0" - "8.1" + - "8.2" steps: - name: "Checkout" diff --git a/docker-compose.yml b/docker-compose.yml index 98dfe7ab4..9c36afacc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -103,24 +103,31 @@ services: php74: <<: *services_php54 build: - context: .docker/php74_81 + context: .docker/php74_82 args: PHP_VERSION: '7.4' php80: <<: *services_php54 build: - context: .docker/php74_81 + context: .docker/php74_82 args: PHP_VERSION: '8.0' php81: <<: *services_php54 build: - context: .docker/php74_81 + context: .docker/php74_82 args: PHP_VERSION: '8.1' + php82: + <<: *services_php54 + build: + context: .docker/php74_82 + args: + PHP_VERSION: '8.2' + db: image: mysql:5.5.62 environment: From 0241c0b26cb95440a36ce25589275096d0329c07 Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Mon, 9 Jan 2023 22:06:26 +0100 Subject: [PATCH 27/59] PHP 8.2 > Removed properties from Doctrine_RawSql and used _preQueried in case of clear() and moved the property _pendingJoinConditions fom Doctrine_Query up to Doctrine_Query_Abstract in the hierarchy. --- lib/Doctrine/Query.php | 5 ----- lib/Doctrine/Query/Abstract.php | 5 +++++ lib/Doctrine/RawSql.php | 7 +------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 99f54a170..2ae35ee15 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -160,11 +160,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable */ protected $_parsers = array(); - /** - * @var array $_pendingJoinConditions an array containing pending joins - */ - protected $_pendingJoinConditions = array(); - /** * @var array */ diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 3025bd09e..6042ed18e 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -267,6 +267,11 @@ abstract class Doctrine_Query_Abstract */ protected $_preQueried = false; + /** + * @var array $_pendingJoinConditions an array containing pending joins + */ + protected $_pendingJoinConditions = array(); + /** * Fix for http://www.doctrine-project.org/jira/browse/DC-701 * diff --git a/lib/Doctrine/RawSql.php b/lib/Doctrine/RawSql.php index 7fb3d9b7c..73220e2e9 100644 --- a/lib/Doctrine/RawSql.php +++ b/lib/Doctrine/RawSql.php @@ -42,11 +42,6 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract * @var array $fields */ private $fields = array(); - /** - * @var false - */ - protected $_preQuery; - protected $_pendingJoinConditions; /** * Constructor. @@ -64,7 +59,7 @@ function __construct(Doctrine_Connection $connection = null, Doctrine_Hydrator_A protected function clear() { - $this->_preQuery = false; + $this->_preQueried = false; $this->_pendingJoinConditions = array(); } From 81c839b70c59ad417c8d9fbf8bdd100e2738c93c Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Tue, 10 Jan 2023 12:24:05 +0100 Subject: [PATCH 28/59] add double to type check. bug #88 --- lib/Doctrine/Record.php | 2 +- tests/RecordTestCase.php | 12 ++++++++++++ tests/models/Location2.php | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/models/Location2.php diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 4ab93f04d..c64c6465a 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1558,7 +1558,7 @@ protected function _isValueModified($type, $old, $new) if ($type == 'boolean' && (is_bool($old) || is_numeric($old)) && (is_bool($new) || is_numeric($new)) && $old == $new) { return false; - } else if (in_array($type, array('decimal', 'float')) && is_numeric($old) && is_numeric($new)) { + } else if (in_array($type, array('decimal', 'float', 'double')) && is_numeric($old) && is_numeric($new)) { return $old * 100 != $new * 100; } else if (in_array($type, array('integer', 'int')) && is_numeric($old) && is_numeric($new)) { return $old != $new; diff --git a/tests/RecordTestCase.php b/tests/RecordTestCase.php index b0b06efb5..dc818570b 100644 --- a/tests/RecordTestCase.php +++ b/tests/RecordTestCase.php @@ -41,6 +41,7 @@ public function prepareTables() $this->tables[] = 'Book'; $this->tables[] = 'EntityAddress'; $this->tables[] = 'UnderscoreColumn'; + $this->tables[] = 'Location2'; parent::prepareTables(); } @@ -1022,4 +1023,15 @@ public function testDeleteReturnBooleanAndThrowsException() $this->fail(); } } + + public function testDoubleIsModified() + { + $location = new Location2(); + $location->lat = '12.345'; + + $location->save(); + $location->lat = 12.345; + + $this->assertFalse($location->isModified()); + } } diff --git a/tests/models/Location2.php b/tests/models/Location2.php new file mode 100644 index 000000000..80ad551cf --- /dev/null +++ b/tests/models/Location2.php @@ -0,0 +1,10 @@ +hasColumn('id', 'integer', 10, array('primary' => true)); + $this->hasColumn('lat', 'double', 10); + $this->hasColumn('lon', 'double', 10); + } +} From 46257508243e038b7faf9f0620b603828e9e2b3c Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Sat, 11 Feb 2023 09:47:41 +0100 Subject: [PATCH 29/59] PHP 8.1 > Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated --- lib/Doctrine/Table.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 02659b761..0842bafc8 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -1179,6 +1179,10 @@ public function getColumnName($fieldName) return $this->_columnNames[$fieldName]; } + if (null === $fieldName) { + return ''; + } + return strtolower($fieldName); } From 8d045bd445180d82306d99455d5a7781e3fe7650 Mon Sep 17 00:00:00 2001 From: thePanz Date: Fri, 17 Nov 2023 17:43:45 +0100 Subject: [PATCH 30/59] Update(github) Update github workflows, use composer caches --- .github/workflows/continuous-integration.yml | 76 +++++++++++--------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 23e86a887..210a6d22f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,39 +1,51 @@ name: "Continuous Integration" on: - push: - branches: - - master - pull_request: + push: + branches: + - master + pull_request: env: - fail-fast: true + fail-fast: true jobs: - tests: - name: "Doctrine1 Tests" - runs-on: "ubuntu-22.04" - - strategy: - matrix: - php-version: - - "7.4" - - "8.0" - - "8.1" - - "8.2" - - steps: - - name: "Checkout" - uses: "actions/checkout@v3" - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.23.0" - with: - php-version: "${{ matrix.php-version }}" - # extensions: "${{ matrix.extension }}" - - - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@2.2.0" - - - name: "Run Tests" - run: "cd tests && php run.php" + tests: + name: "Doctrine1 Tests" + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" + - "8.0" + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: "true" + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php-version }}" + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist + + - name: Run Tests + run: cd tests && php run.php From 0978095bf51d95a8875df705c590a21363cec797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Pf=C3=A4hler?= <10995809+paddyhamburg@users.noreply.github.com> Date: Tue, 27 Jun 2023 14:55:03 +0200 Subject: [PATCH 31/59] Fix array key access in lib/Doctrine/Import/Builder.php Co-authored-by: Alexandre Quercia --- lib/Doctrine/Import/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Import/Builder.php b/lib/Doctrine/Import/Builder.php index d27cd4206..7dc64d4ab 100644 --- a/lib/Doctrine/Import/Builder.php +++ b/lib/Doctrine/Import/Builder.php @@ -783,7 +783,7 @@ public function buildPhpDocs(array $definition) if (isset($definition['relations']) && ! empty($definition['relations'])) { foreach ($definition['relations'] as $relation) { $type = (isset($relation['type']) && $relation['type'] == Doctrine_Relation::MANY) ? 'Doctrine_Collection' : $this->_classPrefix . $relation['class']; - if ($relation["type"] == Doctrine_Relation::ONE) { + if ((isset($relation['type']) ? $relation['type'] : null) == Doctrine_Relation::ONE) { $properties[] = array($relation['class'], $relation['alias'], ""); $getters[] = array($relation['class'], $relation['alias'], ""); $setters[] = array($definition['topLevelClassName'], $relation['alias'], $relation['class'], ""); From 9b426e67eb8ca9d883e4988e0da901d689b0e6fb Mon Sep 17 00:00:00 2001 From: Emanuele Panzeri Date: Wed, 17 Jan 2024 15:51:02 +0100 Subject: [PATCH 32/59] CI: add PHP v8.3 to the CI pipelines (#108) --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 210a6d22f..bfc4e4b41 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -21,6 +21,7 @@ jobs: - "8.0" - "8.1" - "8.2" + - "8.3" steps: - name: Checkout From 46791a337e2af53b815cb56acd92dee6719b46da Mon Sep 17 00:00:00 2001 From: thePanz Date: Wed, 17 Jan 2024 15:31:23 +0100 Subject: [PATCH 33/59] Remove PHP Pear configurations --- build.properties.dev | 11 - build.xml | 94 --- package.xml | 1625 ------------------------------------------ 3 files changed, 1730 deletions(-) delete mode 100644 build.properties.dev delete mode 100644 build.xml delete mode 100644 package.xml diff --git a/build.properties.dev b/build.properties.dev deleted file mode 100644 index e7f708229..000000000 --- a/build.properties.dev +++ /dev/null @@ -1,11 +0,0 @@ -version=1.2.3 -stability=stable -build.dir=build -dist.dir=dist -report.dir=reports -log.archive.dir=logs -test.phpunit_configuration_file= -test.phpunit_generate_coverage=0 -test.pmd_reports=0 -test.pdepend_exec= -test.phpmd_exec= \ No newline at end of file diff --git a/build.xml b/build.xml deleted file mode 100644 index 5ff0aea54..000000000 --- a/build.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Doctrine - PHP5 Database ORM - pear.doctrine-project.org - -Doctrine is an ORM (object relational mapper) for PHP 5.2.x+ that sits on top of -a powerful DBAL (database abstraction layer). One of its key features is the -ability to optionally write database queries in an OO (object oriented) -SQL-dialect called DQL inspired by Hibernates HQL. This provides developers with -a powerful alternative to SQL that maintains a maximum of flexibility without -requiring needless code duplication. - - - LGPL - - - - - - - - - - - - - \ No newline at end of file diff --git a/package.xml b/package.xml deleted file mode 100644 index 056831624..000000000 --- a/package.xml +++ /dev/null @@ -1,1625 +0,0 @@ - - - Doctrine - pear.doctrine-project.org - PHP5 Database ORM - Doctrine is an ORM (object relational mapper) for PHP 5.2.x+ that sits on top of -a powerful DBAL (database abstraction layer). One of its key features is the -ability to optionally write database queries in an OO (object oriented) -SQL-dialect called DQL inspired by Hibernates HQL. This provides developers with -a powerful alternative to SQL that maintains a maximum of flexibility without -requiring needless code duplication. - - Konsta Vesterinen - zYne- - kvesteri@cc.hut.fi - yes - - - Jonathan H. Wage - jwage - jonwage@gmail.com - yes - - 2010-03-29 - - - 1.2.2 - 1.2.2 - - - stable - stable - - LGPL license - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5.2.3 - - - 1.4.0b1 - - - PEAR - pear.php.net - 1.3.6 - - - pdo - - - - - pdo_dblib - - - pdo_mysql - - - pdo_odbc - - - pdo_sqlite - - - pdo_oci - - - pdo_pgsql - - - - - - - - 1.2.2 - 1.2.2 - - - stable - stable - - 2010-03-29 - LGPL license - -- - - - - - 1.2.1 - 1.2.1 - - - stable - stable - - 2009-12-07 - LGPL license - -- - - - - - 1.2.0 - 1.2.0 - - - stable - stable - - 2009-11-30 - LGPL license - -- - - - - - 1.1.2 - 1.1.2 - - - stable - stable - - 2009-06-15 - LGPL license - -- - - - - - 1.1.1 - 1.1.1 - - - stable - stable - - 2009-05-11 - LGPL license - -- - - - - - 1.1.0 - 1.1.0 - - - stable - stable - - 2009-03-16 - LGPL license - -- - - - - - 1.0.2 - 1.0.2 - - - stable - stable - - 2008-09-11 - LGPL license - -- - - - - - 1.0.1 - 1.0.1 - - - stable - stable - - 2008-09-09 - LGPL license - -- - - - - - 1.0.0 - 1.0.0 - - - stable - stable - - 2008-09-01 - LGPL license - -- - - - - - 0.11.0 - 0.11.0 - - - stable - stable - - 2008-06-23 - LGPL license - -- - - - - - 0.10.4 - 0.10.4 - - - beta - beta - - 2008-03-28 - LGPL license - -- - - - - - 0.10.3 - 0.10.3 - - - beta - beta - - 2008-03-18 - LGPL license - -- - - - - - 0.10.2 - 0.10.2 - - - beta - beta - - 2008-03-01 - LGPL license - -- - - - - - 0.10.1 - 0.10.1 - - - beta - beta - - 2008-02-29 - LGPL license - -- - - - - - 0.10.0 - 0.10.0 - - - beta - beta - - 2008-02-13 - LGPL license - -- - - - - - 0.9 - 0.9 - - - beta - beta - - 2008-02-06 - MIT license - -barfoo - - - - From 5ec53b7b7a4bbc46a20cad7e2f367a7b9af83ad7 Mon Sep 17 00:00:00 2001 From: thePanz Date: Wed, 17 Jan 2024 15:31:46 +0100 Subject: [PATCH 34/59] Update GitAttributes file --- .gitattributes | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitattributes b/.gitattributes index 884d89b58..bf85d2fd1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,8 @@ +/.docker export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.travis.yml export-ignore -/build.properties.dev export-ignore -/build.xml export-ignore +/.github export-ignore + +/docker-compose.yml /tests export-ignore /tools export-ignore From 0df2b8b1ddaa5bc5f36eb30601f14a09287b425a Mon Sep 17 00:00:00 2001 From: thePanz Date: Wed, 17 Jan 2024 15:22:14 +0100 Subject: [PATCH 35/59] Fix PHP deprecations on ArrayAccess and additional classes --- lib/Doctrine/Access.php | 33 ++----- lib/Doctrine/Connection/Common.php | 5 +- lib/Doctrine/Hydrator.php | 14 +-- lib/Doctrine/Hydrator/Abstract.php | 7 +- .../Hydrator/ArrayHierarchyDriver.php | 5 +- lib/Doctrine/Hydrator/ArrayShallowDriver.php | 5 +- lib/Doctrine/Hydrator/Graph.php | 3 + lib/Doctrine/Hydrator/NoneDriver.php | 5 +- .../Hydrator/RecordHierarchyDriver.php | 5 +- lib/Doctrine/Hydrator/ScalarDriver.php | 9 +- lib/Doctrine/Hydrator/SingleScalarDriver.php | 6 +- lib/Doctrine/Locator/Injectable.php | 16 ++-- lib/Doctrine/Record.php | 86 +++++++++---------- lib/Doctrine/Relation.php | 36 +++++--- lib/Doctrine/Table.php | 6 +- 15 files changed, 130 insertions(+), 111 deletions(-) diff --git a/lib/Doctrine/Access.php b/lib/Doctrine/Access.php index 82204abc9..f066e7f4a 100644 --- a/lib/Doctrine/Access.php +++ b/lib/Doctrine/Access.php @@ -96,10 +96,7 @@ public function __unset($name) } /** - * Check if an offset axists - * - * @param mixed $offset - * @return boolean Whether or not this object contains $offset + * @return bool */ #[\ReturnTypeWillChange] public function offsetExists($offset) @@ -108,10 +105,6 @@ public function offsetExists($offset) } /** - * An alias of get() - * - * @see get, __get - * @param mixed $offset * @return mixed */ #[\ReturnTypeWillChange] @@ -127,11 +120,6 @@ public function offsetGet($offset) } /** - * Sets $offset to $value - * - * @see set, __set - * @param mixed $offset - * @param mixed $value * @return void */ #[\ReturnTypeWillChange] @@ -145,22 +133,19 @@ public function offsetSet($offset, $value) } /** - * Unset a given offset - * - * @see set, offsetSet, __set - * @param mixed $offset + * @return void */ #[\ReturnTypeWillChange] public function offsetUnset($offset) { - return $this->remove($offset); + $this->remove($offset); } /** * Remove the element with the specified offset * * @param mixed $offset The offset to remove - * @return boolean True if removed otherwise false + * @return bool True if removed otherwise false */ public function remove($offset) { @@ -191,8 +176,8 @@ public function set($offset, $value) } /** - * Check if the specified offset exists - * + * Check if the specified offset exists + * * @param mixed $offset The offset to check * @return boolean True if exists otherwise false */ @@ -202,9 +187,9 @@ public function contains($offset) } /** - * Add the value - * - * @param mixed $value The value to add + * Add the value + * + * @param mixed $value The value to add * @return void */ public function add($value) diff --git a/lib/Doctrine/Connection/Common.php b/lib/Doctrine/Connection/Common.php index 1f1aa21b6..36f7e286c 100644 --- a/lib/Doctrine/Connection/Common.php +++ b/lib/Doctrine/Connection/Common.php @@ -38,12 +38,13 @@ class Doctrine_Connection_Common extends Doctrine_Connection * @param string $query * @param mixed $limit * @param mixed $offset + * @return string */ public function modifyLimitQuery($query, $limit = false,$offset = false,$isManip=false) { $limit = (int) $limit; $offset = (int) $offset; - + if ($limit && $offset) { $query .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; } elseif ($limit && ! $offset) { @@ -54,4 +55,4 @@ public function modifyLimitQuery($query, $limit = false,$offset = false,$isManip return $query; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator.php b/lib/Doctrine/Hydrator.php index 05ab94599..129743e32 100644 --- a/lib/Doctrine/Hydrator.php +++ b/lib/Doctrine/Hydrator.php @@ -51,7 +51,7 @@ public function __construct() /** * Set the hydration mode * - * @param mixed $hydrationMode One of the Doctrine_Core::HYDRATE_* constants or + * @param mixed $hydrationMode One of the Doctrine_Core::HYDRATE_* constants or * a string representing the name of the hydration mode or * or an instance of the hydration class */ @@ -112,9 +112,9 @@ public function getHydratorDriverClassName($mode = null) /** * Get an instance of the hydration driver for the passed hydration mode * - * @param string $mode - * @param array $tableAliases - * @return object Doctrine_Hydrator_Abstract + * @param string $mode + * @param array $tableAliases + * @return Doctrine_Hydrator_Abstract */ public function getHydratorDriver($mode, $tableAliases) { @@ -138,8 +138,8 @@ public function getHydratorDriver($mode, $tableAliases) * Hydrate the query statement in to its final data structure by one of the * hydration drivers. * - * @param object $stmt - * @param array $tableAliases + * @param object $stmt + * @param array $tableAliases * @return mixed $result */ public function hydrateResultSet($stmt, $tableAliases) @@ -149,4 +149,4 @@ public function hydrateResultSet($stmt, $tableAliases) return $result; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/Abstract.php b/lib/Doctrine/Hydrator/Abstract.php index a603e5fd7..3a4dc7dc4 100644 --- a/lib/Doctrine/Hydrator/Abstract.php +++ b/lib/Doctrine/Hydrator/Abstract.php @@ -97,11 +97,11 @@ public function onDemandReset() * (I.e. ORACLE limit/offset emulation adds doctrine_rownum to the result set). * * @param string $name - * @return boolean + * @return bool */ protected function _isIgnoredName($name) { - return $name == 'DOCTRINE_ROWNUM'; + return $name === 'DOCTRINE_ROWNUM'; } /** @@ -114,8 +114,7 @@ protected function _isIgnoredName($name) * The key idea is the loop over the rowset only once doing all the needed operations * within this massive loop. * - * @param mixed $stmt * @return mixed */ abstract public function hydrateResultSet($stmt); -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/ArrayHierarchyDriver.php b/lib/Doctrine/Hydrator/ArrayHierarchyDriver.php index ae281eb47..731ad0090 100644 --- a/lib/Doctrine/Hydrator/ArrayHierarchyDriver.php +++ b/lib/Doctrine/Hydrator/ArrayHierarchyDriver.php @@ -32,6 +32,9 @@ */ class Doctrine_Hydrator_ArrayHierarchyDriver extends Doctrine_Hydrator_ArrayDriver { + /** + * @return array + */ public function hydrateResultSet($stmt) { $collection = parent::hydrateResultSet($stmt); @@ -80,4 +83,4 @@ public function hydrateResultSet($stmt) } return $trees; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/ArrayShallowDriver.php b/lib/Doctrine/Hydrator/ArrayShallowDriver.php index cad4a3424..b595122b6 100644 --- a/lib/Doctrine/Hydrator/ArrayShallowDriver.php +++ b/lib/Doctrine/Hydrator/ArrayShallowDriver.php @@ -32,6 +32,9 @@ */ class Doctrine_Hydrator_ArrayShallowDriver extends Doctrine_Hydrator_ScalarDriver { + /** + * @return array + */ public function hydrateResultSet($stmt) { $cache = array(); @@ -41,4 +44,4 @@ public function hydrateResultSet($stmt) } return $result; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/Graph.php b/lib/Doctrine/Hydrator/Graph.php index bb4ae6a24..8578f4871 100644 --- a/lib/Doctrine/Hydrator/Graph.php +++ b/lib/Doctrine/Hydrator/Graph.php @@ -50,6 +50,9 @@ protected function _getCustomIndexField($alias) return isset($this->_queryComponents[$alias]['map']) ? $this->_queryComponents[$alias]['map'] : null; } + /** + * @return Doctrine_Collection|mixed + */ public function hydrateResultSet($stmt) { // Used variables during hydration diff --git a/lib/Doctrine/Hydrator/NoneDriver.php b/lib/Doctrine/Hydrator/NoneDriver.php index d4ed09dd7..6da15a6d6 100644 --- a/lib/Doctrine/Hydrator/NoneDriver.php +++ b/lib/Doctrine/Hydrator/NoneDriver.php @@ -33,8 +33,11 @@ */ class Doctrine_Hydrator_NoneDriver extends Doctrine_Hydrator_Abstract { + /** + * @return mixed + */ public function hydrateResultSet($stmt) { return $stmt->fetchAll(PDO::FETCH_NUM); } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/RecordHierarchyDriver.php b/lib/Doctrine/Hydrator/RecordHierarchyDriver.php index f32055d0f..28c54e20e 100644 --- a/lib/Doctrine/Hydrator/RecordHierarchyDriver.php +++ b/lib/Doctrine/Hydrator/RecordHierarchyDriver.php @@ -32,8 +32,11 @@ */ class Doctrine_Hydrator_RecordHierarchyDriver extends Doctrine_Hydrator_RecordDriver { + /** + * @return Doctrine_Collection + */ public function hydrateResultSet($stmt) { return parent::hydrateResultSet($stmt)->toHierarchy(); } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/ScalarDriver.php b/lib/Doctrine/Hydrator/ScalarDriver.php index 894ff3f50..d3ce87e66 100644 --- a/lib/Doctrine/Hydrator/ScalarDriver.php +++ b/lib/Doctrine/Hydrator/ScalarDriver.php @@ -32,6 +32,9 @@ */ class Doctrine_Hydrator_ScalarDriver extends Doctrine_Hydrator_Abstract { + /** + * @return array + */ public function hydrateResultSet($stmt) { $cache = array(); @@ -55,7 +58,7 @@ protected function _gatherRowData($data, &$cache, $aliasPrefix = true) } // cache general information like the column name <-> field name mapping $e = explode('__', $key); - $columnName = strtolower(array_pop($e)); + $columnName = strtolower(array_pop($e)); $cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))]; $table = $this->_queryComponents[$cache[$key]['dqlAlias']]['table']; // check whether it's an aggregate value or a regular field @@ -84,7 +87,7 @@ protected function _gatherRowData($data, &$cache, $aliasPrefix = true) $fieldName = $cache[$key]['fieldName']; $rowDataKey = $aliasPrefix ? $dqlAlias . '_' . $fieldName:$fieldName; - + if ($cache[$key]['isSimpleType'] || $cache[$key]['isAgg']) { $rowData[$rowDataKey] = $value; } else { @@ -94,4 +97,4 @@ protected function _gatherRowData($data, &$cache, $aliasPrefix = true) } return $rowData; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Hydrator/SingleScalarDriver.php b/lib/Doctrine/Hydrator/SingleScalarDriver.php index ebcad6230..bf7589522 100644 --- a/lib/Doctrine/Hydrator/SingleScalarDriver.php +++ b/lib/Doctrine/Hydrator/SingleScalarDriver.php @@ -32,6 +32,10 @@ */ class Doctrine_Hydrator_SingleScalarDriver extends Doctrine_Hydrator_Abstract { + /** + * @param mixed $stmt + * @return array|mixed + */ public function hydrateResultSet($stmt) { $result = array(); @@ -44,4 +48,4 @@ public function hydrateResultSet($stmt) return $result; } } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Locator/Injectable.php b/lib/Doctrine/Locator/Injectable.php index 884042dcd..b32ccf404 100644 --- a/lib/Doctrine/Locator/Injectable.php +++ b/lib/Doctrine/Locator/Injectable.php @@ -66,7 +66,7 @@ public function setLocator(Doctrine_Locator $locator) /** * getLocator * returns the locator associated with this object - * + * * if there are no locator locally associated then * this method tries to fetch the current global locator * @@ -101,7 +101,7 @@ public function locate($name) } else { // get the name of the concrete implementation $concreteImpl = $this->_resources[$name]; - + return $this->getLocator()->locate($concreteImpl); } } else { @@ -115,13 +115,13 @@ public function locate($name) * * @param string $name the name of the resource to bind * @param mixed $value the value of the resource - * @return Doctrine_Locator this object + * @return static this object */ - public function bind($name, $resource) + public function bind($name, $value) { - $this->_resources[$name] = $resource; - - return $this; + $this->_resources[$name] = $value; + + return $this; } /** @@ -146,4 +146,4 @@ public static function getNullObject() { return self::$_null; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index c64c6465a..2a2d92c06 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -151,7 +151,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * @var string */ protected $_pendingDeletes = array(); - + /** * Array of pending un links in format alias => keys to be executed after save * @@ -259,7 +259,7 @@ public function __construct($table = null, $isNewEntry = false) } $repository = $this->_table->getRepository(); - + // Fix for #1682 and #1841. // Doctrine_Table does not have the repository yet during dummy record creation. if ($repository) { @@ -399,9 +399,9 @@ public function isValid($deep = false, $hooks = true) $event = new Doctrine_Event($this, Doctrine_Event::RECORD_VALIDATE); $this->preValidate($event); $this->getTable()->getRecordListener()->preValidate($event); - + if ( ! $event->skipOperation) { - + $validator = new Doctrine_Validator(); $validator->validateRecord($this); $this->validate(); @@ -553,7 +553,7 @@ public function postInsert($event) /** * Empty template method to provide concrete Record classes with the possibility - * to hook into the validation procedure. Useful for cleaning up data before + * to hook into the validation procedure. Useful for cleaning up data before * validating it. */ public function preValidate($event) @@ -587,14 +587,14 @@ public function preDqlDelete($event) { } /** - * Empty template method to provide Record classes with the ability to alter hydration + * Empty template method to provide Record classes with the ability to alter hydration * before it runs */ public function preHydrate($event) { } /** - * Empty template method to provide Record classes with the ability to alter hydration + * Empty template method to provide Record classes with the ability to alter hydration * after it runs */ public function postHydrate($event) @@ -633,7 +633,7 @@ public function getErrorStack() if ( ! $this->_errorStack) { $this->_errorStack = new Doctrine_Validator_ErrorStack(get_class($this)); } - + return $this->_errorStack; } @@ -944,7 +944,7 @@ public function state($state = null) if ($state == null) { return $this->_state; } - + $err = false; if (is_integer($state)) { if ($state >= 1 && $state <= 7) { @@ -1090,7 +1090,7 @@ public function clearRelated($name = null) * in order to check. If the reference didn't already exist and it doesn't * exist in the database, the related reference will be cleared immediately. * - * @param string $name + * @param string $name * @return boolean Whether or not the related relationship exists */ public function relatedExists($name) @@ -1170,18 +1170,18 @@ public function load(array $data = array()) // only load the data from database if the Doctrine_Record is in proxy state if ($this->exists() && $this->isInProxyState()) { $id = $this->identifier(); - + if ( ! is_array($id)) { $id = array($id); } - + if (empty($id)) { return false; } $table = $this->getTable(); $data = empty($data) ? $table->find($id, Doctrine_Core::HYDRATE_ARRAY) : $data; - + if (is_array($data)) { foreach ($data as $field => $value) { if ($table->hasField($field) && ( ! array_key_exists($field, $this->_data) || $this->_data[$field] === self::$_null)) { @@ -1189,19 +1189,19 @@ public function load(array $data = array()) } } } - + if ($this->isModified()) { $this->_state = Doctrine_Record::STATE_DIRTY; } else if (!$this->isInProxyState()) { $this->_state = Doctrine_Record::STATE_CLEAN; } - + return true; } - + return false; } - + /** * indicates whether record has any not loaded fields * @@ -1225,8 +1225,8 @@ public function isInProxyState() * sets a fieldname to have a custom accessor or check if a field has a custom * accessor defined (when called without $accessor parameter). * - * @param string $fieldName - * @param string $accessor + * @param string $fieldName + * @param string $accessor * @return boolean */ public function hasAccessor($fieldName, $accessor = null) @@ -1242,7 +1242,7 @@ public function hasAccessor($fieldName, $accessor = null) /** * clears the accessor for a field name * - * @param string $fieldName + * @param string $fieldName * @return void */ public function clearAccessor($fieldName) @@ -1254,7 +1254,7 @@ public function clearAccessor($fieldName) /** * gets the custom accessor for a field name * - * @param string $fieldName + * @param string $fieldName * @return string $accessor */ public function getAccessor($fieldName) @@ -1280,8 +1280,8 @@ public function getAccessors() * sets a fieldname to have a custom mutator or check if a field has a custom * mutator defined (when called without the $mutator parameter) * - * @param string $fieldName - * @param string $mutator + * @param string $fieldName + * @param string $mutator * @return boolean */ public function hasMutator($fieldName, $mutator = null) @@ -1297,7 +1297,7 @@ public function hasMutator($fieldName, $mutator = null) /** * gets the custom mutator for a field name * - * @param string $fieldname + * @param string $fieldname * @return string */ public function getMutator($fieldName) @@ -1311,7 +1311,7 @@ public function getMutator($fieldName) /** * clears the custom mutator for a field name * - * @param string $fieldName + * @param string $fieldName * @return void */ public function clearMutator($fieldName) @@ -1357,7 +1357,7 @@ public function get($fieldName, $load = true) if ($this->_table->getAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE) || $this->hasAccessor($fieldName)) { $componentName = $this->_table->getComponentName(); - $accessor = $this->hasAccessor($fieldName) + $accessor = $this->hasAccessor($fieldName) ? $this->getAccessor($fieldName) : 'get' . Doctrine_Inflector::classify($fieldName); @@ -1388,10 +1388,10 @@ protected function _get($fieldName, $load = true) } else { $value = $this->_data[$fieldName]; } - + return $value; } - + try { if ( ! isset($this->_references[$fieldName])) { if ($load) { @@ -1494,10 +1494,10 @@ protected function _set($fieldName, $value, $load = true) } else { $old = $this->_data[$fieldName]; } - + if ($this->_isValueModified($type, $old, $value)) { if ($value === null) { - $value = $this->_table->getDefaultValueOf($fieldName); + $value = $this->_table->getDefaultValueOf($fieldName); } $this->_data[$fieldName] = $value; $this->_modified[] = $fieldName; @@ -1578,7 +1578,7 @@ protected function _isValueModified($type, $old, $new) /** * Places a related component in the object graph. * - * This method inserts a related component instance in this record + * This method inserts a related component instance in this record * relations, populating the foreign keys accordingly. * * @param string $name related component alias in the relation @@ -1588,11 +1588,11 @@ protected function _isValueModified($type, $old, $new) public function coreSetRelated($name, $value) { $rel = $this->_table->getRelation($name); - + if ($value === null) { $value = self::$_null; } - + // one-to-many or one-to-one relation if ($rel instanceof Doctrine_Relation_ForeignKey || $rel instanceof Doctrine_Relation_LocalKey) { if ( ! $rel->isOneToOne()) { @@ -1782,7 +1782,7 @@ public function replace(Doctrine_Connection $conn = null) /** * retrieves an array of modified fields and associated new values. - * + * * @param boolean $old pick the old values (instead of the new ones) * @param boolean $last pick only lastModified values (@see getLastModified()) * @return array $a @@ -1794,8 +1794,8 @@ public function getModified($old = false, $last = false) $modified = $last ? $this->_lastModified:$this->_modified; foreach ($modified as $fieldName) { if ($old) { - $a[$fieldName] = isset($this->_oldValues[$fieldName]) - ? $this->_oldValues[$fieldName] + $a[$fieldName] = isset($this->_oldValues[$fieldName]) + ? $this->_oldValues[$fieldName] : $this->getTable()->getDefaultValueOf($fieldName); } else { $a[$fieldName] = $this->_data[$fieldName]; @@ -1819,7 +1819,7 @@ public function getLastModified($old = false) * Retrieves data prepared for a sql transaction. * * Returns an array of modified fields and values with data preparation; - * adds column aggregation inheritance and converts Records into primary + * adds column aggregation inheritance and converts Records into primary * key values. * * @param array $array @@ -1914,10 +1914,10 @@ public function toArray($deep = true, $prefixKey = false) if ($this->_state == self::STATE_LOCKED || $this->_state == self::STATE_TLOCKED) { return false; } - + $stateBeforeLock = $this->_state; $this->_state = $this->exists() ? self::STATE_LOCKED : self::STATE_TLOCKED; - + $a = array(); foreach ($this as $column => $value) { @@ -2455,7 +2455,7 @@ public function unlink($alias, $ids = array(), $now = false) // fix for #1622 if ( ! isset($this->_references[$alias]) && $this->hasRelation($alias)) { $this->loadReference($alias); - } + } $allIds = array(); if (isset($this->_references[$alias])) { @@ -2635,8 +2635,8 @@ public function linkInDb($alias, $ids) } /** - * Reset the modified array and store the old array in lastModified so it - * can be accessed by users after saving a record, since the modified array + * Reset the modified array and store the old array in lastModified so it + * can be accessed by users after saving a record, since the modified array * is reset after the object is saved. * * @return void @@ -2689,7 +2689,7 @@ public function deleteNode() { $this->getNode()->delete(); } - + /** * Helps freeing the memory occupied by the entity. * Cuts all references the entity has to other entities and removes the entity diff --git a/lib/Doctrine/Relation.php b/lib/Doctrine/Relation.php index df83c3aa5..cbdcb6ff2 100644 --- a/lib/Doctrine/Relation.php +++ b/lib/Doctrine/Relation.php @@ -41,12 +41,12 @@ abstract class Doctrine_Relation implements ArrayAccess * constant for ONE_TO_ONE and MANY_TO_ONE relationships */ const ONE = 0; - + /** * constant for MANY_TO_MANY and ONE_TO_MANY relationships */ const MANY = 1; - + // TRUE => mandatory, everything else is just a default value. this should be refactored // since TRUE can bot be used as a default value this way. All values should be default values. /** @@ -93,10 +93,10 @@ abstract class Doctrine_Relation implements ArrayAccess * refTable the reference table object (if any) * * onDelete referential delete action - * + * * onUpdate referential update action * - * deferred deferred constraint checking + * deferred deferred constraint checking * * alias relation alias * @@ -114,10 +114,10 @@ abstract class Doctrine_Relation implements ArrayAccess * in the parent table or in the child table. * * SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the - * child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier + * child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier * specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported. * - * NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary + * NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary * key value is not allowed to proceed if there is a related foreign key value in the referenced table. * * RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as @@ -135,7 +135,7 @@ public function __construct(array $definition) if (isset($definition[$key])) { $def[$key] = $definition[$key]; } else { - $def[$key] = $this->definition[$key]; + $def[$key] = $this->definition[$key]; } } $this->definition = $def; @@ -169,22 +169,31 @@ public function isEqual() return $this->definition['equal']; } + /** + * @return bool + */ #[\ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->definition[$offset]); } + /** + * @return mixed + */ #[\ReturnTypeWillChange] public function offsetGet($offset) { if (isset($this->definition[$offset])) { return $this->definition[$offset]; } - + return null; } + /** + * @return void + */ #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { @@ -193,6 +202,9 @@ public function offsetSet($offset, $value) } } + /** + * @return void + */ #[\ReturnTypeWillChange] public function offsetUnset($offset) { @@ -204,7 +216,7 @@ public function offsetUnset($offset) * * @return array */ - public function toArray() + public function toArray() { return $this->definition; } @@ -231,7 +243,7 @@ final public function getType() { return $this->definition['type']; } - + /** * Checks whether this relation cascades deletions to the related objects * on the application level. @@ -277,7 +289,7 @@ final public function getLocal() { return $this->definition['local']; } - + /** * getLocalFieldName * returns the field name of the local column @@ -309,7 +321,7 @@ final public function getForeign() { return $this->definition['foreign']; } - + /** * getLocalFieldName * returns the field name of the foreign column diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 0842bafc8..faac80574 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -963,7 +963,7 @@ public function bind($args, $type) * @param string $componentName the name of the related component * @param string $options relation options * @see Doctrine_Relation::_$definition - * @return Doctrine_Record this object + * @return void */ public function hasOne() { @@ -976,7 +976,7 @@ public function hasOne() * @param string $componentName the name of the related component * @param string $options relation options * @see Doctrine_Relation::_$definition - * @return Doctrine_Record this object + * @return void */ public function hasMany() { @@ -992,7 +992,7 @@ public function hasMany() * side. * * @param string $alias the relation alias to search for. - * @return boolean true if the relation exists. Otherwise false. + * @return bool true if the relation exists. Otherwise false. */ public function hasRelation($alias) { From 2373ce38d0a933b36ca9b78a6fea76c55324ee59 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 20 Jan 2024 16:14:52 +0100 Subject: [PATCH 36/59] fix(Query): add failed test for column added twice with custom aliases --- tests/Ticket/585TestCase.php | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/Ticket/585TestCase.php diff --git a/tests/Ticket/585TestCase.php b/tests/Ticket/585TestCase.php new file mode 100644 index 000000000..9c2ed8f5c --- /dev/null +++ b/tests/Ticket/585TestCase.php @@ -0,0 +1,70 @@ +. + */ + +class Doctrine_Ticket_585_TestCase extends Doctrine_UnitTestCase +{ + private function doTestWithAllColumnsAliased($hydrateType, $expectedKeys) + { + try { + $query = Doctrine_Query::create() + ->select('u.id as aliasId, u.name as aliasName') + ->from('User u') + ->leftJoin('u.Email e') + ; + + $results = $query->execute(array(), $hydrateType); + + $expectedSql = 'SELECT e.id AS e__0, e.name AS e__1 FROM entity e LEFT JOIN email e2 ON e.email_id = e2.id WHERE (e.type = 0)'; + + $this->assertEqual($expectedSql, $query->getSqlQuery()); + $this->assertEqual($expectedKeys, array_keys($results[0])); + $this->assertEqual(count($this->users), count($results)); + + $this->pass(); + } catch (Exception $e) { + $this->fail($e->getMessage()); + } + } + + public function test_hydrateScalar_withAllColumnsAliased_thenResultsHasAllRecords() + { + $hydrateType = Doctrine_Core::HYDRATE_SCALAR; + $expectedKeys = array('u_aliasId', 'u_aliasName'); + + $this->doTestWithAllColumnsAliased($hydrateType, $expectedKeys); + } + + public function test_hydrateArrayShallow_withAllColumnsAliased_thenResultsHasAllRecords() + { + $hydrateType = Doctrine_Core::HYDRATE_ARRAY_SHALLOW; + $expectedKeys = array('aliasId', 'aliasName'); + + $this->doTestWithAllColumnsAliased($hydrateType, $expectedKeys); + } + + public function test_hydrateArray_withAllColumnsAliased_thenResultsHasAllRecords() + { + $hydrateType = Doctrine_Core::HYDRATE_ARRAY; + $expectedKeys = array('aliasId', 'aliasName'); + + $this->doTestWithAllColumnsAliased($hydrateType, $expectedKeys); + } +} From 29961c70864cf56c69c0f08740406067cf0bf114 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 20 Jan 2024 16:15:37 +0100 Subject: [PATCH 37/59] Revert "Added fields with alias to pendingFields array, fixed DC-585" This reverts commit e3ae69c2260dae6dfbceb4e24138b2379f3da2e6. --- lib/Doctrine/Query.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 2ae35ee15..c446274d3 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -480,7 +480,7 @@ public function processPendingFields($componentAlias) } $sql = array(); - foreach ($fields as $fieldAlias => $fieldName) { + foreach ($fields as $fieldName) { $columnName = $table->getColumnName($fieldName); if (($owner = $table->getColumnOwner($columnName)) !== null && $owner !== $table->getComponentName()) { @@ -492,17 +492,10 @@ public function processPendingFields($componentAlias) . ' AS ' . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); } else { - // Fix for http://www.doctrine-project.org/jira/browse/DC-585 - // Take the field alias if available - if (isset($this->_aggregateAliasMap[$fieldAlias])) { - $aliasSql = $this->_aggregateAliasMap[$fieldAlias]; - } else { - $columnName = $table->getColumnName($fieldName); - $aliasSql = $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); - } + $columnName = $table->getColumnName($fieldName); $sql[] = $this->_conn->quoteIdentifier($tableAlias) . '.' . $this->_conn->quoteIdentifier($columnName) . ' AS ' - . $aliasSql; + . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); } } @@ -656,13 +649,6 @@ public function parseSelect($dql) $this->_queryComponents[$componentAlias]['agg'][$index] = $alias; $this->_neededTables[] = $tableAlias; - - // Fix for http://www.doctrine-project.org/jira/browse/DC-585 - // Add selected columns to pending fields - if (preg_match('/^([^\(]+)\.(\'?)(.*?)(\'?)$/', $expression, $field)) { - $this->_pendingFields[$componentAlias][$alias] = $field[3]; - } - } else { $e = explode('.', $terms[0]); From 1d68711221c57bd7b96d71cb757dcbe0a242f4d5 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 20 Jan 2024 16:16:51 +0100 Subject: [PATCH 38/59] Fix(Query): column added twice with custom aliases --- lib/Doctrine/Hydrator/Graph.php | 6 ++++++ lib/Doctrine/Query.php | 4 ++++ lib/Doctrine/Query/Abstract.php | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/lib/Doctrine/Hydrator/Graph.php b/lib/Doctrine/Hydrator/Graph.php index 8578f4871..b227f3874 100644 --- a/lib/Doctrine/Hydrator/Graph.php +++ b/lib/Doctrine/Hydrator/Graph.php @@ -311,11 +311,17 @@ protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents) $table = $this->_queryComponents[$cache[$key]['dqlAlias']]['table']; $fieldName = $table->getFieldName($last); $cache[$key]['fieldName'] = $fieldName; + + if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last])) { + $fieldName = $this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last]; + } + if ($table->isIdentifier($fieldName)) { $cache[$key]['isIdentifier'] = true; } else { $cache[$key]['isIdentifier'] = false; } + $type = $table->getTypeOfColumn($last); if ($type == 'integer' || $type == 'string') { $cache[$key]['isSimpleType'] = true; diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index c446274d3..a4d0b40f8 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -648,6 +648,10 @@ public function parseSelect($dql) $this->_queryComponents[$componentAlias]['agg'][$index] = $alias; + if (preg_match('/^([^\(]+)\.(\'?)(.*?)(\'?)$/', $expression, $field)) { + $this->_queryComponents[$componentAlias]['agg_field'][$index] = $field[3]; + } + $this->_neededTables[] = $tableAlias; } else { $e = explode('.', $terms[0]); diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 6042ed18e..247886f1c 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -206,6 +206,16 @@ abstract class Doctrine_Query_Abstract * * map the name of the column / aggregate value this * component is mapped to a collection + * + * agg_field the field names for each aggregates + * Example: + * DQL: COMPONENT.FIELD as ALIAS + * SQL: TABLE.COLUMN as TABLE__0 + * $_queryComponents + * agg: + * 0: ALIAS + * agg_field: + * 0: FIELD */ protected $_queryComponents = array(); @@ -1259,6 +1269,9 @@ protected function _constructQueryFromCache($cached) if (isset($components['agg'])) { $queryComponents[$alias]['agg'] = $components['agg']; } + if (isset($components['agg_field'])) { + $queryComponents[$alias]['agg_field'] = $components['agg_field']; + } if (isset($components['map'])) { $queryComponents[$alias]['map'] = $components['map']; } @@ -1289,6 +1302,9 @@ public function getCachedForm($customComponent = null) if (isset($components['agg'])) { $componentInfo[$alias]['agg'] = $components['agg']; } + if (isset($components['agg_field'])) { + $componentInfo[$alias]['agg_field'] = $components['agg_field']; + } if (isset($components['map'])) { $componentInfo[$alias]['map'] = $components['map']; } From 4f020aea6ff0951022a8fcfdfd1a90aca92f219f Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Mon, 29 Jan 2024 20:15:48 +0100 Subject: [PATCH 39/59] Fixed test 1325TestCase.php --- tests/Ticket/1325TestCase.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Ticket/1325TestCase.php b/tests/Ticket/1325TestCase.php index d1847e46e..2b230a269 100644 --- a/tests/Ticket/1325TestCase.php +++ b/tests/Ticket/1325TestCase.php @@ -41,6 +41,8 @@ public function prepareTables() public function testShouldInsertWithoutAlias() { + $now = time(); + $elem = new Ticket_1325_TableName_NoAlias(); $elem->id = 1; $elem->save(); @@ -49,13 +51,14 @@ public function testShouldInsertWithoutAlias() ->from('Ticket_1325_TableName_NoAlias') ->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY); - $now = time(); $time = strtotime($res['event_date']); $this->assertTrue(($now + 5 >= $time) && ($time >= $now)); } public function testShouldInsertWithAlias() { + $now = time(); + $elem = new Ticket_1325_TableName_Aliased(); $elem->id = 1; $elem->save(); @@ -64,9 +67,8 @@ public function testShouldInsertWithAlias() ->from('Ticket_1325_TableName_Aliased') ->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY); - $now = time(); $time = strtotime($res['eventDate']); - $this->assertTrue(strtotime($res['eventDate']) > 0); + $this->assertTrue(($now + 5 >= $time) && ($time >= $now)); } } From cc51a4fb20f93038ce72e31d4170706cef97417f Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Wed, 24 Jan 2024 13:28:39 +0100 Subject: [PATCH 40/59] fix(tests) replace use of iconv in SearchTestCase.php --- tests/SearchTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SearchTestCase.php b/tests/SearchTestCase.php index c73245565..7a291b7b3 100644 --- a/tests/SearchTestCase.php +++ b/tests/SearchTestCase.php @@ -229,7 +229,7 @@ public function testUtf8AnalyzerKnowsToHandleOtherEncodingsWorks() $analyzer = new Doctrine_Search_Analyzer_Utf8(); // convert our test string to iso8859-15 - $iso = iconv('UTF-8','ISO8859-15', 'un éléphant ça trompe énormément'); + $iso = mb_convert_encoding('un éléphant ça trompe énormément', 'ISO-8859-15', 'UTF-8'); $words = $analyzer->analyze($iso, 'ISO8859-15'); $this->assertEqual($words[1], 'éléphant'); From 7327db8c3d44da8e16e90353b0415f7a0b928ac1 Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Wed, 24 Jan 2024 13:28:44 +0100 Subject: [PATCH 41/59] add(composer): ext-iconv is now a requirement --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 053673e5d..778193c61 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "require": { "php": ">=5.3", "ext-zlib": "*", + "ext-iconv": "*", "ext-mbstring": "*", "ext-pdo": "*" }, From eeb177794db8d442dfbc4e1c30448e9c6f70f3b1 Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Thu, 15 Dec 2022 19:35:20 +0100 Subject: [PATCH 42/59] Adding columns defined in actAs-templates to the docblock of the generated model class. --- lib/Doctrine/Import/Builder.php | 142 ++++++++++++++++-- .../gh110/Ticket_gh110_TestRecord.snapshot | 66 ++++++++ tests/Ticket/gh110TestCase.php | 81 ++++++++++ 3 files changed, 277 insertions(+), 12 deletions(-) create mode 100644 tests/Ticket/gh110/Ticket_gh110_TestRecord.snapshot create mode 100644 tests/Ticket/gh110TestCase.php diff --git a/lib/Doctrine/Import/Builder.php b/lib/Doctrine/Import/Builder.php index 7dc64d4ab..8f1bc34da 100644 --- a/lib/Doctrine/Import/Builder.php +++ b/lib/Doctrine/Import/Builder.php @@ -179,6 +179,25 @@ class Doctrine_Import_Builder extends Doctrine_Builder */ protected $_phpDocEmail = '##EMAIL##'; + + /** + * Contains the actAs columns after running buildSetUp + * + * @var array + */ + private $actAsColumns = array(); + /** * _tpl * @@ -396,9 +415,7 @@ public function buildTableDefinition(array $definition) /** * buildSetUp * - * @param array $options - * @param array $columns - * @param array $relations + * @param array $definition * @return string */ public function buildSetUp(array $definition) @@ -857,21 +874,33 @@ public function buildPhpDocs(array $definition) return $ret; } + /** + * find class matching $name + * + * @param $name + * @return class-string + */ + private function findTemplateClassMatchingName($name) + { + $classname = $name; + if (class_exists("Doctrine_Template_$name", true)) { + $classname = "Doctrine_Template_$name"; + } + + return $classname; + } + /** * emit a behavior assign * * @param int $level * @param string $name * @param string $option + * @param class-string $classname * @return string assignation code */ - private function emitAssign($level, $name, $option) + private function emitAssign($level, $name, $option, $classname) { - // find class matching $name - $classname = $name; - if (class_exists("Doctrine_Template_$name", true)) { - $classname = "Doctrine_Template_$name"; - } return " \$" . strtolower($name) . "$level = new $classname($option);". PHP_EOL; } @@ -943,6 +972,7 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi $currentParent = $parent; if (is_array($actAs)) { foreach($actAs as $template => $options) { + $className = $this->findTemplateClassMatchingName($template); if ($template == 'actAs') { // found another actAs $build .= $this->innerBuildActAs($options, $level + 1, $parent, $emittedActAs); @@ -959,7 +989,8 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi } $optionPHP = $this->varExport($realOptions); - $build .= $this->emitAssign($level, $template, $optionPHP); + $build .= $this->emitAssign($level, $template, $optionPHP, $className); + $this->determineActAsColumns($className, $realOptions); if ($level == 0) { $emittedActAs[] = $this->emitActAs($level, $template); } else { @@ -969,7 +1000,8 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi $parent = $template; $build .= $this->innerBuildActAs($leftActAs, $level, $template, $emittedActAs); } else { - $build .= $this->emitAssign($level, $template, null); + $build .= $this->emitAssign($level, $template, null, $className); + $this->determineActAsColumns($className, array($options)); if ($level == 0) { $emittedActAs[] = $this->emitActAs($level, $template); } else { @@ -979,7 +1011,9 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi } } } else { - $build .= $this->emitAssign($level, $actAs, null); + $className = $this->findTemplateClassMatchingName($actAs); + $build .= $this->emitAssign($level, $actAs, null, $className); + $this->determineActAsColumns($className, array()); if ($level == 0) { $emittedActAs[] = $this->emitActAs($level, $actAs); } else { @@ -990,6 +1024,87 @@ private function innerBuildActAs($actAs, $level = 0, $parent = null, array &$emi return $build; } + /** + * Adds the columns of the used actAs behaviors to the comment block. + * + * @param class-string $className + * @param array $instanceOptions + * + * @throws Doctrine_Import_Builder_Exception + */ + private function determineActAsColumns($className, $instanceOptions) + { + // No class specified or class does not exist. + if (!$className || !class_exists($className)) { + return; + } + + // PHP >= 7.4 is planned as a minimum version for the upcoming release of doctrine1, + // therefore we simply skip the generation of actAs columns if run below 7.0, as + // instantiation exceptions are not supported before PHP 7 + if (PHP_VERSION_ID <= 70000) { + return; + } + + try { + $actAsInstance = new $className($instanceOptions); + } catch (Error $e) { + // The class can't be instantiated, skipping it + return; + } + + if (!$actAsInstance || !method_exists($actAsInstance, 'getOptions')) { + return; + } + + $options = $actAsInstance->getOptions(); + + // Some behaviors do not contain an array of columns, e.g. SoftDelete. + if (!is_array(reset($options))) { + $options = array($options); + } + + foreach ($options as $name => $column) { + if (!is_array($column) || !array_key_exists('name', $column) || !array_key_exists('type', $column)) { + // 'name' or 'type' not found. + continue; + } + + if (array_key_exists('disabled', $column) && $column['disabled']) { + // Column has been disabled. + continue; + } + + // Add field, if it does not exist already. + if (array_key_exists($name, $this->actAsColumns)) { + continue; + } + + $this->actAsColumns[$name] = $column; + } + } + + private function mergeDefinitionAndActAsColumns(array $definitionColumns, array $actAsColumns) + { + $result = $definitionColumns; + + foreach ($actAsColumns as $actAsOptionName => $actAsColumn) { + $actAsColumnName = isset($actAsColumn['name']) ? $actAsColumn['name'] : $actAsOptionName; + + foreach ($result as $optionName => $column) { + $name = isset($column['name']) ? $column['name'] : $optionName; + if ($name === $actAsColumnName) { + continue 2; + } + } + + $result[$actAsOptionName] = $actAsColumn; + } + + return $result; + } + + /** * Build php code for adding record listeners * @@ -1122,6 +1237,8 @@ public function buildDefinition(array $definition) $className = $definition['className']; $extends = isset($definition['inheritance']['extends']) ? $definition['inheritance']['extends']:$this->_baseClassName; + // Clear actAsColumns + $this->actAsColumns = array(); if ( ! (isset($definition['no_definition']) && $definition['no_definition'] === true)) { $tableDefinitionCode = $this->buildTableDefinition($definition); $setUpCode = $this->buildSetUp($definition); @@ -1136,6 +1253,7 @@ public function buildDefinition(array $definition) $setUpCode.= $this->buildToString($definition); + $definition['columns'] = $this->mergeDefinitionAndActAsColumns($definition['columns'], $this->actAsColumns); $docs = PHP_EOL . $this->buildPhpDocs($definition); $content = sprintf(self::$_tpl, $docs, $abstract, diff --git a/tests/Ticket/gh110/Ticket_gh110_TestRecord.snapshot b/tests/Ticket/gh110/Ticket_gh110_TestRecord.snapshot new file mode 100644 index 000000000..a6b440b47 --- /dev/null +++ b/tests/Ticket/gh110/Ticket_gh110_TestRecord.snapshot @@ -0,0 +1,66 @@ +/** + * Ticket_gh110_TestRecord + * + * This class has been auto-generated by the Doctrine ORM Framework + * + * @property int $id Type: integer(4) + * @property my_custom_type $created_at Type: my_custom_type + * @property string $deleted_at Type: timestamp, Timestamp in ISO-8601 format (YYYY-MM-DD HH:MI:SS) + * + * @method int getId() Type: integer(4) + * @method my_custom_type getCreatedAt() Type: my_custom_type + * @method string getDeletedAt() Type: timestamp, Timestamp in ISO-8601 format (YYYY-MM-DD HH:MI:SS) + * + * @method Ticket_gh110_TestRecord setId(int $val) Type: integer(4) + * @method Ticket_gh110_TestRecord setCreatedAt(my_custom_type $val) Type: my_custom_type + * @method Ticket_gh110_TestRecord setDeletedAt(string $val) Type: timestamp, Timestamp in ISO-8601 format (YYYY-MM-DD HH:MI:SS) + * + * @package ##PACKAGE## + * @subpackage ##SUBPACKAGE## + * @author ##NAME## <##EMAIL##> + * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $ + */ +class Ticket_gh110_TestRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('id', 'integer', 4, array( + 'type' => 'integer', + 'length' => 4, + )); + $this->hasColumn('created_at', 'my_custom_type', null, array( + 'type' => 'my_custom_type', + 'length' => '', + )); + } + + public function setUp() + { + parent::setUp(); + $softdelete0 = new Doctrine_Template_SoftDelete(array( + )); + $timestampable0 = new Doctrine_Template_Timestampable(array( + 'updated' => + array( + 'disabled' => true, + ), + 'unknown_column' => + array( + ), + )); + $unknownactas0 = new UnknownActAs(array( + )); + $gh110_template0 = new Doctrine_Template_gh110_Template(array( + )); + $gh110_invalid_template0 = new gh110_Invalid_Template(array( + )); + $gh110_abstract_template0 = new gh110_Abstract_Template(array( + )); + $this->actAs($softdelete0); + $this->actAs($timestampable0); + $this->actAs($unknownactas0); + $this->actAs($gh110_template0); + $this->actAs($gh110_invalid_template0); + $this->actAs($gh110_abstract_template0); + } +} \ No newline at end of file diff --git a/tests/Ticket/gh110TestCase.php b/tests/Ticket/gh110TestCase.php new file mode 100644 index 000000000..6528b9b43 --- /dev/null +++ b/tests/Ticket/gh110TestCase.php @@ -0,0 +1,81 @@ +buildDefinition( + array( + 'className' => 'Ticket_gh110_TestRecord', + 'topLevelClassName' => 'Ticket_gh110_TestRecord', + 'is_base_class' => true, + 'columns' => array( + 'id' => array( + 'type' => 'integer', + 'length' => 4, + ), + 'my_custom_created_at' => array( + 'name' => 'created_at', + 'type' => 'my_custom_type', + 'length' => '', + ) + ), + 'actAs' => array( + 'SoftDelete' => array(), + 'Timestampable' => array( + 'updated' => array( + 'disabled' => true, + ), + 'unknown_column' => array() + ), + 'UnknownActAs' => array(), + // This template brings an already defined column + 'gh110_Template' => array(), + 'gh110_Invalid_Template' => array(), + 'gh110_Abstract_Template' => array(), + ) + ) + ); + + // Can be used to update the snapshot. + //file_put_contents(dirname(__FILE__) . '/gh110/Ticket_gh110_TestRecord.snapshot', $class); + $this->assertEqual($class, file_get_contents(dirname(__FILE__) . '/gh110/Ticket_gh110_TestRecord.snapshot')); + } +} + +abstract class gh110_Abstract_Template {} + +/** This is just a simple class without the required getOptions()-Method */ +class gh110_Invalid_Template {} + +class Doctrine_Template_gh110_Template extends Doctrine_Template +{ + protected $_options = array( + 'created' => array( + 'name' => 'created_at', + 'alias' => null, + 'type' => 'timestamp', + 'format' => 'Y-m-d H:i:s', + 'disabled' => false, + 'expression' => false, + 'options' => array('notnull' => true) + ) + ); + + /** + * Set table definition for Timestampable behavior + * + * @return void + */ + public function setTableDefinition() + { + if ( ! $this->_options['created']['disabled']) { + $name = $this->_options['created']['name']; + if ($this->_options['created']['alias']) { + $name .= ' as ' . $this->_options['created']['alias']; + } + $this->hasColumn($name, $this->_options['created']['type'], null, $this->_options['created']['options']); + } + } +} From 9e0ac04183438045e79219b65c11a1153134aa7e Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Tue, 6 Feb 2024 00:06:27 +0100 Subject: [PATCH 43/59] Update readme: we dont have 1.5 here --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eede636ae..27f085e1b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Installation Using [Composer](http://getcomposer.org/doc/00-intro.md) as dependency management: - composer require friendsofsymfony1/doctrine1 "1.5.*" + composer require friendsofsymfony1/doctrine1 "1.4.*" composer install From 36799478ea8825065540ae92ecf9b125b7029056 Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Tue, 6 Feb 2024 11:04:02 +0100 Subject: [PATCH 44/59] Update min PHP version to v7.4 (#122) Co-authored-by: Emanuele Panzeri Co-authored-by: Thomas --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 778193c61..befc24307 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": ">=5.3", + "php": "^7.4 || ^8.0", "ext-zlib": "*", "ext-iconv": "*", "ext-mbstring": "*", From 1990ab33339370d40c3333dd0660b6bf34d50856 Mon Sep 17 00:00:00 2001 From: Sergei Miami Date: Fri, 9 Feb 2024 11:00:11 +0100 Subject: [PATCH 45/59] Fix invalid docblock for Collection::fromArray() --- lib/Doctrine/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/Collection.php index 25b7ca441..ce8951539 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/Collection.php @@ -811,7 +811,7 @@ public function toHierarchy() /** * Populate a Doctrine_Collection from an array of data * - * @param string $array + * @param array $array * @return void */ public function fromArray($array, $deep = true) From ff63f6cd7dacaf2a5887fd6bf108df287d527916 Mon Sep 17 00:00:00 2001 From: Sergei Miami Date: Fri, 9 Feb 2024 11:00:34 +0100 Subject: [PATCH 46/59] Remove unused variable from Collection::fromArray() --- lib/Doctrine/Collection.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/Collection.php index ce8951539..7b3c60104 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/Collection.php @@ -816,7 +816,6 @@ public function toHierarchy() */ public function fromArray($array, $deep = true) { - $data = array(); foreach ($array as $rowKey => $row) { $this[$rowKey]->fromArray($row, $deep); } From b756c4380b28830363a7c83b4b43a9ad2d892841 Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Tue, 6 Feb 2024 09:13:51 +0100 Subject: [PATCH 47/59] [composer] add sort-packages --- composer.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index befc24307..f5779e514 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,10 @@ ], "require": { "php": "^7.4 || ^8.0", - "ext-zlib": "*", "ext-iconv": "*", "ext-mbstring": "*", - "ext-pdo": "*" + "ext-pdo": "*", + "ext-zlib": "*" }, "support": { "issues": "https://github.com/FriendsOfSymfony1/doctrine1/issues", @@ -39,5 +39,8 @@ "branch-alias": { "dev-master": "1.4-dev" } + }, + "config": { + "sort-packages": true } } From b2e59a6b51be773dbc703b6e02c6b36b80ca3b30 Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Sat, 17 Feb 2024 07:55:58 +0100 Subject: [PATCH 48/59] introduce __DIR__ constants --- lib/Doctrine/Core.php | 4 +-- lib/Doctrine/Parser/sfYaml/sfYaml.php | 4 +-- lib/Doctrine/Parser/sfYaml/sfYamlDumper.php | 2 +- lib/Doctrine/Parser/sfYaml/sfYamlInline.php | 2 +- lib/Doctrine/Parser/sfYaml/sfYamlParser.php | 2 +- tests/CliTestCase.php | 2 +- tests/CliTestCase/cli-default.php | 4 +-- tests/CliTestCase/cli-with-custom-tasks.php | 4 +-- ...li-without-autoregistered-custom-tasks.php | 4 +-- tests/DoctrineTest.php | 20 +++++------ tests/DoctrineTest/UnitTestCase.php | 2 +- tests/Export/PgsqlTestCase.php | 4 +-- tests/Export/RecordTestCase.php | 2 +- tests/Export/SchemaTestCase.php | 2 +- tests/ExtensionTestCase.php | 2 +- tests/Import/BuilderTestCase.php | 4 +-- tests/Import/PluginHierarchyTestCase.php | 4 +-- tests/Import/SchemaTestCase.php | 4 +-- tests/Migration/DiffTestCase.php | 8 ++--- tests/Search/FileTestCase.php | 2 +- tests/Search/IndexerTestCase.php | 2 +- tests/TaskTestCase.php | 2 +- tests/Ticket/1527TestCase.php | 4 +-- tests/Ticket/1727TestCase.php | 34 +++++++++---------- tests/Ticket/2375TestCase.php | 6 ++-- tests/Ticket/DC221TestCase.php | 6 ++-- tests/Ticket/DC292TestCase.php | 6 ++-- tests/Ticket/DC95TestCase.php | 10 +++--- tests/Ticket/gh110TestCase.php | 4 +-- tests/run.php | 6 ++-- tests/unsolved.php | 4 +-- 31 files changed, 83 insertions(+), 83 deletions(-) diff --git a/lib/Doctrine/Core.php b/lib/Doctrine/Core.php index 382bf9510..8662d3284 100644 --- a/lib/Doctrine/Core.php +++ b/lib/Doctrine/Core.php @@ -564,7 +564,7 @@ public static function setPath($path) public static function getPath() { if ( ! self::$_path) { - self::$_path = realpath(dirname(__FILE__) . '/..'); + self::$_path = dirname(__DIR__); } return self::$_path; @@ -1132,7 +1132,7 @@ public static function compile($target = null, $includedDrivers = array()) public static function autoload($className) { if (strpos($className, 'sfYaml') === 0) { - require dirname(__FILE__) . '/Parser/sfYaml/' . $className . '.php'; + require __DIR__ . '/Parser/sfYaml/' . $className . '.php'; return true; } diff --git a/lib/Doctrine/Parser/sfYaml/sfYaml.php b/lib/Doctrine/Parser/sfYaml/sfYaml.php index 1d89ccc97..7e0c14f3f 100644 --- a/lib/Doctrine/Parser/sfYaml/sfYaml.php +++ b/lib/Doctrine/Parser/sfYaml/sfYaml.php @@ -87,7 +87,7 @@ public static function load($input) return $input; } - require_once dirname(__FILE__).'/sfYamlParser.php'; + require_once __DIR__.'/sfYamlParser.php'; $yaml = new sfYamlParser(); @@ -116,7 +116,7 @@ public static function load($input) */ public static function dump($array, $inline = 2) { - require_once dirname(__FILE__).'/sfYamlDumper.php'; + require_once __DIR__.'/sfYamlDumper.php'; $yaml = new sfYamlDumper(); diff --git a/lib/Doctrine/Parser/sfYaml/sfYamlDumper.php b/lib/Doctrine/Parser/sfYaml/sfYamlDumper.php index 0ada2b37d..4ed3c8fbc 100644 --- a/lib/Doctrine/Parser/sfYaml/sfYamlDumper.php +++ b/lib/Doctrine/Parser/sfYaml/sfYamlDumper.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -require_once(dirname(__FILE__).'/sfYamlInline.php'); +require_once(__DIR__.'/sfYamlInline.php'); /** * sfYamlDumper dumps PHP variables to YAML strings. diff --git a/lib/Doctrine/Parser/sfYaml/sfYamlInline.php b/lib/Doctrine/Parser/sfYaml/sfYamlInline.php index 77096e43f..5f4f31168 100644 --- a/lib/Doctrine/Parser/sfYaml/sfYamlInline.php +++ b/lib/Doctrine/Parser/sfYaml/sfYamlInline.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -require_once dirname(__FILE__).'/sfYaml.php'; +require_once __DIR__.'/sfYaml.php'; /** * sfYamlInline implements a YAML parser/dumper for the YAML inline syntax. diff --git a/lib/Doctrine/Parser/sfYaml/sfYamlParser.php b/lib/Doctrine/Parser/sfYaml/sfYamlParser.php index 91da2dcb1..f8bdb34d7 100644 --- a/lib/Doctrine/Parser/sfYaml/sfYamlParser.php +++ b/lib/Doctrine/Parser/sfYaml/sfYamlParser.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -require_once(dirname(__FILE__).'/sfYamlInline.php'); +require_once(__DIR__.'/sfYamlInline.php'); if (!defined('PREG_BAD_UTF8_OFFSET_ERROR')) { diff --git a/tests/CliTestCase.php b/tests/CliTestCase.php index 967c86c8f..c2e206533 100644 --- a/tests/CliTestCase.php +++ b/tests/CliTestCase.php @@ -57,7 +57,7 @@ class Doctrine_Cli_TestCase extends UnitTestCase protected function getFixturesPath() { if (! isset($this->fixturesPath)) { - $this->fixturesPath = dirname(__FILE__) . '/CliTestCase'; + $this->fixturesPath = __DIR__ . '/CliTestCase'; } return $this->fixturesPath; diff --git a/tests/CliTestCase/cli-default.php b/tests/CliTestCase/cli-default.php index cf3e8f524..c0e4c46a8 100644 --- a/tests/CliTestCase/cli-default.php +++ b/tests/CliTestCase/cli-default.php @@ -5,10 +5,10 @@ * @author Dan Bettles */ -require_once(dirname(dirname(dirname(__FILE__))) . '/lib/Doctrine/Core.php'); +require_once dirname(__DIR__, 2) . '/lib/Doctrine/Core.php'; spl_autoload_register(array('Doctrine_Core', 'autoload')); -require_once(dirname(__FILE__) . '/TestTask02.php'); +require_once(__DIR__ . '/TestTask02.php'); $cli = new Doctrine_Cli(); $cli->run($_SERVER['argv']); diff --git a/tests/CliTestCase/cli-with-custom-tasks.php b/tests/CliTestCase/cli-with-custom-tasks.php index ef081e51f..8d16617ad 100644 --- a/tests/CliTestCase/cli-with-custom-tasks.php +++ b/tests/CliTestCase/cli-with-custom-tasks.php @@ -5,12 +5,12 @@ * @author Dan Bettles */ -require_once(dirname(dirname(dirname(__FILE__))) . '/lib/Doctrine/Core.php'); +require_once dirname(__DIR__, 2) . '/lib/Doctrine/Core.php'; spl_autoload_register(array('Doctrine_Core', 'autoload')); $cli = new Doctrine_Cli(); -require_once(dirname(__FILE__) . '/TestTask02.php'); +require_once(__DIR__ . '/TestTask02.php'); //Either...: $cli->registerTaskClass('Doctrine_Cli_TestCase_TestTask02'); diff --git a/tests/CliTestCase/cli-without-autoregistered-custom-tasks.php b/tests/CliTestCase/cli-without-autoregistered-custom-tasks.php index f9b644f5a..a7b6d2599 100644 --- a/tests/CliTestCase/cli-without-autoregistered-custom-tasks.php +++ b/tests/CliTestCase/cli-without-autoregistered-custom-tasks.php @@ -5,10 +5,10 @@ * @author Dan Bettles */ -require_once(dirname(dirname(dirname(__FILE__))) . '/lib/Doctrine/Core.php'); +require_once dirname(__DIR__, 2) . '/lib/Doctrine/Core.php'; spl_autoload_register(array('Doctrine_Core', 'autoload')); -require_once(dirname(__FILE__) . '/TestTask02.php'); +require_once(__DIR__ . '/TestTask02.php'); $cli = new Doctrine_Cli(array('autoregister_custom_tasks' => false)); $cli->run($_SERVER['argv']); diff --git a/tests/DoctrineTest.php b/tests/DoctrineTest.php index 59e60b050..3bafe851a 100644 --- a/tests/DoctrineTest.php +++ b/tests/DoctrineTest.php @@ -32,10 +32,10 @@ * @version $Revision$ */ -require_once dirname(__FILE__) . '/DoctrineTest/UnitTestCase.php'; -require_once dirname(__FILE__) . '/DoctrineTest/GroupTest.php'; -require_once dirname(__FILE__) . '/DoctrineTest/Doctrine_UnitTestCase.php'; -require_once dirname(__FILE__) . '/DoctrineTest/Reporter.php'; +require_once __DIR__ . '/DoctrineTest/UnitTestCase.php'; +require_once __DIR__ . '/DoctrineTest/GroupTest.php'; +require_once __DIR__ . '/DoctrineTest/Doctrine_UnitTestCase.php'; +require_once __DIR__ . '/DoctrineTest/Reporter.php'; class DoctrineTest { @@ -75,13 +75,13 @@ public function run() { $testGroup = $this->testGroup; if (PHP_SAPI === 'cli') { - require_once(dirname(__FILE__) . '/DoctrineTest/Reporter/Cli.php'); + require_once(__DIR__ . '/DoctrineTest/Reporter/Cli.php'); $reporter = new DoctrineTest_Reporter_Cli(); $argv = $_SERVER['argv']; array_shift($argv); $options = $this->parseOptions($argv); } else { - require_once(dirname(__FILE__) . '/DoctrineTest/Reporter/Html.php'); + require_once(__DIR__ . '/DoctrineTest/Reporter/Html.php'); $options = $_GET; if (isset($options['filter'])) { if ( ! is_array($options['filter'])) { @@ -148,7 +148,7 @@ public function run() * somebody could give it a try. Just replace this block of code * with the one below * - define('PHPCOVERAGE_HOME', dirname(dirname(__FILE__)) . '/vendor/spikephpcoverage'); + define('PHPCOVERAGE_HOME', dirname(__DIR__) . '/vendor/spikephpcoverage'); require_once PHPCOVERAGE_HOME . '/CoverageRecorder.php'; require_once PHPCOVERAGE_HOME . '/reporter/HtmlCoverageReporter.php'; @@ -170,8 +170,8 @@ public function run() $ret = $testGroup->run($reporter, $filter); $result['coverage'] = xdebug_get_code_coverage(); xdebug_stop_code_coverage(); - file_put_contents(dirname(__FILE__) . '/coverage/coverage.txt', serialize($result)); - require_once dirname(__FILE__) . '/DoctrineTest/Coverage.php'; + file_put_contents(__DIR__ . '/coverage/coverage.txt', serialize($result)); + require_once __DIR__ . '/DoctrineTest/Coverage.php'; $coverageGeneration = new DoctrineTest_Coverage(); $coverageGeneration->generateReport(); return $ret; @@ -203,7 +203,7 @@ public function run() */ public function requireModels() { - $models = new DirectoryIterator(dirname(__FILE__) . '/models/'); + $models = new DirectoryIterator(__DIR__ . '/models/'); foreach($models as $key => $file) { if ($file->isFile() && ! $file->isDot()) { diff --git a/tests/DoctrineTest/UnitTestCase.php b/tests/DoctrineTest/UnitTestCase.php index a2b4193fd..f1aca2fe5 100644 --- a/tests/DoctrineTest/UnitTestCase.php +++ b/tests/DoctrineTest/UnitTestCase.php @@ -183,7 +183,7 @@ public function getPassCount() public function getPassesAndFailsCachePath() { - $dir = dirname(__FILE__) . '/doctrine_tests'; + $dir = __DIR__ . '/doctrine_tests'; if ( ! is_dir($dir)) { mkdir($dir, 0777, true); } diff --git a/tests/Export/PgsqlTestCase.php b/tests/Export/PgsqlTestCase.php index aa99596bc..d2a393fea 100644 --- a/tests/Export/PgsqlTestCase.php +++ b/tests/Export/PgsqlTestCase.php @@ -128,7 +128,7 @@ public function testCreateTableSupportsMultiplePks() public function testExportSql() { $sql = $this->export->exportClassesSql(array("FooRecord", "FooReferenceRecord", "FooLocallyOwned", "FooForeignlyOwned", "FooForeignlyOwnedWithPK", "FooBarRecord", "BarRecord")); - //dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files'); + //__DIR__ . DIRECTORY_SEPARATOR . '_files'); $this->assertEqual($sql, array ( 0 => 'CREATE TABLE foo_reference (foo1 BIGINT, foo2 BIGINT, PRIMARY KEY(foo1, foo2))', 1 => 'CREATE TABLE foo_locally_owned (id BIGSERIAL, name VARCHAR(200), PRIMARY KEY(id))', @@ -175,4 +175,4 @@ public function testAlterTableSqlIdentifierQuoting() 1 => 'ALTER TABLE "mytable" DROP "oldfield"' )); } -} \ No newline at end of file +} diff --git a/tests/Export/RecordTestCase.php b/tests/Export/RecordTestCase.php index 39a6976af..c51f14f53 100644 --- a/tests/Export/RecordTestCase.php +++ b/tests/Export/RecordTestCase.php @@ -97,7 +97,7 @@ public function testExportSupportsForeignKeysForManyToManyRelations() public function testExportModelFromDirectory() { - Doctrine_Core::createTablesFromModels(dirname(__FILE__) . DIRECTORY_SEPARATOR .'..' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'export'); + Doctrine_Core::createTablesFromModels(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'export'); $this->assertEqual($this->adapter->pop(), 'COMMIT'); $this->assertEqual($this->adapter->pop(), 'ALTER TABLE cms__category_languages ADD CONSTRAINT cms__category_languages_category_id_cms__category_id FOREIGN KEY (category_id) REFERENCES cms__category(id) ON DELETE CASCADE'); $this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'); diff --git a/tests/Export/SchemaTestCase.php b/tests/Export/SchemaTestCase.php index 960611a6f..b1f0d2943 100644 --- a/tests/Export/SchemaTestCase.php +++ b/tests/Export/SchemaTestCase.php @@ -56,7 +56,7 @@ class Doctrine_Export_Schema_TestCase extends Doctrine_UnitTestCase public function testYmlExport() { $export = new Doctrine_Export_Schema(); - $export->exportSchema('schema-export.yml', 'yml', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'models', $this->tables); + $export->exportSchema('schema-export.yml', 'yml', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'models', $this->tables); unlink('schema-export.yml'); } } diff --git a/tests/ExtensionTestCase.php b/tests/ExtensionTestCase.php index c7dd166c8..667f637f6 100755 --- a/tests/ExtensionTestCase.php +++ b/tests/ExtensionTestCase.php @@ -34,7 +34,7 @@ class Doctrine_Extension_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { - Doctrine_Core::setExtensionsPath(dirname(__FILE__).'/Extension'); + Doctrine_Core::setExtensionsPath(__DIR__.'/Extension'); spl_autoload_register(array('Doctrine_Core', 'extensionsAutoload')); Doctrine_Manager::getInstance() diff --git a/tests/Import/BuilderTestCase.php b/tests/Import/BuilderTestCase.php index 7415c0911..84f0804c5 100644 --- a/tests/Import/BuilderTestCase.php +++ b/tests/Import/BuilderTestCase.php @@ -34,7 +34,7 @@ class Doctrine_Import_Builder_TestCase extends Doctrine_UnitTestCase { public function testInheritanceGeneration() { - $path = dirname(__FILE__) . '/import_builder_test'; + $path = __DIR__ . '/import_builder_test'; $import = new Doctrine_Import_Schema(); $import->setOption('generateTableClasses', true); @@ -122,4 +122,4 @@ public function testBaseTableClass() $class = $builder->buildTableClassDefinition('MyTestTable', array('className' => 'MyTest')); $this->assertTrue(strpos($class, 'class MyTestTable extends MyBaseTable')); } -} \ No newline at end of file +} diff --git a/tests/Import/PluginHierarchyTestCase.php b/tests/Import/PluginHierarchyTestCase.php index 6082cbcc4..26df10f42 100644 --- a/tests/Import/PluginHierarchyTestCase.php +++ b/tests/Import/PluginHierarchyTestCase.php @@ -55,7 +55,7 @@ public function testImportOfHieriarchyOfPluginGeneration() END; file_put_contents('wiki.yml', $yml); - $path = dirname(__FILE__) . '/tmp/import_builder_test'; + $path = __DIR__ . '/tmp/import_builder_test'; $import = new Doctrine_Import_Schema(); $import->setOption('generateTableClasses', true); @@ -83,4 +83,4 @@ public function testImportOfHieriarchyOfPluginGeneration() Doctrine_Lib::removeDirectories($path); unlink('wiki.yml'); } -} \ No newline at end of file +} diff --git a/tests/Import/SchemaTestCase.php b/tests/Import/SchemaTestCase.php index a480499db..c47a30358 100644 --- a/tests/Import/SchemaTestCase.php +++ b/tests/Import/SchemaTestCase.php @@ -37,7 +37,7 @@ class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase public function testYmlImport() { - $path = dirname(__FILE__) . '/import_builder_test'; + $path = __DIR__ . '/import_builder_test'; $import = new Doctrine_Import_Schema(); $import->importSchema('schema.yml', 'yml', $path); @@ -110,4 +110,4 @@ protected function _verifyMultiDirectionalRelationship($class, $relationAlias, $ return false; } } -} \ No newline at end of file +} diff --git a/tests/Migration/DiffTestCase.php b/tests/Migration/DiffTestCase.php index 7a05d7c1d..7f6eb78d8 100644 --- a/tests/Migration/DiffTestCase.php +++ b/tests/Migration/DiffTestCase.php @@ -34,9 +34,9 @@ class Doctrine_Migration_Diff_TestCase extends Doctrine_UnitTestCase { public function testTest() { - $from = dirname(__FILE__) . '/Diff/schema/from.yml'; - $to = dirname(__FILE__) . '/Diff/schema/to.yml'; - $migrationsPath = dirname(__FILE__) . '/Diff/migrations'; + $from = __DIR__ . '/Diff/schema/from.yml'; + $to = __DIR__ . '/Diff/schema/to.yml'; + $migrationsPath = __DIR__ . '/Diff/migrations'; Doctrine_Lib::makeDirectories($migrationsPath); $diff = new Doctrine_Migration_Diff($from, $to, $migrationsPath); @@ -76,4 +76,4 @@ public function testTest() Doctrine_Lib::removeDirectories($migrationsPath); } -} \ No newline at end of file +} diff --git a/tests/Search/FileTestCase.php b/tests/Search/FileTestCase.php index 7f2a81c34..849626d6f 100644 --- a/tests/Search/FileTestCase.php +++ b/tests/Search/FileTestCase.php @@ -48,7 +48,7 @@ public function testSearchFileAutoCreatesFileTable() public function testIndexDirectoryIndexesAllFiles() { - $this->_search->indexDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files'); + $this->_search->indexDirectory(__DIR__ . DIRECTORY_SEPARATOR . '_files'); $resultSet = $this->_search->search('dbms'); diff --git a/tests/Search/IndexerTestCase.php b/tests/Search/IndexerTestCase.php index f24cfbd04..6deb6d0f1 100644 --- a/tests/Search/IndexerTestCase.php +++ b/tests/Search/IndexerTestCase.php @@ -48,7 +48,7 @@ public function testIndexexCanRecursivelyIndexDirectories() $indexer = new Doctrine_Search_Indexer(); - $indexer->indexDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files'); + $indexer->indexDirectory(__DIR__ . DIRECTORY_SEPARATOR . '_files'); } public function testIndexerAddsFiles() diff --git a/tests/TaskTestCase.php b/tests/TaskTestCase.php index 7dd644734..f60c70535 100644 --- a/tests/TaskTestCase.php +++ b/tests/TaskTestCase.php @@ -91,7 +91,7 @@ public function testSettasknameSetsTheNameOfTheTask() */ protected function loadPhpFixture($basename) { - require_once(dirname(__FILE__) . '/TaskTestCase/' . $basename); + require_once(__DIR__ . '/TaskTestCase/' . $basename); } public function testSettasknameThrowsAnExceptionIfTheTaskNameIsInvalid() diff --git a/tests/Ticket/1527TestCase.php b/tests/Ticket/1527TestCase.php index 8751aca90..40c8fe188 100644 --- a/tests/Ticket/1527TestCase.php +++ b/tests/Ticket/1527TestCase.php @@ -50,7 +50,7 @@ public function testTest() $schema = $import->buildSchema($yml, 'yml'); $this->assertEqual($schema['Ticket_1527_User']['columns']['username']['extra']['test'], '123'); - $path = dirname(__FILE__) . '/../tmp'; + $path = dirname(__DIR__) . '/tmp'; $import->importSchema($yml, 'yml', $path); require_once($path . '/generated/BaseTicket_1527_User.php'); @@ -58,4 +58,4 @@ public function testTest() $username = Doctrine_Core::getTable('Ticket_1527_User')->getDefinitionOf('username'); $this->assertEqual($username['extra']['test'], '123'); } -} \ No newline at end of file +} diff --git a/tests/Ticket/1727TestCase.php b/tests/Ticket/1727TestCase.php index 968de753e..5be1f3de1 100644 --- a/tests/Ticket/1727TestCase.php +++ b/tests/Ticket/1727TestCase.php @@ -34,36 +34,36 @@ class Doctrine_Ticket_1727_TestCase extends Doctrine_UnitTestCase { public function testTest() { - $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); - $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models1 = Doctrine_Core::loadModels(__DIR__ . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models2 = Doctrine_Core::loadModels(__DIR__ . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); - $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1'); - $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1'); + $models1 = Doctrine_Core::loadModels(__DIR__ . '/1727/models1'); + $models2 = Doctrine_Core::loadModels(__DIR__ . '/1727/models1'); $this->assertEqual($models1, $models2); - $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); - $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models1 = Doctrine_Core::loadModels(__DIR__ . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models2 = Doctrine_Core::loadModels(__DIR__ . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); - $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); - $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models1 = Doctrine_Core::loadModels(__DIR__ . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models2 = Doctrine_Core::loadModels(__DIR__ . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); - $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2'); - $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2'); + $models1 = Doctrine_Core::loadModels(__DIR__ . '/1727/models2'); + $models2 = Doctrine_Core::loadModels(__DIR__ . '/1727/models2'); $this->assertEqual($models1, $models2); - $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); - $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models1 = Doctrine_Core::loadModels(__DIR__ . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models2 = Doctrine_Core::loadModels(__DIR__ . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); - $models1 = Doctrine_Core::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2')); - $models2 = Doctrine_Core::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2')); + $models1 = Doctrine_Core::loadModels(array(__DIR__ . '/1727/models1', __DIR__ . '/1727/models2')); + $models2 = Doctrine_Core::loadModels(array(__DIR__ . '/1727/models1', __DIR__ . '/1727/models2')); $this->assertEqual($models1, $models2); - $models1 = Doctrine_Core::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2'), Doctrine_Core::MODEL_LOADING_CONSERVATIVE); - $models2 = Doctrine_Core::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2'), Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models1 = Doctrine_Core::loadModels(array(__DIR__ . '/1727/models1', __DIR__ . '/1727/models2'), Doctrine_Core::MODEL_LOADING_CONSERVATIVE); + $models2 = Doctrine_Core::loadModels(array(__DIR__ . '/1727/models1', __DIR__ . '/1727/models2'), Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); } -} \ No newline at end of file +} diff --git a/tests/Ticket/2375TestCase.php b/tests/Ticket/2375TestCase.php index 8d10be404..0eb85c36c 100644 --- a/tests/Ticket/2375TestCase.php +++ b/tests/Ticket/2375TestCase.php @@ -34,8 +34,8 @@ class Doctrine_Ticket_2375_TestCase extends Doctrine_UnitTestCase { public function testTest() { - $models1Dir = dirname(__FILE__) . '/2375/models1'; - $models2Dir = dirname(__FILE__) . '/2375/models2'; + $models1Dir = __DIR__ . '/2375/models1'; + $models2Dir = __DIR__ . '/2375/models2'; // try loading a couple initial models @@ -96,4 +96,4 @@ public function testTest() $this->assertEqual($loadedModels['Ticket_2375_Model5'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model5.php'); $this->assertEqual($loadedModels['Ticket_2375_Model6'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model5.php'); } -} \ No newline at end of file +} diff --git a/tests/Ticket/DC221TestCase.php b/tests/Ticket/DC221TestCase.php index 6d7c8ca97..0ce9074cd 100644 --- a/tests/Ticket/DC221TestCase.php +++ b/tests/Ticket/DC221TestCase.php @@ -34,8 +34,8 @@ class Doctrine_Ticket_DC221_TestCase extends Doctrine_UnitTestCase { public function testTest() { - $migration1 = new Doctrine_Migration(dirname(__FILE__) . '/DC221'); - $migration2 = new Doctrine_Migration(dirname(__FILE__) . '/DC221'); + $migration1 = new Doctrine_Migration(__DIR__ . '/DC221'); + $migration2 = new Doctrine_Migration(__DIR__ . '/DC221'); $this->assertEqual($migration1->getMigrationClasses(), $migration2->getMigrationClasses()); } -} \ No newline at end of file +} diff --git a/tests/Ticket/DC292TestCase.php b/tests/Ticket/DC292TestCase.php index e0ecb5f14..73822f1c3 100644 --- a/tests/Ticket/DC292TestCase.php +++ b/tests/Ticket/DC292TestCase.php @@ -34,15 +34,15 @@ class Doctrine_Ticket_DC292_TestCase extends Doctrine_UnitTestCase { public function testTest() { - $dir = dirname(__FILE__) . '/DC292/migrations'; + $dir = __DIR__ . '/DC292/migrations'; if ( ! is_dir($dir)) { mkdir($dir, 0777, true); } $migration = new Doctrine_Migration($dir); - $diff = new Doctrine_Migration_Diff(dirname(__FILE__) . '/DC292/from.yml', dirname(__FILE__) . '/DC292/to.yml', $migration); + $diff = new Doctrine_Migration_Diff(__DIR__ . '/DC292/from.yml', __DIR__ . '/DC292/to.yml', $migration); $changes = $diff->generateChanges(); $this->assertEqual(2, count($changes['created_columns']['article'])); $this->assertTrue(isset($changes['created_columns']['article']['created_at'])); $this->assertTrue(isset($changes['created_columns']['article']['updated_at'])); } -} \ No newline at end of file +} diff --git a/tests/Ticket/DC95TestCase.php b/tests/Ticket/DC95TestCase.php index 247e0378d..f09d31f2d 100644 --- a/tests/Ticket/DC95TestCase.php +++ b/tests/Ticket/DC95TestCase.php @@ -42,7 +42,7 @@ public function testClassDoesNotExistBeforeImport() public function testClassExistsAfterImport() { - Doctrine_Core::setModelsDirectory(dirname(__FILE__) . '/DC95/models'); + Doctrine_Core::setModelsDirectory(__DIR__ . '/DC95/models'); $import = new Doctrine_Import_Schema(); $import->setOptions(array( @@ -52,8 +52,8 @@ public function testClassExistsAfterImport() 'classPrefix' => 'DC95_', 'classPrefixFiles' => true )); - $modelsPath = dirname(__FILE__) . '/DC95/models'; - $import->importSchema(dirname(__FILE__) . '/DC95/schema.yml', 'yml', $modelsPath); + $modelsPath = __DIR__ . '/DC95/models'; + $import->importSchema(__DIR__ . '/DC95/schema.yml', 'yml', $modelsPath); /* $this->assertTrue(file_exists($modelsPath . '/DC95/Base/Article.php')); @@ -63,6 +63,6 @@ public function testClassExistsAfterImport() */ Doctrine_Core::setModelsDirectory(null); - Doctrine_Lib::removeDirectories(dirname(__FILE__) . '/DC95/models'); + Doctrine_Lib::removeDirectories(__DIR__ . '/DC95/models'); } -} \ No newline at end of file +} diff --git a/tests/Ticket/gh110TestCase.php b/tests/Ticket/gh110TestCase.php index 6528b9b43..f140d88ed 100644 --- a/tests/Ticket/gh110TestCase.php +++ b/tests/Ticket/gh110TestCase.php @@ -39,8 +39,8 @@ public function testAddActAsColumnsToDocBlock() ); // Can be used to update the snapshot. - //file_put_contents(dirname(__FILE__) . '/gh110/Ticket_gh110_TestRecord.snapshot', $class); - $this->assertEqual($class, file_get_contents(dirname(__FILE__) . '/gh110/Ticket_gh110_TestRecord.snapshot')); + //file_put_contents(__DIR__ . '/gh110/Ticket_gh110_TestRecord.snapshot', $class); + $this->assertEqual($class, file_get_contents(__DIR__ . '/gh110/Ticket_gh110_TestRecord.snapshot')); } } diff --git a/tests/run.php b/tests/run.php index 2b32582de..d1dd2c7ee 100644 --- a/tests/run.php +++ b/tests/run.php @@ -1,6 +1,6 @@ addTestCase($unsorted); */ -exit($test->run() ? 0 : 1); \ No newline at end of file +exit($test->run() ? 0 : 1); diff --git a/tests/unsolved.php b/tests/unsolved.php index e10461a6b..0009580a0 100644 --- a/tests/unsolved.php +++ b/tests/unsolved.php @@ -1,12 +1,12 @@ "; From f7a6e297f2f089288247c0cf3d22a0dd7a15815c Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Sat, 3 Feb 2024 20:58:20 +0100 Subject: [PATCH 49/59] PHP 8.1 > ReturnTypeWillChange attributes added --- lib/Doctrine/Collection/Iterator.php | 4 ++++ lib/Doctrine/Collection/Iterator/Expandable.php | 1 + lib/Doctrine/Collection/Iterator/Normal.php | 1 + lib/Doctrine/Collection/Iterator/Offset.php | 1 + lib/Doctrine/Node/MaterializedPath/LevelOrderIterator.php | 5 +++++ lib/Doctrine/Node/MaterializedPath/PostOrderIterator.php | 5 +++++ lib/Doctrine/Node/MaterializedPath/PreOrderIterator.php | 5 +++++ lib/Doctrine/Node/NestedSet/PreOrderIterator.php | 5 +++++ 8 files changed, 27 insertions(+) diff --git a/lib/Doctrine/Collection/Iterator.php b/lib/Doctrine/Collection/Iterator.php index 3fdc79cd0..1c6dbe283 100644 --- a/lib/Doctrine/Collection/Iterator.php +++ b/lib/Doctrine/Collection/Iterator.php @@ -74,6 +74,7 @@ public function __construct($collection) * * @return void */ + #[\ReturnTypeWillChange] public function rewind() { $this->index = 0; @@ -88,6 +89,7 @@ public function rewind() * * @return integer */ + #[\ReturnTypeWillChange] public function key() { return $this->key; @@ -98,6 +100,7 @@ public function key() * * @return Doctrine_Record */ + #[\ReturnTypeWillChange] public function current() { return $this->collection->get($this->key); @@ -108,6 +111,7 @@ public function current() * * @return void */ + #[\ReturnTypeWillChange] public function next() { $this->index++; diff --git a/lib/Doctrine/Collection/Iterator/Expandable.php b/lib/Doctrine/Collection/Iterator/Expandable.php index 7c18c5c58..3bfab7dd5 100644 --- a/lib/Doctrine/Collection/Iterator/Expandable.php +++ b/lib/Doctrine/Collection/Iterator/Expandable.php @@ -32,6 +32,7 @@ */ class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator { + #[\ReturnTypeWillChange] public function valid() { if ($this->index < $this->count) { diff --git a/lib/Doctrine/Collection/Iterator/Normal.php b/lib/Doctrine/Collection/Iterator/Normal.php index 540bdad63..c256bd6fb 100644 --- a/lib/Doctrine/Collection/Iterator/Normal.php +++ b/lib/Doctrine/Collection/Iterator/Normal.php @@ -35,6 +35,7 @@ class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator /** * @return boolean whether or not the iteration will continue */ + #[\ReturnTypeWillChange] public function valid() { return ($this->index < $this->count); diff --git a/lib/Doctrine/Collection/Iterator/Offset.php b/lib/Doctrine/Collection/Iterator/Offset.php index 181b73f21..128b1ef10 100644 --- a/lib/Doctrine/Collection/Iterator/Offset.php +++ b/lib/Doctrine/Collection/Iterator/Offset.php @@ -32,6 +32,7 @@ */ class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator { + #[\ReturnTypeWillChange] public function valid() { } } \ No newline at end of file diff --git a/lib/Doctrine/Node/MaterializedPath/LevelOrderIterator.php b/lib/Doctrine/Node/MaterializedPath/LevelOrderIterator.php index 6283563c3..718a85c0d 100644 --- a/lib/Doctrine/Node/MaterializedPath/LevelOrderIterator.php +++ b/lib/Doctrine/Node/MaterializedPath/LevelOrderIterator.php @@ -41,26 +41,31 @@ public function __construct($node, $opts) throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function rewind() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function valid() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function current() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function key() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function next() { throw new Doctrine_Exception('Not yet implemented'); diff --git a/lib/Doctrine/Node/MaterializedPath/PostOrderIterator.php b/lib/Doctrine/Node/MaterializedPath/PostOrderIterator.php index 1cc002f06..be67e3678 100644 --- a/lib/Doctrine/Node/MaterializedPath/PostOrderIterator.php +++ b/lib/Doctrine/Node/MaterializedPath/PostOrderIterator.php @@ -41,26 +41,31 @@ public function __construct($node, $opts) throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function rewind() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function valid() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function current() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function key() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function next() { throw new Doctrine_Exception('Not yet implemented'); diff --git a/lib/Doctrine/Node/MaterializedPath/PreOrderIterator.php b/lib/Doctrine/Node/MaterializedPath/PreOrderIterator.php index 4ea31bd8c..d00438fec 100644 --- a/lib/Doctrine/Node/MaterializedPath/PreOrderIterator.php +++ b/lib/Doctrine/Node/MaterializedPath/PreOrderIterator.php @@ -41,26 +41,31 @@ public function __construct($node, $opts) throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function rewind() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function valid() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function current() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function key() { throw new Doctrine_Exception('Not yet implemented'); } + #[\ReturnTypeWillChange] public function next() { throw new Doctrine_Exception('Not yet implemented'); diff --git a/lib/Doctrine/Node/NestedSet/PreOrderIterator.php b/lib/Doctrine/Node/NestedSet/PreOrderIterator.php index a35a72223..9cc399d7d 100644 --- a/lib/Doctrine/Node/NestedSet/PreOrderIterator.php +++ b/lib/Doctrine/Node/NestedSet/PreOrderIterator.php @@ -100,6 +100,7 @@ public function __construct($record, $opts) * * @return void */ + #[\ReturnTypeWillChange] public function rewind() { $this->index = -1; @@ -111,6 +112,7 @@ public function rewind() * * @return integer */ + #[\ReturnTypeWillChange] public function key() { return $this->key; @@ -121,6 +123,7 @@ public function key() * * @return Doctrine_Record */ + #[\ReturnTypeWillChange] public function current() { $record = $this->collection->get($this->key); @@ -133,6 +136,7 @@ public function current() * * @return void */ + #[\ReturnTypeWillChange] public function next() { while ($current = $this->advanceIndex()) { @@ -149,6 +153,7 @@ public function next() /** * @return boolean whether or not the iteration will continue */ + #[\ReturnTypeWillChange] public function valid() { return ($this->index < $this->count); From 931eef150e07796bc13919ef35f6d87f92d27487 Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Thu, 22 Feb 2024 17:14:30 +0100 Subject: [PATCH 50/59] fixed CI tasks on relevant folders --- .github/workflows/continuous-integration.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index bfc4e4b41..26b4f3b23 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,10 +1,23 @@ name: "Continuous Integration" on: + pull_request: + branches: + - master + paths: + - .github/workflows/continuous-integration.yml + - composer.* + - lib/** + - tests/** + push: branches: - master - pull_request: + paths: + - .github/workflows/continuous-integration.yml + - composer.* + - lib/** + - tests/** env: fail-fast: true From a5527246cbd52628f5dc85b0422fcf4f6c8105ba Mon Sep 17 00:00:00 2001 From: iricketson Date: Mon, 29 Apr 2024 03:07:32 -0600 Subject: [PATCH 51/59] Fix Doctrine lengthValidator deprecation on null float/decimal values (#136) --- lib/Doctrine/Validator.php | 2 +- tests/ValidatorTestCase.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Validator.php b/lib/Doctrine/Validator.php index bab8fe82c..75e63dbbb 100644 --- a/lib/Doctrine/Validator.php +++ b/lib/Doctrine/Validator.php @@ -89,7 +89,7 @@ public function validateRecord(Doctrine_Record $record) */ public static function validateLength($value, $type, $maximumLength) { - if ($maximumLength === null ) { + if ($maximumLength === null || $value === null) { return true; } if ($type == 'timestamp' || $type == 'integer' || $type == 'enum') { diff --git a/tests/ValidatorTestCase.php b/tests/ValidatorTestCase.php index 92943fa29..28cb5fa5e 100644 --- a/tests/ValidatorTestCase.php +++ b/tests/ValidatorTestCase.php @@ -123,7 +123,19 @@ public function testIsValidType() $this->assertTrue(Doctrine_Validator::isValidType($var, 'object')); } - public function testValidate2() + public function testIsValidLength() + { + // Test length is less than maximum length + $this->assertTrue(Doctrine_Validator::validateLength(1.2345, "decimal", 5)); + + // Test null value is less than maximum length + $this->assertTrue(Doctrine_Validator::validateLength(null, "decimal", 4)); + + // Test length is greater than maximum length + $this->assertFalse(Doctrine_Validator::validateLength(1.2345, "decimal", 4)); + } + + public function testValidate2() { $test = new ValidatorTest(); $test->mymixed = "message"; From 5ef828701caea00235a87486dc69d878cb016158 Mon Sep 17 00:00:00 2001 From: thePanz Date: Fri, 14 Jun 2024 18:39:11 +0200 Subject: [PATCH 52/59] Fix code style, remove extra whitespaces --- lib/Doctrine/Import/Schema.php | 106 +++++++++---------- lib/Doctrine/Parser.php | 6 +- tests/BaseTestCase.php | 4 +- tests/ConnectionTestCase.php | 44 ++++---- tests/Data/ExportTestCase.php | 4 +- tests/Data/ImportTestCase.php | 24 ++--- tests/DoctrineTest/Doctrine_UnitTestCase.php | 1 + tests/DoctrineTest/GroupTest.php | 2 +- tests/DoctrineTest/UnitTestCase.php | 8 +- tests/DriverTestCase.php | 29 ++--- tests/Export/SchemaTestCase.php | 2 +- tests/Export/SqliteTestCase.php | 28 ++--- tests/Import/BuilderTestCase.php | 6 +- tests/Import/PluginHierarchyTestCase.php | 6 +- tests/Import/SchemaTestCase.php | 20 ++-- tests/ImportTestCase.php | 8 +- tests/Migration/DiffTestCase.php | 4 +- tests/ParserTestCase.php | 20 ++-- tests/Ticket/1118TestCase.php | 4 +- tests/Ticket/1351TestCase.php | 4 +- tests/Ticket/1527TestCase.php | 4 +- tests/Ticket/1617TestCase.php | 4 +- tests/Ticket/2355TestCase.php | 6 +- tests/Ticket/915TestCase.php | 4 +- tests/Ticket/DC147TestCase.php | 10 +- tests/Ticket/DC23TestCase.php | 8 +- tests/Ticket/DC23bTestCase.php | 16 +-- tests/Ticket/DC95TestCase.php | 2 +- 28 files changed, 192 insertions(+), 192 deletions(-) diff --git a/lib/Doctrine/Import/Schema.php b/lib/Doctrine/Import/Schema.php index 65ea075d5..25dc4869b 100644 --- a/lib/Doctrine/Import/Schema.php +++ b/lib/Doctrine/Import/Schema.php @@ -154,7 +154,7 @@ class Doctrine_Import_Schema /** * Returns an array of definition keys that can be applied at the global level. - * + * * @return array */ public static function getGlobalDefinitionKeys() @@ -165,7 +165,7 @@ public static function getGlobalDefinitionKeys() /** * getOption * - * @param string $name + * @param string $name * @return void */ public function getOption($name) @@ -188,8 +188,8 @@ public function getOptions() /** * setOption * - * @param string $name - * @param string $value + * @param string $name + * @param string $value * @return void */ public function setOption($name, $value) @@ -198,11 +198,11 @@ public function setOption($name, $value) $this->_options[$name] = $value; } } - + /** * setOptions * - * @param string $options + * @param array $options * @return void */ public function setOptions($options) @@ -230,7 +230,7 @@ public function buildSchema($schema, $format) $e = explode('.', $s); if (end($e) === $format) { $array = array_merge($array, $this->parseSchema($s, $format)); - } + } } else if (is_dir($s)) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($s), RecursiveIteratorIterator::LEAVES_ONLY); @@ -270,20 +270,20 @@ public function importSchema($schema, $format = 'yml', $directory = null, $model $builder = new Doctrine_Import_Builder(); $builder->setTargetPath($directory); $builder->setOptions($this->getOptions()); - + $array = $this->buildSchema($schema, $format); - if (count($array) == 0) { + if (count($array) == 0) { throw new Doctrine_Import_Exception( sprintf('No ' . $format . ' schema found in ' . implode(", ", $schema)) - ); + ); } foreach ($array as $name => $definition) { if ( ! empty($models) && !in_array($definition['className'], $models)) { continue; } - + $builder->buildRecord($definition); } } @@ -313,7 +313,7 @@ public function parseSchema($schema, $type) 'package' => null, 'inheritance' => array(), 'detect_relations' => false); - + $array = Doctrine_Parser::load($schema, $type); // Loop over and build up all the global values and remove them from the array @@ -431,14 +431,14 @@ public function parseSchema($schema, $type) $build[$className][$key] = isset($build[$className][$key]) ? $build[$className][$key]:$defaultValue; } } - + $build[$className]['className'] = $className; $build[$className]['tableName'] = $tableName; $build[$className]['columns'] = $columns; - + // Make sure that anything else that is specified in the schema makes it to the final array $build[$className] = Doctrine_Lib::arrayDeepMerge($table, $build[$className]); - + // We need to keep track of the className for the connection $build[$className]['connectionClassName'] = $build[$className]['className']; } @@ -448,11 +448,11 @@ public function parseSchema($schema, $type) /** * _processInheritance - * + * * Perform some processing on inheritance. * Sets the default type and sets some default values for certain types * - * @param string $array + * @param string $array * @return void */ protected function _processInheritance($array) @@ -472,9 +472,9 @@ protected function _processInheritance($array) if ($array[$className]['inheritance']['type'] == 'column_aggregation') { // Set the keyField to 'type' by default if ( ! isset($array[$className]['inheritance']['keyField'])) { - $array[$className]['inheritance']['keyField'] = 'type'; + $array[$className]['inheritance']['keyField'] = 'type'; } - + // Set the keyValue to the name of the child class if it does not exist if ( ! isset($array[$className]['inheritance']['keyValue'])) { $array[$className]['inheritance']['keyValue'] = $className; @@ -510,22 +510,22 @@ protected function _processInheritance($array) // Populate the parents subclasses if ($definition['inheritance']['type'] == 'column_aggregation') { - // Fix for 2015: loop through superclasses' inheritance to the base-superclass to - // make sure we collect all keyFields needed (and not only the first) - $inheritanceFields = array($definition['inheritance']['keyField'] => $definition['inheritance']['keyValue']); + // Fix for 2015: loop through superclasses' inheritance to the base-superclass to + // make sure we collect all keyFields needed (and not only the first) + $inheritanceFields = array($definition['inheritance']['keyField'] => $definition['inheritance']['keyValue']); - $superClass = $definition['inheritance']['extends']; - $multiInheritanceDef = $array[$superClass]; + $superClass = $definition['inheritance']['extends']; + $multiInheritanceDef = $array[$superClass]; - while (count($multiInheritanceDef['inheritance']) > 0 && array_key_exists('extends', $multiInheritanceDef['inheritance']) && $multiInheritanceDef['inheritance']['type'] == 'column_aggregation') { + while (count($multiInheritanceDef['inheritance']) > 0 && array_key_exists('extends', $multiInheritanceDef['inheritance']) && $multiInheritanceDef['inheritance']['type'] == 'column_aggregation') { $superClass = $multiInheritanceDef['inheritance']['extends']; - + // keep original keyField with it's keyValue - if ( ! isset($inheritanceFields[$multiInheritanceDef['inheritance']['keyField']])) { + if ( ! isset($inheritanceFields[$multiInheritanceDef['inheritance']['keyField']])) { $inheritanceFields[$multiInheritanceDef['inheritance']['keyField']] = $multiInheritanceDef['inheritance']['keyValue']; - } - $multiInheritanceDef = $array[$superClass]; - } + } + $multiInheritanceDef = $array[$superClass]; + } $array[$parent]['inheritance']['subclasses'][$definition['className']] = $inheritanceFields; } @@ -555,10 +555,10 @@ protected function _findBaseSuperClass($array, $class) * buildRelationships * * Loop through an array of schema information and build all the necessary relationship information - * Will attempt to auto complete relationships and simplify the amount of information required + * Will attempt to auto complete relationships and simplify the amount of information required * for defining a relationship * - * @param string $array + * @param string $array * @return void */ protected function _buildRelationships($array) @@ -591,10 +591,10 @@ protected function _buildRelationships($array) if ( ! isset($properties['relations'])) { continue; } - + $className = $properties['className']; $relations = $properties['relations']; - + foreach ($relations as $alias => $relation) { $class = isset($relation['class']) ? $relation['class']:$alias; if ( ! isset($array[$class])) { @@ -602,7 +602,7 @@ protected function _buildRelationships($array) } $relation['class'] = $class; $relation['alias'] = isset($relation['alias']) ? $relation['alias'] : $alias; - + // Attempt to guess the local and foreign if (isset($relation['refClass'])) { $relation['local'] = isset($relation['local']) ? $relation['local']:Doctrine_Inflector::tableize($name) . '_id'; @@ -611,11 +611,11 @@ protected function _buildRelationships($array) $relation['local'] = isset($relation['local']) ? $relation['local']:Doctrine_Inflector::tableize($relation['class']) . '_id'; $relation['foreign'] = isset($relation['foreign']) ? $relation['foreign']:'id'; } - + if (isset($relation['refClass'])) { $relation['type'] = 'many'; } - + if (isset($relation['type']) && $relation['type']) { $relation['type'] = $relation['type'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY; } else { @@ -625,18 +625,18 @@ protected function _buildRelationships($array) if (isset($relation['foreignType']) && $relation['foreignType']) { $relation['foreignType'] = $relation['foreignType'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY; } - + $relation['key'] = $this->_buildUniqueRelationKey($relation); - + $this->_validateSchemaElement('relation', array_keys($relation), $className . '->relation->' . $relation['alias']); - + $this->_relations[$className][$alias] = $relation; } } - + // Now we auto-complete opposite ends of relationships $this->_autoCompleteOppositeRelations(); - + // Make sure we do not have any duplicate relations $this->_fixDuplicateRelations(); @@ -644,7 +644,7 @@ protected function _buildRelationships($array) foreach ($this->_relations as $className => $relations) { $array[$className]['relations'] = $relations; } - + return $array; } @@ -663,22 +663,22 @@ protected function _autoCompleteOppositeRelations() if ((isset($relation['equal']) && $relation['equal']) || (isset($relation['autoComplete']) && $relation['autoComplete'] === false)) { continue; } - + $newRelation = array(); $newRelation['foreign'] = $relation['local']; $newRelation['local'] = $relation['foreign']; $newRelation['class'] = isset($relation['foreignClass']) ? $relation['foreignClass']:$className; $newRelation['alias'] = isset($relation['foreignAlias']) ? $relation['foreignAlias']:$className; $newRelation['foreignAlias'] = $alias; - + // this is so that we know that this relation was autogenerated and // that we do not need to include it if it is explicitly declared in the schema by the users. - $newRelation['autogenerated'] = true; - + $newRelation['autogenerated'] = true; + if (isset($relation['refClass'])) { $newRelation['refClass'] = $relation['refClass']; $newRelation['type'] = isset($relation['foreignType']) ? $relation['foreignType']:$relation['type']; - } else { + } else { if (isset($relation['foreignType'])) { $newRelation['type'] = $relation['foreignType']; } else { @@ -720,7 +720,7 @@ protected function _fixDuplicateRelations() } } } - + $this->_relations[$className] = $uniqueRelations; } } @@ -731,7 +731,7 @@ protected function _fixDuplicateRelations() * Build a unique key to identify a relationship by * Md5 hash of all the relationship parameters * - * @param string $relation + * @param string $relation * @return void */ protected function _buildUniqueRelationKey($relation) @@ -742,8 +742,8 @@ protected function _buildUniqueRelationKey($relation) /** * _validateSchemaElement * - * @param string $name - * @param string $value + * @param string $name + * @param string $value * @return void */ protected function _validateSchemaElement($name, $element, $path) @@ -768,4 +768,4 @@ protected function _validateSchemaElement($name, $element, $path) } } } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Parser.php b/lib/Doctrine/Parser.php index d9c8c124d..8d7571e98 100644 --- a/lib/Doctrine/Parser.php +++ b/lib/Doctrine/Parser.php @@ -62,7 +62,7 @@ abstract public function dumpData($array, $path = null, $charset = null); * Get instance of the specified parser * * @param string $type - * @return void + * @return Doctrine_Parser * @author Jonathan H. Wage */ static public function getParser($type) @@ -94,7 +94,7 @@ static public function load($path, $type = 'xml', $charset = 'UTF-8') * * Interface for pulling and dumping data to a file * - * @param string $array + * @param array $array * @param string $path * @param string $type * @param string $charset The charset of the data being dumped @@ -115,7 +115,7 @@ static public function dump($array, $type = 'xml', $path = null, $charset = null * Either should allow php code in it. * * @param string $path - * @return void + * @return false|string */ public function doLoad($path) { diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 5a865cab2..ae65c91f3 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -45,7 +45,7 @@ public function testAggressiveModelLoading() // Make sure it does not include the base classes $this->assertTrue( ! isset($models['BaseAggressiveModelLoadingUser'])); - + $filteredModels = Doctrine_Core::filterInvalidModels($models); // Make sure filterInvalidModels filters out base abstract classes @@ -85,7 +85,7 @@ public function testModelLoadingCacheInformation() $this->assertTrue(in_array('AggressiveModelLoadingUser', $models)); $this->assertTrue(in_array('ConservativeModelLoadingProfile', $models)); $this->assertTrue(in_array('ConservativeModelLoadingContact', $models)); - + $modelFiles = Doctrine_Core::getLoadedModelFiles(); $this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingUser'])); $this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingProfile'])); diff --git a/tests/ConnectionTestCase.php b/tests/ConnectionTestCase.php index 70d3f28be..9a4b0072a 100644 --- a/tests/ConnectionTestCase.php +++ b/tests/ConnectionTestCase.php @@ -30,10 +30,10 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase +class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase { - public function testUnknownModule() + public function testUnknownModule() { try { $this->connection->unknown; @@ -43,7 +43,7 @@ public function testUnknownModule() } } - public function testGetModule() + public function testGetModule() { $this->assertTrue($this->connection->unitOfWork instanceof Doctrine_Connection_UnitOfWork); //$this->assertTrue($this->connection->dataDict instanceof Doctrine_DataDict); @@ -52,7 +52,7 @@ public function testGetModule() $this->assertTrue($this->connection->export instanceof Doctrine_Export); } - public function testFetchAll() + public function testFetchAll() { $this->conn->exec('DROP TABLE entity'); $this->conn->exec('CREATE TABLE entity (id INT, name TEXT)'); @@ -80,16 +80,16 @@ public function testFetchAll() public function testFetchOne() { $c = $this->conn->fetchOne('SELECT COUNT(1) FROM entity'); - + $this->assertEqual($c, 2); - + $c = $this->conn->fetchOne('SELECT COUNT(1) FROM entity WHERE id = ?', array(1)); - + $this->assertEqual($c, 1); } - - public function testFetchColumn() + + public function testFetchColumn() { $a = $this->conn->fetchColumn('SELECT * FROM entity'); @@ -105,7 +105,7 @@ public function testFetchColumn() )); } - public function testFetchArray() + public function testFetchArray() { $a = $this->conn->fetchArray('SELECT * FROM entity'); @@ -122,7 +122,7 @@ public function testFetchArray() )); } - public function testFetchRow() + public function testFetchRow() { $c = $this->conn->fetchRow('SELECT * FROM entity'); @@ -132,24 +132,24 @@ public function testFetchRow() )); $c = $this->conn->fetchRow('SELECT * FROM entity WHERE id = ?', array(1)); - + $this->assertEqual($c, array ( 'id' => '1', 'name' => 'zYne', )); } - public function testFetchPairs() + public function testFetchPairs() { $this->conn->exec('DROP TABLE entity'); } - public function testGetManager() + public function testGetManager() { $this->assertTrue($this->connection->getManager() === $this->manager); } - public function testDeleteOnTransientRecordIsIgnored() + public function testDeleteOnTransientRecordIsIgnored() { $user = $this->connection->create('User'); try { @@ -159,7 +159,7 @@ public function testDeleteOnTransientRecordIsIgnored() } } - public function testGetTable() + public function testGetTable() { $table = $this->connection->getTable('Group'); $this->assertTrue($table instanceof Doctrine_Table); @@ -176,23 +176,23 @@ public function testGetTable() } - public function testCreate() + public function testCreate() { $email = $this->connection->create('Email'); $this->assertTrue($email instanceof Email); } - public function testGetDbh() + public function testGetDbh() { $this->assertTrue($this->connection->getDbh() instanceof PDO); } - public function testCount() + public function testCount() { $this->assertTrue(is_integer(count($this->connection))); } - public function testGetIterator() + public function testGetIterator() { $this->assertTrue($this->connection->getIterator() instanceof ArrayIterator); } @@ -203,12 +203,12 @@ public function testGetState() $this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->transaction->getState()), 'open'); } - public function testGetTables() + public function testGetTables() { $this->assertTrue(is_array($this->connection->getTables())); } - public function testRollback() + public function testRollback() { $this->connection->beginTransaction(); $this->assertEqual($this->connection->transaction->getTransactionLevel(),1); diff --git a/tests/Data/ExportTestCase.php b/tests/Data/ExportTestCase.php index 3c176c3d0..03d6e5fa2 100644 --- a/tests/Data/ExportTestCase.php +++ b/tests/Data/ExportTestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Data_Export_TestCase extends Doctrine_UnitTestCase +class Doctrine_Data_Export_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { @@ -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/Data/ImportTestCase.php b/tests/Data/ImportTestCase.php index fa07a25cd..76e67dccb 100644 --- a/tests/Data/ImportTestCase.php +++ b/tests/Data/ImportTestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Data_Import_TestCase extends Doctrine_UnitTestCase +class Doctrine_Data_Import_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { @@ -43,17 +43,17 @@ public function prepareTables() $this->tables[] = 'I18nNumberLang'; parent::prepareTables(); } - + public function testInlineMany() { $yml = <<assertEqual($i[4]['rgt'], 3); $this->assertEqual($i[4]['level'], 1); $this->assertEqual($i[4]['root_id'], $i[3]['root_id']); - + $this->assertEqual($i[5]['name'], 'Item 2.2'); $this->assertEqual($i[5]['lft'], 4); $this->assertEqual($i[5]['rgt'], 11); @@ -367,7 +367,7 @@ public function testMany2ManyManualDataFixtures() unlink('test.yml'); } - + public function testInvalidElementThrowsException() { self::prepareTables(); @@ -609,4 +609,4 @@ public function setUp() { $this->actAs('I18n', array('fields' => array('name', 'title'))); } -} \ No newline at end of file +} diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index a1f0fb2f7..3fa7bcbcd 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -48,6 +48,7 @@ class Doctrine_UnitTestCase extends UnitTestCase protected $generic = false; protected $conn; protected $adapter; + /** @var Doctrine_Export */ protected $export; protected $expr; protected $dataDict; diff --git a/tests/DoctrineTest/GroupTest.php b/tests/DoctrineTest/GroupTest.php index b17f5e37e..5f4eb14b9 100644 --- a/tests/DoctrineTest/GroupTest.php +++ b/tests/DoctrineTest/GroupTest.php @@ -109,4 +109,4 @@ public function getTestCases() { return $this->_testCases; } -} \ No newline at end of file +} diff --git a/tests/DoctrineTest/UnitTestCase.php b/tests/DoctrineTest/UnitTestCase.php index f1aca2fe5..cfa461e13 100644 --- a/tests/DoctrineTest/UnitTestCase.php +++ b/tests/DoctrineTest/UnitTestCase.php @@ -2,9 +2,7 @@ class UnitTestCase { protected $_passed = 0; - protected $_failed = 0; - protected $_messages = array(); protected static $_passesAndFails = array('passes' => array(), 'fails' => array()); @@ -115,7 +113,7 @@ public function assertNotNull($expr) } } - public function pass() + public function pass() { $class = get_class($this); if ( ! isset(self::$_passesAndFails['fails'][$class])) { @@ -126,7 +124,7 @@ public function pass() public function fail($message = "") { - $this->_fail($message); + $this->_fail($message); } public function _fail($message = "") @@ -166,7 +164,7 @@ public function run(DoctrineTest_Reporter $reporter = null, $filter = null) } } - public function getMessages() + public function getMessages() { return $this->_messages; } diff --git a/tests/DriverTestCase.php b/tests/DriverTestCase.php index c247eed3c..1369d39c6 100644 --- a/tests/DriverTestCase.php +++ b/tests/DriverTestCase.php @@ -1,29 +1,29 @@ name = $name; } - public function getName() + public function getName() { return $this->name; } - public function pop() + public function pop() { return array_pop($this->queries); } - public function forceException($name, $message = '', $code = 0) + public function forceException($name, $message = '', $code = 0) { $this->exception = array($name, $message, $code); } @@ -102,7 +102,7 @@ public function lastInsertId() } public function beginTransaction() - { + { $this->queries[] = 'BEGIN TRANSACTION'; } @@ -111,8 +111,8 @@ public function commit() $this->queries[] = 'COMMIT'; } - public function rollBack() - { + public function rollBack() + { $this->queries[] = 'ROLLBACK'; } @@ -142,7 +142,7 @@ public function setAttribute($attribute, $value) class AdapterStatementMock { private $mock; - + private $query; public function __construct(AdapterMock $mock, $query) @@ -180,6 +180,7 @@ class Doctrine_Driver_UnitTestCase extends UnitTestCase protected $manager; protected $conn; protected $adapter; + /** @var Doctrine_Export */ protected $export; protected $dataDict; protected $transaction; @@ -224,12 +225,12 @@ public function init() if ($this->adapter->getName() == 'oci') $name = 'Oracle'; - + $tx = 'Doctrine_Transaction_' . ucwords($name); $dataDict = 'Doctrine_DataDict_' . ucwords($name); - + $exc = 'Doctrine_Connection_' . ucwords($name) . '_Exception'; - + $this->exc = new $exc(); if (class_exists($tx)) $this->transaction = new $tx($this->conn); diff --git a/tests/Export/SchemaTestCase.php b/tests/Export/SchemaTestCase.php index b1f0d2943..fabb76a0a 100644 --- a/tests/Export/SchemaTestCase.php +++ b/tests/Export/SchemaTestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Export_Schema_TestCase extends Doctrine_UnitTestCase +class Doctrine_Export_Schema_TestCase extends Doctrine_UnitTestCase { public $tables = array('Entity', 'EntityReference', diff --git a/tests/Export/SqliteTestCase.php b/tests/Export/SqliteTestCase.php index 377696153..0227f02aa 100644 --- a/tests/Export/SqliteTestCase.php +++ b/tests/Export/SqliteTestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Export_Sqlite_TestCase extends Doctrine_UnitTestCase +class Doctrine_Export_Sqlite_TestCase extends Doctrine_UnitTestCase { public function testCreateDatabaseDoesNotExecuteSqlAndCreatesSqliteFile() { @@ -44,17 +44,17 @@ public function testDropDatabaseDoesNotExecuteSqlAndDeletesSqliteFile() $this->assertFalse(file_exists('sqlite.db')); } - public function testCreateTableSupportsAutoincPks() + public function testCreateTableSupportsAutoincPks() { $name = 'mytable'; - + $fields = array('id' => array('type' => 'integer', 'unsigned' => 1, 'autoincrement' => true)); $this->export->createTable($name, $fields); $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INTEGER PRIMARY KEY AUTOINCREMENT)'); } - public function testCreateTableSupportsDefaultAttribute() + public function testCreateTableSupportsDefaultAttribute() { $name = 'mytable'; $fields = array('name' => array('type' => 'char', 'length' => 10, 'default' => 'def'), @@ -66,15 +66,15 @@ public function testCreateTableSupportsDefaultAttribute() $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (name CHAR(10) DEFAULT \'def\', type INTEGER DEFAULT 12, PRIMARY KEY(name, type))'); } - public function testCreateTableSupportsMultiplePks() + public function testCreateTableSupportsMultiplePks() { $name = 'mytable'; $fields = array('name' => array('type' => 'char', 'length' => 10), 'type' => array('type' => 'integer', 'length' => 3)); - + $options = array('primary' => array('name', 'type')); $this->export->createTable($name, $fields, $options); - + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (name CHAR(10), type INTEGER, PRIMARY KEY(name, type))'); } public function testCreateTableSupportsIndexes() @@ -89,7 +89,7 @@ public function testCreateTableSupportsIndexes() $this->export->createTable('sometable', $fields, $options); - //this was the old line, but it looks like the table is created first + //this was the old line, but it looks like the table is created first //and then the index so i replaced it with the ones below //$this->assertEqual($var, 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id, name))'); @@ -111,7 +111,7 @@ public function testIdentifierQuoting() $this->export->createTable('sometable', $fields, $options); - //this was the old line, but it looks like the table is created first + //this was the old line, but it looks like the table is created first //and then the index so i replaced it with the ones below //$this->assertEqual($var, 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id, name))'); @@ -121,17 +121,17 @@ public function testIdentifierQuoting() $this->conn->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, false); } - public function testQuoteMultiplePks() + public function testQuoteMultiplePks() { $this->conn->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true); $name = 'mytable'; $fields = array('name' => array('type' => 'char', 'length' => 10), 'type' => array('type' => 'integer', 'length' => 3)); - + $options = array('primary' => array('name', 'type')); $this->export->createTable($name, $fields, $options); - + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE "mytable" ("name" CHAR(10), "type" INTEGER, PRIMARY KEY("name", "type"))'); $this->conn->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, false); @@ -157,14 +157,14 @@ public function testCreateTableSupportsIndexesWithCustomSorting() $options = array('primary' => array('id'), 'indexes' => array('myindex' => array( 'fields' => array( - 'id' => array('sorting' => 'ASC'), + 'id' => array('sorting' => 'ASC'), 'name' => array('sorting' => 'DESC') ) )) ); $this->export->createTable('sometable', $fields, $options); - + //removed this assertion and inserted the two below // $this->assertEqual($this->adapter->pop(), 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id ASC, name DESC))'); diff --git a/tests/Import/BuilderTestCase.php b/tests/Import/BuilderTestCase.php index 84f0804c5..5de915e88 100644 --- a/tests/Import/BuilderTestCase.php +++ b/tests/Import/BuilderTestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Import_Builder_TestCase extends Doctrine_UnitTestCase +class Doctrine_Import_Builder_TestCase extends Doctrine_UnitTestCase { public function testInheritanceGeneration() { @@ -55,10 +55,10 @@ public function testInheritanceGeneration() $this->assertTrue($schemaTestInheritanceParent->isSubclassOf('PackageSchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceChild1->isSubclassOf('BaseSchemaTestInheritanceChild1')); $this->assertTrue($schemaTestInheritanceChild2->isSubclassOf('BaseSchemaTestInheritanceChild2')); - + $this->assertTrue($schemaTestInheritanceChild1->isSubclassOf('SchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceChild1->isSubclassOf('BaseSchemaTestInheritanceParent')); - + $this->assertTrue($schemaTestInheritanceChild2->isSubclassOf('SchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceChild2->isSubclassOf('BaseSchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceChild2->isSubclassOf('SchemaTestInheritanceChild1')); diff --git a/tests/Import/PluginHierarchyTestCase.php b/tests/Import/PluginHierarchyTestCase.php index 26df10f42..0d286e1fb 100644 --- a/tests/Import/PluginHierarchyTestCase.php +++ b/tests/Import/PluginHierarchyTestCase.php @@ -75,11 +75,11 @@ public function testImportOfHieriarchyOfPluginGeneration() 3 => 'CREATE TABLE wiki_test (id INTEGER PRIMARY KEY AUTOINCREMENT)', 4 => 'CREATE UNIQUE INDEX wiki_test_translation_sluggable_idx ON wiki_test_translation (slug)', ); - + foreach($sql as $idx => $req) { $this->assertEqual($req, $result[$idx]); - } - + } + Doctrine_Lib::removeDirectories($path); unlink('wiki.yml'); } diff --git a/tests/Import/SchemaTestCase.php b/tests/Import/SchemaTestCase.php index c47a30358..05b021b60 100644 --- a/tests/Import/SchemaTestCase.php +++ b/tests/Import/SchemaTestCase.php @@ -30,11 +30,11 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase +class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase { public $buildSchema; public $schema; - + public function testYmlImport() { $path = __DIR__ . '/import_builder_test'; @@ -45,7 +45,7 @@ public function testYmlImport() if ( ! file_exists($path . '/SchemaTestUser.php')) { $this->fail(); } - + if ( ! file_exists($path . '/SchemaTestProfile.php')) { $this->fail(); } @@ -54,7 +54,7 @@ public function testYmlImport() Doctrine_Lib::removeDirectories($path); } - + public function testBuildSchema() { $schema = new Doctrine_Import_Schema(); @@ -77,7 +77,7 @@ public function testBuildSchema() $this->assertTrue(array_key_exists('detect_relations', $model) && is_bool($model['detect_relations'])); $this->assertEqual($array['AliasTest']['columns']['test_col']['name'], 'test_col as test_col_alias'); } - + public function testSchemaRelationshipCompletion() { $this->buildSchema = new Doctrine_Import_Schema(); @@ -87,22 +87,22 @@ public function testSchemaRelationshipCompletion() foreach ($properties['relations'] as $alias => $relation) { if ( ! $this->_verifyMultiDirectionalRelationship($name, $alias, $relation)) { $this->fail(); - + return false; } } } - + $this->pass(); } - + protected function _verifyMultiDirectionalRelationship($class, $relationAlias, $relation) { $foreignClass = $relation['class']; $foreignAlias = isset($relation['foreignAlias']) ? $relation['foreignAlias']:$class; - + $foreignClassRelations = $this->schema[$foreignClass]['relations']; - + // Check to see if the foreign class has the opposite end defined for the class/foreignAlias if (isset($foreignClassRelations[$foreignAlias])) { return true; diff --git a/tests/ImportTestCase.php b/tests/ImportTestCase.php index 8d062a252..3fbe5f276 100644 --- a/tests/ImportTestCase.php +++ b/tests/ImportTestCase.php @@ -30,11 +30,11 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Import_TestCase extends Doctrine_UnitTestCase +class Doctrine_Import_TestCase extends Doctrine_UnitTestCase { - public function prepareTables() + public function prepareTables() { } - public function prepareData() + public function prepareData() { } public function testImport() @@ -51,4 +51,4 @@ public function testImport() $this->assertTrue(file_exists('Import/_files/generated/BaseImportTestUser.php')); Doctrine_Lib::removeDirectories('Import/_files'); } -} \ No newline at end of file +} diff --git a/tests/Migration/DiffTestCase.php b/tests/Migration/DiffTestCase.php index 7f6eb78d8..bfd0b2514 100644 --- a/tests/Migration/DiffTestCase.php +++ b/tests/Migration/DiffTestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Migration_Diff_TestCase extends Doctrine_UnitTestCase +class Doctrine_Migration_Diff_TestCase extends Doctrine_UnitTestCase { public function testTest() { @@ -60,7 +60,7 @@ public function testTest() $this->assertEqual(count($files), 2); $this->assertTrue(strpos($files[0], '_version1.php')); $this->assertTrue(strpos($files[1], '_version2.php')); - + $code1 = file_get_contents($files[0]); $this->assertTrue(strpos($code1, 'this->dropTable')); $this->assertTrue(strpos($code1, 'this->createTable')); diff --git a/tests/ParserTestCase.php b/tests/ParserTestCase.php index 7f5e54862..8afca682d 100644 --- a/tests/ParserTestCase.php +++ b/tests/ParserTestCase.php @@ -30,19 +30,19 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Parser_TestCase extends Doctrine_UnitTestCase +class Doctrine_Parser_TestCase extends Doctrine_UnitTestCase { public function testGetParserInstance() { $instance = Doctrine_Parser::getParser('Yml'); - + if ($instance instanceof Doctrine_Parser_Yml) { $this->pass(); } else { $this->fail(); } } - + public function testFacadeLoadAndDump() { Doctrine_Parser::dump(array('test' => 'good job', 'test2' => true, array('testing' => false)), 'yml', 'test.yml'); @@ -51,7 +51,7 @@ public function testFacadeLoadAndDump() $this->assertEqual($array, array('test' => 'good job', 'test2' => true, array('testing' => false))); unlink('test.yml'); } - + public function testParserSupportsEmbeddingPhpSyntax() { $parser = Doctrine_Parser::getParser('Yml'); @@ -62,12 +62,12 @@ public function testParserSupportsEmbeddingPhpSyntax() w00t: not now "; $data = $parser->doLoad($yml); - + $array = $parser->loadData($data); - + $this->assertEqual($array, array('test' => 'good job', 'test2' => true, 'testing' => false, 'w00t' => 'not now')); } - + public function testParserWritingToDisk() { $parser = Doctrine_Parser::getParser('Yml'); @@ -76,15 +76,15 @@ public function testParserWritingToDisk() $this->assertEqual('test', file_get_contents('test.yml')); unlink('test.yml'); } - + public function testParserReturningLoadedData() { $parser = Doctrine_Parser::getParser('Yml'); $result = $parser->doDump('test'); - + $this->assertEqual('test', $result); } - + public function testLoadFromString() { $yml = "--- diff --git a/tests/Ticket/1118TestCase.php b/tests/Ticket/1118TestCase.php index 44aa90c50..3f0d9a54b 100644 --- a/tests/Ticket/1118TestCase.php +++ b/tests/Ticket/1118TestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Ticket_1118_TestCase extends Doctrine_UnitTestCase +class Doctrine_Ticket_1118_TestCase extends Doctrine_UnitTestCase { // Test that when a foreign key is detected that it sets the foreign key to the same type and length // of the related table primary key @@ -70,4 +70,4 @@ public function testTest() unlink('test.yml'); } -} \ No newline at end of file +} diff --git a/tests/Ticket/1351TestCase.php b/tests/Ticket/1351TestCase.php index 8a7a6b27a..e402926ea 100644 --- a/tests/Ticket/1351TestCase.php +++ b/tests/Ticket/1351TestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Ticket_1351_TestCase extends Doctrine_UnitTestCase +class Doctrine_Ticket_1351_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { @@ -76,4 +76,4 @@ public function setUp() $i18n0->addChild($searchable1); $this->actAs($i18n0); } -} \ No newline at end of file +} diff --git a/tests/Ticket/1527TestCase.php b/tests/Ticket/1527TestCase.php index 40c8fe188..6d23902df 100644 --- a/tests/Ticket/1527TestCase.php +++ b/tests/Ticket/1527TestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Ticket_1527_TestCase extends Doctrine_UnitTestCase +class Doctrine_Ticket_1527_TestCase extends Doctrine_UnitTestCase { public function testTest() { @@ -52,7 +52,7 @@ public function testTest() $path = dirname(__DIR__) . '/tmp'; $import->importSchema($yml, 'yml', $path); - + require_once($path . '/generated/BaseTicket_1527_User.php'); require_once($path . '/Ticket_1527_User.php'); $username = Doctrine_Core::getTable('Ticket_1527_User')->getDefinitionOf('username'); diff --git a/tests/Ticket/1617TestCase.php b/tests/Ticket/1617TestCase.php index fc36a8bd9..8c8f71be6 100644 --- a/tests/Ticket/1617TestCase.php +++ b/tests/Ticket/1617TestCase.php @@ -29,7 +29,7 @@ * @since 1.1 * @version $Revision$ */ -class Doctrine_Ticket_1617_TestCase extends Doctrine_UnitTestCase +class Doctrine_Ticket_1617_TestCase extends Doctrine_UnitTestCase { public function testBuildSchema() { @@ -38,4 +38,4 @@ public function testBuildSchema() $this->assertEqual($array['term']['columns']['language']['name'], 'lang as language'); } -} \ No newline at end of file +} diff --git a/tests/Ticket/2355TestCase.php b/tests/Ticket/2355TestCase.php index c661703ca..918038635 100644 --- a/tests/Ticket/2355TestCase.php +++ b/tests/Ticket/2355TestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Ticket_2355_TestCase extends Doctrine_UnitTestCase +class Doctrine_Ticket_2355_TestCase extends Doctrine_UnitTestCase { public function setUp() { @@ -163,7 +163,7 @@ public function setTableDefinition() $this->index('episode', array( - 'fields' => + 'fields' => array( 0 => 'season', 1 => 'number', @@ -300,4 +300,4 @@ public function setUp() 'foreign' => 'id', 'onDelete' => 'CASCADE')); } -} \ No newline at end of file +} diff --git a/tests/Ticket/915TestCase.php b/tests/Ticket/915TestCase.php index c73ca976a..93ee51ce8 100644 --- a/tests/Ticket/915TestCase.php +++ b/tests/Ticket/915TestCase.php @@ -36,7 +36,7 @@ public function prepareData() { } public function prepareTables() { $this->tables[] = 'Account'; - parent::prepareTables(); + parent::prepareTables(); } public function testBug() @@ -72,4 +72,4 @@ public function testBug() $this->pass(); } } -} \ No newline at end of file +} diff --git a/tests/Ticket/DC147TestCase.php b/tests/Ticket/DC147TestCase.php index 2b0eb5487..d2783dbad 100644 --- a/tests/Ticket/DC147TestCase.php +++ b/tests/Ticket/DC147TestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Ticket_DC147_TestCase extends Doctrine_UnitTestCase +class Doctrine_Ticket_DC147_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { @@ -50,8 +50,8 @@ public function testInlineMultiple() name: isbn2 ISBN3: name: isbn3 -DC147_Product: - Product_1: +DC147_Product: + Product_1: name: book3 MultipleValues: Multi_1: @@ -60,7 +60,7 @@ public function testInlineMultiple() Multi_2: value: 232323233 Multiple: ISBN3 - Product_2: + Product_2: name: book4 MultipleValues: Multi_3: @@ -171,4 +171,4 @@ public function setUp() $this->hasOne('DC147_Product as Product', array('local' => 'product_id', 'foreign' => 'id')); } -} \ No newline at end of file +} diff --git a/tests/Ticket/DC23TestCase.php b/tests/Ticket/DC23TestCase.php index 20de702d7..2c17a2e6c 100644 --- a/tests/Ticket/DC23TestCase.php +++ b/tests/Ticket/DC23TestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Ticket_DC23_TestCase extends Doctrine_UnitTestCase +class Doctrine_Ticket_DC23_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { @@ -54,8 +54,8 @@ public function testTest() title: Test body: Testing -Ticket_DC23_User: - User_1: +Ticket_DC23_User: + User_1: name: jwage Contact: name: Test Contact @@ -196,4 +196,4 @@ public function setUp() ) ); } -} \ No newline at end of file +} diff --git a/tests/Ticket/DC23bTestCase.php b/tests/Ticket/DC23bTestCase.php index 682844ff2..b28d63149 100644 --- a/tests/Ticket/DC23bTestCase.php +++ b/tests/Ticket/DC23bTestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Ticket_DC23b_TestCase extends Doctrine_UnitTestCase +class Doctrine_Ticket_DC23b_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { @@ -45,8 +45,8 @@ public function testInlineSite() { $yml = <<hasOne('Ticket_Product as Product', array('local' => 'product_id', 'foreign' => 'id')); } -} \ No newline at end of file +} diff --git a/tests/Ticket/DC95TestCase.php b/tests/Ticket/DC95TestCase.php index f09d31f2d..c4d2bdcbd 100644 --- a/tests/Ticket/DC95TestCase.php +++ b/tests/Ticket/DC95TestCase.php @@ -30,7 +30,7 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Ticket_DC95_TestCase extends Doctrine_UnitTestCase +class Doctrine_Ticket_DC95_TestCase extends Doctrine_UnitTestCase { public function testClassDoesNotExistBeforeImport() { From f47a79078e7d816669a42007eb563ae28a296c9f Mon Sep 17 00:00:00 2001 From: thePanz Date: Wed, 26 Jun 2024 17:28:47 +0200 Subject: [PATCH 53/59] Tests: ensure models contain only one record per file --- tests/MigrationTestCase.php | 26 --------------- tests/Relation/OneToOneTestCase.php | 32 +++++++++---------- tests/models/Blog.php | 20 ------------ tests/models/{gnatEmail.php => GnatEmail.php} | 4 +-- tests/models/{gnatUser.php => GnatUser.php} | 15 ++++----- tests/models/GnatUserTable.php | 3 ++ tests/models/Group.php | 4 --- tests/models/GroupTable.php | 5 +++ tests/models/MigrationPhonenumber.php | 10 ++++++ tests/models/MigrationProfile.php | 9 ++++++ tests/models/MigrationUser.php | 10 ++++++ tests/models/RelationTest.php | 16 ---------- tests/models/RelationTestChild.php | 19 +++++++++++ tests/models/TagTemplate.php | 14 ++++++++ tests/models/Taggable.php | 8 +++++ tests/models/User.php | 4 --- tests/models/UserTable.php | 5 +++ tests/models/VersioningTest.php | 29 ----------------- tests/models/VersioningTest2.php | 13 ++++++++ tests/models/VersioningTest3.php | 17 ++++++++++ 20 files changed, 136 insertions(+), 127 deletions(-) rename tests/models/{gnatEmail.php => GnatEmail.php} (69%) rename tests/models/{gnatUser.php => GnatUser.php} (58%) create mode 100644 tests/models/GnatUserTable.php create mode 100644 tests/models/GroupTable.php create mode 100644 tests/models/MigrationPhonenumber.php create mode 100644 tests/models/MigrationProfile.php create mode 100644 tests/models/MigrationUser.php create mode 100644 tests/models/RelationTestChild.php create mode 100644 tests/models/TagTemplate.php create mode 100644 tests/models/Taggable.php create mode 100644 tests/models/UserTable.php create mode 100644 tests/models/VersioningTest2.php create mode 100644 tests/models/VersioningTest3.php diff --git a/tests/MigrationTestCase.php b/tests/MigrationTestCase.php index 59b2b336c..7b718ba54 100644 --- a/tests/MigrationTestCase.php +++ b/tests/MigrationTestCase.php @@ -128,29 +128,3 @@ public function testMigrationClassNameInflected() } } } - -class MigrationPhonenumber extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('user_id', 'integer'); - $this->hasColumn('phonenumber', 'string', 255); - } -} - -class MigrationUser extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('username', 'string', 255); - $this->hasColumn('password', 'string', 255); - } -} - -class MigrationProfile extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('name', 'string', 255); - } -} diff --git a/tests/Relation/OneToOneTestCase.php b/tests/Relation/OneToOneTestCase.php index b65f9dcf0..11264350f 100644 --- a/tests/Relation/OneToOneTestCase.php +++ b/tests/Relation/OneToOneTestCase.php @@ -30,14 +30,14 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Relation_OneToOne_TestCase extends Doctrine_UnitTestCase +class Doctrine_Relation_OneToOne_TestCase extends Doctrine_UnitTestCase { - public function prepareData() + public function prepareData() { } - public function prepareTables() - { - $this->tables = array('gnatUser','gnatEmail','Email','Entity','Record_City', 'Record_Country', 'SelfRefTest'); - + public function prepareTables() + { + $this->tables = array('GnatUser','GnatEmail','Email','Entity','Record_City', 'Record_Country', 'SelfRefTest'); + parent::prepareTables(); } @@ -46,27 +46,27 @@ public function testOneToOneAggregateRelationWithAliasesIsSupported() $city = new Record_City(); $country = $city->Country; - $this->assertTrue($country instanceof Record_Country); + $this->assertTrue($country instanceof Record_Country); } - + public function testSelfReferentialOneToOneRelationsAreSupported() { $ref = new SelfRefTest(); - + $rel = $ref->getTable()->getRelation('createdBy'); $this->assertEqual($rel->getForeign(), 'id'); $this->assertEqual($rel->getLocal(), 'created_by'); - + $ref->name = 'ref 1'; $ref->createdBy->name = 'ref 2'; - + $ref->save(); } public function testSelfReferentialOneToOneRelationsAreSupported2() { $this->connection->clear(); - + $ref = $this->conn->queryOne("FROM SelfRefTest s WHERE s.name = 'ref 1'"); $this->assertEqual($ref->name, 'ref 1'); $this->assertEqual($ref->createdBy->name, 'ref 2'); @@ -88,14 +88,14 @@ public function testUnsetRelation() public function testSavingRelatedObjects() { - $user = new gnatUser(); + $user = new GnatUser(); $user->name = 'test'; - $email = new gnatEmail(); + $email = new GnatEmail(); $email->address = 'test3@test.com'; $user->Email = $email; $user->save(); - $this->assertTrue($user->Email instanceOf gnatEmail); + $this->assertTrue($user->Email instanceOf GnatEmail); $this->assertEqual($user->foreign_id, $user->Email->id); - + } } diff --git a/tests/models/Blog.php b/tests/models/Blog.php index 00acbb1b1..1dc3018f1 100644 --- a/tests/models/Blog.php +++ b/tests/models/Blog.php @@ -10,23 +10,3 @@ public function setUp() $this->actAs('Taggable'); } } -class Taggable extends Doctrine_Template -{ - public function setUp() - { - //$this->hasMany('[Component]TagTemplate as Tag'); - } -} -class TagTemplate extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('name', 'string', 100); - $this->hasColumn('description', 'string'); - } - - public function setUp() - { - //$this->hasOne('[Component]', array('onDelete' => 'CASCADE')); - } -} diff --git a/tests/models/gnatEmail.php b/tests/models/GnatEmail.php similarity index 69% rename from tests/models/gnatEmail.php rename to tests/models/GnatEmail.php index 209ef6fd3..e07c6b8b6 100644 --- a/tests/models/gnatEmail.php +++ b/tests/models/GnatEmail.php @@ -1,10 +1,8 @@ hasColumn('address', 'string', 150); } - - } diff --git a/tests/models/gnatUser.php b/tests/models/GnatUser.php similarity index 58% rename from tests/models/gnatUser.php rename to tests/models/GnatUser.php index e6a66915b..f336231e3 100644 --- a/tests/models/gnatUser.php +++ b/tests/models/GnatUser.php @@ -1,19 +1,16 @@ -hasColumn('name', 'string', 150); $this->hasColumn('foreign_id', 'integer', 10, array ('unique' => true,)); } - + public function setUp() { parent::setUp(); - $this->hasOne('gnatEmail as Email', array('local'=> 'foreign_id', 'foreign'=>'id', 'onDelete'=>'CASCADE')); + $this->hasOne('GnatEmail as Email', array('local'=> 'foreign_id', 'foreign'=>'id', 'onDelete'=>'CASCADE')); } - -} +} diff --git a/tests/models/GnatUserTable.php b/tests/models/GnatUserTable.php new file mode 100644 index 000000000..f2c039b87 --- /dev/null +++ b/tests/models/GnatUserTable.php @@ -0,0 +1,3 @@ + Doctrine_Connection -// won't initialize grouptable when Doctrine_Connection->getTable('Group') is called -class GroupTable { } - class Group extends Entity { public function setUp() diff --git a/tests/models/GroupTable.php b/tests/models/GroupTable.php new file mode 100644 index 000000000..cc25211eb --- /dev/null +++ b/tests/models/GroupTable.php @@ -0,0 +1,5 @@ + Doctrine_Connection +// won't initialize grouptable when Doctrine_Connection->getTable('Group') is called +class GroupTable { } diff --git a/tests/models/MigrationPhonenumber.php b/tests/models/MigrationPhonenumber.php new file mode 100644 index 000000000..af55ef786 --- /dev/null +++ b/tests/models/MigrationPhonenumber.php @@ -0,0 +1,10 @@ +hasColumn('user_id', 'integer'); + $this->hasColumn('phonenumber', 'string', 255); + } +} diff --git a/tests/models/MigrationProfile.php b/tests/models/MigrationProfile.php new file mode 100644 index 000000000..8302b6751 --- /dev/null +++ b/tests/models/MigrationProfile.php @@ -0,0 +1,9 @@ +hasColumn('name', 'string', 255); + } +} diff --git a/tests/models/MigrationUser.php b/tests/models/MigrationUser.php new file mode 100644 index 000000000..7c366179f --- /dev/null +++ b/tests/models/MigrationUser.php @@ -0,0 +1,10 @@ +hasColumn('username', 'string', 255); + $this->hasColumn('password', 'string', 255); + } +} diff --git a/tests/models/RelationTest.php b/tests/models/RelationTest.php index 2932d7ca0..92f73cf8c 100644 --- a/tests/models/RelationTest.php +++ b/tests/models/RelationTest.php @@ -7,19 +7,3 @@ public function setTableDefinition() $this->hasColumn('parent_id', 'integer'); } } - -class RelationTestChild extends RelationTest -{ - public function setUp() - { - $this->hasOne('RelationTest as Parent', array( - 'local' => 'parent_id', - 'foreign' => 'id', - 'onDelete' => 'CASCADE', - )); - $this->hasMany('RelationTestChild as Children', array( - 'local' => 'id', - 'foreign' => 'parent_id', - )); - } -} diff --git a/tests/models/RelationTestChild.php b/tests/models/RelationTestChild.php new file mode 100644 index 000000000..7f1087e43 --- /dev/null +++ b/tests/models/RelationTestChild.php @@ -0,0 +1,19 @@ +hasOne('RelationTest as Parent', array( + 'local' => 'parent_id', + 'foreign' => 'id', + 'onDelete' => 'CASCADE', + )); + $this->hasMany('RelationTestChild as Children', array( + 'local' => 'id', + 'foreign' => 'parent_id', + )); + } +} diff --git a/tests/models/TagTemplate.php b/tests/models/TagTemplate.php new file mode 100644 index 000000000..9ecc7c9e3 --- /dev/null +++ b/tests/models/TagTemplate.php @@ -0,0 +1,14 @@ +hasColumn('name', 'string', 100); + $this->hasColumn('description', 'string'); + } + + public function setUp() + { + //$this->hasOne('[Component]', array('onDelete' => 'CASCADE')); + } +} diff --git a/tests/models/Taggable.php b/tests/models/Taggable.php new file mode 100644 index 000000000..98e6a6581 --- /dev/null +++ b/tests/models/Taggable.php @@ -0,0 +1,8 @@ +hasMany('[Component]TagTemplate as Tag'); + } +} diff --git a/tests/models/User.php b/tests/models/User.php index 9cd73295b..f093d0d08 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -2,10 +2,6 @@ require_once('Entity.php'); -// UserTable doesn't extend Doctrine_Table -> Doctrine_Connection -// won't initialize grouptable when Doctrine_Connection->getTable('User') is called -class UserTable extends Doctrine_Table { } - class User extends Entity { public function setUp() diff --git a/tests/models/UserTable.php b/tests/models/UserTable.php new file mode 100644 index 000000000..3f5e84710 --- /dev/null +++ b/tests/models/UserTable.php @@ -0,0 +1,5 @@ + Doctrine_Connection +// won't initialize grouptable when Doctrine_Connection->getTable('User') is called +class UserTable extends Doctrine_Table { } diff --git a/tests/models/VersioningTest.php b/tests/models/VersioningTest.php index 8219d1bcf..7cb60d492 100644 --- a/tests/models/VersioningTest.php +++ b/tests/models/VersioningTest.php @@ -11,32 +11,3 @@ public function setUp() $this->actAs('Versionable'); } } - -class VersioningTest2 extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('name', 'string'); - $this->hasColumn('version', 'integer'); - } - public function setUp() - { - $this->actAs('Versionable', array('auditLog' => false)); - } -} - -class VersioningTest3 extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('name', 'string'); - $this->hasColumn('version', 'integer'); - } - public function setUp() - { - - $this->actAs('Versionable', array('tableName' => 'tbl_prefix_comments_version', - 'className' => 'VersioningTestClass')); - - } -} \ No newline at end of file diff --git a/tests/models/VersioningTest2.php b/tests/models/VersioningTest2.php new file mode 100644 index 000000000..c48e9de31 --- /dev/null +++ b/tests/models/VersioningTest2.php @@ -0,0 +1,13 @@ +hasColumn('name', 'string'); + $this->hasColumn('version', 'integer'); + } + public function setUp() + { + $this->actAs('Versionable', array('auditLog' => false)); + } +} diff --git a/tests/models/VersioningTest3.php b/tests/models/VersioningTest3.php new file mode 100644 index 000000000..dd6a30403 --- /dev/null +++ b/tests/models/VersioningTest3.php @@ -0,0 +1,17 @@ +hasColumn('name', 'string'); + $this->hasColumn('version', 'integer'); + } + public function setUp() + { + $this->actAs('Versionable', array( + 'tableName' => 'tbl_prefix_comments_version', + 'className' => 'VersioningTestClass' + )); + } +} From 773e8ba7715768a436c85dea7bb71c0fa503bd47 Mon Sep 17 00:00:00 2001 From: Ian Ricketson Date: Wed, 3 Jul 2024 10:59:40 -0600 Subject: [PATCH 54/59] Fix return type --- lib/Doctrine/Record.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 2a2d92c06..d92005e75 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1985,7 +1985,7 @@ public function merge($data, $deep = true) * @link http://www.doctrine-project.org/documentation/manual/1_1/en/working-with-models * @param string $array array of data, see link for documentation * @param bool $deep whether or not to act on relations - * @return void + * @return Doctrine_Record */ public function fromArray(array $array, $deep = true) { From e7bbbb0080df5017a0753324123ce3e13866fd48 Mon Sep 17 00:00:00 2001 From: thePanz Date: Thu, 27 Jun 2024 16:44:54 +0200 Subject: [PATCH 55/59] Add(typehint) Add typehint to methods and return types --- lib/Doctrine/Connection.php | 30 +++++-------- lib/Doctrine/Manager.php | 40 +++++++++++------ lib/Doctrine/Migration.php | 46 +++++++++----------- tests/DoctrineTest/Doctrine_UnitTestCase.php | 2 + 4 files changed, 60 insertions(+), 58 deletions(-) diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 73a7e5fa7..6bb9e7ce8 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -52,6 +52,8 @@ * @version $Revision$ * @author Konsta Vesterinen * @author Lukas Smith (MDB2 library) + * + * @property Doctrine_Export $export */ abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate, Serializable { @@ -241,26 +243,19 @@ public function isConnected() } /** - * getOptions - * * Get array of all options * - * @return void + * @return array */ - public function getOptions() + public function getOptions(): array { return $this->options; } /** - * getOption - * - * Retrieves option - * - * @param string $option - * @return void + * @return null|mixed */ - public function getOption($option) + public function getOption(string $option) { if (isset($this->options[$option])) { return $this->options[$option]; @@ -268,14 +263,11 @@ public function getOption($option) } /** - * setOption - * * Set option value * - * @param string $option - * @return void + * @return mixed */ - public function setOption($option, $value) + public function setOption(string $option, $value) { return $this->options[$option] = $value; } @@ -1545,8 +1537,8 @@ public function dropDatabase() * which is always guaranteed to exist. Mysql: 'mysql', PostgreSQL: 'postgres', etc. * This value is set in the Doctrine_Export_{DRIVER} classes if required * - * @param string $info - * @return void + * @param array $info + * @return Doctrine_Connection */ public function getTmpConnection($info) { @@ -1569,7 +1561,7 @@ public function getTmpConnection($info) $username = $this->getOption('username'); $password = $this->getOption('password'); - $conn = $this->getManager()->openConnection(array($pdoDsn, $username, $password), 'doctrine_tmp_connection', false); + $conn = $this->getManager()->openConnection([$pdoDsn, $username, $password], 'doctrine_tmp_connection', false); $conn->setOption('username', $username); $conn->setOption('password', $password); diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index a2b08944d..9c07f8d3e 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -274,7 +274,7 @@ public static function connection($adapter = null, $name = null) /** * Opens a new connection and saves it to Doctrine_Manager->connections * - * @param PDO|Doctrine_Adapter_Interface $adapter database driver + * @param array|string|PDO|Doctrine_Adapter_Interface $adapter database driver * @param string $name name of the connection, if empty numeric key is used * @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name * @throws Doctrine_Manager_Exception if trying to open connection for unknown driver @@ -292,17 +292,17 @@ public function openConnection($adapter, $name = null, $setCurrent = true) if ( ! isset($adapter[0])) { throw new Doctrine_Manager_Exception('Empty data source name given.'); } - $e = explode(':', $adapter[0]); + $schema = explode(':', $adapter[0]); - if ($e[0] == 'uri') { - $e[0] = 'odbc'; + if ($schema[0] === 'uri') { + $schema[0] = 'odbc'; } $parts['dsn'] = $adapter[0]; - $parts['scheme'] = $e[0]; - $parts['user'] = (isset($adapter[1])) ? $adapter[1] : null; - $parts['pass'] = (isset($adapter[2])) ? $adapter[2] : null; - $driverName = $e[0]; + $parts['scheme'] = $schema[0]; + $parts['user'] = $adapter[1] ?? null; + $parts['pass'] = $adapter[2] ?? null; + $driverName = $schema[0]; $adapter = $parts; } else { $parts = $this->parseDsn($adapter); @@ -329,7 +329,7 @@ public function openConnection($adapter, $name = null, $setCurrent = true) return $this->_connections[$name]; } } else { - $name = $this->_index; + $name = (string) $this->_index; $this->_index++; } @@ -352,11 +352,23 @@ public function openConnection($adapter, $name = null, $setCurrent = true) /** * Parse a pdo style dsn in to an array of parts * - * @param array $dsn An array of dsn information - * @return array The array parsed + * @param string $dsn An array of dsn information + * @return array{ + * dsn: string, + * scheme: string, + * host: ?string, + * user: ?string, + * pass: ?string, + * password: ?string, + * port: ?string, + * path: ?string, + * query: ?string, + * fragment: ?string, + * unix_socket: ?string, + * } * @todo package:dbal */ - public function parsePdoDsn($dsn) + public function parsePdoDsn($dsn): array { $parts = array(); @@ -401,7 +413,7 @@ public function parsePdoDsn($dsn) * @param string $dsn * @return array $parts */ - protected function _buildDsnPartsArray($dsn) + protected function _buildDsnPartsArray(string $dsn) { // fix sqlite dsn so that it will parse correctly $dsn = str_replace("////", "/", $dsn); @@ -437,7 +449,7 @@ protected function _buildDsnPartsArray($dsn) * @return array Parsed contents of DSN * @todo package:dbal */ - public function parseDsn($dsn) + public function parseDsn(string $dsn) { $parts = $this->_buildDsnPartsArray($dsn); diff --git a/lib/Doctrine/Migration.php b/lib/Doctrine/Migration.php index 0208ce540..e05eed9fc 100644 --- a/lib/Doctrine/Migration.php +++ b/lib/Doctrine/Migration.php @@ -187,7 +187,7 @@ public function loadMigrationClass($name, $path = null) } if ($class === false) { - return false; + return; } if (empty($this->_migrationClasses)) { @@ -305,17 +305,15 @@ public function getNextMigrationClassVersion() * migrate to. It will automatically know whether you are migrating up or down * based on the current version of the database. * - * @param integer $to Version to migrate to - * @param boolean $dryRun Whether or not to run the migrate process as a dry run - * @return integer $to Version number migrated to + * @param int $to Version to migrate to + * @param bool $dryRun Whether or not to run the migrate process as a dry run + * @return int|false Returns the migration version reached by the migration, false otherwise * @throws Doctrine_Exception */ public function migrate($to = null, $dryRun = false) { $this->clearErrors(); - $this->_createMigrationTable(); - $this->_connection->beginTransaction(); try { @@ -335,24 +333,22 @@ public function migrate($to = null, $dryRun = false) if ($dryRun) { return false; - } else { - $this->_throwErrorsException(); } - } else { - if ($dryRun) { - $this->_connection->rollback(); - if ($this->hasErrors()) { - return false; - } else { - return $to; - } - } else { - $this->_connection->commit(); - $this->setCurrentVersion($to); - return $to; + $this->_throwErrorsException(); + } + + if ($dryRun) { + $this->_connection->rollback(); + if ($this->hasErrors()) { + return false; } + return $to; } - return false; + + $this->_connection->commit(); + $this->setCurrentVersion($to); + + return $to; } /** @@ -435,12 +431,12 @@ public function getMigrationClass($num) } /** - * Throw an exception with all the errors trigged during the migration + * Throw an exception with all the errors triggered during the migration * - * @return void - * @throws Doctrine_Migration_Exception $e + * @return never-returns + * @throws Doctrine_Migration_Exception */ - protected function _throwErrorsException() + protected function _throwErrorsException(): void { $messages = array(); $num = 0; diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index 3fa7bcbcd..c158d5da2 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -216,6 +216,7 @@ public function init() } } } + public function prepareTables() { foreach($this->tables as $name) { $name = ucwords($name); @@ -230,6 +231,7 @@ public function prepareTables() { $this->conn->export->exportClasses($this->tables); $this->objTable = $this->connection->getTable('User'); } + public function prepareData() { $groups = new Doctrine_Collection($this->connection->getTable('Group')); From 5c857c27ff1eb5aae78d1019eefbd41219bc57aa Mon Sep 17 00:00:00 2001 From: thePanz Date: Fri, 11 Oct 2024 21:55:41 +0200 Subject: [PATCH 56/59] Add(typehint): Add typehint to methods and void return to Doctrine_Query_Abstract::clear() --- lib/Doctrine/Query.php | 5 +---- lib/Doctrine/Query/Abstract.php | 4 +--- lib/Doctrine/RawSql.php | 6 +++--- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index a4d0b40f8..bf80f1d1e 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -187,10 +187,7 @@ public static function create($conn = null, $class = null) return new $class($conn); } - /** - * Clears all the sql parts. - */ - protected function clear() + protected function clear(): void { $this->_preQueried = false; $this->_pendingJoinConditions = array(); diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 247886f1c..ae78b1f68 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -1917,10 +1917,8 @@ public function offset($offset) /** * Resets all the sql parts. - * - * @return void */ - protected function clear() + protected function clear(): void { $this->_sqlParts = array( 'select' => array(), diff --git a/lib/Doctrine/RawSql.php b/lib/Doctrine/RawSql.php index 73220e2e9..99d0b6d18 100644 --- a/lib/Doctrine/RawSql.php +++ b/lib/Doctrine/RawSql.php @@ -57,7 +57,7 @@ function __construct(Doctrine_Connection $connection = null, Doctrine_Hydrator_A $this->useQueryCache(false); } - protected function clear() + protected function clear(): void { $this->_preQueried = false; $this->_pendingJoinConditions = array(); @@ -108,9 +108,9 @@ protected function _addDqlQueryPart($queryPartName, $queryPart, $append = false) /** * Add select parts to fields. * - * @param $queryPart sting The name of the querypart + * @param $queryPart string The name of the querypart */ - private function _parseSelectFields($queryPart) + private function _parseSelectFields(string $queryPart): void { preg_match_all('/{([^}{]*)}/U', $queryPart, $m); $this->fields = $m[1]; From 5ffcb732739b6e293315b4ea2d63d6f9a6073c33 Mon Sep 17 00:00:00 2001 From: thePanz Date: Sat, 26 Oct 2024 00:47:47 +0200 Subject: [PATCH 57/59] Fix(typehint) Fix PHP deprecations on Doctrine_Record_Filter::filterSet() and ::filterGet() and sub-classes --- lib/Doctrine/Record/Filter.php | 10 ++++++++-- lib/Doctrine/Record/Filter/Compound.php | 14 +++----------- lib/Doctrine/Record/Filter/Standard.php | 8 ++------ 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/Record/Filter.php b/lib/Doctrine/Record/Filter.php index b122ff723..24123b6d4 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|null + */ protected $_table; public function setTable(Doctrine_Table $table) @@ -40,6 +43,9 @@ public function setTable(Doctrine_Table $table) $this->_table = $table; } + /** + * @return Doctrine_Table|null + */ public function getTable() { return $this->_table; @@ -56,7 +62,7 @@ public function init() * * @return Doctrine_Record the given record * - * @thrown Doctrine_Exception when this way is not available + * @throws Doctrine_Exception when this way is not available */ abstract public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value); @@ -67,7 +73,7 @@ abstract public function filterSet(Doctrine_Record $record, $propertyOrRelation, * * @return mixed * - * @thrown Doctrine_Exception when this way is not available + * @throws Doctrine_Exception when this way is not available */ 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 38e599aec..f4e212af8 100644 --- a/lib/Doctrine/Record/Filter/Compound.php +++ b/lib/Doctrine/Record/Filter/Compound.php @@ -57,13 +57,9 @@ public function init() } /** - * Provides a way for setting property or relation value to the given record. + * @return Doctrine_Record * - * @param string $propertyOrRelation - * - * @return Doctrine_Record the given record - * - * @thrown Doctrine_Record_UnknownPropertyException when this way is not available + * @throws Doctrine_Record_UnknownPropertyException */ public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) { @@ -90,13 +86,9 @@ public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) } /** - * Provides a way for getting property or relation value from the given record. - * - * @param string $propertyOrRelation - * * @return mixed * - * @thrown Doctrine_Record_UnknownPropertyException when this way is not available + * @throws Doctrine_Record_UnknownPropertyException */ public function filterGet(Doctrine_Record $record, $propertyOrRelation) { diff --git a/lib/Doctrine/Record/Filter/Standard.php b/lib/Doctrine/Record/Filter/Standard.php index f2a665358..e4fc5cf51 100644 --- a/lib/Doctrine/Record/Filter/Standard.php +++ b/lib/Doctrine/Record/Filter/Standard.php @@ -34,9 +34,7 @@ class Doctrine_Record_Filter_Standard extends Doctrine_Record_Filter { /** - * @param string $propertyOrRelation - * - * @thrown Doctrine_Record_UnknownPropertyException + * @return Doctrine_Record the given record */ public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) { @@ -44,9 +42,7 @@ public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value) } /** - * @param string $propertyOrRelation - * - * @thrown Doctrine_Record_UnknownPropertyException + * @return mixed */ public function filterGet(Doctrine_Record $record, $propertyOrRelation) { From 1fcab9a197981298886f8c3b15fd667bc062e88a Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 23 Dec 2024 21:36:22 +0100 Subject: [PATCH 58/59] Added php 8.4 to ci pipeline --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 26b4f3b23..811bfdf8a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -35,6 +35,7 @@ jobs: - "8.1" - "8.2" - "8.3" + - "8.4" steps: - name: Checkout From bbd1cddc25dbc2325abd05d213efa0659770226e Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Mon, 23 Dec 2024 21:47:16 +0100 Subject: [PATCH 59/59] PHP 8.4 > Implicitly marking parameter as nullable is deprecated --- lib/Doctrine/Cli.php | 6 +++--- lib/Doctrine/Collection.php | 10 +++++----- lib/Doctrine/Connection/Mssql.php | 4 ++-- lib/Doctrine/Query.php | 4 ++-- lib/Doctrine/Query/Abstract.php | 11 ++++++----- lib/Doctrine/Query/Part.php | 2 +- lib/Doctrine/RawSql.php | 6 +++--- lib/Doctrine/Record.php | 8 ++++---- lib/Doctrine/Table.php | 6 +++--- lib/Doctrine/Tree/Interface.php | 4 ++-- lib/Doctrine/Tree/NestedSet.php | 4 ++-- tests/DoctrineTest/GroupTest.php | 2 +- tests/DoctrineTest/UnitTestCase.php | 2 +- 13 files changed, 35 insertions(+), 34 deletions(-) diff --git a/lib/Doctrine/Cli.php b/lib/Doctrine/Cli.php index f6cd3dd4f..b366ef2d7 100644 --- a/lib/Doctrine/Cli.php +++ b/lib/Doctrine/Cli.php @@ -71,10 +71,10 @@ class Doctrine_Cli /** * __construct * - * @param array [$config=array()] - * @param object|null [$formatter=null] Doctrine_Cli_Formatter + * @param array $config + * @param Doctrine_Cli_Formatter|null $formatter */ - public function __construct(array $config = array(), Doctrine_Cli_Formatter $formatter = null) + public function __construct(array $config = array(), ?Doctrine_Cli_Formatter $formatter = null) { $this->setConfig($config); $this->setFormatter($formatter ? $formatter : new Doctrine_Cli_AnsiColorFormatter()); diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/Collection.php index 7b3c60104..80afe5290 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/Collection.php @@ -924,10 +924,10 @@ protected function compareRecords($a, $b) * Saves all records of this collection and processes the * difference of the last snapshot and the current data * - * @param Doctrine_Connection $conn optional connection parameter + * @param Doctrine_Connection|null $conn optional connection parameter * @return Doctrine_Collection */ - public function save(Doctrine_Connection $conn = null, $processDiff = true) + public function save(?Doctrine_Connection $conn = null, $processDiff = true) { if ($conn == null) { $conn = $this->_table->getConnection(); @@ -959,10 +959,10 @@ public function save(Doctrine_Connection $conn = null, $processDiff = true) * Replaces all records of this collection and processes the * difference of the last snapshot and the current data * - * @param Doctrine_Connection $conn optional connection parameter + * @param Doctrine_Connection|null $conn optional connection parameter * @return Doctrine_Collection */ - public function replace(Doctrine_Connection $conn = null, $processDiff = true) + public function replace(?Doctrine_Connection $conn = null, $processDiff = true) { if ($conn == null) { $conn = $this->_table->getConnection(); @@ -995,7 +995,7 @@ public function replace(Doctrine_Connection $conn = null, $processDiff = true) * * @return Doctrine_Collection */ - public function delete(Doctrine_Connection $conn = null, $clearColl = true) + public function delete(?Doctrine_Connection $conn = null, $clearColl = true) { if ($conn == null) { $conn = $this->_table->getConnection(); diff --git a/lib/Doctrine/Connection/Mssql.php b/lib/Doctrine/Connection/Mssql.php index ecce33f10..ac6a1e7e1 100644 --- a/lib/Doctrine/Connection/Mssql.php +++ b/lib/Doctrine/Connection/Mssql.php @@ -108,12 +108,12 @@ public function quoteIdentifier($identifier, $checkOption = false) * @param mixed $limit * @param mixed $offset * @param boolean $isSubQuery - * @param Doctrine_Query $queryOrigin + * @param Doctrine_Query|null $queryOrigin * @link https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php#L607 * @link http://www.toosweettobesour.com/2010/09/16/doctrine-1-2-mssql-alternative-limitpaging/ * @return string */ - public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false, $isSubQuery = false, Doctrine_Query $queryOrigin = null) + public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false, $isSubQuery = false, ?Doctrine_Query $queryOrigin = null) { if ($limit === false || !($limit > 0)) { return $query; diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index bf80f1d1e..36a8425d9 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -2174,9 +2174,9 @@ public function query($query, $params = array(), $hydrationMode = null) /** * Copies a Doctrine_Query object. * - * @return Doctrine_Query Copy of the Doctrine_Query instance. + * @return Doctrine_Query|null Copy of the Doctrine_Query instance. */ - public function copy(Doctrine_Query $query = null) + public function copy(?Doctrine_Query $query = null) { if ( ! $query) { $query = $this; diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index ae78b1f68..aa4ff498c 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -292,14 +292,15 @@ abstract class Doctrine_Query_Abstract /** * Constructor. * - * @param Doctrine_Connection $connection The connection object the query will use. - * @param Doctrine_Hydrator_Abstract $hydrator The hydrator that will be used for generating result sets. + * @param Doctrine_Connection|null $connection The connection object the query will use. + * @param Doctrine_Hydrator_Abstract|null $hydrator The hydrator that will be used for generating result sets. * * @throws Doctrine_Connection_Exception */ - public function __construct(Doctrine_Connection $connection = null, - Doctrine_Hydrator_Abstract $hydrator = null) - { + public function __construct( + ?Doctrine_Connection $connection = null, + ?Doctrine_Hydrator_Abstract $hydrator = null + ) { if ($connection === null) { $connection = Doctrine_Manager::getInstance()->getCurrentConnection(); } else { diff --git a/lib/Doctrine/Query/Part.php b/lib/Doctrine/Query/Part.php index 629ed2ad4..dc5a35759 100644 --- a/lib/Doctrine/Query/Part.php +++ b/lib/Doctrine/Query/Part.php @@ -42,7 +42,7 @@ abstract class Doctrine_Query_Part /** * @param Doctrine_Query $query the query object associated with this parser */ - public function __construct($query, Doctrine_Query_Tokenizer $tokenizer = null) + public function __construct($query, ?Doctrine_Query_Tokenizer $tokenizer = null) { $this->query = $query; diff --git a/lib/Doctrine/RawSql.php b/lib/Doctrine/RawSql.php index 99d0b6d18..279720164 100644 --- a/lib/Doctrine/RawSql.php +++ b/lib/Doctrine/RawSql.php @@ -46,10 +46,10 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract /** * Constructor. * - * @param Doctrine_Connection The connection object the query will use. - * @param Doctrine_Hydrator_Abstract The hydrator that will be used for generating result sets. + * @param Doctrine_Connection|null $connection The connection object the query will use. + * @param Doctrine_Hydrator_Abstract|null $hydrator The hydrator that will be used for generating result sets. */ - function __construct(Doctrine_Connection $connection = null, Doctrine_Hydrator_Abstract $hydrator = null) { + function __construct(?Doctrine_Connection $connection = null, ?Doctrine_Hydrator_Abstract $hydrator = null) { parent::__construct($connection, $hydrator); // Fix #1472. It's alid to disable QueryCache since there's no DQL for RawSql. diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index d92005e75..6edaeb31a 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1729,7 +1729,7 @@ public function resetPendingUnlinks() * @throws Exception if record is not valid and validation is active * @return void */ - public function save(Doctrine_Connection $conn = null) + public function save(?Doctrine_Connection $conn = null) { if ($conn === null) { $conn = $this->_table->getConnection(); @@ -1746,7 +1746,7 @@ public function save(Doctrine_Connection $conn = null) * @param Doctrine_Connection $conn optional connection parameter * @return TRUE if the record was saved sucessfully without errors, FALSE otherwise. */ - public function trySave(Doctrine_Connection $conn = null) { + public function trySave(?Doctrine_Connection $conn = null) { try { $this->save($conn); return true; @@ -1772,7 +1772,7 @@ public function trySave(Doctrine_Connection $conn = null) { * @throws Doctrine_Connection_Exception if something fails at database level * @return integer number of rows affected */ - public function replace(Doctrine_Connection $conn = null) + public function replace(?Doctrine_Connection $conn = null) { if ($conn === null) { $conn = $this->_table->getConnection(); @@ -2197,7 +2197,7 @@ public function getIterator() * * @return boolean true if successful */ - public function delete(Doctrine_Connection $conn = null) + public function delete(?Doctrine_Connection $conn = null) { if ($conn == null) { $conn = $this->_table->getConnection(); diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index faac80574..2f85f606b 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -2066,10 +2066,10 @@ public function enumIndex($fieldName, $value) * * @param string $fieldName * @param string $value - * @param Doctrine_Record $record record to consider; if it does not exists, it is created + * @param Doctrine_Record|null $record record to consider; if it does not exist, it is created * @return Doctrine_Validator_ErrorStack $errorStack */ - public function validateField($fieldName, $value, Doctrine_Record $record = null) + public function validateField($fieldName, $value, ?Doctrine_Record $record = null) { if ($record instanceof Doctrine_Record) { $errorStack = $record->getErrorStack(); @@ -2222,7 +2222,7 @@ public function removeColumn($fieldName) * * @return array numeric array */ - public function getColumnNames(array $fieldNames = null) + public function getColumnNames(?array $fieldNames = null) { if ($fieldNames === null) { return array_keys($this->_columns); diff --git a/lib/Doctrine/Tree/Interface.php b/lib/Doctrine/Tree/Interface.php index 4a88116c4..e7f5f688c 100644 --- a/lib/Doctrine/Tree/Interface.php +++ b/lib/Doctrine/Tree/Interface.php @@ -35,9 +35,9 @@ interface Doctrine_Tree_Interface { /** * creates root node from given record or from a new record * - * @param Doctrine_Record $record instance of Doctrine_Record + * @param Doctrine_Record|null $record instance of Doctrine_Record */ - public function createRoot(Doctrine_Record $record = null); + public function createRoot(?Doctrine_Record $record = null); /** * returns root node diff --git a/lib/Doctrine/Tree/NestedSet.php b/lib/Doctrine/Tree/NestedSet.php index 53ba87269..b44371b61 100644 --- a/lib/Doctrine/Tree/NestedSet.php +++ b/lib/Doctrine/Tree/NestedSet.php @@ -82,9 +82,9 @@ public function setTableDefinition() * the records id will be assigned to the root id. You must use numeric columns for the id * and root id columns. * - * @param object $record instance of Doctrine_Record + * @param Doctrine_Record|null $record instance of Doctrine_Record */ - public function createRoot(Doctrine_Record $record = null) + public function createRoot(?Doctrine_Record $record = null) { if ($this->getAttribute('hasManyRoots')) { if ( ! $record || ( ! $record->exists() && ! $record->getNode()->getRootValue()) diff --git a/tests/DoctrineTest/GroupTest.php b/tests/DoctrineTest/GroupTest.php index 5f4eb14b9..c76147471 100644 --- a/tests/DoctrineTest/GroupTest.php +++ b/tests/DoctrineTest/GroupTest.php @@ -52,7 +52,7 @@ public function shouldBeRun($testCase, $filter) } return true; } - public function run(DoctrineTest_Reporter $reporter = null, $filter = null) + public function run(?DoctrineTest_Reporter $reporter = null, $filter = null) { set_time_limit(900); diff --git a/tests/DoctrineTest/UnitTestCase.php b/tests/DoctrineTest/UnitTestCase.php index cfa461e13..0865b40f7 100644 --- a/tests/DoctrineTest/UnitTestCase.php +++ b/tests/DoctrineTest/UnitTestCase.php @@ -155,7 +155,7 @@ 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 ($this->isTestMethod($method)) {