diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..aae774fe Binary files /dev/null and b/.DS_Store differ diff --git a/composer.json b/composer.json index 00ee34f5..ca9895e5 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,7 @@ "guzzlehttp/guzzle": "^7.9", "psr/http-client": "^1.0", "ext-json": "*", - "php": "^8.1", - "ext-curl": "*" + "php": "^8.1" }, "require-dev": { "phpunit/phpunit": "^11.0" diff --git a/composer.lock b/composer.lock index c89e6fb9..29cf9391 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,74 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "192bca4f447c8cb126e7bd26a103e456", + "content-hash": "a40f40801cc414111c75ed0aa2a56c4a", "packages": [ + { + "name": "clue/stream-filter", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/clue/stream-filter.git", + "reference": "049509fef80032cb3f051595029ab75b49a3c2f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/clue/stream-filter/zipball/049509fef80032cb3f051595029ab75b49a3c2f7", + "reference": "049509fef80032cb3f051595029ab75b49a3c2f7", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "Clue\\StreamFilter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering" + } + ], + "description": "A simple and modern approach to stream filtering in PHP", + "homepage": "https://github.com/clue/stream-filter", + "keywords": [ + "bucket brigade", + "callback", + "filter", + "php_user_filter", + "stream", + "stream_filter_append", + "stream_filter_register" + ], + "support": { + "issues": "https://github.com/clue/stream-filter/issues", + "source": "https://github.com/clue/stream-filter/tree/v1.7.0" + }, + "funding": [ + { + "url": "https://clue.engineering/support", + "type": "custom" + }, + { + "url": "https://github.com/clue", + "type": "github" + } + ], + "time": "2023-12-20T15:40:13+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "7.9.2", @@ -331,6 +397,287 @@ ], "time": "2024-07-18T11:15:46+00:00" }, + { + "name": "laudis/neo4j-php-client", + "version": "3.2.0", + "source": { + "type": "git", + "url": "https://github.com/neo4j-php/neo4j-php-client.git", + "reference": "749247655fe50a24b04a66d7df0d62a848ae159a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/neo4j-php/neo4j-php-client/zipball/749247655fe50a24b04a66d7df0d62a848ae159a", + "reference": "749247655fe50a24b04a66d7df0d62a848ae159a", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "laudis/typed-enum": "^1.3.2", + "php": "^8.1", + "php-http/discovery": "^1.13", + "php-http/message": "^1.0", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0|^2.0", + "psr/simple-cache": ">=2.0", + "stefanak-michal/bolt": "^7.1.4", + "symfony/polyfill-php80": "^1.2" + }, + "provide": { + "psr/simple-cache-implementation": "2.0|3.0" + }, + "require-dev": { + "cache/integration-tests": "dev-master", + "friendsofphp/php-cs-fixer": "3.15.0", + "kriswallsmith/buzz": "^1.2", + "kubawerlos/php-cs-fixer-custom-fixers": "3.13.*", + "monolog/monolog": "^2.2", + "nyholm/psr7": "^1.3", + "nyholm/psr7-server": "^1.0", + "phpunit/phpunit": "^10.0", + "psalm/plugin-phpunit": "^0.18", + "psr/log": "^3.0", + "rector/rector": "^1.0", + "symfony/uid": "^5.0", + "symfony/var-dumper": "^5.0", + "vimeo/psalm": "^5.0" + }, + "suggest": { + "composer-runtime-api": "Install composer 2 for auto detection of version in user agent", + "ext-bcmath": "Needed to implement bolt protocol", + "ext-sysvsem": "Needed for enabling connection pooling between processes", + "psr/log": "Needed to enable logging" + }, + "type": "library", + "autoload": { + "psr-4": { + "Laudis\\Neo4j\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ghlen Nagels", + "email": "ghlen@pm.me" + } + ], + "description": "Neo4j-PHP-Client is the most advanced PHP Client for Neo4j", + "keywords": [ + "bolt", + "client", + "cluster", + "database", + "driver", + "graph", + "high-availability", + "http", + "neo4j" + ], + "support": { + "issues": "https://github.com/neo4j-php/neo4j-php-client/issues", + "source": "https://github.com/neo4j-php/neo4j-php-client/tree/3.2.0" + }, + "time": "2024-11-29T08:01:56+00:00" + }, + { + "name": "laudis/typed-enum", + "version": "1.3.2", + "source": { + "type": "git", + "url": "https://github.com/transistive/typed-enum.git", + "reference": "65cddd2ed0eedd1ff642d1ef632745ab2522c976" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/transistive/typed-enum/zipball/65cddd2ed0eedd1ff642d1ef632745ab2522c976", + "reference": "65cddd2ed0eedd1ff642d1ef632745ab2522c976", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.3", + "phpunit/phpunit": "9.*", + "psalm/plugin-phpunit": "^0.16", + "vimeo/psalm": "^4.12" + }, + "type": "library", + "autoload": { + "psr-4": { + "Laudis\\TypedEnum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ghlen Nagels", + "email": "ghlen@pm.me" + } + ], + "description": "A small class allowing for typed enumerations.", + "support": { + "issues": "https://github.com/transistive/typed-enum/issues", + "source": "https://github.com/transistive/typed-enum/tree/1.3.2" + }, + "time": "2022-01-04T23:33:30+00:00" + }, + { + "name": "php-http/discovery", + "version": "1.20.0", + "source": { + "type": "git", + "url": "https://github.com/php-http/discovery.git", + "reference": "82fe4c73ef3363caed49ff8dd1539ba06044910d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/discovery/zipball/82fe4c73ef3363caed49ff8dd1539ba06044910d", + "reference": "82fe4c73ef3363caed49ff8dd1539ba06044910d", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0|^2.0", + "php": "^7.1 || ^8.0" + }, + "conflict": { + "nyholm/psr7": "<1.0", + "zendframework/zend-diactoros": "*" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "*", + "psr/http-factory-implementation": "*", + "psr/http-message-implementation": "*" + }, + "require-dev": { + "composer/composer": "^1.0.2|^2.0", + "graham-campbell/phpspec-skip-example-extension": "^5.0", + "php-http/httplug": "^1.0 || ^2.0", + "php-http/message-factory": "^1.0", + "phpspec/phpspec": "^5.1 || ^6.1 || ^7.3", + "sebastian/comparator": "^3.0.5 || ^4.0.8", + "symfony/phpunit-bridge": "^6.4.4 || ^7.0.1" + }, + "type": "composer-plugin", + "extra": { + "class": "Http\\Discovery\\Composer\\Plugin", + "plugin-optional": true + }, + "autoload": { + "psr-4": { + "Http\\Discovery\\": "src/" + }, + "exclude-from-classmap": [ + "src/Composer/Plugin.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations", + "homepage": "http://php-http.org", + "keywords": [ + "adapter", + "client", + "discovery", + "factory", + "http", + "message", + "psr17", + "psr7" + ], + "support": { + "issues": "https://github.com/php-http/discovery/issues", + "source": "https://github.com/php-http/discovery/tree/1.20.0" + }, + "time": "2024-10-02T11:20:13+00:00" + }, + { + "name": "php-http/message", + "version": "1.16.2", + "source": { + "type": "git", + "url": "https://github.com/php-http/message.git", + "reference": "06dd5e8562f84e641bf929bfe699ee0f5ce8080a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/message/zipball/06dd5e8562f84e641bf929bfe699ee0f5ce8080a", + "reference": "06dd5e8562f84e641bf929bfe699ee0f5ce8080a", + "shasum": "" + }, + "require": { + "clue/stream-filter": "^1.5", + "php": "^7.2 || ^8.0", + "psr/http-message": "^1.1 || ^2.0" + }, + "provide": { + "php-http/message-factory-implementation": "1.0" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.6", + "ext-zlib": "*", + "guzzlehttp/psr7": "^1.0 || ^2.0", + "laminas/laminas-diactoros": "^2.0 || ^3.0", + "php-http/message-factory": "^1.0.2", + "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", + "slim/slim": "^3.0" + }, + "suggest": { + "ext-zlib": "Used with compressor/decompressor streams", + "guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories", + "laminas/laminas-diactoros": "Used with Diactoros Factories", + "slim/slim": "Used with Slim Framework PSR-7 implementation" + }, + "type": "library", + "autoload": { + "files": [ + "src/filters.php" + ], + "psr-4": { + "Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "HTTP Message related tools", + "homepage": "http://php-http.org", + "keywords": [ + "http", + "message", + "psr-7" + ], + "support": { + "issues": "https://github.com/php-http/message/issues", + "source": "https://github.com/php-http/message/tree/1.16.2" + }, + "time": "2024-10-02T11:34:13+00:00" + }, { "name": "psr/http-client", "version": "1.0.3", @@ -491,6 +838,57 @@ }, "time": "2023-04-04T09:54:51+00:00" }, + { + "name": "psr/simple-cache", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865", + "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "support": { + "source": "https://github.com/php-fig/simple-cache/tree/3.0.0" + }, + "time": "2021-10-29T13:26:27+00:00" + }, { "name": "ralouphie/getallheaders", "version": "3.0.3", @@ -535,6 +933,73 @@ }, "time": "2019-03-08T08:55:37+00:00" }, + { + "name": "stefanak-michal/bolt", + "version": "v7.1.6", + "source": { + "type": "git", + "url": "https://github.com/neo4j-php/Bolt.git", + "reference": "0c229b6c0094a91a0ad1467911353d048978fdf9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/neo4j-php/Bolt/zipball/0c229b6c0094a91a0ad1467911353d048978fdf9", + "reference": "0c229b6c0094a91a0ad1467911353d048978fdf9", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-mbstring": "*", + "php": "^8.1", + "psr/simple-cache": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^9" + }, + "suggest": { + "ext-openssl": "Needed when using StreamSocket connection class with SSL", + "ext-sockets": "Needed when using Socket connection class", + "laudis/neo4j-php-client": "Neo4j-PHP-Client is the most advanced PHP Client for Neo4j", + "stefanak-michal/neo4j-bolt-wrapper": "Wrapper for Neo4j PHP Bolt library to simplify usage." + }, + "type": "library", + "autoload": { + "psr-4": { + "Bolt\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michal Stefanak", + "homepage": "https://www.linkedin.com/in/michalstefanak/", + "role": "Developer" + } + ], + "description": "PHP library to provide connectivity to graph database over TCP socket with Bolt specification", + "homepage": "https://github.com/neo4j-php/Bolt", + "keywords": [ + "Socket", + "bolt", + "database", + "neo4j" + ], + "support": { + "docs": "https://www.neo4j.com/docs/bolt/current/", + "issues": "https://github.com/neo4j-php/Bolt/issues", + "source": "https://github.com/neo4j-php/Bolt" + }, + "funding": [ + { + "url": "https://ko-fi.com/michalstefanak", + "type": "ko-fi" + } + ], + "time": "2024-12-03T19:05:38+00:00" + }, { "name": "symfony/deprecation-contracts", "version": "v3.5.1", @@ -601,6 +1066,86 @@ } ], "time": "2024-09-25T14:20:29+00:00" + }, + { + "name": "symfony/polyfill-php80", + "version": "v1.31.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-09T11:45:10+00:00" } ], "packages-dev": [ diff --git a/queryCounters/Neo4jBookmarkIntegration.php b/queryCounters/Neo4jBookmarkIntegration.php new file mode 100644 index 00000000..189fe17e --- /dev/null +++ b/queryCounters/Neo4jBookmarkIntegration.php @@ -0,0 +1,66 @@ +post($connectionUrl, [ + 'json' => [ + 'statement' => 'CREATE (n:Person {name: $name}) RETURN n.name AS name', + 'parameters' => [ + 'name' => 'Alice' + ], + 'includeCounters' => true, + 'bookmarks' => $resultCounters->getBookmarks(), + ], + 'headers' => [ + 'Authorization' => 'Basic ' . $auth, + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ], +]); + +$data = json_decode($response->getBody()->getContents(), true); + +foreach ($data['counters'] as $key => $value) { + if (property_exists($resultCounters, $key)) { + $resultCounters->$key = $value; + } +} + +if (isset($data['bookmark'])) { + $resultCounters->addBookmark($data['bookmark']); +} + +echo json_encode([ + 'data' => $data['results'][0]['data'] ?? [], + 'counters' => $data['counters'], + 'bookmarks' => $resultCounters->getBookmarks(), +], JSON_PRETTY_PRINT); + +echo ('test'); \ No newline at end of file diff --git a/queryCounters/queryCounters3.php b/queryCounters/queryCounters3.php new file mode 100644 index 00000000..3991b443 --- /dev/null +++ b/queryCounters/queryCounters3.php @@ -0,0 +1,57 @@ +post('https://6f72daa1.databases.neo4j.io/db/neo4j/query/v2', [ + 'json' => [ + 'statement' => "CREATE (n:Person {name: 'Peter'}) RETURN n.name AS name", + 'includeCounters' => true, + + ], + 'headers' => [ + 'Authorization' => 'Basic ' . $auth, + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'Impersonate-User' => $impersonatedUser + ] +]); + + +$data = json_decode($response->getBody()->getContents(), true); + + + +$counters = new \Neo4j\QueryAPI\Objects\ResultCounters( + containsUpdates: $data['counters']['containsUpdates'], + nodesCreated: $data['counters']['nodesCreated'], + nodesDeleted: $data['counters']['nodesDeleted'], + propertiesSet: $data['counters']['propertiesSet'], + relationshipsCreated: $data['counters']['relationshipsCreated'], + relationshipsDeleted: $data['counters']['relationshipsDeleted'], + labelsAdded: $data['counters']['labelsAdded'], + labelsRemoved: $data['counters']['labelsRemoved'], + indexesAdded: $data['counters']['indexesAdded'], + indexesRemoved: $data['counters']['indexesRemoved'], + constraintsAdded: $data['counters']['constraintsAdded'], + constraintsRemoved: $data['counters']['constraintsRemoved'], + containsSystemUpdates: $data['counters']['containsSystemUpdates'], + systemUpdates: $data['counters']['systemUpdates'] +); + + + diff --git a/queryCounters/queryCountersTest.php b/queryCounters/queryCountersTest.php new file mode 100644 index 00000000..127c168d --- /dev/null +++ b/queryCounters/queryCountersTest.php @@ -0,0 +1,52 @@ + 1, + 'relationships_created' => 2, + 'properties_set' => 3, + ]); + + $this->assertEquals(1, $counters->get('nodes_created')); + $this->assertEquals(2, $counters->get('relationships_created')); + $this->assertEquals(3, $counters->get('properties_set')); + } + + public function testGetNonExistingCounterReturnsZero(): void + { + $counters = new queryCounters([ + 'nodes_created' => 1, + ]); + + $this->assertEquals(0, $counters->get('labels_added')); + $this->assertEquals(0, $counters->get('relationships_deleted')); + } + + public function testToArray(): void + { + $inputCounters = [ + 'nodes_created' => 1, + 'relationships_created' => 2, + 'properties_set' => 3, + ]; + + $counters = new queryCounters($inputCounters); + + $this->assertEquals($inputCounters, $counters->toArray()); + } + + public function testEmptyCountersArray(): void + { + $counters = new queryCounters([]); + + $this->assertEquals(0, $counters->get('nodes_created')); + $this->assertEquals(0, $counters->get('relationships_created')); + $this->assertEmpty($counters->toArray()); + } +} diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 00000000..81c6780b Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/Objects/ResultCounters.php b/src/Objects/ResultCounters.php new file mode 100644 index 00000000..b5cad70d --- /dev/null +++ b/src/Objects/ResultCounters.php @@ -0,0 +1,116 @@ +bookmarks = $bookmarks; + } + + + public function ContainsSystemUpdates(): bool + { + return $this->containsSystemUpdates; + } + + public function containsUpdates(): bool + { + return $this->containsUpdates; + } + + public function getNodesCreated(): int + { + return $this->nodesCreated; + } + + public function getNodesDeleted(): int + { + return $this->nodesDeleted; + } + + public function getPropertiesSet(): int + { + return $this->propertiesSet; + } + + public function getRelationshipsCreated(): int + { + return $this->relationshipsCreated; + } + + public function getRelationshipsDeleted(): int + { + return $this->relationshipsDeleted; + } + + public function getLabelsAdded(): int + { + return $this->labelsAdded; + } + + public function getIndexesAdded(): int + { + return $this->indexesAdded; + } + + public function getIndexesRemoved(): int + { + return $this->indexesRemoved; + } + + public function getConstraintsAdded(): int + { + return $this->constraintsAdded; + } + + public function getConstraintsRemoved(): int + { + return $this->constraintsRemoved; + } + + public function getSystemUpdates(): int + { + return $this->systemUpdates; + } + + public function getLabelsRemoved(): int + { + return $this->labelsRemoved; + } + public function getBookmarks(): array + { + return $this->bookmarks; + } + + public function addBookmark(string $bookmark): void + { + if (!in_array($bookmark, $this->bookmarks)) { + $this->bookmarks[] = $bookmark; + } + } + +// public function clearBookmarks(): void +// { +// $this->bookmarks = []; +// } + +} + + diff --git a/src/Results/ResultRow.php b/src/Results/ResultRow.php index e0813412..31907e57 100644 --- a/src/Results/ResultRow.php +++ b/src/Results/ResultRow.php @@ -1,26 +1,5 @@ values = []; -// foreach ($this->resultRow as $index => $value) { -// $this->values[$this->keys[$index]] = $value['_value']; -// } -// } -// -// public function get(string $column): mixed -// { -// return $this->values[$column] ?? null; -// } -//} - - namespace Neo4j\QueryAPI\Results; diff --git a/src/Results/ResultSet.php b/src/Results/ResultSet.php index 651a037a..03b90638 100644 --- a/src/Results/ResultSet.php +++ b/src/Results/ResultSet.php @@ -3,9 +3,8 @@ use ArrayIterator; use Countable; -use InvalidArgumentException; use IteratorAggregate; -use Neo4j\QueryAPI\OGM; +use Neo4j\QueryAPI\Objects\ResultCounters; use Traversable; class ResultSet implements IteratorAggregate, Countable @@ -13,7 +12,7 @@ class ResultSet implements IteratorAggregate, Countable /** * @param list $rows */ - public function __construct(private readonly array $rows) + public function __construct(private readonly array $rows,private ResultCounters $counters) { } @@ -21,6 +20,10 @@ public function getIterator(): Traversable { return new ArrayIterator($this->rows); } + public function getQueryCounters(): ?ResultCounters + { + return $this->counters; + } public function count(): int { diff --git a/src/query-api-test.php b/src/query-api-test.php index 779db7ef..139597f9 100644 --- a/src/query-api-test.php +++ b/src/query-api-test.php @@ -1,25 +1,2 @@ -run($query, []); - -// Display the results -echo "
";
-print_r($results);
-echo "
"; diff --git a/src/run_query.php b/src/run_query.php index 7ac3aaf3..95f11776 100644 --- a/src/run_query.php +++ b/src/run_query.php @@ -6,7 +6,6 @@ require __DIR__ . '/../vendor/autoload.php'; try { - // Login to the Neo4j instance $api = Neo4jQueryAPI::login( 'https://f2455ee6.databases.neo4j.io', // Replace with your Neo4j instance URL 'neo4j', // Replace with your Neo4j username @@ -14,7 +13,6 @@ ); - // Define a Cypher query $query = "MATCH (n:Person) RETURN n LIMIT 10"; // Fetch results in plain JSON format @@ -37,4 +35,4 @@ echo "Runtime Error: " . $e->getMessage(); } catch (Exception $e) { echo "General Error: " . $e->getMessage(); -} +} \ No newline at end of file diff --git a/tests/.DS_Store b/tests/.DS_Store new file mode 100644 index 00000000..e2460bc8 Binary files /dev/null and b/tests/.DS_Store differ diff --git a/tests/Integration/Neo4jQueryApiIntegrationTempTest.php b/tests/Integration/Neo4jQueryApiIntegrationTempTest.php index a7da7a35..e69de29b 100644 --- a/tests/Integration/Neo4jQueryApiIntegrationTempTest.php +++ b/tests/Integration/Neo4jQueryApiIntegrationTempTest.php @@ -1,59 +0,0 @@ -api = $this->initializeApi(); - - $this->clearDatabase(); - $this->setupConstraints(); - $this->api->populateTestData(['bob1', 'alicy']); - $this->api->validateData(); - } - - private function initializeApi(): Transaction - { - return Transaction::login( - getenv('NEO4J_ADDRESS'), - getenv('NEO4J_USERNAME'), - getenv('NEO4J_PASSWORD') - ); - } - - private function clearDatabase(): void - { - $this->api->run('MATCH (n) DETACH DELETE n', []); - } - - private function populateTestData(array $names): void - { - foreach ($names as $name) { - $this->api->run('CREATE (:Person {name: $name})', ['name' => $name]); - } - } - - public function testResultRowIntegration(): void - { - $resultSet = $this->api->run('MATCH (p:Person) RETURN p.name AS name, p.email AS email, p.age AS age, p AS person', []); - - foreach ($resultSet as $resultRow) { - - $name = $resultRow->get('name'); - $email = $resultRow->get('email'); - $age = $resultRow->get('age'); - - echo "Name: $name, Email: $email, Age: $age\n"; - - } - } - - -} \ No newline at end of file diff --git a/tests/Unit/Neo4jQueryAPIUnitTest.php b/tests/Unit/Neo4jQueryAPIUnitTest.php index 91ff5f1a..291dd491 100644 --- a/tests/Unit/Neo4jQueryAPIUnitTest.php +++ b/tests/Unit/Neo4jQueryAPIUnitTest.php @@ -7,7 +7,7 @@ use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; -use Neo4j\QueryAPI\Transaction; +use Neo4j\QueryAPI\Neo4jQueryAPI; use PHPUnit\Framework\TestCase; class Neo4jQueryAPIUnitTest extends TestCase @@ -27,11 +27,11 @@ protected function setUp(): void public function testCorrectClientSetup(): void { - $neo4jQueryAPI = Transaction::login($this->address, $this->username, $this->password); + $neo4jQueryAPI = Neo4jQueryAPI::login($this->address, $this->username, $this->password); - $this->assertInstanceOf(Transaction::class, $neo4jQueryAPI); + $this->assertInstanceOf(Neo4jQueryAPI::class, $neo4jQueryAPI); - $clientReflection = new \ReflectionClass(Transaction::class); + $clientReflection = new \ReflectionClass(Neo4jQueryAPIs::class); $clientProperty = $clientReflection->getProperty('client'); $client = $clientProperty->getValue($neo4jQueryAPI); @@ -48,7 +48,6 @@ public function testCorrectClientSetup(): void */ public function testRunSuccess(): void { - $mock = new MockHandler([ new Response(200, ['X-Foo' => 'Bar'], '{"hello":"world"}'), ]); @@ -56,7 +55,7 @@ public function testRunSuccess(): void $handlerStack = HandlerStack::create($mock); $client = new Client(['handler' => $handlerStack]); - $neo4jQueryAPI = new Transaction($client); + $neo4jQueryAPI = new Neo4jQueryAPI($client); $cypherQuery = 'MATCH (n:Person) RETURN n LIMIT 5'; diff --git a/tests/Unit/ResultSetTest.php b/tests/Unit/ResultSetTest.php index 2cdcd90e..189a30bb 100644 --- a/tests/Unit/ResultSetTest.php +++ b/tests/Unit/ResultSetTest.php @@ -14,13 +14,21 @@ class ResultSetTest extends TestCase /** * Test that an empty keys array throws an exception. */ + public function testEmptyKeysThrowException(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The keys array cannot be empty.'); $mockOgm = $this->createMock(OGM::class); - new ResultSet([], [], $mockOgm); + $resultSet = new ResultSet($mockOgm); + + // Call initialize with empty keys + $resultSet->initialize([], [ + [ + ['$type' => 'String', '_value' => 'Bob'], + ], + ]); } /** @@ -31,7 +39,8 @@ public function testValidResultSet(): void $mockOgm = $this->createMock(OGM::class); $mockOgm->method('map')->willReturnCallback(fn($value) => $value['_value'] ?? null); - $resultSet = new ResultSet( + $resultSet = new ResultSet($mockOgm); + $resultSet->initialize( ['name', 'age', 'email'], [ [ @@ -61,7 +70,8 @@ public function testInvalidColumnAccess(): void $mockOgm = $this->createMock(OGM::class); $mockOgm->method('map')->willReturnCallback(fn($value) => $value['_value'] ?? null); - $resultSet = new ResultSet( + $resultSet = new ResultSet($mockOgm); + $resultSet->initialize( ['name', 'age', 'email'], [ [ @@ -89,7 +99,8 @@ public function testMultipleRows(): void $mockOgm = $this->createMock(OGM::class); $mockOgm->method('map')->willReturnCallback(fn($value) => $value['_value'] ?? null); - $resultSet = new ResultSet( + $resultSet = new ResultSet($mockOgm); + $resultSet->initialize( ['name', 'age', 'email'], [ [