diff --git a/composer.json b/composer.json index 2f914a00..93aadab1 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "keywords": ["activerecord", "orm"], "homepage": "http://www.phpactiverecord.org/", "license": "MIT", - "version": "2.0.0-rc.7", + "version": "2.0.0-rc.8", "require": { "php": ">=8.1.0", "ext-bcmath": "*" diff --git a/lib/WhereClause.php b/lib/WhereClause.php index 82d0e7c8..8e6934ae 100644 --- a/lib/WhereClause.php +++ b/lib/WhereClause.php @@ -88,13 +88,13 @@ public function to_s(Connection $connection, string $prependTableName = '', arra } $ret = ''; - if (1 == count($values) && is_array($values[0])) { - $num_values = count($values[0]); - } else { - $num_values = count($values); - } + $num_values = count($values); $quotes = 0; + if (1 == $num_values && is_array($values[0]) && 0 == count($values[0])) { + return '1=0'; + } + for ($i = 0, $j = 0; $i < strlen($expression); ++$i) { $ch = $expression[$i]; diff --git a/test/ActiveRecordFindTest.php b/test/ActiveRecordFindTest.php index 200fecb2..c3f1c64a 100644 --- a/test/ActiveRecordFindTest.php +++ b/test/ActiveRecordFindTest.php @@ -1,6 +1,5 @@ []])->to_a(); + $this->assertEquals(0, count($authors)); + } + public function testFindWithEmptyArray() { $this->expectException(RecordNotFound::class); @@ -166,13 +171,6 @@ public function testFindAllWithNoBindValues() $this->assertEquals(1, $authors[0]->author_id); } - public function testFindAllWithEmptyArrayBindValueThrowsException() - { - $this->expectException(DatabaseException::class); - $this->expectExceptionMessage('No bound parameter for index 0'); - Author::where(['author_id IN(?)', []])->to_a(); - } - public function testFindHashUsingAlias() { $venues = Venue::where(['marquee' => 'Warner Theatre', 'city' => [ diff --git a/test/WhereClauseTest.php b/test/WhereClauseTest.php index 0703e316..259d3fe1 100644 --- a/test/WhereClauseTest.php +++ b/test/WhereClauseTest.php @@ -3,7 +3,6 @@ use ActiveRecord\ConnectionManager; use ActiveRecord\Exception\DatabaseException; use ActiveRecord\WhereClause; -use test\models\Author; class WhereClauseTest extends DatabaseTestCase { @@ -135,12 +134,6 @@ public function testSubstituteEscapeQuotesWithConnectionsEscapeMethod(): void $this->assertEquals("name=$escaped", $a->to_s(ConnectionManager::get_connection(), substitute: true)); } - public function testBindInvalidParameterNumberArrayWithIn() - { - $this->expectException(DatabaseException::class); - Author::where(['author_id IN(?)', []])->to_a(); - } - public function testSubstituteUsingAlternateValues(): void { $a = new WhereClause('name=?', ['Tito']);