From fa8f3739fae07e082d05bd9ff81f8f0343ae7d32 Mon Sep 17 00:00:00 2001 From: Andrejs Semovs Date: Thu, 8 Dec 2016 16:57:48 +0100 Subject: [PATCH 1/3] Fix Mapper::query() method to pass param types. --- lib/Mapper.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Mapper.php b/lib/Mapper.php index 7cf9595..5be0dd4 100644 --- a/lib/Mapper.php +++ b/lib/Mapper.php @@ -559,10 +559,11 @@ public function create(array $data, array $options = []) * * @param string $sql Raw query or SQL to run against the datastore * @param array Optional $conditions Array of binds in column => value pairs to use for prepared statement + * @param array Optional $types Array of DBAL column types (e.g. to specify custom type for IN () condition) */ - public function query($sql, array $params = []) + public function query($sql, array $params = [], array $types = []) { - $result = $this->connection()->executeQuery($sql, $params); + $result = $this->connection()->executeQuery($sql, $params, $types); if ($result) { return $this->collection($result); } From c21a0786f93cc887bd484d2e38a84a3abfe561f0 Mon Sep 17 00:00:00 2001 From: Andrejs Semovs Date: Sun, 11 Dec 2016 23:50:43 +0200 Subject: [PATCH 2/3] Fix Validation unit test error message --- tests/Validation.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Validation.php b/tests/Validation.php index 4a8fdac..acd80a0 100644 --- a/tests/Validation.php +++ b/tests/Validation.php @@ -112,7 +112,8 @@ public function testLength() $mapper->save($entity); $this->assertTrue($entity->hasErrors()); - $this->assertContains("Email must be at least 4 long", $entity->errors('email')); + // This error message is used for length range validation + $this->assertContains("Email must be 4 characters long", $entity->errors('email')); } public function testDisabledValidation() From e96b2937e19fb9b4e5e8651d906dee895e1e5aee Mon Sep 17 00:00:00 2001 From: Andrejs Semovs Date: Thu, 30 Nov 2017 02:25:41 +0100 Subject: [PATCH 3/3] Add tests for custom query with indexed param types --- tests/QuerySql.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/QuerySql.php b/tests/QuerySql.php index 17a2fd9..234898e 100644 --- a/tests/QuerySql.php +++ b/tests/QuerySql.php @@ -404,6 +404,29 @@ public function testCustomQueryWithSqlAndNamedParams() $this->assertSame($postCount, $i); } + public function testCustomQueryWithSqlAndIndexedParamTypes() + { + $mapper = test_spot_mapper('SpotTest\Entity\Tag'); + $names = ['Tag 1', 'Tag 2']; + + $tags = $mapper->query( + "SELECT * FROM " . $mapper->table() . " WHERE name IN (?)", + [$names], + [\Doctrine\DBAL\Connection::PARAM_STR_ARRAY] + ); + $this->assertInstanceOf('Spot\Entity\Collection', $tags); + $tagCount = count($tags); + + $i = 0; + foreach ($tags as $tag) { + $i++; + $this->assertInstanceOf('SpotTest\Entity\Tag', $tag); + $this->assertContains($tag->getName(), $names); + } + + $this->assertSame($tagCount, $i); + } + /** * @dataProvider identifierProvider */