|
34 | 34 | use Google\Cloud\Spanner\V1\TypeAnnotationCode; |
35 | 35 | use Google\Cloud\Spanner\V1\TypeCode; |
36 | 36 | use Google\Cloud\Spanner\ValueMapper; |
| 37 | +use Google\Cloud\Spanner\Uuid; |
37 | 38 | use PHPUnit\Framework\TestCase; |
38 | 39 | use Testing\Data\Book; |
39 | 40 | use Testing\Data\User; |
@@ -73,7 +74,8 @@ public function simpleTypes() |
73 | 74 | [1, Database::TYPE_INT64], |
74 | 75 | ['john', Database::TYPE_STRING], |
75 | 76 | [3.1415, Database::TYPE_FLOAT64], |
76 | | - [false, Database::TYPE_BOOL] |
| 77 | + [false, Database::TYPE_BOOL], |
| 78 | + [new Uuid('f47ac10b-58cc-4372-a567-0e02b2c3d479'), Database::TYPE_UUID] |
77 | 79 | ]; |
78 | 80 | } |
79 | 81 |
|
@@ -858,7 +860,8 @@ public function simpleTypeValues() |
858 | 860 | [new Bytes('hello world'), base64_encode('hello world')], |
859 | 861 | [new Proto('hello world', 'foo'), 'hello world'], |
860 | 862 | [['foo', 'bar']], |
861 | | - ['{\"rating\":9,\"open\":true}'] |
| 863 | + ['{\"rating\":9,\"open\":true}'], |
| 864 | + [new Uuid('f47ac10b-58cc-4372-a567-0e02b2c3d479'), 'f47ac10b-58cc-4372-a567-0e02b2c3d479'] |
862 | 865 | ]; |
863 | 866 | } |
864 | 867 |
|
@@ -1379,4 +1382,50 @@ public function provideFloatTypes() |
1379 | 1382 | [Database::TYPE_FLOAT32] |
1380 | 1383 | ]; |
1381 | 1384 | } |
| 1385 | + |
| 1386 | + public function testDecodeValuesUuid() |
| 1387 | + { |
| 1388 | + $uuid = 'f47ac10b-58cc-4372-a567-0e02b2c3d479'; |
| 1389 | + $res = $this->mapper->decodeValues( |
| 1390 | + $this->createField(Database::TYPE_UUID), |
| 1391 | + $this->createRow($uuid), |
| 1392 | + Result::RETURN_ASSOCIATIVE |
| 1393 | + ); |
| 1394 | + $this->assertInstanceOf(Uuid::class, $res['rowName']); |
| 1395 | + $this->assertEquals($uuid, $res['rowName']->get()); |
| 1396 | + } |
| 1397 | + |
| 1398 | + public function testFormatParamsForExecuteSqlArrayUuid() |
| 1399 | + { |
| 1400 | + $uuid = new Uuid('f47ac10b-58cc-4372-a567-0e02b2c3d479'); |
| 1401 | + $params = [ |
| 1402 | + 'array' => [$uuid] |
| 1403 | + ]; |
| 1404 | + |
| 1405 | + $res = $this->mapper->formatParamsForExecuteSql($params); |
| 1406 | + |
| 1407 | + $this->assertEquals($uuid->get(), $res['params']['array'][0]); |
| 1408 | + $this->assertEquals(Database::TYPE_ARRAY, $res['paramTypes']['array']['code']); |
| 1409 | + $this->assertEquals(Database::TYPE_UUID, $res['paramTypes']['array']['arrayElementType']['code']); |
| 1410 | + } |
| 1411 | + |
| 1412 | + public function testFormatParamsForExecuteSqlStructUuid() |
| 1413 | + { |
| 1414 | + $uuid = new Uuid('f47ac10b-58cc-4372-a567-0e02b2c3d479'); |
| 1415 | + $params = [ |
| 1416 | + 'struct' => [ |
| 1417 | + 'uuid' => $uuid |
| 1418 | + ] |
| 1419 | + ]; |
| 1420 | + $types = [ |
| 1421 | + 'struct' => (new StructType()) |
| 1422 | + ->add('uuid', Database::TYPE_UUID) |
| 1423 | + ]; |
| 1424 | + |
| 1425 | + $res = $this->mapper->formatParamsForExecuteSql($params, $types); |
| 1426 | + |
| 1427 | + $this->assertEquals($uuid->get(), $res['params']['struct'][0]); |
| 1428 | + $this->assertEquals(Database::TYPE_STRUCT, $res['paramTypes']['struct']['code']); |
| 1429 | + $this->assertEquals(Database::TYPE_UUID, $res['paramTypes']['struct']['structType']['fields'][0]['type']['code']); |
| 1430 | + } |
1382 | 1431 | } |
0 commit comments