From 0ab73e8e6300981c496d6b41324307e9f45d1b6e Mon Sep 17 00:00:00 2001 From: Anton Afanasev Date: Tue, 28 Mar 2023 13:03:21 +0700 Subject: [PATCH] Upgrade dbal dependency to ^2.13|^3.0 --- composer.json | 4 ++-- lib/Magomogo/Persisted/Container/SqlDb.php | 4 ++-- .../Container/SqlDb/SchemaCreatorTest.php | 17 ++++++++--------- test/Persisted/Container/SqlDbTest.php | 6 +++--- test/Persisted/Container/SqliteDbTest.php | 18 +++++++++--------- .../Persisted/Test/Person/Properties.php | 2 +- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index f552b7b..1f6aac7 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,8 @@ "description": "A way to make domain-specific models persistent", "homepage": "https://github.com/Magomogo/persisted-models", "require": { - "php":">=5.6.0", - "doctrine/dbal": "~2.5.0" + "php":"^7.1 || ^8.0", + "doctrine/dbal": "^2.13|^3.0" }, "require-dev": { "ext-pdo": "*", diff --git a/lib/Magomogo/Persisted/Container/SqlDb.php b/lib/Magomogo/Persisted/Container/SqlDb.php index 176b841..e1b1112 100644 --- a/lib/Magomogo/Persisted/Container/SqlDb.php +++ b/lib/Magomogo/Persisted/Container/SqlDb.php @@ -119,7 +119,7 @@ private function begin($properties) { if (!is_null($properties->id($this))) { - $row = $this->db->fetchAssoc( + $row = $this->db->fetchAssociative( 'SELECT * FROM ' . $this->db->quoteIdentifier($this->names->propertiesToName($properties)) . ' WHERE ' . $this->db->quoteIdentifier(($properties->naturalKeyFieldName() ?: 'id')) . '=?', array($properties->id($this)) @@ -194,7 +194,7 @@ private function loadCollections($collections, $ownerProperties) $referenceName = $this->names->manyToManyRelationName($collection, $ownerProperties); $rightPropertiesName = $this->names->collectionToName($collection); - $list = $this->db->fetchAll( + $list = $this->db->fetchAllAssociative( 'SELECT * FROM ' . $this->db->quoteIdentifier($referenceName) . ' WHERE ' . $this->db->quoteIdentifier($leftPropertiesName) . '=?', array($ownerProperties->id($this)) diff --git a/test/Persisted/Container/SqlDb/SchemaCreatorTest.php b/test/Persisted/Container/SqlDb/SchemaCreatorTest.php index 1183deb..f63759a 100644 --- a/test/Persisted/Container/SqlDb/SchemaCreatorTest.php +++ b/test/Persisted/Container/SqlDb/SchemaCreatorTest.php @@ -35,13 +35,13 @@ public function testCreatesATableForPersonProperties() self::schema($this->connection->getSchemaManager())->schemaFor(Person::maxim()); $this->assertRegExp( - '/CREATE TABLE "person" \(id INTEGER NOT NULL, "title" CLOB DEFAULT NULL, "firstName" CLOB DEFAULT NULL/', - $this->connection->fetchColumn("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'person'") + '/CREATE TABLE "person" \(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" CLOB DEFAULT NULL, "firstName" CLOB DEFAULT NULL/', + $this->connection->fetchOne("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'person'") ); $this->assertRegExp( '/CREATE INDEX .+ ON "person" \\("creditCard"\\)/', - $this->connection->fetchColumn("SELECT sql FROM sqlite_master WHERE type = 'index' AND tbl_name = 'person'") + $this->connection->fetchOne("SELECT sql FROM sqlite_master WHERE type = 'index' AND tbl_name = 'person'") ); } @@ -54,18 +54,17 @@ public function testATableForAggregatedProperties() self::asOneLine( <<connection->fetchColumn("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'creditcard'") + $this->connection->fetchOne("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'creditcard'") ); } @@ -78,12 +77,12 @@ public function testCreatesATableForManyToManyReference() $this->assertRegExp( '/CREATE TABLE "person2keymarker" \("person" INTEGER UNSIGNED DEFAULT NULL, "keymarker" VARCHAR\(255\) DEFAULT NULL/', - $this->connection->fetchColumn("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'person2keymarker'") + $this->connection->fetchOne("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'person2keymarker'") ); $this->assertRegExp( '/CREATE INDEX .+ ON "person2keymarker" \\("person"\\)/', - $this->connection->fetchColumn("SELECT sql FROM sqlite_master WHERE type = 'index' AND tbl_name = 'person2keymarker'") + $this->connection->fetchOne("SELECT sql FROM sqlite_master WHERE type = 'index' AND tbl_name = 'person2keymarker'") ); } diff --git a/test/Persisted/Container/SqlDbTest.php b/test/Persisted/Container/SqlDbTest.php index d76d742..e08096c 100644 --- a/test/Persisted/Container/SqlDbTest.php +++ b/test/Persisted/Container/SqlDbTest.php @@ -27,7 +27,7 @@ public function testFollowsTableNamingConvention() public function testLoadsReferencesAccordingToReferenceName() { $db = self::dbMock(); - $db->shouldReceive('fetchAssoc')->andReturn( + $db->shouldReceive('fetchAssociative')->andReturn( array('ref1' => 4, 'ref2' => 5), array() ); @@ -89,7 +89,7 @@ public function testExceptionOnLoadingWhenPropertiesAreNotFound() { $this->setExpectedException('Magomogo\\Persisted\\Exception\\NotFound'); - $container = self::container(m::mock(array('fetchAssoc' => false, 'quoteIdentifier' => 'table'))); + $container = self::container(m::mock(array('fetchAssociative' => false, 'quoteIdentifier' => 'table'))); $notFoundProperties = new TestType1(); $notFoundProperties->persisted(11, $container); @@ -128,7 +128,7 @@ function($arg) use ($wrap) {return $wrap ? "`{$arg}`" : $arg;} private static function container($db = null) { - return new SqlDb($db ?: m::mock(array('fetchAssoc' => array())), new DbNames()); + return new SqlDb($db ?: m::mock(array('fetchAssociative' => array())), new DbNames()); } } diff --git a/test/Persisted/Container/SqliteDbTest.php b/test/Persisted/Container/SqliteDbTest.php index d5cb485..e0bfc93 100644 --- a/test/Persisted/Container/SqliteDbTest.php +++ b/test/Persisted/Container/SqliteDbTest.php @@ -27,9 +27,9 @@ protected function setUp() public function testFixtureHasCorrectTablesCreated() { - $this->assertEquals(array(), $this->fixture->db->fetchAll("SELECT * FROM company")); - $this->assertEquals(array(), $this->fixture->db->fetchAll("SELECT * FROM person")); - $this->assertEquals(array(), $this->fixture->db->fetchAll("SELECT * FROM creditcard")); + $this->assertEquals(array(), $this->fixture->db->fetchAllAssociative("SELECT * FROM company")); + $this->assertEquals(array(), $this->fixture->db->fetchAllAssociative("SELECT * FROM person")); + $this->assertEquals(array(), $this->fixture->db->fetchAllAssociative("SELECT * FROM creditcard")); } public function testSavesCreditCardIntoDatabase() @@ -46,7 +46,7 @@ public function testSavesCreditCardIntoDatabase() 'ccv' => '234', 'cardholderName' => 'Maxim Gnatenko' ), - $this->fixture->db->fetchAssoc("SELECT * FROM creditcard") + $this->fixture->db->fetchAssociative("SELECT * FROM creditcard") ); } @@ -66,7 +66,7 @@ public function testSavesAPersonHavingCreditCardIntoDatabase() 'creditCard' => 1, 'birthDay' => '1975-07-07', ), - self::smoothBirthDayFormatDifference($this->fixture->db->fetchAssoc("SELECT * FROM person")) + self::smoothBirthDayFormatDifference($this->fixture->db->fetchAssociative("SELECT * FROM person")) ); $this->assertEquals( @@ -79,7 +79,7 @@ public function testSavesAPersonHavingCreditCardIntoDatabase() 'ccv' => '234', 'cardholderName' => 'Maxim Gnatenko' ), - $this->fixture->db->fetchAssoc("SELECT * FROM creditcard") + $this->fixture->db->fetchAssociative("SELECT * FROM creditcard") ); } @@ -113,14 +113,14 @@ public function testWritesEmployeePropertiesIntoPersonPropertiesTable() 'creditCard' => 1, 'birthDay' => '1975-07-07' ), - self::smoothBirthDayFormatDifference($this->fixture->db->fetchAssoc("SELECT * FROM person")) + self::smoothBirthDayFormatDifference($this->fixture->db->fetchAssociative("SELECT * FROM person")) ); } public function testCreatesTwoRecordsOfSameType() { $this->persistTwoKeymarkers(); - $this->assertEquals('2', $this->fixture->db->fetchColumn('select count(1) from keymarker')); + $this->assertEquals('2', $this->fixture->db->fetchOne('select count(1) from keymarker')); } private function persistTwoKeymarkers() @@ -142,7 +142,7 @@ public function testWorksWithNulls() $id = $vova->save($this->sqliteContainer()); $this->assertNull( - $this->fixture->db->fetchColumn("SELECT lastName FROM person WHERE id = ?", array($id)) + $this->fixture->db->fetchOne("SELECT lastName FROM person WHERE id = ?", array($id)) ); $person = Person\Model::load($this->sqliteContainer(), $id); diff --git a/test/_classes/Magomogo/Persisted/Test/Person/Properties.php b/test/_classes/Magomogo/Persisted/Test/Person/Properties.php index 2e5f5d4..9a152fb 100644 --- a/test/_classes/Magomogo/Persisted/Test/Person/Properties.php +++ b/test/_classes/Magomogo/Persisted/Test/Person/Properties.php @@ -45,7 +45,7 @@ class Properties extends AbstractProperties protected function init() { $this->creditCard = new CreditCard\Model(new CreditCard\Properties); - $this->birthDay = new \DateTime('1970-01-01T00:00:00+07:00'); + $this->birthDay = new \DateTime('1970-01-02T00:00:00+07:00'); $this->hasCollection(new Keymarker\Collection(), 'tags'); } }