Skip to content

Commit e4e179f

Browse files
Add/update SymfonyDriver unit tests
1 parent 3960eb4 commit e4e179f

File tree

7 files changed

+37
-123
lines changed

7 files changed

+37
-123
lines changed

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@
5858
}
5959
},
6060
"scripts": {
61-
"test": "vendor/bin/phpunit",
62-
"test:unit": "vendor/bin/phpunit --testsuite='Unit tests'",
63-
"test:functional": "vendor/bin/phpunit --testsuite='Functional tests'",
6461
"psalm": "APP_ENV=dev php bin/console.php cache:warmup && vendor/bin/psalm --show-info=true",
6562
"fix-cs": "vendor/bin/php-cs-fixer fix",
6663
"check-cs": "vendor/bin/php-cs-fixer fix --dry-run",

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ services:
3131
environment:
3232
- NEO4J_AUTH=neo4j/testtest
3333

34-
# advertise "neo4j:7687" instead of localhost for proper routing
35-
- NEO4J_server_default__advertised__address=neo4j
36-
- NEO4J_server_bolt_advertised__address=neo4j:7687
34+
# advertise neo4j:7687 instead of localhost
35+
- NEO4J_server_default__advertised__address=${DEFAULT_ADDRESS-localhost}
36+
- NEO4J_server_bolt_advertised__address=${DEFAULT_ADDRESS-localhost}:7687
3737
networks:
3838
- neo4j-symfony

docs/README.md

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Make sure Composer is installed globally, as explained in the
1414
[installation chapter](https://getcomposer.org/doc/00-intro.md)
1515
of the Composer documentation.
1616

17+
Applications that don't use Symfony Flex
18+
1719
### Step 1: Download the Bundle
1820

1921
Open a command console, enter your project directory and execute the
@@ -40,7 +42,7 @@ return [
4042
## Documentation
4143

4244
The bundle is a convenient way of registering services. We register `Drivers` and one
43-
`Client`. You will always have alias for the default services:
45+
`Clients`. You will always have alias for the default services:
4446

4547
* neo4j.driver
4648
* neo4j.client
@@ -51,14 +53,7 @@ The bundle is a convenient way of registering services. We register `Drivers` an
5153
```yaml
5254
neo4j:
5355
drivers:
54-
- alias: default
55-
```
56-
57-
Or even simpler, if you want to use all defaults:
58-
59-
```yaml
60-
neo4j:
61-
drivers: []
56+
default: ~
6257
```
6358
6459
With the minimal configuration we have services named:
@@ -97,47 +92,6 @@ neo4j:
9792
username: '%neo4j.backup-user%'
9893
password: '%neo4j.backup-pass%'
9994
```
100-
101-
## Testing
102-
103-
### Prerequisites
104-
105-
Functional tests require a Neo4j instance to be running. The easiest way to set this up is using Docker Compose:
106-
107-
```bash
108-
$ docker-compose up -d
109-
```
110-
111-
This will start a Neo4j instance accessible at `bolt://neo4j:testtest@neo4j:7687`.
112-
113-
> **Note:** For single-instance Neo4j setups, use the `bolt://` scheme. The `neo4j://` scheme is intended for clustered setups with routing support.
114-
115-
### Running Tests
116-
117-
Run all tests:
118-
119-
```bash
120-
$ composer test
121-
```
122-
123-
Run only unit tests (no Neo4j instance required):
124-
125-
```bash
126-
$ composer test:unit
127-
```
128-
129-
Run only functional tests (requires Neo4j instance):
130-
131-
```bash
132-
$ composer test:functional
133-
```
134-
135-
You can also run PHPUnit directly:
136-
137-
```bash
138-
$ ./vendor/bin/phpunit
139-
```
140-
14195
### Code Quality
14296
14397
Check code style:
@@ -164,4 +118,4 @@ See an example application at https://github.com/neo4j-examples/movies-symfony-p
164118

165119
## License
166120

167-
The MIT License (MIT). Please see [License File](LICENSE) for more information.
121+
The MIT License (MIT). Please see [License File](../LICENSE) for more information.

src/Collector/Neo4jDataCollector.php

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -43,62 +43,26 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
4343

4444
$statement[$key] = $t->recursiveToArray($value);
4545
}
46-
47-
if (isset($summary['result']) && method_exists($summary['result'], 'getStatement')) {
48-
/** @var object $result */
49-
$result = $summary['result'];
50-
if (method_exists($result, 'getStatement')) {
51-
$resultStatement = $result->getStatement();
52-
$statement['statement'] = $t->recursiveToArray($resultStatement);
53-
if (is_object($resultStatement) && method_exists($resultStatement, 'getParameters')) {
54-
$params = $resultStatement->getParameters();
55-
$statement['parameters'] = is_array($params)
56-
? $params
57-
: $t->recursiveToArray($params);
58-
}
59-
}
60-
}
6146
$successfulStatements[] = $statement;
6247
}
6348

6449
$failedStatements = array_map(
65-
function (array $x) use ($t) {
66-
$statement = [
67-
'status' => 'failure',
68-
'time' => $x['time'],
69-
'timestamp' => $x['timestamp'],
70-
'result' => [
71-
'statement' => $x['statement']?->toArray(),
72-
],
73-
'exception' => [
74-
'code' => $x['exception']->getErrors()[0]->getCode(),
75-
'message' => $x['exception']->getErrors()[0]->getMessage(),
76-
'classification' => $x['exception']->getErrors()[0]->getClassification(),
77-
'category' => $x['exception']->getErrors()[0]->getCategory(),
78-
'title' => $x['exception']->getErrors()[0]->getTitle(),
79-
],
80-
'error' => [
81-
'code' => $x['exception']->getErrors()[0]->getCode(),
82-
'message' => $x['exception']->getErrors()[0]->getMessage(),
83-
'classification' => $x['exception']->getErrors()[0]->getClassification(),
84-
'category' => $x['exception']->getErrors()[0]->getCategory(),
85-
'title' => $x['exception']->getErrors()[0]->getTitle(),
86-
],
87-
'alias' => $x['alias'],
88-
];
89-
90-
if (null !== $x['statement']) {
91-
$statement['statement'] = $t->recursiveToArray($x['statement']);
92-
if (is_object($x['statement']) && method_exists($x['statement'], 'getParameters')) {
93-
$params = $x['statement']->getParameters();
94-
$statement['parameters'] = is_array($params)
95-
? $params
96-
: $t->recursiveToArray($params);
97-
}
98-
}
99-
100-
return $statement;
101-
},
50+
static fn (array $x) => [
51+
'status' => 'failure',
52+
'time' => $x['time'],
53+
'timestamp' => $x['timestamp'],
54+
'result' => [
55+
'statement' => $x['statement']?->toArray(),
56+
],
57+
'exception' => [
58+
'code' => $x['exception']->getErrors()[0]->getCode(),
59+
'message' => $x['exception']->getErrors()[0]->getMessage(),
60+
'classification' => $x['exception']->getErrors()[0]->getClassification(),
61+
'category' => $x['exception']->getErrors()[0]->getCategory(),
62+
'title' => $x['exception']->getErrors()[0]->getTitle(),
63+
],
64+
'alias' => $x['alias'],
65+
],
10266
$this->subscriber->getProfiledFailures()
10367
);
10468

@@ -133,18 +97,18 @@ public function getStatements(): array
13397

13498
public function getSuccessfulStatements(): array
13599
{
136-
return array_values(array_filter(
100+
return array_filter(
137101
$this->data['statements'],
138102
static fn (array $x) => 'success' === $x['status']
139-
));
103+
);
140104
}
141105

142106
public function getFailedStatements(): array
143107
{
144-
return array_values(array_filter(
108+
return array_filter(
145109
$this->data['statements'],
146110
static fn (array $x) => 'failure' === $x['status']
147-
));
111+
);
148112
}
149113

150114
/** @api */
@@ -174,7 +138,7 @@ private function recursiveToArray(array|object $obj): mixed
174138
{
175139
if (is_array($obj)) {
176140
return array_map(
177-
fn (mixed $x): mixed => is_array($x) || is_object($x) ? $this->recursiveToArray($x) : $x,
141+
fn (mixed $x): mixed => $this->recursiveToArray($x),
178142
$obj
179143
);
180144
}

src/Decorators/SymfonyTransaction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function rollback(): void
7575
$this->handler->handleTransactionAction(
7676
TransactionState::ROLLED_BACK,
7777
$this->transactionId,
78-
fn () => $this->tsx->rollback(),
78+
fn () => $this->tsx->commit(),
7979
$this->alias,
8080
$this->scheme,
8181
);

tests/App/config/default.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
framework:
1212
secret: test
1313
test: true
14-
profiler: { enabled: true, collect: true, collect_serializer_data: true }
14+
profiler: { enabled: true, collect: true }
1515
router:
1616
resource: '%kernel.project_dir%/tests/App/config/routes.yaml'
1717
type: 'yaml'
@@ -26,11 +26,11 @@ web_profiler:
2626
intercept_redirects: false
2727

2828
parameters:
29-
neo4j.dsn.badname: bolt://localhost:7687
29+
neo4j.dsn.badname: bolt://localhost
3030
neo4j.dsn.secret: neo4j://neo4j:secret@localhost:7688
31-
neo4j.dsn.test: bolt://neo4j:testtest@neo4j:7687
32-
neo4j.dsn.auth: bolt://neo4j:testtest@neo4j:7687
33-
neo4j.dsn.simple: bolt://test:test@localhost:7687
31+
neo4j.dsn.test: neo4j://neo4j:testtest@neo4j
32+
neo4j.dsn.auth: neo4j://neo4j
33+
neo4j.dsn.simple: bolt://test:test@localhost
3434

3535
neo4j:
3636
min_log_level: warning
@@ -73,7 +73,6 @@ neo4j:
7373

7474
- alias: neo4j-test
7575
dsn: "%neo4j.dsn.test%"
76-
profiling: true
7776

7877
- alias: neo4j-auth
7978
dsn: "%neo4j.dsn.auth%"

tests/Functional/IntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testDefaultDsn(): void
8686

8787
$uri = $this->getPrivateProperty($driver, 'parsedUrl');
8888

89-
$this->assertContains($uri->getScheme(), ['neo4j', 'bolt']);
89+
$this->assertSame($uri->getScheme(), 'neo4j');
9090
}
9191

9292
public function testDsn(): void
@@ -96,7 +96,7 @@ public function testDsn(): void
9696

9797
$this->expectException(\RuntimeException::class);
9898
$this->expectExceptionMessageMatches(
99-
"/Cannot connect to any server on alias: neo4j_undefined_configs with Uris: \('bolt:\/\/(localhost|localhostt)(:7687)?'\)/"
99+
"/Cannot connect to any server on alias: neo4j_undefined_configs with Uris: \('bolt:\/\/(localhost|localhostt)'\)/"
100100
);
101101

102102
/**

0 commit comments

Comments
 (0)