Skip to content

Commit

Permalink
Upgrade dbal dependency to ^2.13|^3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Afanasev committed Mar 28, 2023
1 parent ce808b4 commit 0ab73e8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
4 changes: 2 additions & 2 deletions lib/Magomogo/Persisted/Container/SqlDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
17 changes: 8 additions & 9 deletions test/Persisted/Container/SqlDb/SchemaCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
);

}
Expand All @@ -54,18 +54,17 @@ public function testATableForAggregatedProperties()
self::asOneLine(
<<<SQL
CREATE TABLE "creditcard" (
id INTEGER NOT NULL,
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"system" CLOB DEFAULT NULL,
"pan" CLOB DEFAULT NULL,
"validMonth" CLOB DEFAULT NULL,
"validYear" CLOB DEFAULT NULL,
"ccv" CLOB DEFAULT NULL,
"cardholderName" CLOB DEFAULT NULL,
PRIMARY KEY(id)
"cardholderName" CLOB DEFAULT NULL
)
SQL
),
$this->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'")
);
}

Expand All @@ -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'")
);
}

Expand Down
6 changes: 3 additions & 3 deletions test/Persisted/Container/SqlDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}

Expand Down
18 changes: 9 additions & 9 deletions test/Persisted/Container/SqliteDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
);
}

Expand All @@ -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(
Expand All @@ -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")
);
}

Expand Down Expand Up @@ -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()
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 0ab73e8

Please sign in to comment.