Browse Source

Added test for value object in conditions

Jose Lorenzo Rodriguez 10 years ago
parent
commit
0b92431838
1 changed files with 23 additions and 0 deletions
  1. 23 0
      tests/TestCase/Database/ExpressionTypeCastingIntegrationTest.php

+ 23 - 0
tests/TestCase/Database/ExpressionTypeCastingIntegrationTest.php

@@ -48,6 +48,9 @@ class OrderedUuidType extends Type implements ExpressionTypeInterface
 
     public function toExpression($value)
     {
+        if ($value instanceof UuidValue) {
+            $value = $value->value;
+        }
         $substr = function ($start, $length = null) use ($value) {
             return new FunctionExpression(
                 'SUBSTR',
@@ -139,6 +142,26 @@ class ExpressionTypeCastingIntegrationTest extends TestCase
         $this->assertEquals('4c2681c048298a29a7fb413140cf8569', $result[0]['id']);
     }
 
+
+    /**
+     * Tests Select using value object in conditions
+     *
+     * @return void
+     */
+    public function testSelectWithConditionsValueObject()
+    {
+        $this->_insert();
+        $result = $this->connection->newQuery()
+            ->select('id')
+            ->from('ordered_uuid_items')
+            ->where(['id' => new UuidValue('48298a29-81c0-4c26-a7fb-413140cf8569')], ['id' => 'ordered_uuid'])
+            ->execute()
+            ->fetchAll('assoc');
+
+        $this->assertCount(1, $result);
+        $this->assertEquals('4c2681c048298a29a7fb413140cf8569', $result[0]['id']);
+    }
+
     /**
      * Tests using the expression type in with an IN condition
      *