@@ -35,6 +35,38 @@ private function initializeApi(): Neo4jQueryAPI
35
35
);
36
36
}
37
37
38
+ public function testTransactionCommit (): void
39
+ {
40
+ // This test validates if a transaction exists in its own world until we commit it.
41
+ // by create a node in our transaction we validate if it exists within the transaction,
42
+ // but not the database.
43
+ // After we commit our transaction we are able to validate if our created node exists in the database.
44
+
45
+ $ tsx = $ this ->api ->beginTransaction ();
46
+
47
+ // we create a human with a random name and remember our randomly generated name so
48
+ // we can query its existence.
49
+ // by creating it in a transaction it should not exist in the real database yet.
50
+ $ name = mt_rand (1 , 100000 );
51
+ $ tsx ->run ('CREATE (x:Human {name: $name}) ' , ['name ' => $ name ]);
52
+
53
+
54
+ // we simply validate if the human with the random name does not exist in the database, because we
55
+ // haven't commited our transaction yet.
56
+ $ results = $ this ->api ->run ('MATCH (x:Human {name: $name}) RETURN x ' , ['name ' => $ name ]);
57
+ $ this ->assertCount (0 , $ results );
58
+
59
+ // The human should of course only exist in the transaction, so we expect a count of 1 here.
60
+ $ results = $ tsx ->run ('MATCH (x:Human {name: $name}) RETURN x ' , ['name ' => $ name ]);
61
+ $ this ->assertCount (1 , $ results );
62
+
63
+ $ tsx ->commit ();
64
+
65
+ // Now that we have commited our transaction, the human should of course exist in our database
66
+ $ results = $ this ->api ->run ('MATCH (x:Human {name: $name}) RETURN x ' , ['name ' => $ name ]);
67
+ $ this ->assertCount (1 , $ results );
68
+ }
69
+
38
70
/**
39
71
* @throws GuzzleException
40
72
*/
0 commit comments