|
@@ -581,6 +581,48 @@ class QueryRegressionTest extends TestCase
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Tests that getting the count of a query with bind is correct
|
|
|
|
|
+ *
|
|
|
|
|
+ * @see https://github.com/cakephp/cakephp/issues/8466
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testCountWithBind()
|
|
|
|
|
+ {
|
|
|
|
|
+ $table = TableRegistry::get('Articles');
|
|
|
|
|
+ $query = $table
|
|
|
|
|
+ ->find()
|
|
|
|
|
+ ->select(['Articles.title', 'Articles.id'])
|
|
|
|
|
+ ->where("Articles.title LIKE :val")
|
|
|
|
|
+ ->group('Articles.id')
|
|
|
|
|
+ ->bind(':val', '%Second%');
|
|
|
|
|
+ $count = $query->count();
|
|
|
|
|
+ $this->assertEquals(1, $count);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Tests that bind in subqueries works.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testSubqueryBind()
|
|
|
|
|
+ {
|
|
|
|
|
+ $table = TableRegistry::get('Articles');
|
|
|
|
|
+ $sub = $table->find()
|
|
|
|
|
+ ->select(['Articles.id'])
|
|
|
|
|
+ ->where("Articles.title LIKE :val")
|
|
|
|
|
+ ->bind(':val', 'Second %');
|
|
|
|
|
+
|
|
|
|
|
+ $query = $table
|
|
|
|
|
+ ->find()
|
|
|
|
|
+ ->select(['Articles.title'])
|
|
|
|
|
+ ->where(["Articles.id NOT IN" => $sub]);
|
|
|
|
|
+ $result = $query->toArray();
|
|
|
|
|
+ $this->assertCount(2, $result);
|
|
|
|
|
+ $this->assertEquals('First Article', $result[0]->title);
|
|
|
|
|
+ $this->assertEquals('Third Article', $result[1]->title);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Test that deep containments don't generate empty entities for
|
|
* Test that deep containments don't generate empty entities for
|
|
|
* intermediary relations.
|
|
* intermediary relations.
|
|
|
*
|
|
*
|