1
+ <?php
2
+
3
+ use Google \Cloud \Datastore \V1 \Entity as GRPC_Entity ;
4
+ use Google \Cloud \Datastore \V1 \PartitionId ;
5
+
6
+ class GRPCv1MapperTest extends \PHPUnit \Framework \TestCase
7
+ {
8
+ public function testValidValuesMapToGoogleEntity ()
9
+ {
10
+ $ obj_schema = (new \GDS \Schema ('Person ' ))
11
+ ->addString ('name ' )
12
+ ->addInteger ('age ' )
13
+ ->addFloat ('weight ' )
14
+ ->addGeopoint ('location ' )
15
+ ->addDatetime ('dob ' );
16
+
17
+ $ obj_mapper = new \GDS \Mapper \GRPCv1 ();
18
+ $ obj_mapper
19
+ ->setSchema ($ obj_schema );
20
+
21
+
22
+ $ obj_gds_entity = new \GDS \Entity ();
23
+ $ obj_gds_entity ->setSchema ($ obj_schema );
24
+ $ obj_gds_entity ->setKind ('Person ' );
25
+
26
+ $ obj_gds_entity ->name = 'Dave ' ;
27
+ $ obj_gds_entity ->age = 21 ;
28
+ $ obj_gds_entity ->weight = 92.6 ;
29
+ $ obj_gds_entity ->location = new \GDS \Property \Geopoint (1.2 , 3.4 );
30
+ $ obj_gds_entity ->dob = new DateTime ('1979-02-05 08:30:00 ' );
31
+
32
+ $ obj_grpc_entity = new GRPC_Entity ();
33
+
34
+ $ obj_mapper ->mapToGoogle ($ obj_gds_entity , $ obj_grpc_entity );
35
+
36
+
37
+ $ obj_properties = json_decode ($ obj_grpc_entity ->serializeToJsonString ())->properties ;
38
+
39
+ $ this ->assertTrue (property_exists ($ obj_properties ->name , 'stringValue ' ));
40
+ $ this ->assertTrue (property_exists ($ obj_properties ->age , 'integerValue ' ));
41
+ $ this ->assertTrue (property_exists ($ obj_properties ->weight , 'doubleValue ' ));
42
+ $ this ->assertTrue (property_exists ($ obj_properties ->location , 'geoPointValue ' ));
43
+ $ this ->assertTrue (property_exists ($ obj_properties ->dob , 'timestampValue ' ));
44
+ }
45
+
46
+ public function testNullValuesMapToGoogleEntity ()
47
+ {
48
+ $ obj_schema = (new \GDS \Schema ('Person ' ))
49
+ ->addString ('name ' )
50
+ ->addInteger ('age ' )
51
+ ->addFloat ('weight ' )
52
+ ->addGeopoint ('location ' )
53
+ ->addDatetime ('dob ' );
54
+
55
+ $ obj_mapper = new \GDS \Mapper \GRPCv1 ();
56
+ $ obj_mapper
57
+ ->setSchema ($ obj_schema );
58
+
59
+
60
+ $ obj_gds_entity = new \GDS \Entity ();
61
+ $ obj_gds_entity ->setSchema ($ obj_schema );
62
+ $ obj_gds_entity ->setKind ('Person ' );
63
+
64
+ $ obj_gds_entity ->name = null ;
65
+ $ obj_gds_entity ->age = null ;
66
+ $ obj_gds_entity ->weight = null ;
67
+ $ obj_gds_entity ->location = null ;
68
+ $ obj_gds_entity ->dob = null ;
69
+
70
+ $ obj_grpc_entity = new GRPC_Entity ();
71
+
72
+ $ obj_mapper ->mapToGoogle ($ obj_gds_entity , $ obj_grpc_entity );
73
+
74
+
75
+ $ obj_properties = json_decode ($ obj_grpc_entity ->serializeToJsonString ())->properties ;
76
+
77
+ $ this ->assertTrue (property_exists ($ obj_properties ->name , 'nullValue ' ));
78
+ $ this ->assertTrue (property_exists ($ obj_properties ->age , 'nullValue ' ));
79
+ $ this ->assertTrue (property_exists ($ obj_properties ->weight , 'nullValue ' ));
80
+ $ this ->assertTrue (property_exists ($ obj_properties ->location , 'nullValue ' ));
81
+ $ this ->assertTrue (property_exists ($ obj_properties ->dob , 'nullValue ' ));
82
+ }
83
+ }
0 commit comments