Skip to content

Commit 987edd6

Browse files
PratikshaPratiksha
authored andcommitted
DEBUG
1 parent ebb72e9 commit 987edd6

File tree

3 files changed

+155
-2
lines changed

3 files changed

+155
-2
lines changed

.php-cs-fixer.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"php":"8.3.16","version":"3.68.5:v3.68.5#7bedb718b633355272428c60736dc97fb96daf27","indent":" ","lineEnding":"\n","rules":{"binary_operator_spaces":{"default":"at_least_single_space"},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":true,"no_blank_lines_after_class_opening":true,"no_extra_blank_lines":{"tokens":["use"]},"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","const_import","do","else","elseif","final","finally","for","foreach","function","function_import","if","insteadof","interface","namespace","new","private","protected","public","static","switch","trait","try","use","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"unary_operator_spaces":{"only_dec_inc":true},"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"attribute_placement":"ignore","on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"strict_param":true},"hashes":{"tests\/resources\/expected\/complex-query-profile.php":"c0d16588e70d32588ec2e55ba5ae5873","tests\/Unit\/Neo4jExceptionUnitTest.php":"e07e604496e0e4032d2798ee9d2cb1b2","tests\/Unit\/ResultRowTest.php":"b4b307579a75da8307d6d65eb5548cae","tests\/Unit\/Neo4jQueryAPIUnitTest.php":"87e08aca0ccef5589c88bd7249e39496","tests\/Unit\/Neo4jRequestFactoryTest.php":"ebc6d5ee7790df4d69a5b555ad48ff5a","tests\/Unit\/AuthenticationTest.php":"746b185bcfb47a925e35b5b79b854fab","tests\/Integration\/Neo4jQueryAPIIntegrationTest.php":"43f34ad1774e3eeb133a9e3bb96f191d","tests\/Integration\/Neo4jTransactionIntegrationTest.php":"35fcbd5afbec5bb59f35040d9d6c518f","tests\/Integration\/Neo4jOGMTest.php":"e03f51ef605ca818763f3897d7a30830","src\/OGM.php":"211c087b78fca69390701e2f505e46fe","src\/Neo4jQueryAPI.php":"a7a505057617a2de3a94a73065254ecb","src\/BearerAuthentication.php":"51b5f02280a43838465cffa8974648c6","src\/Enums\/AccessMode.php":"88b5c70c4716cc68bcb86e2f162dd347","src\/Results\/ResultRow.php":"92dc1ec9315fa5236a79468ffaf9a60c","src\/Results\/ResultSet.php":"372faa2af185b25b804be1974c34b1ae","src\/Exception\/Neo4jException.php":"89c4c090cd3ba6e94c13eab7ebd0588c","src\/NoAuth.php":"2267e8a5b07aeaaab3165bb105b10807","src\/loginConfig.php":"47e9993051fc556a7fc28bc8f9a01caa","src\/AuthenticateInterface.php":"1da849c5d5b88439e01543d5d5b9f8d9","src\/BasicAuthentication.php":"ab50275cc6841d88d289a63d86ecb118","src\/Configuration.php":"fabfe6acf58bb0bda76453ace4f0757d","src\/ResponseParser.php":"e32270966c3a618bcb5ea9c6497748be","src\/Neo4jRequestFactory.php":"e3279d36e54032c6acf92df10ac47f07","src\/Objects\/Path.php":"e8091a19eb4e70ced4f8f7364dbe78be","src\/Objects\/Node.php":"ac679671f513c6c996dbf75a66fcacb2","src\/Objects\/Authentication.php":"f31af1c057be0f490cc2dba365f03b31","src\/Objects\/ProfiledQueryPlanArguments.php":"02b5fa2d50fec5d0fb0c4ada55ebda69","src\/Objects\/Person.php":"cee5594450a015103e12d4cbe186f167","src\/Objects\/Point.php":"4115d8d1b85a0d6e37b79d303237bcd0","src\/Objects\/ResultSet.php":"a5ba56fc6c6e250c22b183ac26dfd68e","src\/Objects\/ProfiledQueryPlan.php":"75ab6c3ad2ce97675a8e6478d17ac4d9","src\/Objects\/Bookmarks.php":"2c3e7229ce9b56c0352155b3feaac9bb","src\/Objects\/ResultCounters.php":"a9372c98fe7bede10cb004af30ea502f","src\/Objects\/Relationship.php":"e344e22d5a41f1795f3310d55ea51c20","src\/Transaction.php":"ff5454897ddbcc4fc2a984ecb90a90fd","src\/Authentication\/BearerAuthentication.php":"08a9e3c01d3833255cd51c94a17f1aa3","src\/Authentication\/NoAuth.php":"71cc7d784b9d98c62d2342faf38f7dc4","src\/Authentication\/AuthenticateInterface.php":"65b5a1074e11fba04362e754ad97023f","src\/Authentication\/BasicAuthentication.php":"c37b7ef26a59c032ac2a6a7b91c5adae"}}
1+
{"php":"8.3.16","version":"3.68.5:v3.68.5#7bedb718b633355272428c60736dc97fb96daf27","indent":" ","lineEnding":"\n","rules":{"binary_operator_spaces":{"default":"at_least_single_space"},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":true,"no_blank_lines_after_class_opening":true,"no_extra_blank_lines":{"tokens":["use"]},"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","const_import","do","else","elseif","final","finally","for","foreach","function","function_import","if","insteadof","interface","namespace","new","private","protected","public","static","switch","trait","try","use","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"unary_operator_spaces":{"only_dec_inc":true},"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"attribute_placement":"ignore","on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"strict_param":true},"hashes":{"tests\/resources\/expected\/complex-query-profile.php":"c0d16588e70d32588ec2e55ba5ae5873","tests\/Unit\/Neo4jExceptionUnitTest.php":"e07e604496e0e4032d2798ee9d2cb1b2","tests\/Unit\/ResultRowTest.php":"b4b307579a75da8307d6d65eb5548cae","tests\/Unit\/Neo4jQueryAPIUnitTest.php":"87e08aca0ccef5589c88bd7249e39496","tests\/Unit\/Neo4jRequestFactoryTest.php":"ebc6d5ee7790df4d69a5b555ad48ff5a","tests\/Unit\/AuthenticationTest.php":"746b185bcfb47a925e35b5b79b854fab","tests\/Integration\/Neo4jOGMTest.php":"e03f51ef605ca818763f3897d7a30830","src\/OGM.php":"211c087b78fca69390701e2f505e46fe","src\/Neo4jQueryAPI.php":"a7a505057617a2de3a94a73065254ecb","src\/BearerAuthentication.php":"51b5f02280a43838465cffa8974648c6","src\/Enums\/AccessMode.php":"88b5c70c4716cc68bcb86e2f162dd347","src\/Results\/ResultRow.php":"92dc1ec9315fa5236a79468ffaf9a60c","src\/Results\/ResultSet.php":"372faa2af185b25b804be1974c34b1ae","src\/Exception\/Neo4jException.php":"89c4c090cd3ba6e94c13eab7ebd0588c","src\/NoAuth.php":"2267e8a5b07aeaaab3165bb105b10807","src\/loginConfig.php":"47e9993051fc556a7fc28bc8f9a01caa","src\/AuthenticateInterface.php":"1da849c5d5b88439e01543d5d5b9f8d9","src\/BasicAuthentication.php":"ab50275cc6841d88d289a63d86ecb118","src\/Configuration.php":"fabfe6acf58bb0bda76453ace4f0757d","src\/ResponseParser.php":"e32270966c3a618bcb5ea9c6497748be","src\/Neo4jRequestFactory.php":"e3279d36e54032c6acf92df10ac47f07","src\/Objects\/Path.php":"e8091a19eb4e70ced4f8f7364dbe78be","src\/Objects\/Node.php":"ac679671f513c6c996dbf75a66fcacb2","src\/Objects\/Authentication.php":"f31af1c057be0f490cc2dba365f03b31","src\/Objects\/ProfiledQueryPlanArguments.php":"02b5fa2d50fec5d0fb0c4ada55ebda69","src\/Objects\/Person.php":"cee5594450a015103e12d4cbe186f167","src\/Objects\/Point.php":"4115d8d1b85a0d6e37b79d303237bcd0","src\/Objects\/ResultSet.php":"a5ba56fc6c6e250c22b183ac26dfd68e","src\/Objects\/ProfiledQueryPlan.php":"75ab6c3ad2ce97675a8e6478d17ac4d9","src\/Objects\/Bookmarks.php":"2c3e7229ce9b56c0352155b3feaac9bb","src\/Objects\/ResultCounters.php":"a9372c98fe7bede10cb004af30ea502f","src\/Objects\/Relationship.php":"e344e22d5a41f1795f3310d55ea51c20","src\/Transaction.php":"ff5454897ddbcc4fc2a984ecb90a90fd","src\/Authentication\/BearerAuthentication.php":"08a9e3c01d3833255cd51c94a17f1aa3","src\/Authentication\/NoAuth.php":"71cc7d784b9d98c62d2342faf38f7dc4","src\/Authentication\/AuthenticateInterface.php":"65b5a1074e11fba04362e754ad97023f","src\/Authentication\/BasicAuthentication.php":"c37b7ef26a59c032ac2a6a7b91c5adae","tests\/Unit\/TransactionUnitTest.php":"e6c97ac9afb0b948ac8216baabfc9e22","tests\/Integration\/Neo4jQueryAPIIntegrationTest.php":"3dc17347951ae97e0131e0793f8f90e5","tests\/Integration\/Neo4jTransactionIntegrationTest.php":"d3a4350d427634b229daeca751d8bf47"}}

tests/Integration/Neo4jTransactionIntegrationTest.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PHPUnit\Framework\TestCase;
1010

1111
/**
12-
* @api
12+
* @api
1313
*/
1414
class Neo4jTransactionIntegrationTest extends TestCase
1515
{
@@ -54,6 +54,7 @@ private function populateTestData(): void
5454
$this->api->run('CREATE (:Person {name: $name})', ['name' => $name]);
5555
}
5656
}
57+
5758
public function testTransactionCommit(): void
5859
{
5960

@@ -75,4 +76,55 @@ public function testTransactionCommit(): void
7576
$this->assertCount(1, $results); // Updated to expect 1 result
7677
}
7778

79+
public function testTransactionRollback(): void
80+
{
81+
$tsx = $this->api->beginTransaction();
82+
83+
$name = 'rollback_' . mt_rand(1, 100000);
84+
$tsx->run("CREATE (x:Human {name: \$name})", ['name' => $name]);
85+
$results = $tsx->run("MATCH (x:Human {name: \$name}) RETURN x", ['name' => $name]);
86+
$this->assertCount(1, $results);
87+
88+
$tsx->rollback();
89+
90+
// Ensure the node is not in the database
91+
$results = $this->api->run("MATCH (x:Human {name: \$name}) RETURN x", ['name' => $name]);
92+
$this->assertCount(0, $results);
93+
}
94+
95+
public function testCreateNodeAndCommit(): void
96+
{
97+
$tsx = $this->api->beginTransaction();
98+
99+
$name = 'committed_' . mt_rand(1, 100000);
100+
$tsx->run("CREATE (x:Person {name: \$name})", ['name' => $name]);
101+
102+
$results = $this->api->run("MATCH (x:Person {name: \$name}) RETURN x", ['name' => $name]);
103+
$this->assertCount(0, $results);
104+
105+
$tsx->commit();
106+
$results = $this->api->run("MATCH (x:Person {name: \$name}) RETURN x", ['name' => $name]);
107+
$this->assertCount(1, $results);
108+
}
109+
110+
public function testCreateNodeAndRollback(): void
111+
{
112+
$tsx = $this->api->beginTransaction();
113+
114+
$name = 'rollback_' . mt_rand(1, 100000);
115+
$tsx->run("CREATE (x:Person {name: \$name})", ['name' => $name]);
116+
117+
$results = $tsx->run("MATCH (x:Person {name: \$name}) RETURN x", ['name' => $name]);
118+
$this->assertCount(1, $results);
119+
120+
$results = $this->api->run("MATCH (x:Person {name: \$name}) RETURN x", ['name' => $name]);
121+
$this->assertCount(0, $results);
122+
123+
$tsx->rollback();
124+
$results = $this->api->run("MATCH (x:Person {name: \$name}) RETURN x", ['name' => $name]);
125+
$this->assertCount(0, $results);
126+
}
127+
128+
129+
78130
}

tests/Unit/TransactionUnitTest.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI\Tests\Unit;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Neo4j\QueryAPI\Transaction;
7+
use Neo4j\QueryAPI\Neo4jRequestFactory;
8+
use Neo4j\QueryAPI\ResponseParser;
9+
use Psr\Http\Client\ClientInterface;
10+
use Psr\Http\Message\RequestInterface;
11+
use Psr\Http\Message\ResponseInterface;
12+
13+
/**
14+
* @api
15+
*/
16+
class TransactionUnitTest extends TestCase
17+
{
18+
private ClientInterface $client;
19+
private Neo4jRequestFactory $requestFactory;
20+
private ResponseParser $responseParser;
21+
private Transaction $transaction;
22+
23+
private string $transactionId = 'txn123';
24+
private string $clusterAffinity = 'leader';
25+
26+
protected function setUp(): void
27+
{
28+
$this->client = $this->createMock(ClientInterface::class);
29+
$this->requestFactory = $this->createMock(Neo4jRequestFactory::class);
30+
$this->responseParser = $this->createMock(ResponseParser::class);
31+
32+
$this->transaction = new Transaction(
33+
$this->client,
34+
$this->responseParser,
35+
$this->requestFactory,
36+
$this->clusterAffinity,
37+
$this->transactionId
38+
);
39+
}
40+
41+
public function testRunCallsBuildTransactionRunRequest()
42+
{
43+
$query = "CREATE (:Person {name: \$name})";
44+
$parameters = ['name' => 'Alice'];
45+
46+
$mockRequest = $this->createMock(RequestInterface::class);
47+
$mockResponse = $this->createMock(ResponseInterface::class);
48+
$mockResultSet = $this->createMock(\Neo4j\QueryAPI\Results\ResultSet::class);
49+
50+
$this->requestFactory->expects($this->once())
51+
->method('buildTransactionRunRequest')
52+
->with($query, $parameters, $this->transactionId, $this->clusterAffinity)
53+
->willReturn($mockRequest);
54+
55+
$this->client->expects($this->once())
56+
->method('sendRequest')
57+
->with($mockRequest)
58+
->willReturn($mockResponse);
59+
60+
$this->responseParser->expects($this->once())
61+
->method('parseRunQueryResponse')
62+
->with($mockResponse)
63+
->willReturn($mockResultSet);
64+
65+
$result = $this->transaction->run($query, $parameters);
66+
67+
$this->assertSame($mockResultSet, $result);
68+
}
69+
70+
public function testCommitCallsBuildCommitRequest()
71+
{
72+
$mockRequest = $this->createMock(RequestInterface::class);
73+
74+
$this->requestFactory->expects($this->once())
75+
->method('buildCommitRequest')
76+
->with($this->transactionId, $this->clusterAffinity)
77+
->willReturn($mockRequest);
78+
79+
$this->client->expects($this->once())
80+
->method('sendRequest')
81+
->with($mockRequest);
82+
83+
$this->transaction->commit();
84+
}
85+
86+
public function testRollbackCallsBuildRollbackRequest()
87+
{
88+
$mockRequest = $this->createMock(RequestInterface::class);
89+
90+
$this->requestFactory->expects($this->once())
91+
->method('buildRollbackRequest')
92+
->with($this->transactionId, $this->clusterAffinity)
93+
->willReturn($mockRequest);
94+
95+
$this->client->expects($this->once())
96+
->method('sendRequest')
97+
->with($mockRequest);
98+
99+
$this->transaction->rollback();
100+
}
101+
}

0 commit comments

Comments
 (0)