[
  {
    "path": ".gitignore",
    "content": "neo4jphp.phar\nbuild\ndocs\nvendor/\n/.idea/\ncomposer.lock"
  },
  {
    "path": ".travis.yml",
    "content": "language: php\nphp:\n  - 5.3\n  - 5.4\n  - 5.5\n\nbefore_script:\n    - pecl install -f memcached-2.1.0\n    - phpenv config-add phpconfig.ini\n    - composer install --dev\n\nscript: ./vendor/bin/phing ci\n"
  },
  {
    "path": "LICENSE",
    "content": "All project code is licensed under the MIT License\nhttp://www.opensource.org/licenses/mit-license.php\n\nCopyright (c) 2011 Josh Adell <josh.adell@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "Neo4jPhpVersionTask.php",
    "content": "<?php\nrequire_once __DIR__.'/lib/Everyman/Neo4j/Version.php';\n\nclass Neo4jPhpVersionTask extends Task\n{\n\tprotected $property;\n\n\tpublic function init(){}\n\n\tpublic function setProperty($name)\n\t{\n\t\t$this->property = $name;\n\t}\n\n\tpublic function main()\n\t{\n\t\t$version = \\Everyman\\Neo4j\\Version::CURRENT;\n\t\t$this->log(\"neo4jphp version: $version\");\n\t\t$this->project->setProperty($this->property, $version);\n\t}\n}"
  },
  {
    "path": "README.md",
    "content": "Neo4jPHP\n========\nAuthor: Josh Adell <josh.adell@gmail.com>  \nCopyright (c) 2011-2012\n\nPHP Wrapper for the Neo4j graph database REST interface\n\nIn-depth documentation and examples: http://github.com/jadell/neo4jphp/wiki\n\nAPI documentation: http://jadell.github.com/neo4jphp\n\n[![Build Status](https://secure.travis-ci.org/jadell/neo4jphp.png?branch=master)](http://travis-ci.org/jadell/neo4jphp)\n\nInstall\n-------\n\n### Using Composer\n1. From the command line `composer require \"everyman/neo4jphp\" \"dev-master\"`\n1. In your PHP script `require(\"vendor/autoload.php\");`\n\nConnection Test\n---------------\nCreate a script named `neo4jphp_connect_test.php`:\n\n```php\n    <?php\n    require('vendor/autoload.php');\n    \n    $client = new Everyman\\Neo4j\\Client('localhost', 7474);\n    print_r($client->getServerInfo());\n```\n\nChange `localhost` or `7474` to the host name and port of your Neo4j instance.\n\nExecute the script:\n\n    > php neo4jphp_connect_test.php\n\nIf you see your server's information, then you have successfully connected!\n\n\nGet Started\n-----------\nFull documentation on all the features of Neo4jPHP is available on the wiki: https://github.com/jadell/neo4jphp/wiki\n\n\nContributions\n-------------\nhttp://github.com/jadell/neo4jphp/graphs/contributors\n\nAll contributions are welcome! If you wish to contribute, please read the following guidelines:\n\n* Before implementing new features, [open an issue](https://github.com/jadell/neo4jphp/issues) describing the feature.\n* Include unit tests for any bug fixes or new features.\n* Include only one bug fix or new feature per pull request.\n* Make sure all unit tests run before submitting a pull request.\n* Follow the coding style of the existing code: tabs for indentation, class/method braces on newlines, spaces after commas, etc.\n* Contributing code means that you agree that any contributed code, documentation, or other artifacts may be released under the same license as the rest of the library.\n\n### Quick Contributor Setup\nInstall the developer tools:\n\n    > composer install --dev\n    \nAfter making your changes, run the unit tests and code style checker:\n\n    > vendor/bin/phing ci\n    \nRun only unit tests:\n\n    > vendor/bin/phing test\n    \nRun only style checker:\n\n    > vendor/bin/phing cs\n\nPull requests will not be accepted unless all tests pass and all code meets the existing style guidelines.\n\n### Special Thanks\n* Jacob Hansson <jacob@voltvoodoo.com> - Cypher query support\n* Nigel Small <nigel@nigelsmall.name> - GEOFF import/export\n  * [http://py2neo.org/](http://py2neo.org/)\n\n\nChanges\n-------\n\n0.1.0\n\n* Cypher and Gremlin results handle nested arrays of nodes/relationships\n* Batch request with no operations succeeds\n* Delete index where index does not exist succeeds\n\n0.0.7-beta\n\n* Retrieve reference node in one operation\n* Find and return only the first matching relationship\n* Optionally use HTTPS and basic authentication\n* Keep index configuration when retrieved from server\n* Add Memcache caching plugin\n* Do not allow use if cUrl is not detected\n* PHAR is uncompressed by default\n\n0.0.6-beta\n\n* Create full-text indexes; easier instantiation of common index types\n* Client can be initialized with a string and port instead of a Transport object\n* Setting a `null` property has the same effect as removing the property\n* Handle scalar values from Gremlin scripts properly\n* Cypher and Gremlin queries can take an array of named parameters\n* Cypher no longer uses positional parameters\n* Use server info to determine Cypher plugin endpoint\n\n0.0.5-beta\n\n* Open a batch on the client to apply to all subsequent data manipulation calls\n* Batch operations correctly set and update locally cached entities\n* Method chaining on node and relationship save, load and delete\n* Instantiate new nodes and relationships from the client\n* Change to cache initialization; new EntityCache object\n\n0.0.4-beta\n\n* Client::getServerInfo() retrieves server information and connection test\n* Add to index brought up to Neo4j server 1.5 specification\n* Return paths from Cypher queries\n* Properly encode URL entities\n* Connection and transport errors throw exceptions\n* Fix \"unable to connect\" bug from returning false positive\n"
  },
  {
    "path": "build.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project name=\"Neo4jPHP\" default=\"test\">\n\t<taskdef name=\"neo4jphpversion\" classname=\"Neo4jPhpVersionTask\" />\n\n\t<!-- Target: test -->\n\t<target name=\"test\" description=\"Verify all unit tests pass; fail if not\">\n\t\t<exec executable=\"vendor/bin/phpunit\" passthru=\"true\" checkreturn=\"true\">\n\t\t\t<arg line=\"-c tests/phpunit.xml\" />\n\t\t</exec>\n\t</target>\n\n\t<!-- Target: cs -->\n\t<target name=\"cs\" description=\"Verify that coding style guidelines are met; fail if not\">\n\t\t<exec executable=\"vendor/bin/phpcs\" passthru=\"true\" checkreturn=\"true\">\n\t\t\t<arg line=\"--standard=./tests/cs/ruleset.xml\" />\n\t\t\t<arg line=\"-s\" />\n\t\t\t<arg line=\"lib\" />\n\t\t</exec>\n\t</target>\n\n\t<!-- Target: ci -->\n\t<target name=\"ci\" description=\"Run all targets that verify CI build is good\">\n\t\t<phingcall target=\"test\" />\n\t\t<phingcall target=\"cs\" />\n\t</target>\n\n\t<!-- Target: build -->\n\t<target name=\"build\" description=\"Copy all package release files to a build directory\">\n\t\t<delete dir=\"./build\" />\n\t\t<mkdir dir=\"./build\" />\n\t\t<copy todir=\"./build\">\n\t\t\t<fileset dir=\".\">\n\t\t\t\t<include name=\"README.md\" />\n\t\t\t\t<include name=\"LICENSE\" />\n\t\t\t\t<include name=\"lib/\" />\n\t\t\t</fileset>\n\t\t</copy>\n\t</target>\n\n\t<!-- Target: package -->\n\t<target name=\"package\" description=\"Package the release files into an executable PHAR\" depends=\"build\">\n\t\t<neo4jphpversion property=\"version\" />\n\t\t<delete file=\"./neo4jphp.phar\" />\n\t\t<pharpackage\n\t\t\tdestfile=\"./neo4jphp.phar\"\n\t\t\tbasedir=\"./build\"\n\t\t\tcompression=\"none\"\n\t\t\tstub=\"./stub.php\"\n\t\t\tsignature=\"sha1\">\n\t\t\t<fileset dir=\"./build\">\n\t\t\t\t<include name=\"**/**\" />\n\t\t\t</fileset>\n\t\t\t<metadata>\n\t\t\t\t<element name=\"version\" value=\"${version}\" />\n\t\t\t\t<element name=\"authors\">\n\t\t\t\t\t<element name=\"Josh Adell\">\n\t\t\t\t\t\t<element name=\"email\" value=\"josh.adell@gmail.com\" />\n\t\t\t\t\t</element>\n\t\t\t\t</element>\n\t\t\t</metadata>\n\t\t</pharpackage>\n\t</target>\n</project>\n"
  },
  {
    "path": "composer.json",
    "content": "{\n  \"name\": \"everyman/neo4jphp\",\n  \"type\": \"library\",\n  \"description\": \"Wrapper for the Neo4j graph database REST interface\",\n  \"keywords\": [\"neo4j\",\"graph\",\"database\"],\n  \"homepage\": \"http://github.com/jadell/neo4jphp/wiki\",\n  \"license\": \"MIT\",\n  \"authors\": [\n    {\"name\": \"Josh Adell\", \"email\": \"josh.adell@gmail.com\", \"homepage\": \"http://joshadell.com\"}\n  ],\n  \"require\": {\n    \"php\": \">=5.3.0\",\n    \"ext-curl\": \"*\"\n  },\n  \"require-dev\": {\n    \"phing/phing\": \"2.6.*\",\n    \"phpunit/phpunit\": \"3.7.*\",\n    \"squizlabs/php_codesniffer\": \"1.5.*\"\n  },\n  \"autoload\": {\n    \"psr-0\": {\"Everyman\\\\Neo4j\":\"lib/\"}\n  }\n}\n"
  },
  {
    "path": "docblox.dist.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<docblox>\n\t<files>\n\t\t<directory>lib</directory>\n\t</files>\n\t<parser>\n\t\t<target>docs</target>\n\t</parser>\n\t<transformer>\n\t\t<target>docs</target>\n\t</transformer>\n</docblox>"
  },
  {
    "path": "examples/bacon.php",
    "content": "#!/usr/bin/env php\n<?php\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index\\NodeIndex,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node;\n\nrequire_once 'example_bootstrap.php';\n\n$cmd = !empty($argv[1]) ? $argv[1] : null;\n$from = '';\n$to = '';\n\nif (!$cmd) {\n\techo <<<HELP\nUsage:\n{$argv[0]}\n\tDisplay usage instructions\n\n{$argv[0]} init\n\tInitialize the data.  This only needs to be done once.\n\n{$argv[0]} path <from name> <to name>\n\tFind a path from one actor to another.\n\n\nHELP;\n\texit(0);\n}\n\n$client = new Client();\n$actors = new NodeIndex($client, 'actors');\n\n// Initialize the data\nif ($cmd == 'init') {\n\t$keanu = $client->makeNode()->setProperty('name', 'Keanu Reeves')->save();\n\t$laurence = $client->makeNode()->setProperty('name', 'Laurence Fishburne')->save();\n\t$jennifer = $client->makeNode()->setProperty('name', 'Jennifer Connelly')->save();\n\t$kevin = $client->makeNode()->setProperty('name', 'Kevin Bacon')->save();\n\n\t$actors->add($keanu, 'name', $keanu->getProperty('name'));\n\t$actors->add($laurence, 'name', $laurence->getProperty('name'));\n\t$actors->add($jennifer, 'name', $jennifer->getProperty('name'));\n\t$actors->add($kevin, 'name', $kevin->getProperty('name'));\n\n\t$matrix = $client->makeNode()->setProperty('title', 'The Matrix')->save();\n\t$higherLearning = $client->makeNode()->setProperty('title', 'Higher Learning')->save();\n\t$mysticRiver = $client->makeNode()->setProperty('title', 'Mystic River')->save();\n\n\t$keanu->relateTo($matrix, 'IN')->save();\n\t$laurence->relateTo($matrix, 'IN')->save();\n\n\t$laurence->relateTo($higherLearning, 'IN')->save();\n\t$jennifer->relateTo($higherLearning, 'IN')->save();\n\n\t$laurence->relateTo($mysticRiver, 'IN')->save();\n\t$kevin->relateTo($mysticRiver, 'IN')->save();\n\n// Find a path\n} else if ($cmd == 'path' && !empty($argv[2]) && !empty($argv[3])) {\n\t$from = $argv[2];\n\t$to = $argv[3];\n\n\t$fromNode = $actors->findOne('name', $from);\n\tif (!$fromNode) {\n\t\techo \"$from not found\\n\";\n\t\texit(1);\n\t}\n\n\t$toNode = $actors->findOne('name', $to);\n\tif (!$toNode) {\n\t\techo \"$to not found\\n\";\n\t\texit(1);\n\t}\n\n\t// Each degree is an actor and movie node\n\t$maxDegrees = 6;\n\t$depth = $maxDegrees * 2;\n\n\t$path = $fromNode->findPathsTo($toNode)\n\t\t->setmaxDepth($depth)\n\t\t->getSinglePath();\n\n\tif ($path) {\n\t\tforeach ($path as $i => $node) {\n\t\t\tif ($i % 2 == 0) {\n\t\t\t\t$degree = $i/2;\n\t\t\t\techo str_repeat(\"\\t\", $degree);\n\t\t\t\techo $degree . ': ' .$node->getProperty('name');\n\t\t\t\tif ($i+1 != count($path)) {\n\t\t\t\t\techo \" was in \";\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\techo $node->getProperty('title') . \" with\\n\";\n\t\t\t}\n\t\t}\n\t\techo \"\\n\";\n\t}\n}\n\n"
  },
  {
    "path": "examples/batch_benchmarks.php",
    "content": "#!/usr/bin/env php\n<?php\nnamespace Everyman\\Neo4j;\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Batch,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node;\n\nrequire_once 'example_bootstrap.php';\n\n$client = new Client();\n\n$runs = 5;\n$series = array(\n\t10,\n\t100,\n\t250,\n\t500,\n\t1000,\n\t2500,\n\t5000,\n);\n\n$trials = array(\n\tnew CreateNode($client),\n\tnew CreateRelationship($client),\n\tnew CreateFullRelationship($client),\n);\nforeach ($trials as $trial) {\n\t$trial->benchmark($series, $runs);\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// Benchmark trials ///////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////\n\nabstract class Benchmark\n{\n\tprotected $client = null;\n\tprotected $title = 'unknown';\n\n\tabstract protected function batch($size);\n\tabstract protected function sequential($size);\n\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->client = $client;\n\t}\n\n\tpublic function benchmark($series, $runs)\n\t{\n\t\techo \"Benchmark: {$this->title}\\n\";\n\t\tforeach ($series as $size) {\n\t\t\t$batchTotal = 0;\n\t\t\t$seqTotal = 0;\n\t\t\tfor ($i=0; $i<$runs; $i++) {\n\t\t\t\techo \"{$size}\\t{$i}\\t\";\n\n\t\t\t\t$batchTotal += $batchTime = $this->batch($size);\n\t\t\t\techo \"{$batchTime}\\t\";\n\n\t\t\t\t$seqTotal += $seqTime = $this->sequential($size);\n\t\t\t\techo \"{$seqTime}\\n\";\n\t\t\t}\n\t\t\t$batchAvg = round($batchTotal/$runs,2);\n\t\t\t$seqAvg = round($seqTotal/$runs,2);\n\t\t\techo \"\\t\\t$batchAvg\\t$seqAvg\\n\\n\";\n\t\t}\n\t\t\n\t}\n}\n\nclass CreateNode extends Benchmark\n{\n\tprotected $title = 'Create nodes';\n\n\tprotected function batch($size)\n\t{\n\t\t$start = time();\n\t\t$this->client->startBatch();\n\t\tforeach(range(1, $size) as $id) {\n\t\t\t$this->client->makeNode()->setProperty('stop_id', $id)->save();\n\t\t}\n\t\t$this->client->commitBatch();\n\t\t$end = time();\n\t\treturn $end - $start;\n\t}\n\n\tprotected function sequential($size)\n\t{\n\t\t$start = time();\n\t\tforeach(range(1, $size) as $id) {\n\t\t\t$this->client->makeNode()->setProperty('stop_id', $id)->save();\n\t\t}\n\t\t$end = time();\n\t\treturn $end - $start;\n\t}\n}\n\nclass CreateRelationship extends Benchmark\n{\n\tprotected $title = 'Create relationships';\n\n\tprotected function batch($size)\n\t{\n\t\t$nodeA = $this->client->makeNode()->save();\n\t\t$nodeB = $this->client->makeNode()->save();\n\n\t\t$start = time();\n\t\t$this->client->startBatch();\n\t\tforeach(range(1, $size) as $id) {\n\t\t\t$nodeA->relateTo($nodeB, 'TEST')->setProperty('stop_id', $id)->save();\n\t\t}\n\t\t$this->client->commitBatch();\n\t\t$end = time();\n\t\treturn $end - $start;\n\t}\n\n\tprotected function sequential($size)\n\t{\n\t\t$nodeA = $this->client->makeNode()->save();\n\t\t$nodeB = $this->client->makeNode()->save();\n\n\t\t$start = time();\n\t\tforeach(range(1, $size) as $id) {\n\t\t\t$nodeA->relateTo($nodeB, 'TEST')->setProperty('stop_id', $id)->save();\n\t\t}\n\t\t$end = time();\n\t\treturn $end - $start;\n\t}\n}\n\nclass CreateFullRelationship extends Benchmark\n{\n\tprotected $title = 'Create full relationships (start node, end node, relationship)';\n\n\tprotected function batch($size)\n\t{\n\t\t$start = time();\n\t\t$this->client->startBatch();\n\t\tforeach(range(1, $size) as $id) {\n\t\t\t$nodeA = $this->client->makeNode()->save();\n\t\t\t$nodeB = $this->client->makeNode()->save();\n\t\t\t$nodeA->relateTo($nodeB, 'TEST')->setProperty('stop_id', $id)->save();\n\t\t}\n\t\t$this->client->commitBatch();\n\t\t$end = time();\n\t\treturn $end - $start;\n\t}\n\n\tprotected function sequential($size)\n\t{\n\t\t$start = time();\n\t\tforeach(range(1, $size) as $id) {\n\t\t\t$nodeA = $this->client->makeNode()->save();\n\t\t\t$nodeB = $this->client->makeNode()->save();\n\t\t\t$nodeA->relateTo($nodeB, 'TEST')->setProperty('stop_id', $id)->save();\n\t\t}\n\t\t$end = time();\n\t\treturn $end - $start;\n\t}\n}\n"
  },
  {
    "path": "examples/cypher.php",
    "content": "#!/usr/bin/env php\n<?php\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index\\NodeIndex,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Cypher;\n\nrequire_once 'example_bootstrap.php';\n\n$cmd = !empty($argv[1]) ? $argv[1] : null;\n\nif (!$cmd) {\n\techo <<<HELP\nUsage:\n{$argv[0]}\n\tDisplay usage instructions\n\n{$argv[0]} init\n\tInitialize the data.  This only needs to be done once.\n\n{$argv[0]} actors <movie_name>\n\tGet a list of all actors in the movie.\n\n\nHELP;\n\texit(0);\n}\n\n$client = new Client();\n$actors = new NodeIndex($client, 'actors');\n\n// Initialize the data\nif ($cmd == 'init') {\n\t$keanu = $client->makeNode()->setProperty('name', 'Keanu Reeves')->save();\n\t$laurence = $client->makeNode()->setProperty('name', 'Laurence Fishburne')->save();\n\t$jennifer = $client->makeNode()->setProperty('name', 'Jennifer Connelly')->save();\n\t$kevin = $client->makeNode()->setProperty('name', 'Kevin Bacon')->save();\n\n\t$actors->add($keanu, 'name', $keanu->getProperty('name'));\n\t$actors->add($laurence, 'name', $laurence->getProperty('name'));\n\t$actors->add($jennifer, 'name', $jennifer->getProperty('name'));\n\t$actors->add($kevin, 'name', $kevin->getProperty('name'));\n\n\t$matrix = $client->makeNode()->setProperty('title', 'The Matrix')->save();\n\t$higherLearning = $client->makeNode()->setProperty('title', 'Higher Learning')->save();\n\t$mysticRiver = $client->makeNode()->setProperty('title', 'Mystic River')->save();\n\n\t$keanu->relateTo($matrix, 'IN')->save();\n\t$laurence->relateTo($matrix, 'IN')->save();\n\n\t$laurence->relateTo($higherLearning, 'IN')->save();\n\t$jennifer->relateTo($higherLearning, 'IN')->save();\n\n\t$laurence->relateTo($mysticRiver, 'IN')->save();\n\t$kevin->relateTo($mysticRiver, 'IN')->save();\n\n// Find all actors in a movie\n} else if ($cmd == 'actors') {\n\t\n\tif(!empty($argv[2])) {\n\t\t$movie = implode(\" \", array_slice($argv,2));\n\t} else {\n\t\t$movie = \"The Matrix\";\n\t}\n\t\n\t$queryTemplate = \"START actor=node:actors('name:*') \".\n\t\t\"MATCH (actor) -[:IN]- (movie)\".\n\t\t\"WHERE movie.title = {title}\".\n\t\t\"RETURN actor\";\n\t$query = new Cypher\\Query($client, $queryTemplate, array('title'=>$movie));\n\t$result = $query->getResultSet();\n\t\n\techo \"Found \".count($result).\" actors:\\n\";\n\tforeach($result as $row) {\n\t\techo \"  \".$row['actor']->getProperty('name').\"\\n\";\n\t}\n}\n\n"
  },
  {
    "path": "examples/directions.php",
    "content": "#!/usr/bin/env php\n<?php\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index\\NodeIndex,\n\tEveryman\\Neo4j\\Path,\n\tEveryman\\Neo4j\\PathFinder,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node;\n\nrequire_once 'example_bootstrap.php';\n\n$cmd = !empty($argv[1]) ? $argv[1] : null;\n$from = '';\n$to = '';\n$paths = array();\n\nif (!$cmd) {\n\techo <<<HELP\nUsage:\n{$argv[0]}\n\tDisplay usage instructions\n\n{$argv[0]} init\n\tInitialize the data.  This only needs to be done once.\n\n{$argv[0]} map\n\tDisplay the available points and the connections and distances between them.\n\n{$argv[0]} path <start> <end> [<algorithm>]\n\tFind a path from one node to another.\n\talgorithm is optional, and can be one of:\n\t\toptimal: Find the shortest paths by distance.  Default.\n\t\tsimple:  Find the shortest paths by number of nodes.\n\t\tall:     Find all paths, regardless of length.\n\n\nHELP;\n\texit(0);\n}\n\n$client = new Client();\n$intersections = new NodeIndex($client, 'intersections1');\n\n$inters = array(\n\t'A'=>null,\n\t'B'=>null,\n\t'C'=>null,\n\t'D'=>null,\n\t'E'=>null,\n\t'F'=>null,\n);\n\n$streets = array(\n\t// name, start, end, direction, travel time\n\tarray('A', 'B', array('direction'=>'east', 'distance'=>2.1, 'name'=>'AB')),\n\tarray('A', 'D', array('direction'=>'south', 'distance'=>2.1, 'name'=>'AD')),\n\tarray('A', 'E', array('direction'=>'south', 'distance'=>3.1, 'name'=>'AE')),\n\n\tarray('B', 'A', array('direction'=>'west', 'distance'=>2.1, 'name'=>'AB')),\n\tarray('B', 'C', array('direction'=>'east', 'distance'=>2.1, 'name'=>'BC')),\n\tarray('B', 'E', array('direction'=>'south', 'distance'=>2.1, 'name'=>'BE')),\n\n\tarray('C', 'B', array('direction'=>'west', 'distance'=>2.1, 'name'=>'BC')),\n\tarray('C', 'F', array('direction'=>'south', 'distance'=>1.1, 'name'=>'CF')),\n\n\tarray('D', 'A', array('direction'=>'north', 'distance'=>2.1, 'name'=>'AD')),\n\tarray('D', 'E', array('direction'=>'east', 'distance'=>2.1, 'name'=>'DE')),\n\n\tarray('E', 'D', array('direction'=>'west', 'distance'=>2.1, 'name'=>'DE')),\n\tarray('E', 'B', array('direction'=>'north', 'distance'=>2.1, 'name'=>'BE')),\n\n\tarray('F', 'C', array('direction'=>'north', 'distance'=>1.1, 'name'=>'CF')),\n\tarray('F', 'E', array('direction'=>'west', 'distance'=>2.1, 'name'=>'FE')),\n);\n\n$turns = array(\n\t'east' => array(\n\t\t'north' => 'left',\n\t\t'south' => 'right',\n\t\t'west' => 'u-turn',\n\t),\n\t'west' => array(\n\t\t'north' => 'right',\n\t\t'south' => 'left',\n\t\t'east' => 'u-turn',\n\t),\n\t'north' => array(\n\t\t'east' => 'right',\n\t\t'west' => 'left',\n\t\t'south' => 'u-turn',\n\t),\n\t'south' => array(\n\t\t'east' => 'left',\n\t\t'west' => 'right',\n\t\t'north' => 'u-turn',\n\t),\n);\n\n// Initialize the data\nif ($cmd == 'init') {\n\techo \"Initializing data.\\n\";\n\tforeach ($inters as $inter => $temp) {\n\t\t$node = $client->makeNode()->setProperty('name', $inter)->save();\n\t\t$intersections->add($node, 'name', $node->getProperty('name'));\n\t\t$inters[$inter] = $node;\n\t}\n\n\tforeach ($streets as $info) {\n\t\t$start = $inters[$info[0]];\n\t\t$end = $inters[$info[1]];\n\t\t$properties = $info[2];\n\t\t$street = $start->relateTo($end, 'CONNECTS')->setProperties($properties);\n\t\t$street->save();\n\t}\n\n// Find a path\n} else if ($cmd == 'path' && !empty($argv[2]) && !empty($argv[3])) {\n\t$from = $argv[2];\n\t$to = $argv[3];\n\n\t$algorithm = null;\n\t$all = !empty($argv[4]) && $argv[4] == 'all';\n\n\t$fromNode = $intersections->findOne('name', $from);\n\t$toNode = $intersections->findOne('name', $to);\n\n\t$finder = $fromNode->findPathsTo($toNode, 'CONNECTS', Relationship::DirectionOut)\n\t\t->setMaxDepth(5);\n\n\t$algorithm = !empty($argv[4]) ? $argv[4] : null;\n\n\t// Find all paths regardless of complexity or distance\n\tif ($algorithm == 'all') {\n\t\t$finder->setAlgorithm(PathFinder::AlgoAllSimple);\n\n\t// Find paths with the smallest number of instructions\n\t} else if ($algorithm == 'simple') {\n\t\t$finder->setAlgorithm(PathFinder::AlgoShortest);\n\n\t// Find the most optimal paths\n\t} else {\n\t\t$finder->setAlgorithm(PathFinder::AlgoDijkstra)\n\t\t\t->setCostProperty('distance');\n\t}\n\n\t$paths = $finder->getPaths();\n}\n\necho <<<MAP\nMap:\n\tA <-2-> B <-2-> C\n\t^\\      ^       ^\n\t| \\     |       |\n\t|  \\    |       |\n\t|   \\   |       |\n\t2   3\\  2       1\n\t|     \\ |       |\n\t|      \\|       |\n\tV       V       V\n\tD <-2-> E <-2-- F \nMAP;\necho \"\\n\\n\";\n\nforeach ($paths as $i => $path) {\n\t$path->setContext(Path::ContextRelationship);\n\t$prevDirection = null;\n\t$totalDistance = 0;\n\n\techo \"Path \" . ($i+1) .\":\\n\";\n\tforeach ($path as $j => $rel) {\n\t\t$direction = $rel->getProperty('direction');\n\t\t$distance = $rel->getProperty('distance');\n\t\t$name = $rel->getProperty('name');\n\n\t\tif (!$prevDirection) {\n\t\t\t$action = 'Head';\n\t\t} else if ($prevDirection == $direction) {\n\t\t\t$action = 'Continue';\n\t\t} else {\n\t\t\t$turn = $turns[$prevDirection][$direction];\n\t\t\t$action = \"Turn $turn, and continue\";\n\t\t}\n\t\t$prevDirection = $direction;\n\t\t$step = $j+1;\n\t\t$totalDistance += $distance;\n\n\t\techo \"\\t{$step}: {$action} {$direction} on {$name} for {$distance} miles.\\n\";\n\t}\n\techo \"\\tTravel distance: {$totalDistance}\\n\\n\";\n}\n\n\n\n"
  },
  {
    "path": "examples/example_bootstrap.php",
    "content": "<?php\nerror_reporting(-1);\nini_set('display_errors', 1);\nspl_autoload_register(function ($sClass) {\n\t$sLibPath = __DIR__.'/../lib/';\n\t$sClassFile = str_replace('\\\\',DIRECTORY_SEPARATOR,$sClass).'.php';\n\t$sClassPath = $sLibPath.$sClassFile;\n\tif (file_exists($sClassPath)) {\n\t\trequire($sClassPath);\n\t}\n});\n"
  },
  {
    "path": "examples/gremlin.php",
    "content": "#!/usr/bin/env php\n<?php\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index\\NodeIndex,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Gremlin;\n\nrequire_once 'example_bootstrap.php';\n\n$cmd = !empty($argv[1]) ? $argv[1] : null;\n\nif (!$cmd) {\n\techo <<<HELP\nUsage:\n{$argv[0]}\n\tDisplay usage instructions\n\n{$argv[0]} init\n\tInitialize the data.  This only needs to be done once.\n\n{$argv[0]} actors\n\tGet a list of all actors in the database.\n\nHELP;\n\texit(0);\n}\n\n$client = new Client();\n$actors = new NodeIndex($client, 'actors');\n\n// Initialize the data\nif ($cmd == 'init') {\n\t$keanu = $client->makeNode()->setProperty('name', 'Keanu Reeves')->save();\n\t$laurence = $client->makeNode()->setProperty('name', 'Laurence Fishburne')->save();\n\t$jennifer = $client->makeNode()->setProperty('name', 'Jennifer Connelly')->save();\n\t$kevin = $client->makeNode()->setProperty('name', 'Kevin Bacon')->save();\n\n\t$actors->add($keanu, 'name', $keanu->getProperty('name'));\n\t$actors->add($laurence, 'name', $laurence->getProperty('name'));\n\t$actors->add($jennifer, 'name', $jennifer->getProperty('name'));\n\t$actors->add($kevin, 'name', $kevin->getProperty('name'));\n\n\t$matrix = $client->makeNode()->setProperty('title', 'The Matrix')->save();\n\t$higherLearning = $client->makeNode()->setProperty('title', 'Higher Learning')->save();\n\t$mysticRiver = $client->makeNode()->setProperty('title', 'Mystic River')->save();\n\n\t$keanu->relateTo($matrix, 'IN')->save();\n\t$laurence->relateTo($matrix, 'IN')->save();\n\n\t$laurence->relateTo($higherLearning, 'IN')->save();\n\t$jennifer->relateTo($higherLearning, 'IN')->save();\n\n\t$laurence->relateTo($mysticRiver, 'IN')->save();\n\t$kevin->relateTo($mysticRiver, 'IN')->save();\n\n// Find all actors in a movie\n} else if ($cmd == 'actors') {\n\t$queryTemplate = \"g.V.in(type).dedup.sort{it.name}.toList()\";\n\t$params = array('type' => 'IN');\n\t$query = new Gremlin\\Query($client, $queryTemplate, $params);\n\t$result = $query->getResultSet();\n\t\n\tforeach ($result as $row) {\n\t\techo \"* \" . $row[0]->getProperty('name').\"\\n\";\n\t}\n}\n\n"
  },
  {
    "path": "examples/indexing.php",
    "content": "#!/usr/bin/env php\n<?php\nuse Everyman\\Neo4j\\Client,\n    Everyman\\Neo4j\\Index\\NodeIndex,\n    Everyman\\Neo4j\\Index\\RelationshipIndex,\n    Everyman\\Neo4j\\Index\\NodeFulltextIndex,\n    Everyman\\Neo4j\\Node,\n    Everyman\\Neo4j\\Batch;\n\nrequire_once 'example_bootstrap.php';\n\n$client = new Client();\n\n$actorIndex = new NodeIndex($client, 'actors');\n$roleIndex = new RelationshipIndex($client, 'roles');\n$plotIndex = new NodeFulltextIndex($client, 'plots');\n$plotIndex->save();\n\n$leslie = $client->makeNode()\n\t->setProperty('name', 'Leslie Nielsen')\n\t->save();\n\n$airplane = $client->makeNode()\n\t->setProperty('title', 'Airplane')\n\t->save();\n\n$rumack = $leslie->relateTo($airplane, 'PLAYED')\n\t->setProperty('character', 'Dr. Rumack')\n\t->save();\n\n$actorIndex->add($leslie, 'name', $leslie->getProperty('name'));\n$roleIndex->add($rumack, 'character', $rumack->getProperty('character'));\n$plotIndex->add($airplane, 'synopsis', 'An airplane crew takes ill. Surely the only person capable of landing the plane is an ex-pilot afraid to fly. But don\\'t call him Shirley.');\n\necho $actorIndex->queryOne('name:Leslie*')->getProperty('name') . \"\\n\";\necho $roleIndex->queryOne('character:*u*')->getProperty('character') . \"\\n\";\necho $plotIndex->queryOne('synopsis:lend~0.2')->getProperty('title') . \"\\n\";\n\n\n"
  },
  {
    "path": "examples/widgets.php",
    "content": "#!/usr/bin/env php\n<?php\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index\\NodeIndex,\n\tEveryman\\Neo4j\\Path,\n\tEveryman\\Neo4j\\PathFinder,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Cypher,\n\tEveryman\\Neo4j\\Traversal;\n\nrequire_once 'example_bootstrap.php';\n\n$cmd = !empty($argv[1]) ? $argv[1] : null;\n$from = '';\n$to = '';\n$paths = array();\n\nif (!$cmd) {\n\techo <<<HELP\nUsage:\n{$argv[0]}\n\tDisplay usage instructions\n\n{$argv[0]} init\n\tInitialize the data.  This only needs to be done once.\n\n{$argv[0]} parts\n\tDisplay the available parts in the system.\n\n{$argv[0]} stores <part> [<language>]\n\tFind all the stores where the given part was sold.\n\tLanguage can be one of:\n\t\ttraverse: use the javascript traversal. Default.\n\t\tcypher: use a cypher query\n\n\nHELP;\n\texit(0);\n}\n\n$client = new Client();\n$partsIndex = new NodeIndex($client, 'parts3');\n\n$parts = array('widget','gadget','gizmo');\n$stores = array(\"Bob's Old Houseware\",\"Mainstreet Hardware\",\"Nutz N' Boltz\", \"Doodad Emporium\");\n// Store, part list\n$orders = array(\n\tarray(0, array(0,1)),\n\tarray(0, array(1)),\n\tarray(1, array(1,2)),\n\tarray(1, array(0,2)),\n\tarray(2, array(0,1,2)),\n\tarray(3, array(2)),\n\tarray(3, array(0)),\n);\n\n// Initialize the data\nif ($cmd == 'init') {\n\techo \"Initializing data.\\n\";\n\t$p = array();\n\t$s = array();\n\n\tforeach ($parts as $part) {\n\t\t$node = $client->makeNode()->setProperty('name', $part)->save();\n\t\t$partsIndex->add($node, 'name', $node->getProperty('name'));\n\t\t$p[] = $node;\n\t}\n\n\tforeach ($stores as $store) {\n\t\t$node = $client->makeNode()->setProperty('name', $store)->save();\n\t\t$s[] = $node;\n\t}\n\n\tforeach ($orders as $order) {\n\t\t$node = $client->makeNode()->save();\n\n\t\t$s[$order[0]]->relateTo($node, 'SOLD')->save();\n\t\tforeach ($order[1] as $pi) {\n\t\t\t$node->relateTo($p[$pi], 'CONTAINS')->save();\n\t\t}\n\t}\n\n// List parts\n} else if ($cmd == 'parts') {\n\t$partsList = $partsIndex->query('name:*');\n\tforeach ($partsList as $part) {\n\t\techo \"* {$part->getProperty('name')}\\n\";\n\t}\n\n// Find stores where the part was sold\n} else if ($cmd == 'stores' && !empty($argv[2])) {\n\t$partName = $argv[2];\n\n\t// Use the Cypher query language\n\tif (!empty($argv[3]) && $argv[3] == 'cypher') {\n\t\t$queryTemplate = \"START part=node:parts3('name:{$partName}') \".\n\t\t\t\"MATCH (store)-[:SOLD]->()-[:CONTAINS]->(part) \".\n\t\t\t// Use the count(*) to force distinct values until Cypher gets DISTINCT keyword support\n\t\t\t\"RETURN store, count(*)\";\n\t\t$query = new Cypher\\Query($client, $queryTemplate);\n\t\t$result = $query->getResultSet();\n\t\n\t\techo \"Found \".count($result).\" stores:\\n\";\n\t\tforeach($result as $row) {\n\t\t\techo \"* \".$row['store']->getProperty('name').\"\\n\";\n\t\t}\n\t\n\t// Use javascript traversal\n\t} else {\n\t\t$part = $partsIndex->findOne('name', $partName);\n\t\tif (!$part) {\n\t\t\tdie(\"{$partName} not found.\\n\");\n\t\t}\n\n\t\t$traversal = new Traversal($client);\n\t\t$traversal->addRelationship('CONTAINS', Relationship::DirectionIn)\n\t\t\t->addRelationship('SOLD', Relationship::DirectionIn)\n\t\t\t->setMaxDepth(4)\n\t\t\t->setReturnFilter('javascript', '(position.length() > 0 && position.lastRelationship().getType() == \"SOLD\");');\n\n\t\t$stores = $traversal->getResults($part, Traversal::ReturnTypeNode);\n\t\techo \"Found \".count($stores).\" stores:\\n\";\n\t\tforeach ($stores as $store) {\n\t\t\techo \"* {$store->getProperty('name')}\\n\";\n\t\t}\n\t}\n}\n\n\n\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Batch/AddTo.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Batch;\n\nuse Everyman\\Neo4j\\Batch,\n\tEveryman\\Neo4j\\Command\\Batch as Command,\n\tEveryman\\Neo4j\\Index,\n\tEveryman\\Neo4j\\PropertyContainer;\n\n/**\n * An add-to-index operation\n */\nclass AddTo extends Operation\n{\n\tprotected $command = null;\n\tprotected $index = null;\n\tprotected $key = null;\n\tprotected $value = null;\n\n\t/**\n\t * Build the operation\n\t *\n\t * @param Batch $batch\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Batch $batch, Index $index, PropertyContainer $entity, $key, $value, $opId)\n\t{\n\t\tparent::__construct($batch, 'addto', $entity, $opId);\n\t\t$this->index = $index;\n\t\t$this->key = $key;\n\t\t$this->value = $value;\n\t}\n\n\t/**\n\t * Get the command that represents this operation\n\t *\n\t * @return Batch\\Command\n\t */\n\tpublic function getCommand()\n\t{\n\t\tif (!$this->command) {\n\t\t\t$this->command = new Command\\AddToIndex(\n\t\t\t\t$this->batch->getClient(),\n\t\t\t\t$this->index,\n\t\t\t\t$this->entity,\n\t\t\t\t$this->key,\n\t\t\t\t$this->value,\n\t\t\t\t$this->opId,\n\t\t\t\t$this->batch\n\t\t\t);\n\t\t}\n\t\treturn $this->command;\n\t}\n\n\t/**\n\t * Get the index\n\t *\n\t * @return Index\n\t */\n\tpublic function getIndex()\n\t{\n\t\treturn $this->index;\n\t}\n\n\t/**\n\t * Get the key being indexed\n\t *\n\t * @return string\n\t */\n\tpublic function getKey()\n\t{\n\t\treturn $this->key;\n\t}\n\n\t/**\n\t * Get the value being indexed\n\t *\n\t * @return mixed\n\t */\n\tpublic function getValue()\n\t{\n\t\treturn $this->value;\n\t}\n\n\t/**\n\t * Based on this operations parameters, generate a consistent id\n\t *\n\t * @return mixed\n\t */\n\tpublic function matchId()\n\t{\n\t\treturn parent::matchId() . spl_object_hash($this->index) . $this->key . $this->value;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Batch/Delete.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Batch;\n\nuse Everyman\\Neo4j\\Batch,\n\tEveryman\\Neo4j\\Command\\Batch as Command,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\PropertyContainer;\n\n/**\n * A delete operation\n */\nclass Delete extends Operation\n{\n\tprotected $command = null;\n\n\t/**\n\t * Build the operation\n\t *\n\t * @param Batch $batch\n\t * @param PropertyContainer $entity\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Batch $batch, PropertyContainer $entity, $opId)\n\t{\n\t\tparent::__construct($batch, 'delete', $entity, $opId);\n\t}\n\n\t/**\n\t * Get the command that represents this operation\n\t *\n\t * @return Batch\\Command\n\t */\n\tpublic function getCommand()\n\t{\n\t\tif (!$this->command) {\n\t\t\t$entity = $this->entity;\n\t\t\t$command = null;\n\t\t\tif ($entity instanceof Node) {\n\t\t\t\t$command = new Command\\DeleteNode($this->batch->getClient(), $entity, $this->opId);\n\t\t\t} else if ($entity instanceof Relationship) {\n\t\t\t\t$command = new Command\\DeleteRelationship($this->batch->getClient(), $entity, $this->opId);\n\t\t\t}\n\n\t\t\t$this->command = $command;\n\t\t}\n\t\treturn $this->command;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Batch/Operation.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Batch;\n\nuse Everyman\\Neo4j\\Batch,\n\tEveryman\\Neo4j\\PropertyContainer;\n\n/**\n * A single operation in a batch\n */\nabstract class Operation\n{\n\tprotected $batch = null;\n\tprotected $operation = null;\n\tprotected $entity = null;\n\tprotected $opId = null;\n\n\tprotected $reserved = false;\n\n\t/**\n\t * Build the operation\n\t *\n\t * @param Batch $batch\n\t * @param string $operation\n\t * @param PropertyContainer $entity\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Batch $batch, $operation, PropertyContainer $entity, $opId)\n\t{\n\t\t$this->batch = $batch;\n\t\t$this->operation = $operation;\n\t\t$this->entity = $entity;\n\t\t$this->opId = $opId;\n\t}\n\n\t/**\n\t * Get the underlying batch command for this operation\n\t *\n\t * @return Batch\\Command\n\t */\n\tabstract public function getCommand();\n\n\t/**\n\t * Return the associated entity\n\t *\n\t * @return PropertyContainer\n\t */\n\tpublic function getEntity()\n\t{\n\t\treturn $this->entity;\n\t}\n\n\t/**\n\t * Get the operation id\n\t *\n\t * @return integer\n\t */\n\tpublic function getId()\n\t{\n\t\treturn $this->opId;\n\t}\n\n\t/**\n\t * Based on this operations parameters, generate a consistent id\n\t *\n\t * @return mixed\n\t */\n\tpublic function matchId()\n\t{\n\t\treturn $this->operation . spl_object_hash($this->entity);\n\t}\n\n\t/**\n\t * Reserve this operation to prevent it from being double-committed\n\t * Once an operation has been reserved, future reserve calls will\n\t * return false, indicating it has already been reserved.\n\t * This is mostly useful during commit to prevent an operation being\n\t * sent twice\n\t *\n\t * @return boolean true if reservation succeeded\n\t */\n\tpublic function reserve()\n\t{\n\t\tif (!$this->reserved) {\n\t\t\t$this->reserved = true;\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Batch/RemoveFrom.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Batch;\n\nuse Everyman\\Neo4j\\Batch,\n\tEveryman\\Neo4j\\Command\\Batch as Command,\n\tEveryman\\Neo4j\\Index,\n\tEveryman\\Neo4j\\PropertyContainer;\n\n/**\n * A remove-from-index operation\n */\nclass RemoveFrom extends Operation\n{\n\tprotected $command = null;\n\tprotected $index = null;\n\tprotected $key = null;\n\tprotected $value = null;\n\n\t/**\n\t * Build the operation\n\t *\n\t * @param Batch $batch\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Batch $batch, Index $index, PropertyContainer $entity, $key, $value, $opId)\n\t{\n\t\tparent::__construct($batch, 'removefrom', $entity, $opId);\n\t\t$this->index = $index;\n\t\t$this->key = $key;\n\t\t$this->value = $value;\n\t}\n\n\t/**\n\t * Get the command that represents this operation\n\t *\n\t * @return Batch\\Command\n\t */\n\tpublic function getCommand()\n\t{\n\t\tif (!$this->command) {\n\t\t\t$this->command = new Command\\RemoveFromIndex(\n\t\t\t\t$this->batch->getClient(),\n\t\t\t\t$this->index,\n\t\t\t\t$this->entity,\n\t\t\t\t$this->key,\n\t\t\t\t$this->value,\n\t\t\t\t$this->opId\n\t\t\t);\n\t\t}\n\t\treturn $this->command;\n\t}\n\n\t/**\n\t * Based on this operations parameters, generate a consistent id\n\t *\n\t * @return mixed\n\t */\n\tpublic function matchId()\n\t{\n\t\treturn parent::matchId() . spl_object_hash($this->index) . $this->key . $this->value;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Batch/Save.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Batch;\n\nuse Everyman\\Neo4j\\Batch,\n\tEveryman\\Neo4j\\Command\\Batch as Command,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\PropertyContainer;\n\n/**\n * A save operation\n */\nclass Save extends Operation\n{\n\tprotected $command = null;\n\n\t/**\n\t * Build the operation\n\t *\n\t * @param Batch $batch\n\t * @param PropertyContainer $entity\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Batch $batch, PropertyContainer $entity, $opId)\n\t{\n\t\tparent::__construct($batch, 'save', $entity, $opId);\n\t}\n\n\t/**\n\t * Get the command that represents this operation\n\t *\n\t * @return Batch\\Command\n\t */\n\tpublic function getCommand()\n\t{\n\t\tif (!$this->command) {\n\t\t\t$entity = $this->entity;\n\t\t\t$command = null;\n\t\t\tif (!$entity->hasId()) {\n\t\t\t\tif ($entity instanceof Node) {\n\t\t\t\t\t$command = new Command\\CreateNode($this->batch->getClient(), $entity, $this->opId);\n\t\t\t\t} else if ($entity instanceof Relationship) {\n\t\t\t\t\t$command = new Command\\CreateRelationship($this->batch->getClient(), $entity, $this->opId, $this->batch);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif ($entity instanceof Node) {\n\t\t\t\t\t$command = new Command\\UpdateNode($this->batch->getClient(), $entity, $this->opId);\n\t\t\t\t} else if ($entity instanceof Relationship) {\n\t\t\t\t\t$command = new Command\\UpdateRelationship($this->batch->getClient(), $entity, $this->opId);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t$this->command = $command;\n\t\t}\n\t\treturn $this->command;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Batch.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * A set of operations expected to succeed (or fail) atomically\n */\nclass Batch\n{\n\tprotected $client = null;\n\n\tprotected $committed = false;\n\tprotected $operations = array();\n\tprotected $matches = array();\n\n\t/**\n\t * Build the batch and set its client\n\t *\n\t * @param Client $client\n\t */\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->client = $client;\n\t}\n\n\t/**\n\t * Add the given entity to the given index with the given key/value\n\t *\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @return integer\n\t */\n\tpublic function addToIndex(Index $index, PropertyContainer $entity, $key, $value)\n\t{\n\t\treturn $this->addOperation(new Batch\\AddTo($this, $index, $entity, $key, $value, $this->nextId()));\n\t}\n\n\t/**\n\t * Commit the batch to the server\n\t *\n\t * @return boolean\n\t */\n\tpublic function commit()\n\t{\n\t\tif ($this->committed) {\n\t\t\tthrow new Exception('Cannot commit the same batch more than once.');\n\t\t}\n\t\t$this->committed = true;\n\n\t\treturn $this->client->commitBatch($this);\n\t}\n\n\t/**\n\t * Add an entity to the batch to delete\n\t *\n\t * @param PropertyContainer $entity\n\t * @return integer\n\t */\n\tpublic function delete(PropertyContainer $entity)\n\t{\n\t\treturn $this->addOperation(new Batch\\Delete($this, $entity, $this->nextId()));\n\t}\n\n\t/**\n\t * Get the batch's client\n\t *\n\t * @return Client\n\t */\n\tpublic function getClient()\n\t{\n\t\treturn $this->client;\n\t}\n\n\t/**\n\t * Return the list of operations in this batch\n\t *\n\t * @return array\n\t */\n\tpublic function getOperations()\n\t{\n\t\treturn $this->operations;\n\t}\n\n\t/**\n\t * Remove the given entity from the given index with the given key/value\n\t *\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @return integer\n\t */\n\tpublic function removeFromIndex(Index $index, PropertyContainer $entity, $key=null, $value=null)\n\t{\n\t\treturn $this->addOperation(new Batch\\RemoveFrom($this, $index, $entity, $key, $value, $this->nextId()));\n\t}\n\n\t/**\n\t * Reserve an operation to prevent it from being double-committed\n\t * Once an operation has been reserved, future reserve calls will\n\t * return false, indicating it has already been reserved.\n\t * This is mostly useful during commit to prevent an operation being\n\t * sent twice\n\t *\n\t * @param integer $opId\n\t * @return mixed array operation if not yet reserved, false otherwise\n\t */\n\tpublic function reserve($opId)\n\t{\n\t\tif (isset($this->operations[$opId]) && $this->operations[$opId]->reserve()) {\n\t\t\treturn $this->operations[$opId];\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Add an entity to the batch to save\n\t *\n\t * @param PropertyContainer $entity\n\t * @return integer\n\t */\n\tpublic function save(PropertyContainer $entity)\n\t{\n\t\treturn $this->addOperation(new Batch\\Save($this, $entity, $this->nextId()));\n\t}\n\n\t/**\n\t * Add an operation to the batch\n\t *\n\t * @param Batch\\Operation $operation\n\t * @return integer operation index\n\t */\n\tprotected function addOperation(Batch\\Operation $operation)\n\t{\n\t\t$opId = $operation->getId();\n\t\t$matchId = $operation->matchId();\n\n\t\tif (isset($this->matches[$matchId])) {\n\t\t\treturn $this->matches[$matchId]->getId();\n\t\t}\n\n\t\t$this->operations[$opId] = $operation;\n\t\t$this->matches[$matchId] = $operation;\n\t\treturn $opId;\n\t}\n\n\t/**\n\t * Get the next unused id\n\t *\n\t * @return integer\n\t */\n\tprotected function nextId()\n\t{\n\t\treturn count($this->operations);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Cache/EntityCache.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cache;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\PropertyContainer,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Cache;\n\n/**\n * Store and retrieve cached entities without hitting the server\n */\nclass EntityCache\n{\n\tprotected $client = null;\n\tprotected $cache = null;\n\tprotected $cacheTimeout = null;\n\n\t/**\n\t * Set the client and caching plugin to use\n\t *\n\t * @param Client $client\n\t * @param Cache $cache\n\t * @param integer $cacheTimeout\n\t */\n\tpublic function __construct(Client $client, Cache $cache=null, $cacheTimeout=null)\n\t{\n\t\t$this->client = $client;\n\t\t$this->setCache($cache, $cacheTimeout);\n\t}\n\n\t/**\n\t * Delete an entity from the cache\n\t *\n\t * @param PropertyContainer $entity\n\t */\n\tpublic function deleteCachedEntity(PropertyContainer $entity)\n\t{\n\t\t$this->getCache()->delete($this->getEntityCacheKey($entity));\n\t}\n\n\t/**\n\t * Get an entity from the cache\n\t *\n\t * @param integer $id\n\t * @param string $type\n\t */\n\tpublic function getCachedEntity($id, $type)\n\t{\n\t\tif ($type != 'node' && $type != 'relationship') {\n\t\t\tthrow new Exception('Unknown entity type: '.$type);\n\t\t}\n\n\t\t$entity = $this->getCache()->get(\"{$type}-{$id}\");\n\t\tif ($entity) {\n\t\t\t$entity->setClient($this->client);\n\t\t}\n\t\treturn $entity;\n\t}\n\n\t/**\n\t * Set the cache to use\n\t *\n\t * @param Cache $cache\n\t * @param integer $cacheTimeout\n\t */\n\tpublic function setCache(Cache $cache=null, $cacheTimeout=null)\n\t{\n\t\t$this->cache = $cache;\n\t\t$this->cacheTimeout = (int)$cacheTimeout;\n\t}\n\n\t/**\n\t * Set an entity in the cache\n\t *\n\t * @param PropertyContainer $entity\n\t */\n\tpublic function setCachedEntity(PropertyContainer $entity)\n\t{\n\t\t$this->getCache()->set($this->getEntityCacheKey($entity), $entity, $this->cacheTimeout);\n\t}\n\n\t/**\n\t * Get the cache plugin\n\t *\n\t * @return Cache\n\t */\n\tprotected function getCache()\n\t{\n\t\tif ($this->cache === null) {\n\t\t\t$this->setCache(new Cache\\None(), $this->cacheTimeout);\n\t\t}\n\t\treturn $this->cache;\n\t}\n\n\t/**\n\t * Determine the cache key used to retrieve the given entity from the cache\n\t *\n\t * @param PropertyContainer $entity\n\t * @return string\n\t */\n\tprotected function getEntityCacheKey(PropertyContainer $entity)\n\t{\n\t\tif ($entity instanceof Node) {\n\t\t\treturn 'node-'.$entity->getId();\n\t\t} else if ($entity instanceof Relationship) {\n\t\t\treturn 'relationship-'.$entity->getId();\n\t\t}\n\t\tthrow new Exception('Unknown entity type: '.get_class($entity));\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Cache/Memcache.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cache;\n\nuse Everyman\\Neo4j\\Cache;\n\n/**\n * Use the Memcache extension\n */\nclass Memcache implements Cache\n{\n\tprotected $memcache = null;\n\n\t/**\n\t * Initialize the Memcache connection\n\t *\n\t * @param Memcache $memcache\n\t */\n\tpublic function __construct(\\Memcache $memcache)\n\t{\n\t\t$this->memcache = $memcache;\n\t}\n\n\t/**\n\t * Delete a value from the cache\n\t *\n\t * @param string $key\n\t * @return boolean true on success\n\t */\n\tpublic function delete($key)\n\t{\n\t\treturn $this->memcache->delete($key);\n\t}\n\n\t/**\n\t * Retrieve a value\n\t * Returns false if the key does not\n\t * exist, or the value is false\n\t *\n\t * @param string $key\n\t * @return mixed\n\t */\n\tpublic function get($key)\n\t{\n\t\treturn $this->memcache->get($key);\n\t}\n\n\t/**\n\t * Store a value in the cache\n\t * $expire is specified as an integer:\n\t *   - less than or equal to 2592000 (the number of seconds in 30 days)\n\t *     will be considered an expire time of that many seconds from the\n\t *     current timestamp\n\t *   - Greater than that amount will be considered as literal Unix\n\t *     timestamp values\n\t *   - 0 means \"never expire.\"\n\t *\n\t * @param string $key\n\t * @param mixed $value\n\t * @param integer $expire\n\t * @return boolean true on success\n\t */\n\tpublic function set($key, $value, $expire=0)\n\t{\n\t\treturn $this->memcache->set($key, $value, 0, $expire);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Cache/Memcached.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cache;\n\nuse Everyman\\Neo4j\\Cache;\n\n/**\n * Use the Memcached extension\n */\nclass Memcached implements Cache\n{\n\tprotected $memcached = null;\n\n\t/**\n\t * Initialize the Memcached connection\n\t *\n\t * @param Memcached $memcached\n\t */\n\tpublic function __construct(\\Memcached $memcached)\n\t{\n\t\t$this->memcached = $memcached;\n\t}\n\n\t/**\n\t * Delete a value from the cache\n\t *\n\t * @param string $key\n\t * @return boolean true on success\n\t */\n\tpublic function delete($key)\n\t{\n\t\treturn $this->memcached->delete($key);\n\t}\n\n\t/**\n\t * Retrieve a value\n\t * Returns false if the key does not\n\t * exist, or the value is false\n\t *\n\t * @param string $key\n\t * @return mixed\n\t */\n\tpublic function get($key)\n\t{\n\t\treturn $this->memcached->get($key);\n\t}\n\n\t/**\n\t * Store a value in the cache\n\t * $expire is specified as an integer:\n\t *   - less than or equal to 2592000 (the number of seconds in 30 days)\n\t *     will be considered an expire time of that many seconds from the\n\t *     current timestamp\n\t *   - Greater than that amount will be considered as literal Unix\n\t *     timestamp values\n\t *   - 0 means \"never expire.\"\n\t *\n\t * @param string $key\n\t * @param mixed $value\n\t * @param integer $expire\n\t * @return boolean true on success\n\t */\n\tpublic function set($key, $value, $expire=0)\n\t{\n\t\treturn $this->memcached->set($key, $value, $expire);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Cache/None.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cache;\n\nuse Everyman\\Neo4j\\Cache;\n\n/**\n * Cache that always indicates success but does not store anything\n */\nclass None implements Cache\n{\n\t/**\n\t * Delete always succeeds\n\t *\n\t * @param string $key\n\t * @return boolean true on success\n\t */\n\tpublic function delete($key)\n\t{\n\t\treturn true;\n\t}\n\n\t/**\n\t * Always false, since no value is stored\n\t *\n\t * @param string $key\n\t * @return mixed\n\t */\n\tpublic function get($key)\n\t{\n\t\treturn false;\n\t}\n\n\t/**\n\t * Always indicates success, but does not actually store value\n\t *\n\t * @param string $key\n\t * @param mixed $value\n\t * @param integer $expire\n\t * @return boolean true on success\n\t */\n\tpublic function set($key, $value, $expire=0)\n\t{\n\t\treturn true;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Cache/Variable.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cache;\n\nuse Everyman\\Neo4j\\Cache;\n\n/**\n * Cache everything locally to the process\n * Values cached this way are not persisted\n * when the process or request ends.\n */\nclass Variable implements Cache\n{\n\tprotected $items = array();\n\n\t/**\n\t * Delete a value from the cache\n\t *\n\t * @param string $key\n\t * @return boolean true on success\n\t */\n\tpublic function delete($key)\n\t{\n\t\tunset($this->items[$key]);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Retrieve a value\n\t * Returns false if the key does not\n\t * exist, or the value is false\n\t *\n\t * @param string $key\n\t * @return mixed\n\t */\n\tpublic function get($key)\n\t{\n\t\t$value = false;\n\t\tif (isset($this->items[$key])) {\n\t\t\tif ($this->items[$key]['expire'] >= time()) {\n\t\t\t\t$value = $this->items[$key]['value'];\n\t\t\t} else {\n\t\t\t\t$this->delete($key);\n\t\t\t}\n\t\t}\n\n\t\treturn $value;\n\t}\n\n\t/**\n\t * Store a value in the cache\n\t * $expire is specified as an integer:\n\t *   - less than or equal to 2592000 (the number of seconds in 30 days)\n\t *     will be considered an expire time of that many seconds from the\n\t *     current timestamp\n\t *   - Greater than that amount will be considered as literal Unix\n\t *     timestamp values\n\t *   - 0 means \"never expire.\"\n\t *\n\t * @param string $key\n\t * @param mixed $value\n\t * @param integer $expire\n\t * @return boolean true on success\n\t */\n\tpublic function set($key, $value, $expire=0)\n\t{\n\t\t$expire = $this->calculateExpiration($expire);\n\n\t\t$this->items[$key] = array(\n\t\t\t'value' => $value,\n\t\t\t'expire' => $expire,\n\t\t);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Determine the expiration timestamp\n\t *\n\t * @param integer $expire\n\t * @return integer\n\t */\n\tprotected function calculateExpiration($expire)\n\t{\n\t\tif (!$expire) {\n\t\t\t$expire = PHP_INT_MAX;\n\t\t} else if ($expire <= 2592000) {\n\t\t\t$expire = time() + $expire;\n\t\t}\n\t\treturn $expire;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Cache.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Interface for interacting with a caching backend\n */\ninterface Cache\n{\n\t/**\n\t * Delete a value from the cache\n\t *\n\t * @param string $key\n\t * @return boolean true on success\n\t */\n\tpublic function delete($key);\n\n\t/**\n\t * Retrieve a value\n\t * Returns false if the key does not\n\t * exist, or the value is false\n\t *\n\t * @param string $key\n\t * @return mixed\n\t */\n\tpublic function get($key);\n\n\t/**\n\t * Store a value in the cache\n\t * $expire is specified as an integer:\n\t *   - less than or equal to 2592000 (the number of seconds in 30 days)\n\t *     will be considered an expire time of that many seconds from the\n\t *     current timestamp\n\t *   - Greater than that amount will be considered as literal Unix\n\t *     timestamp values\n\t *   - 0 means \"never expire.\"\n\t *\n\t * @param string $key\n\t * @param mixed $value\n\t * @param integer $expire\n\t * @return boolean true on success\n\t */\n\tpublic function set($key, $value, $expire=0);\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Client.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Point of interaction between client and neo4j server\n */\nclass Client\n{\n\tconst ErrorUnknown       = 500;\n\tconst ErrorBadRequest    = 400;\n\tconst ErrorNotFound      = 404;\n\tconst ErrorConflict      = 409;\n\n\tconst RefNodeId = 0;\n\n\tconst CapabilityCypher        = 'cypher';\n\tconst CapabilityGremlin       = 'gremlin';\n\tconst CapabilityLabel         = 'label';\n\tconst CapabilityTransactions  = 'transactions';\n\n\tprotected $transport = null;\n\tprotected $entityMapper = null;\n\tprotected $entityCache = null;\n\tprotected $labelCache = null;\n\tprotected $serverInfo = null;\n\tprotected $openBatch = null;\n\n\t/**\n\t * @var callable The node factory\n\t */\n\tprotected $nodeFactory = null;\n\t/**\n\t * @var callable The relation factory\n\t */\n\tprotected $relFactory = null;\n\n\t/**\n\t * Initialize the client\n\t *\n\t * @param mixed $transport Transport object or string hostname\n\t * @param integer $port Ignored unless $transport is a hostname\n\t */\n\tpublic function __construct($transport=null, $port=7474)\n\t{\n\t\ttry {\n\t\t\tif ($transport === null) {\n\t\t\t\t$transport = new Transport\\Curl();\n\t\t\t} else if (is_string($transport)) {\n\t\t\t\t$transport = new Transport\\Curl($transport, $port);\n\t\t\t}\n\t\t} catch (Exception $e) {\n\t\t\tif ($transport === null) {\n\t\t\t\t$transport = new Transport\\Stream();\n\t\t\t} else if (is_string($transport)) {\n\t\t\t\t$transport = new Transport\\Stream($transport, $port);\n\t\t\t}\n\t\t}\n\n\t\t$this->setTransport($transport);\n\t\t$this->setNodeFactory(function (Client $client, $properties=array()) {\n\t\t\treturn new Node($client);\n\t\t});\n\t\t$this->setRelationshipFactory(function (Client $client, $properties=array()) {\n\t\t\treturn new Relationship($client);\n\t\t});\n\n\t\t$this->labelCache = new Cache\\Variable();\n\t}\n\n\t/**\n\t * Add a set of labels to a node\n\t *\n\t * @param Node  $node\n\t * @param Label[] $labels list of Label objects to add\n\t * @return Label[] of Label objects; the entire list of labels on the given node\n\t *   including the ones just added\n\t */\n\tpublic function addLabels(Node $node, $labels)\n\t{\n\t\t$command = new Command\\AddLabels($this, $node, $labels);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Add statements to a transaction, and optionally commit the transaction\n\t *\n\t * @param Transaction $transaction\n\t * @param array $statements an array of Cypher\\Query objects\n\t * @param boolean $commit should this transaction be committed on this request?\n\t * @return Query\\ResultSet\n\t */\n\tpublic function addStatementsToTransaction(Transaction $transaction, $statements=array(), $commit=false)\n\t{\n\t\t$command = new Command\\AddStatementsToTransaction($this, $transaction, $statements, $commit);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Add an entity to an index\n\t *\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @return boolean\n\t */\n\tpublic function addToIndex(Index $index, PropertyContainer $entity, $key, $value)\n\t{\n\t\tif ($this->openBatch) {\n\t\t\t$this->openBatch->addToIndex($index, $entity, $key, $value);\n\t\t\treturn true;\n\t\t}\n\n\t\treturn $this->runCommand(new Command\\AddToIndex($this, $index, $entity, $key, $value));\n\t}\n\n\t/**\n\t * Begin a Cypher transaction\n\t *\n\t * @return Transaction\n\t */\n\tpublic function beginTransaction()\n\t{\n\t\treturn new Transaction($this);\n\t}\n\n\t/**\n\t * Commit a batch of operations\n\t *\n\t * @param Batch $batch\n\t * @throws Exception\n\t * @return boolean true on success\n\t */\n\tpublic function commitBatch(Batch $batch=null)\n\t{\n\t\tif (!$batch) {\n\t\t\tif (!$this->openBatch) {\n\t\t\t\tthrow new Exception('No open batch to commit.');\n\t\t\t}\n\t\t\t$batch = $this->openBatch;\n\t\t}\n\n\t\tif ($batch === $this->openBatch) {\n\t\t\t$this->endBatch();\n\t\t}\n\n\t\tif (count($batch->getOperations()) < 1) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn $this->runCommand(new Command\\Batch\\Commit($this, $batch));\n\t}\n\n\t/**\n\t * Delete the given index\n\t *\n\t * @param Index $index\n\t * @return boolean\n\t */\n\tpublic function deleteIndex(Index $index)\n\t{\n\t\treturn $this->runCommand(new Command\\DeleteIndex($this, $index));\n\t}\n\n\t/**\n\t * Delete the given node\n\t *\n\t * @param Node $node\n\t * @return boolean\n\t */\n\tpublic function deleteNode(Node $node)\n\t{\n\t\tif ($this->openBatch) {\n\t\t\t$this->openBatch->delete($node);\n\t\t\treturn true;\n\t\t}\n\n\t\treturn $this->runCommand(new Command\\DeleteNode($this, $node));\n\t}\n\n\t/**\n\t * Delete the given relationship\n\t *\n\t * @param Relationship $relationship\n\t * @return boolean\n\t */\n\tpublic function deleteRelationship(Relationship $relationship)\n\t{\n\t\tif ($this->openBatch) {\n\t\t\t$this->openBatch->delete($relationship);\n\t\t\treturn true;\n\t\t}\n\t\treturn $this->runCommand(new Command\\DeleteRelationship($this, $relationship));\n\t}\n\n\t/**\n\t * Detach the current open batch.\n\t *\n\t * The batch can still be committed via the batch returned\n\t * by Client::startBatch()\n\t *\n\t * @return Client\n\t */\n\tpublic function endBatch()\n\t{\n\t\t$this->openBatch = null;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Execute the given Cypher query and return the result\n\t *\n\t * @param Cypher\\Query $query A Cypher query, or a query template.\n\t * @return Query\\ResultSet\n\t */\n\tpublic function executeCypherQuery(Cypher\\Query $query)\n\t{\n\t\t$command = new Command\\ExecuteCypherQuery($this, $query);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Execute the given Gremlin query and return the result\n\t *\n\t * @param Gremlin\\Query $query\n\t * @return Query\\ResultSet\n\t */\n\tpublic function executeGremlinQuery(Gremlin\\Query $query)\n\t{\n\t\t$command = new Command\\ExecuteGremlinQuery($this, $query);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Execute a paged traversal and return the result\n\t *\n\t * @param Pager $pager\n\t * @return array\n\t */\n\tpublic function executePagedTraversal(Pager $pager)\n\t{\n\t\t$command = new Command\\ExecutePagedTraversal($this, $pager);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Execute the given traversal and return the result\n\t *\n\t * @param Traversal $traversal\n\t * @param Node $startNode\n\t * @param string $returnType\n\t * @return array\n\t */\n\tpublic function executeTraversal(Traversal $traversal, Node $startNode, $returnType)\n\t{\n\t\t$command = new Command\\ExecuteTraversal($this, $traversal, $startNode, $returnType);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Get the cache\n\t *\n\t * @return Cache\\EntityCache\n\t */\n\tpublic function getEntityCache()\n\t{\n\t\tif ($this->entityCache === null) {\n\t\t\t$this->setEntityCache(new Cache\\EntityCache($this));\n\t\t}\n\t\treturn $this->entityCache;\n\t}\n\n\t/**\n\t * Get the entity mapper\n\t *\n\t * @return EntityMapper\n\t */\n\tpublic function getEntityMapper()\n\t{\n\t\tif ($this->entityMapper === null) {\n\t\t\t$this->setEntityMapper(new EntityMapper($this));\n\t\t}\n\t\treturn $this->entityMapper;\n\t}\n\n\t/**\n\t * Get all indexes of the given type\n\t *\n\t * @param string $type\n\t * @return mixed false on error, else an array of Index objects\n\t */\n\tpublic function getIndexes($type)\n\t{\n\t\t$command = new Command\\GetIndexes($this, $type);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * List the labels already saved on the server\n\t *\n\t * If a $node is given, only return labels for\n\t * that node.\n\t *\n\t * @param Node $node\n\t * @return array\n\t */\n\tpublic function getLabels(Node $node=null)\n\t{\n\t\t$command = new Command\\GetLabels($this, $node);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Get the requested node\n\t * Using the $force option disables the check\n\t * of whether or not the node exists and will\n\t * return a Node with the given id even if it\n\t * does not.\n\t *\n\t * @param integer $id\n\t * @param boolean $force\n\t * @throws Exception\n\t * @return Node\n\t */\n\tpublic function getNode($id, $force=false)\n\t{\n\t\t$cached = $this->getEntityCache()->getCachedEntity($id, 'node');\n\t\tif ($cached) {\n\t\t\treturn $cached;\n\t\t}\n\n\t\t$node = $this->makeNode();\n\t\t$node->setId($id);\n\n\t\tif ($force) {\n\t\t\treturn $node;\n\t\t}\n\n\t\ttry {\n\t\t\t$this->loadNode($node);\n\t\t} catch (Exception $e) {\n\t\t\tif ($e->getCode() == self::ErrorNotFound) {\n\t\t\t\treturn null;\n\t\t\t} else {\n\t\t\t\tthrow $e;\n\t\t\t}\n\t\t}\n\t\treturn $node;\n\t}\n\n\t/**\n\t * Get all relationships on a node matching the criteria\n\t *\n\t * @param Node   $node\n\t * @param mixed  $types a string or array of strings\n\t * @param string $dir\n\t * @return mixed false on error, else an array of Relationship objects\n\t */\n\tpublic function getNodeRelationships(Node $node, $types=array(), $dir=null)\n\t{\n\t\t$command = new Command\\GetNodeRelationships($this, $node, $types, $dir);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Get the nodes matching the given label\n\t *\n\t * If a property and value are given, only return\n\t * nodes where the given property equals the value\n\t *\n\t * @param Label  $label\n\t * @param string $propertyName\n\t * @param mixed  $propertyValue\n\t * @return Query\\Row\n\t */\n\tpublic function getNodesForLabel(Label $label, $propertyName=null, $propertyValue=null)\n\t{\n\t\t$command = new Command\\GetNodesForLabel($this, $label, $propertyName, $propertyValue);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Get an array of paths matching the finder's criteria\n\t *\n\t * @param PathFinder $finder\n\t * @return array\n\t */\n\tpublic function getPaths(PathFinder $finder)\n\t{\n\t\t$command = new Command\\GetPaths($this, $finder);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Retrieve the reference node (id: 0) from the server\n\t *\n\t * @return Node\n\t */\n\tpublic function getReferenceNode()\n\t{\n\t\treturn $this->getNode(self::RefNodeId);\n\t}\n\n\t/**\n\t * Get the requested relationship\n\t * Using the $force option disables the check\n\t * of whether or not the relationship exists and will\n\t * return a Relationship with the given id even if it\n\t * does not.\n\t *\n\t * @param integer $id\n\t * @param boolean $force\n\t * @throws Exception\n\t * @return Relationship\n\t */\n\tpublic function getRelationship($id, $force=false)\n\t{\n\t\t$cached = $this->getEntityCache()->getCachedEntity($id, 'relationship');\n\t\tif ($cached) {\n\t\t\treturn $cached;\n\t\t}\n\n\t\t$rel = $this->makeRelationship();\n\t\t$rel->setId($id);\n\n\t\tif ($force) {\n\t\t\treturn $rel;\n\t\t}\n\n\n\t\ttry {\n\t\t\t$this->loadRelationship($rel);\n\t\t} catch (Exception $e) {\n\t\t\tif ($e->getCode() == self::ErrorNotFound) {\n\t\t\t\treturn null;\n\t\t\t} else {\n\t\t\t\tthrow $e;\n\t\t\t}\n\t\t}\n\t\treturn $rel;\n\t}\n\n\t/**\n\t * Get a list of all relationship types on the server\n\t *\n\t * @return array\n\t */\n\tpublic function getRelationshipTypes()\n\t{\n\t\t$command = new Command\\GetRelationshipTypes($this);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Retrieve information about the server\n\t *\n\t * @param boolean $force Don't use previous results\n\t * @return array\n\t */\n\tpublic function getServerInfo($force=false)\n\t{\n\t\tif ($this->serverInfo === null || $force) {\n\t\t\t$command = new Command\\GetServerInfo($this);\n\t\t\t$this->serverInfo = $this->runCommand($command);\n\t\t}\n\t\treturn $this->serverInfo;\n\t}\n\n\t/**\n\t * Get the transport\n\t *\n\t * @return Transport\n\t */\n\tpublic function getTransport()\n\t{\n\t\treturn $this->transport;\n\t}\n\n\t/**\n\t * Does the connected database have the requested capability?\n\t *\n\t * @param string $capability\n\t * @return mixed true or string if yes, false otherwise\n\t */\n\tpublic function hasCapability($capability)\n\t{\n\t\t$info = $this->getServerInfo();\n\n\t\tswitch ($capability) {\n\t\t\tcase self::CapabilityLabel:\n\t\t\tcase self::CapabilityTransactions:\n\t\t\t\treturn $info['version']['major'] > 1;\n\n\t\t\tcase self::CapabilityCypher:\n\t\t\t\tif (isset($info['cypher'])) {\n\t\t\t\t\treturn $info['cypher'];\n\t\t\t\t} else if (isset($info['extensions']['CypherPlugin']['execute_query'])) {\n\t\t\t\t\treturn $info['extensions']['CypherPlugin']['execute_query'];\n\t\t\t\t}\n\t\t\t\treturn false;\n\n\t\t\tcase self::CapabilityGremlin:\n\t\t\t\tif (isset($info['extensions']['GremlinPlugin']['execute_script'])) {\n\t\t\t\t\treturn $info['extensions']['GremlinPlugin']['execute_script'];\n\t\t\t\t}\n\t\t\t\treturn false;\n\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Load the given node with data from the server\n\t *\n\t * @param Node $node\n\t * @return boolean\n\t */\n\tpublic function loadNode(Node $node)\n\t{\n\t\t$cached = $this->getEntityCache()->getCachedEntity($node->getId(), 'node');\n\t\tif ($cached) {\n\t\t\t$node->setProperties($cached->getProperties());\n\t\t\treturn true;\n\t\t}\n\n\t\treturn $this->runCommand(new Command\\GetNode($this, $node));\n\t}\n\n\t/**\n\t * Load the given relationship with data from the server\n\t *\n\t * @param Relationship $rel\n\t * @return boolean\n\t */\n\tpublic function loadRelationship(Relationship $rel)\n\t{\n\t\t$cached = $this->getEntityCache()->getCachedEntity($rel->getId(), 'relationship');\n\t\tif ($cached) {\n\t\t\t$rel->setProperties($cached->getProperties());\n\t\t\treturn true;\n\t\t}\n\n\t\treturn $this->runCommand(new Command\\GetRelationship($this, $rel));\n\t}\n\n\t/**\n\t * Retrieve a Label object for the given name\n\t *\n\t * If the name has already been seen, the same\n\t * Label object wil be returned, i. e. only one\n\t * Label will exist per name.\n\t *\n\t * @param string $name\n\t * @return Label\n\t */\n\tpublic function makeLabel($name)\n\t{\n\t\t$label = $this->labelCache->get($name);\n\t\tif (!$label) {\n\t\t\t$label = new Label($this, $name);\n\t\t\t$this->labelCache->set($name, $label);\n\t\t}\n\n\t\treturn $label;\n\t}\n\n\t/**\n\t * Create a new node object bound to this client\n\t *\n\t * @param array $properties\n\t * @throws Exception\n\t * @return Node\n\t */\n\tpublic function makeNode($properties=array())\n\t{\n\t\t$nodeFactory = $this->nodeFactory;\n\t\t$node = $nodeFactory($this, $properties);\n\t\tif (!($node instanceof Node)) {\n\t\t\tthrow new Exception('Node factory did not return a Node object.');\n\t\t}\n\t\treturn $node->setProperties($properties);\n\t}\n\n\t/**\n\t * Create a new relationship object bound to this client\n\t *\n\t * @param array $properties\n\t * @throws Exception\n\t * @return Relationship\n\t */\n\tpublic function makeRelationship($properties=array())\n\t{\n\t\t$relFactory = $this->relFactory;\n\t\t$rel = $relFactory($this, $properties);\n\t\tif (!($rel instanceof Relationship)) {\n\t\t\tthrow new Exception('Relationship factory did not return a Relationship object.');\n\t\t}\n\t\treturn $rel->setProperties($properties);\n\t}\n\n\t/**\n\t * Query an index using a query string.\n\t * The default query language in Neo4j is Lucene\n\t *\n\t * @param Index $index\n\t * @param string $query\n\t * @return array\n\t */\n\tpublic function queryIndex(Index $index, $query)\n\t{\n\t\t$command = new Command\\QueryIndex($this, $index, $query);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Rollback the transaction\n\t *\n\t * @param Transaction $transaction\n\t * @return mixed\n\t */\n\tpublic function rollbackTransaction(Transaction $transaction)\n\t{\n\t\t$command = new Command\\RollbackTransaction($this, $transaction);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Remove an entity from an index\n\t * If $value is not given, all reference of the entity for the key\n\t * are removed.\n\t * If $key is not given, all reference of the entity are removed.\n\t *\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @return boolean\n\t */\n\tpublic function removeFromIndex(Index $index, PropertyContainer $entity, $key=null, $value=null)\n\t{\n\t\tif ($this->openBatch) {\n\t\t\t$this->openBatch->removeFromIndex($index, $entity, $key, $value);\n\t\t\treturn true;\n\t\t}\n\n\t\treturn $this->runCommand(new Command\\RemoveFromIndex($this, $index, $entity, $key, $value));\n\t}\n\n\t/**\n\t * Remove a set of labels from a node\n\t *\n\t * @param Node  $node\n\t * @param array $labels list of Label objects to remove\n\t * @return array of Label objects; the entire list of labels on the given node\n\t *   including the ones just added\n\t */\n\tpublic function removeLabels(Node $node, $labels)\n\t{\n\t\t$command = new Command\\RemoveLabels($this, $node, $labels);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Save the given index\n\t *\n\t * @param Index $index\n\t * @return boolean\n\t */\n\tpublic function saveIndex(Index $index)\n\t{\n\t\treturn $this->runCommand(new Command\\SaveIndex($this, $index));\n\t}\n\n\t/**\n\t * Save the given node\n\t *\n\t * @param Node $node\n\t * @return boolean\n\t */\n\tpublic function saveNode(Node $node)\n\t{\n\t\tif ($this->openBatch) {\n\t\t\t$this->openBatch->save($node);\n\t\t\treturn true;\n\t\t}\n\n\t\tif ($node->hasId()) {\n\t\t\treturn $this->runCommand(new Command\\UpdateNode($this, $node));\n\t\t} else {\n\t\t\treturn $this->runCommand(new Command\\CreateNode($this, $node));\n\t\t}\n\t}\n\n\t/**\n\t * Save the given relationship\n\t *\n\t * @param Relationship $rel\n\t * @return boolean\n\t */\n\tpublic function saveRelationship(Relationship $rel)\n\t{\n\t\tif ($this->openBatch) {\n\t\t\t$this->openBatch->save($rel);\n\t\t\treturn true;\n\t\t}\n\n\t\tif ($rel->hasId()) {\n\t\t\treturn $this->runCommand(new Command\\UpdateRelationship($this, $rel));\n\t\t} else {\n\t\t\treturn $this->runCommand(new Command\\CreateRelationship($this, $rel));\n\t\t}\n\t}\n\n\t/**\n\t * Search an index for matching entities\n\t *\n\t * @param Index $index\n\t * @param string $key\n\t * @param string $value\n\t * @return array\n\t */\n\tpublic function searchIndex(Index $index, $key, $value)\n\t{\n\t\t$command = new Command\\SearchIndex($this, $index, $key, $value);\n\t\treturn $this->runCommand($command);\n\t}\n\n\t/**\n\t * Set the cache to use\n\t *\n\t * @param Cache\\EntityCache $cache\n\t */\n\tpublic function setEntityCache(Cache\\EntityCache $cache)\n\t{\n\t\t$this->entityCache = $cache;\n\t}\n\n\t/**\n\t * Set the entity mapper to use\n\t *\n\t * @param EntityMapper $mapper\n\t */\n\tpublic function setEntityMapper(EntityMapper $mapper)\n\t{\n\t\t$this->entityMapper = $mapper;\n\t}\n\n\t/**\n\t * Set the callback to use to create new Node objects\n\t *\n\t * Takes a callback of the signature callback(Client $client, $properties=array())\n\t * and returns a new Node object.\n\t * The properties can be used to determine what type of Node\n\t * should be returned, but are not set by the factory function.\n\t *\n\t * @param callable $factory\n\t * @throws Exception\n\t * @return Client\n\t */\n\tpublic function setNodeFactory($factory)\n\t{\n\t\tif (!is_callable($factory)) {\n\t\t\tthrow new Exception('Node factory must be callable.');\n\t\t}\n\n\t\t$this->nodeFactory = $factory;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the callback to use to create new Relationship objects\n\t *\n\t * Takes a callback of the signature callback(Client $client, $properties=array())\n\t * and returns a new Relationship object.\n\t * The properties can be used to determine what type of Relationship\n\t * should be returned, but are not set by the factory function.\n\t *\n\t * @param callable $factory\n\t * @throws Exception\n\t * @return Client\n\t */\n\tpublic function setRelationshipFactory($factory)\n\t{\n\t\tif (!is_callable($factory)) {\n\t\t\tthrow new Exception('Relationship factory must be callable.');\n\t\t}\n\n\t\t$this->relFactory = $factory;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the transport to use\n\t *\n\t * @param Transport $transport\n\t */\n\tpublic function setTransport(Transport $transport)\n\t{\n\t\t$this->transport = $transport;\n\t}\n\n\t/**\n\t * Start an implicit batch\n\t *\n\t * Any data manipulation calls that occur between this call\n\t * and the subsequent Client::commitBatch() call will be\n\t * wrapped in a batch operation.\n\t *\n\t * @return Batch\n\t */\n\tpublic function startBatch()\n\t{\n\t\tif (!$this->openBatch) {\n\t\t\t$this->openBatch = new Batch($this);\n\t\t}\n\t\treturn $this->openBatch;\n\t}\n\n\t/**\n\t * Run a command that will talk to the transport\n\t *\n\t * @param Command $command\n\t * @return mixed\n\t */\n\tprotected function runCommand(Command $command)\n\t{\n\t\t$result = $command->execute();\n\t\treturn $result;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/AddLabels.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command\\SetLabels,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Label;\n\n/**\n * Add a set of labels to a node\n */\nclass AddLabels extends SetLabels\n{\n\t/**\n\t * Set the labels to add\n\t *\n\t * @param Client $client\n\t * @param Node   $node\n\t * @param array  $labels\n\t */\n\tpublic function __construct(Client $client, Node $node, $labels)\n\t{\n\t\tparent::__construct($client, $node, $labels, false);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/AddStatementsToTransaction.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Transaction,\n\tEveryman\\Neo4j\\Cypher\\Query,\n\tEveryman\\Neo4j\\Query\\ResultSet;\n\n/**\n * Open, add statements to, and/or commit a Cypher transaction\n */\nclass AddStatementsToTransaction extends Command\n{\n\tprotected $transaction = null;\n\tprotected $statements = array();\n\tprotected $commit = false;\n\n\t/**\n\t * Set the transaction and statements to use\n\t *\n\t * @param Client $client\n\t * @param Transaction $transaction\n\t * @param array $statements\n\t * @param boolean $commit\n\t */\n\tpublic function __construct(Client $client, Transaction $transaction, $statements=array(), $commit=false)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->transaction = $transaction;\n\t\t$this->statements = $statements;\n\t\t$this->commit = $commit;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\tif (!$this->statements && !$this->transaction->getId()) {\n\t\t\tthrow new Exception(\"Cannot keep-alive a transaction without an id\");\n\t\t}\n\n\t\t$statements = array_map(array($this, 'formatStatement'), $this->statements);\n\t\treturn array('statements' => $statements);\n\t}\n\n\t/**\n\t * Format the given query into a transactional statement\n\t *\n\t * @param Query $statement\n\t * @return array\n\t */\n\tprotected function formatStatement(Query $statement)\n\t{\n\t\treturn array(\n\t\t\t'statement'          => $statement->getQuery(),\n\t\t\t'parameters'         => (object)$statement->getParameters(),\n\t\t\t'resultDataContents' => array('rest'),\n\t\t);\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->client->hasCapability(Client::CapabilityTransactions)) {\n\t\t\tthrow new Exception('Transactions unavailable');\n\t\t}\n\n\t\t$path = '/transaction';\n\n\t\t$id = $this->transaction->getId();\n\t\tif ($id) {\n\t\t\t$path .= '/'.$id;\n\t\t}\n\n\t\tif ($this->commit) {\n\t\t\t$path .= '/commit';\n\t\t}\n\n\t\treturn $path;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2 || !empty($data['errors'])) {\n\t\t\t$this->throwException('Error in transaction', $code, $headers, $data);\n\t\t}\n\n\t\tif (!$this->transaction->getId() && !$this->commit) {\n\t\t\t$this->setTransactionId($data);\n\t\t}\n\n\t\t$results = array_map(array($this, 'mapResult'), $data['results']);\n\t\treturn $results;\n\t}\n\n\t/**\n\t * Map the response into a ResultSet\n\t *\n\t * @param array $result\n\t * @return ResultSet\n\t */\n\tprotected function mapResult($result)\n\t{\n\t\t$data = array_map(function ($row) {\n\t\t\treturn $row['rest'];\n\t\t}, $result['data']);\n\n\t\treturn new ResultSet($this->client, array(\n\t\t\t'columns' => $result['columns'],\n\t\t\t'data' => $data,\n\t\t));\n\t}\n\n\t/**\n\t * Parse the transaction id out of the response and set it on the transaction\n\t *\n\t * @param array $data\n\t */\n\tprotected function setTransactionId($data)\n\t{\n\t\t$commit = $data['commit'];\n\t\t$path = parse_url($commit, PHP_URL_PATH);\n\t\t$parts = explode('/', $path);\n\t\t$id = $parts[count($parts)-2];\n\t\t$this->transaction->setId($id);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/AddToIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\PropertyContainer,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Index;\n\n/**\n * Add an entity to an index\n */\nclass AddToIndex extends Command\n{\n\tprotected $index = null;\n\tprotected $entity = null;\n\tprotected $key = null;\n\tprotected $value = null;\n\n\t/**\n\t * Set the index to drive the command\n\t *\n\t * @param Client $client\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t */\n\tpublic function __construct(Client $client, Index $index, PropertyContainer $entity, $key, $value)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->index = $index;\n\t\t$this->entity = $entity;\n\t\t$this->key = $key;\n\t\t$this->value = $value;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\tif (!$this->entity || !$this->entity->hasId()) {\n\t\t\tthrow new Exception('No entity to index specified');\n\t\t}\n\n\t\t$data = array();\n\n\t\t$type = trim((string)$this->index->getType());\n\t\t$data['uri'] = $this->getTransport()->getEndpoint().'/'.$type.'/'.$this->entity->getId();\n\n\n\t\t$key = trim((string)$this->key);\n\t\tif (!$key) {\n\t\t\tthrow new Exception('No key specified to add to index');\n\t\t}\n\t\t$data['key'] = $key;\n\t\t$data['value'] = $this->value;\n\n\t\treturn $data;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$type = trim((string)$this->index->getType());\n\t\tif ($type != Index::TypeNode && $type != Index::TypeRelationship) {\n\t\t\tthrow new Exception('No type specified for index');\n\t\t} else if ($type == Index::TypeNode && !($this->entity instanceof Node)) {\n\t\t\tthrow new Exception('Cannot add a node to a non-node index');\n\t\t} else if ($type == Index::TypeRelationship && !($this->entity instanceof Relationship)) {\n\t\t\tthrow new Exception('Cannot add a relationship to a non-relationship index');\n\t\t}\n\n\t\t$name = trim((string)$this->index->getName());\n\t\tif (!$name) {\n\t\t\tthrow new Exception('No name specified for index');\n\t\t}\n\t\t$name = rawurlencode($name);\n\n\t\treturn '/index/'.$type.'/'.$name;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to add entity to index', $code, $headers, $data);\n\t\t}\n\t\treturn true;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/AddToIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index,\n\tEveryman\\Neo4j\\Batch,\n\tEveryman\\Neo4j\\PropertyContainer,\n\tEveryman\\Neo4j\\Command\\AddToIndex as SingleAddToIndex;\n\n/**\n * Add the given entity to the index\n * Also creates the entity if necessary\n */\nclass AddToIndex extends Command\n{\n\tprotected $batch = null;\n\tprotected $entity = null;\n\n\t/**\n\t * Set the operation to drive the command\n\t *\n\t * @param Client $client\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @param integer $opId\n\t * @param Batch $batch\n\t */\n\tpublic function __construct(Client $client, Index $index, PropertyContainer $entity, $key, $value, $opId, Batch $batch)\n\t{\n\t\tparent::__construct($client, new SingleAddToIndex($client, $index, $entity, $key, $value), $opId);\n\t\t$this->batch = $batch;\n\t\t$this->entity = $entity;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return array\n\t */\n\tprotected function getData()\n\t{\n\t\t$opData = array();\n\n\t\t// Prevent the command from throwing an Exception if an unsaved entity\n\t\tif (!$this->entity->hasId()) {\n\t\t\t$entityId = $this->batch->save($this->entity);\n\t\t\t$reserved = $this->batch->reserve($entityId);\n\t\t\tif ($reserved) {\n\t\t\t\t$opData = array_merge($opData, $reserved->getCommand()->getData());\n\t\t\t}\n\t\t\t$this->entity->setId(-1);\n\t\t\t$body = $this->base->getData();\n\t\t\t$this->entity->setId(null);\n\t\t\t$body['uri'] = \"{{$entityId}}\";\n\t\t} else {\n\t\t\t$body = $this->base->getData();\n\t\t}\n\n\t\t$opData[] = array(\n\t\t\t'method' => strtoupper($this->base->getMethod()),\n\t\t\t'to' => $this->base->getPath(),\n\t\t\t'body' => $body,\n\t\t\t'id' => $this->opId,\n\t\t);\n\t\treturn $opData;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/Command.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Command as SingleCommand,\n\tEveryman\\Neo4j\\Client;\n\n/**\n * A single command executed in a batch\n */\nabstract class Command extends SingleCommand\n{\n\tprotected $base = null;\n\tprotected $opId = null;\n\n\t/**\n\t * Set the operation to drive the command\n\t *\n\t * @param Client $client\n\t * @param SingleCommand $base\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Client $client, SingleCommand $base, $opId)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->base = $base;\n\t\t$this->opId = $opId;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\treturn '/batch';\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return mixed\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to commit batch', $code, $headers, $data);\n\t\t}\n\n\t\tforeach ($data as $result) {\n\t\t\t$this->handleSingleResult($result);\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Handle a single result from the batch of results\n\t *\n\t * @param array $result\n\t * @return mixed\n\t * @throws Exception on failure\n\t */\n\tprotected function handleSingleResult($result)\n\t{\n\t\t$headers = array();\n\t\tif (isset($result['location'])) {\n\t\t\t$headers['Location'] = $result['location'];\n\t\t}\n\t\treturn $this->base->handleResult(200, $headers, $result);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/Commit.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Batch;\n\n/**\n * Commit a batch operation\n * @todo: Handle the case of empty body or body\\data needing to be objects not arrays\n * @todo: Is this really a batch command in itself, or something different?\n */\nclass Commit extends Command\n{\n\tprotected $batch = null;\n\n\t/**\n\t * Set the batch to drive the command\n\t *\n\t * @param Client $client\n\t * @param Batch $batch\n\t */\n\tpublic function __construct(Client $client, Batch $batch)\n\t{\n\t\tparent::__construct($client, $this, null);\n\t\t$this->batch = $batch;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\t$operations = $this->batch->getOperations();\n\t\t$data = array();\n\t\tforeach ($operations as $op) {\n\t\t\tif ($op->reserve()) {\n\t\t\t\t$opData = $op->getCommand()->getData();\n\t\t\t\tforeach ($opData as $datum) {\n\t\t\t\t\t$data[] = $datum;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn $data;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param array $result\n\t */\n\tprotected function handleSingleResult($result)\n\t{\n\t\t$operations = $this->batch->getOperations();\n\t\t$command = $operations[$result['id']]->getCommand();\n\t\treturn $command->handleSingleResult($result);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/CreateNode.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Command\\CreateNode as SingleCreateNode;\n\n/**\n * Create a node in a batch\n */\nclass CreateNode extends Command\n{\n\t/**\n\t * Set the operation to drive the command\n\t *\n\t * @param Client $client\n\t * @param Node $node\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Client $client, Node $node, $opId)\n\t{\n\t\tparent::__construct($client, new SingleCreateNode($client, $node), $opId);\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return array\n\t */\n\tprotected function getData()\n\t{\n\t\t$opData = array(array(\n\t\t\t'method' => strtoupper($this->base->getMethod()),\n\t\t\t'to' => $this->base->getPath(),\n\t\t\t'body' => $this->base->getData(),\n\t\t\t'id' => $this->opId,\n\t\t));\n\t\treturn $opData;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/CreateRelationship.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Batch,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Command\\CreateRelationship as SingleCreateRelationship;\n\n/**\n * Create a relationship in a batch\n * Also creates the endpoint nodes if necessary\n */\nclass CreateRelationship extends Command\n{\n\tprotected $batch = null;\n\tprotected $rel = null;\n\n\t/**\n\t * Set the operation to drive the command\n\t *\n\t * @param Client $client\n\t * @param Relationship $rel\n\t * @param integer $opId\n\t * @param Batch $batch\n\t */\n\tpublic function __construct(Client $client, Relationship $rel, $opId, Batch $batch)\n\t{\n\t\tparent::__construct($client, new SingleCreateRelationship($client, $rel), $opId);\n\t\t$this->batch = $batch;\n\t\t$this->rel = $rel;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return array\n\t */\n\tprotected function getData()\n\t{\n\t\t$opData = array();\n\n\t\t// Prevent the command from throwing an Exception if an unsaved start node\n\t\t$startNode = $this->rel->getStartNode();\n\t\tif (!$startNode->hasId()) {\n\t\t\t$startId = $this->batch->save($startNode);\n\t\t\t$reserved = $this->batch->reserve($startId);\n\t\t\tif ($reserved) {\n\t\t\t\t$opData = array_merge($opData, $reserved->getCommand()->getData());\n\t\t\t}\n\t\t\t$start = \"{{$startId}}/relationships\";\n\t\t} else {\n\t\t\t$start = $this->base->getPath();\n\t\t}\n\n\t\t// Prevent the command from throwing an Exception if an unsaved end node\n\t\t$endNode = $this->rel->getEndNode();\n\t\tif (!$endNode->hasId()) {\n\t\t\t$endId = $this->batch->save($endNode);\n\t\t\t$reserved = $this->batch->reserve($endId);\n\t\t\tif ($reserved) {\n\t\t\t\t$opData = array_merge($opData, $reserved->getCommand()->getData());\n\t\t\t}\n\t\t\t$endNode->setId('temp');\n\t\t\t$data = $this->base->getData();\n\t\t\t$endNode->setId(null);\n\t\t\t$data['to'] = \"{{$endId}}\";\n\t\t} else {\n\t\t\t$data = $this->base->getData();\n\t\t}\n\n\t\t$opData[] = array(\n\t\t\t'method' => strtoupper($this->base->getMethod()),\n\t\t\t'to' => $start,\n\t\t\t'body' => $data,\n\t\t\t'id' => $this->opId,\n\t\t);\n\t\treturn $opData;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/DeleteNode.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Command\\DeleteNode as SingleDeleteNode;\n\n/**\n * Delete a node in a batch\n */\nclass DeleteNode extends Command\n{\n\t/**\n\t * Set the operation to drive the command\n\t *\n\t * @param Client $client\n\t * @param Node $node\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Client $client, Node $node, $opId)\n\t{\n\t\tparent::__construct($client, new SingleDeleteNode($client, $node), $opId);\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return array\n\t */\n\tprotected function getData()\n\t{\n\t\t$opData = array(array(\n\t\t\t'method' => strtoupper($this->base->getMethod()),\n\t\t\t'to' => $this->base->getPath(),\n\t\t\t'id' => $this->opId,\n\t\t));\n\t\treturn $opData;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/DeleteRelationship.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Command\\DeleteRelationship as SingleDeleteRelationship;\n\n/**\n * Delete a relationship in a batch\n */\nclass DeleteRelationship extends Command\n{\n\t/**\n\t * Set the operation to drive the command\n\t *\n\t * @param Client $client\n\t * @param Relationship $rel\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Client $client, Relationship $rel, $opId)\n\t{\n\t\tparent::__construct($client, new SingleDeleteRelationship($client, $rel), $opId);\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return array\n\t */\n\tprotected function getData()\n\t{\n\t\t$opData = array(array(\n\t\t\t'method' => strtoupper($this->base->getMethod()),\n\t\t\t'to' => $this->base->getPath(),\n\t\t\t'id' => $this->opId,\n\t\t));\n\t\treturn $opData;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/RemoveFromIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index,\n\tEveryman\\Neo4j\\Batch,\n\tEveryman\\Neo4j\\PropertyContainer,\n\tEveryman\\Neo4j\\Command\\RemoveFromIndex as SingleRemoveFromIndex;\n\n/**\n * Remove the given entity from the index\n */\nclass RemoveFromIndex extends Command\n{\n\t/**\n\t * Set the operation to drive the command\n\t *\n\t * @param Client $client\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Client $client, Index $index, PropertyContainer $entity, $key, $value, $opId)\n\t{\n\t\tparent::__construct($client, new SingleRemoveFromIndex($client, $index, $entity, $key, $value), $opId);\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return array\n\t */\n\tprotected function getData()\n\t{\n\t\t$opData = array(array(\n\t\t\t'method' => strtoupper($this->base->getMethod()),\n\t\t\t'to' => $this->base->getPath(),\n\t\t\t'id' => $this->opId,\n\t\t));\n\t\treturn $opData;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/UpdateNode.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Command\\UpdateNode as SingleUpdateNode;\n\n/**\n * Update a node in a batch\n */\nclass UpdateNode extends Command\n{\n\t/**\n\t * Set the operation to drive the command\n\t *\n\t * @param Client $client\n\t * @param Node $node\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Client $client, Node $node, $opId)\n\t{\n\t\tparent::__construct($client, new SingleUpdateNode($client, $node), $opId);\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return array\n\t */\n\tprotected function getData()\n\t{\n\t\t$opData = array(array(\n\t\t\t'method' => strtoupper($this->base->getMethod()),\n\t\t\t'to' => $this->base->getPath(),\n\t\t\t'body' => $this->base->getData(),\n\t\t\t'id' => $this->opId,\n\t\t));\n\t\treturn $opData;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/Batch/UpdateRelationship.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command\\Batch;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Command\\UpdateRelationship as SingleUpdateRelationship;\n\n/**\n * Update a relationship in a batch\n */\nclass UpdateRelationship extends Command\n{\n\t/**\n\t * Set the operation to drive the command\n\t *\n\t * @param Client $client\n\t * @param Relationship $rel\n\t * @param integer $opId\n\t */\n\tpublic function __construct(Client $client, Relationship $rel, $opId)\n\t{\n\t\tparent::__construct($client, new SingleUpdateRelationship($client, $rel), $opId);\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return array\n\t */\n\tprotected function getData()\n\t{\n\t\t$opData = array(array(\n\t\t\t'method' => strtoupper($this->base->getMethod()),\n\t\t\t'to' => $this->base->getPath(),\n\t\t\t'body' => $this->base->getData(),\n\t\t\t'id' => $this->opId,\n\t\t));\n\t\treturn $opData;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/CreateNode.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Node;\n\n/**\n * Create a node\n */\nclass CreateNode extends Command\n{\n\tprotected $node = null;\n\n\t/**\n\t * Set the node to drive the command\n\t *\n\t * @param Client $client\n\t * @param Node $node\n\t */\n\tpublic function __construct(Client $client, Node $node)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->node = $node;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn $this->node->getProperties() ?: null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\treturn '/node';\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return boolean true on success\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to create node', $code, $headers, $data);\n\t\t}\n\n\t\t$nodeId = $this->getEntityMapper()->getIdFromUri($headers['Location']);\n\t\t$this->node->setId($nodeId);\n\t\t$this->getEntityCache()->setCachedEntity($this->node);\n\t\treturn true;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/CreateRelationship.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node;\n\n/**\n * Create a relationship\n */\nclass CreateRelationship extends Command\n{\n\tprotected $rel = null;\n\n\t/**\n\t * Set the relationship to drive the command\n\t *\n\t * @param Client $client\n\t * @param Relationship $rel\n\t */\n\tpublic function __construct(Client $client, Relationship $rel)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->rel = $rel;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\t$end = $this->rel->getEndNode();\n\t\t$type = $this->rel->getType();\n\t\tif (!$end || !$end->hasId()) {\n\t\t\tthrow new Exception('No relationship end node specified');\n\t\t} else if (!$type) {\n\t\t\tthrow new Exception('No relationship type specified');\n\t\t}\n\n\t\t$endUri = $this->getTransport()->getEndpoint().'/node/'.$end->getId();\n\t\t$data = array(\n\t\t\t'type' => $type,\n\t\t\t'to'   => $endUri,\n\t\t);\n\n\t\t$properties = $this->rel->getProperties();\n\t\tif ($properties) {\n\t\t\t$data['data'] = $properties;\n\t\t}\n\n\t\treturn $data;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$start = $this->rel->getStartNode();\n\t\tif (!$start || !$start->hasId()) {\n\t\t\tthrow new Exception('No relationship start node specified');\n\t\t}\n\t\treturn '/node/'.$start->getId().'/relationships';\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return boolean true on success\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to create relationship', $code, $headers, $data);\n\t\t}\n\n\t\t$relId = $this->getEntityMapper()->getIdFromUri($headers['Location']);\n\t\t$this->rel->setId($relId);\n\t\t$this->getEntityCache()->setCachedEntity($this->rel);\n\t\treturn true;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/DeleteIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Index;\n\n/**\n * Create an index\n */\nclass DeleteIndex extends Command\n{\n\tprotected $index = null;\n\n\t/**\n\t * Set the index to drive the command\n\t *\n\t * @param Client $client\n\t * @param Index $index\n\t */\n\tpublic function __construct(Client $client, Index $index)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->index = $index;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'delete';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$type = trim((string)$this->index->getType());\n\t\tif ($type != Index::TypeNode && $type != Index::TypeRelationship) {\n\t\t\tthrow new Exception('No type specified for index');\n\t\t}\n\n\t\t$name = trim((string)$this->index->getName());\n\t\tif (!$name) {\n\t\t\tthrow new Exception('No name specified for index');\n\t\t}\n\t\t$name = rawurlencode($name);\n\n\t\treturn '/index/'.$type.'/'.$name;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2 && (int)$code != 404) {\n\t\t\t$this->throwException('Unable to delete index', $code, $headers, $data);\n\t\t}\n\t\treturn true;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/DeleteNode.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Node;\n\n/**\n * Delete a node\n */\nclass DeleteNode extends Command\n{\n\tprotected $node = null;\n\n\t/**\n\t * Set the node to drive the command\n\t *\n\t * @param Client $client\n\t * @param Node $node\n\t */\n\tpublic function __construct(Client $client, Node $node)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->node = $node;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'delete';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->node->hasId()) {\n\t\t\tthrow new Exception('No node id specified for delete');\n\t\t}\n\t\treturn '/node/'.$this->node->getId();\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return boolean true on success\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) == 2) {\n\t\t\t$this->getEntityCache()->deleteCachedEntity($this->node);\n\t\t\treturn true;\n\t\t} else {\n\t\t\t$this->throwException('Unable to delete node', $code, $headers, $data);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/DeleteRelationship.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Relationship;\n\n/**\n * Delete a relationship\n */\nclass DeleteRelationship extends Command\n{\n\tprotected $rel = null;\n\n\t/**\n\t * Set the relationship to drive the command\n\t *\n\t * @param Client $client\n\t * @param Relationship $rel\n\t */\n\tpublic function __construct(Client $client, Relationship $rel)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->rel = $rel;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'delete';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->rel->hasId()) {\n\t\t\tthrow new Exception('No relationship id specified for delete');\n\t\t}\n\t\treturn '/relationship/'.$this->rel->getId();\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return boolean true on success\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) == 2) {\n\t\t\t$this->getEntityCache()->deleteCachedEntity($this->rel);\n\t\t\treturn true;\n\t\t} else {\n\t\t\t$this->throwException('Unable to delete relationship', $code, $headers, $data);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/ExecuteCypherQuery.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\EntityMapper,\n\tEveryman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Cypher\\Query,\n\tEveryman\\Neo4j\\Query\\ResultSet;\n\n/**\n * Perform a query using the Cypher query language and return the results\n */\nclass ExecuteCypherQuery extends Command\n{\n\tprotected $query = null;\n\n\t/**\n\t * Set the query to execute\n\t *\n\t * @param Client $client\n\t * @param Query $query\n\t */\n\tpublic function __construct(Client $client, Query $query)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->query = $query;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\t$data = array('query' => $this->query->getQuery());\n\t\t$params = $this->query->getParameters();\n\t\tif ($params) {\n\t\t\t$data['params'] = $params;\n\t\t}\n\t\treturn $data;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$url = $this->client->hasCapability(Client::CapabilityCypher);\n\t\tif (!$url) {\n\t\t\tthrow new Exception('Cypher unavailable');\n\t\t}\n\n\t\treturn preg_replace('/^.+\\/db\\/data/', '', $url);\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to execute query', $code, $headers, $data);\n\t\t}\n\n\t\treturn new ResultSet($this->client, $data);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/ExecuteGremlinQuery.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\EntityMapper,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Gremlin\\Query,\n\tEveryman\\Neo4j\\Query\\ResultSet;\n\n/**\n * Perform a query using the Gremlin DSL and return the results\n */\nclass ExecuteGremlinQuery extends Command\n{\n\tprotected $query = null;\n\n\t/**\n\t * Set the query to execute\n\t *\n\t * @param Client $client\n\t * @param Query $query\n\t */\n\tpublic function __construct(Client $client, Query $query)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->query = $query;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\t$data = array('script' => $this->query->getQuery());\n\t\t$params = $this->query->getParameters();\n\t\tif ($params) {\n\t\t\t$data['params'] = $params;\n\t\t}\n\t\treturn $data;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$url = $this->client->hasCapability(Client::CapabilityGremlin);\n\t\tif (!$url) {\n\t\t\tthrow new Exception('Gremlin unavailable');\n\t\t}\n\n\t\treturn preg_replace('/^.+\\/db\\/data/', '', $url);\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to execute query', $code, $headers, $data);\n\t\t}\n\n\t\treturn new ResultSet($this->client, $this->normalizeData($data));\n\t}\n\n\t/**\n\t * Normalize the data so a proper ResultSet can be built\n\t * Normalized data has 'data' and 'columns' keys for result set.\n\t *\n\t * @param array $data\n\t * @return array\n\t */\n\tprotected function normalizeData($data)\n\t{\n\t\tif (is_scalar($data)) {\n\t\t\t$data = array($data);\n\t\t}\n\n\t\tif (!array_key_exists('columns', $data)) {\n\t\t\t$columns = array(0);\n\n\t\t\tif (array_key_exists('self', $data)) {\n\t\t\t\t$data = array(array($data));\n\t\t\t} else {\n\t\t\t\tforeach ($data as $i => $entity) {\n\t\t\t\t\t$data[$i] = array($entity);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t$data = array(\n\t\t\t\t'columns' => $columns,\n\t\t\t\t'data' => $data\n\t\t\t);\n\t\t}\n\n\t\treturn $data;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/ExecutePagedTraversal.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Pager;\n\n/**\n * Perform a paged traversal and return the results\n */\nclass ExecutePagedTraversal extends ExecuteTraversal\n{\n\tprotected $pager = null;\n\n\t/**\n\t * Set the pager to execute\n\t *\n\t * @param Client $client\n\t * @param Pager $pager\n\t */\n\tpublic function __construct(Client $client, Pager $pager)\n\t{\n\t\tparent::__construct($client, $pager->getTraversal(), $pager->getStartNode(), $pager->getReturnType());\n\t\t$this->pager = $pager;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn $this->pager->getId() ? null : parent::getData();\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn $this->pager->getId() ? 'get' : parent::getMethod();\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$path = parent::getPath();\n\t\t$path = str_replace('traverse', 'paged/traverse', $path);\n\n\t\t$id = $this->pager->getId();\n\t\tif ($id) {\n\t\t\t$path .= \"/{$id}\";\n\t\t} else {\n\t\t\t$queryParams = array();\n\t\t\t$pageSize = $this->pager->getPageSize();\n\t\t\t$leaseTime = $this->pager->getLeaseTime();\n\t\t\tif ($pageSize) {\n\t\t\t\t$queryParams['pageSize'] = $pageSize;\n\t\t\t}\n\t\t\tif ($leaseTime) {\n\t\t\t\t$queryParams['leaseTime'] = $leaseTime;\n\t\t\t}\n\t\t\t$queryString = http_build_query($queryParams);\n\t\t\t$path .= $queryString ? \"?{$queryString}\" : '';\n\t\t}\n\n\t\treturn $path;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif (isset($headers['Location'])) {\n\t\t\t$traversalId = $this->getEntityMapper()->getIdFromUri($headers['Location']);\n\t\t\t$this->pager->setId($traversalId);\n\t\t}\n\n\t\t// No results found or end of result set indicated by not found\n\t\tif ($code == Client::ErrorNotFound) {\n\t\t\treturn null;\n\t\t}\n\t\treturn parent::handleResult($code, $headers, $data);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/ExecuteTraversal.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Traversal,\n\tEveryman\\Neo4j\\Path,\n\tEveryman\\Neo4j\\Node;\n\n/**\n * Perform a traversal and return the results\n */\nclass ExecuteTraversal extends Command\n{\n\tprotected $traversal = null;\n\tprotected $node = null;\n\tprotected $returnType = null;\n\n\tprotected $results;\n\n\t/**\n\t * Set the traversal to execute\n\t *\n\t * @param Client $client\n\t * @param Traversal $traversal\n\t * @param Node $node\n\t * @param string $returnType\n\t */\n\tpublic function __construct(Client $client, Traversal $traversal, Node $node, $returnType)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->traversal = $traversal;\n\t\t$this->node = $node;\n\t\t$this->returnType = $returnType;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\t$data = array();\n\n\t\t$order = $this->traversal->getOrder();\n\t\tif ($order) {\n\t\t\t$data['order'] = $order;\n\t\t}\n\n\t\t$uniqueness = $this->traversal->getUniqueness();\n\t\tif ($uniqueness) {\n\t\t\t$data['uniqueness'] = $uniqueness;\n\t\t}\n\n\t\t$maxDepth = $this->traversal->getMaxDepth();\n\t\tif ($maxDepth) {\n\t\t\t$data['max_depth'] = $maxDepth;\n\t\t}\n\n\t\t$relationships = $this->traversal->getRelationships();\n\t\tif (count($relationships) > 0) {\n\t\t\t$data['relationships'] = $relationships;\n\t\t}\n\n\t\t$prune = $this->traversal->getPruneEvaluator();\n\t\tif ($prune) {\n\t\t\tif ($prune['language'] == Traversal::Builtin) {\n\t\t\t\t$prune['name'] = $prune['body'];\n\t\t\t\tunset($prune['body']);\n\t\t\t}\n\t\t\t$data['prune_evaluator'] = $prune;\n\t\t}\n\n\t\t$filter = $this->traversal->getReturnFilter();\n\t\tif ($filter) {\n\t\t\tif ($filter['language'] == Traversal::Builtin) {\n\t\t\t\t$filter['name'] = $filter['body'];\n\t\t\t\tunset($filter['body']);\n\t\t\t}\n\t\t\t$data['return_filter'] = $filter;\n\t\t}\n\n\t\treturn $data;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->node->hasId()) {\n\t\t\tthrow new Exception('No node id specified');\n\t\t}\n\n\t\tif ($this->returnType != Traversal::ReturnTypeNode\n\t\t\t&& $this->returnType != Traversal::ReturnTypeRelationship\n\t\t\t&& $this->returnType != Traversal::ReturnTypePath\n\t\t\t&& $this->returnType != Traversal::ReturnTypeFullPath) {\n\t\t\tthrow new Exception('No return type specified for traversal');\n\t\t}\n\n\t\treturn '/node/'.$this->node->getId().'/traverse/'.$this->returnType;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to execute traversal', $code, $headers, $data);\n\t\t}\n\n\t\t$this->results = array();\n\t\tif ($this->returnType == Traversal::ReturnTypeNode) {\n\t\t\t$this->handleNodes($data);\n\t\t} else if ($this->returnType == Traversal::ReturnTypeRelationship) {\n\t\t\t$this->handleRelationships($data);\n\t\t} else if ($this->returnType == Traversal::ReturnTypePath) {\n\t\t\t$this->handlePaths($data);\n\t\t} else if ($this->returnType == Traversal::ReturnTypeFullPath) {\n\t\t\t$this->handlePaths($data, true);\n\t\t}\n\t\treturn $this->results;\n\t}\n\n\t/**\n\t * Handle nodes\n\t *\n\t * @param array $data\n\t */\n\tprotected function handleNodes($data)\n\t{\n\t\tforeach ($data as $nodeData) {\n\t\t\t$this->results[] = $this->getEntityMapper()->makeNode($nodeData);\n\t\t}\n\t}\n\n\t/**\n\t * Handle relationships\n\t *\n\t * @param array $data\n\t */\n\tprotected function handleRelationships($data)\n\t{\n\t\tforeach ($data as $relData) {\n\t\t\t$this->results[] = $this->getEntityMapper()->makeRelationship($relData);\n\t\t}\n\t}\n\n\t/**\n\t * Handle paths\n\t *\n\t * @param array   $data\n\t * @param boolean $full\n\t */\n\tprotected function handlePaths($data, $full=false)\n\t{\n\t\tforeach ($data as $pathData) {\n\t\t\tforeach ($data as $pathData) {\n\t\t\t\t$this->results[] = $this->getEntityMapper()->populatePath(new Path($this->client), $pathData, $full);\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/GetIndexes.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index,\n\tEveryman\\Neo4j\\Exception;\n\n/**\n * Get all indexes of the requested type known by the server\n */\nclass GetIndexes extends Command\n{\n\tprotected $type = null;\n\n\t/**\n\t * Set the type of index to retrieve\n\t *\n\t * @param Client $client\n\t * @param string $type\n\t */\n\tpublic function __construct(Client $client, $type)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->type = $type;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'get';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$type = trim((string)$this->type);\n\t\tif ($type != Index::TypeNode && $type != Index::TypeRelationship) {\n\t\t\tthrow new Exception('No type specified for index');\n\t\t}\n\n\t\treturn '/index/'.$type;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to retrieve indexes', $code, $headers, $data);\n\t\t}\n\n\t\tif (!$data) {\n\t\t\t$data = array();\n\t\t}\n\n\t\t$indexes = array();\n\t\tforeach ($data as $name => $indexData) {\n\t\t\t$indexes[] = new Index($this->client, $this->type, $name, $indexData);\n\t\t}\n\t\treturn $indexes;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/GetLabels.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Node;\n\n/**\n * List all labels on the server\n */\nclass GetLabels extends Command\n{\n\tprotected $node;\n\n\t/**\n\t * Optionally provide a node to limit to\n\t *\n\t * @param Client $client\n\t * @param Node   $node\n\t */\n\tpublic function __construct(Client $client, Node $node=null)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->node = $node;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'get';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->client->hasCapability(Client::CapabilityLabel)) {\n\t\t\tthrow new \\RuntimeException('The connected Neo4j version does not have label capability');\n\t\t}\n\n\t\t$path = \"/labels\";\n\t\tif ($this->node) {\n\t\t\t$id = $this->node->getId();\n\t\t\tif (!is_numeric($id)) {\n\t\t\t\tthrow new \\InvalidArgumentException(\"Node given with no id\");\n\t\t\t}\n\n\t\t\t$path = \"/node/{$id}{$path}\";\n\t\t}\n\t\treturn $path;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return Row\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to labels', $code, $headers, $data);\n\t\t}\n\n\t\t$labels = array_map(array($this->client, 'makeLabel'), $data);\n\n\t\treturn $labels;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/GetNode.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Node;\n\n/**\n * Get and populate a node\n */\nclass GetNode extends Command\n{\n\tprotected $node = null;\n\n\t/**\n\t * Set the node to drive the command\n\t *\n\t * @param Client $client\n\t * @param Node $node\n\t */\n\tpublic function __construct(Client $client, Node $node)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->node = $node;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'get';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->node->hasId()) {\n\t\t\tthrow new Exception('No node id specified');\n\t\t}\n\t\treturn '/node/'.$this->node->getId();\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return boolean true on success\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) == 2) {\n\t\t\t$this->node = $this->getEntityMapper()->populateNode($this->node, $data);\n\t\t\t$this->getEntityCache()->setCachedEntity($this->node);\n\t\t\treturn true;\n\t\t} else {\n\t\t\t$this->throwException('Unable to retrieve node', $code, $headers, $data);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/GetNodeRelationships.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node;\n\n/**\n * Find relationships on a node\n */\nclass GetNodeRelationships extends Command\n{\n\tprotected $node  = null;\n\tprotected $types = null;\n\tprotected $dir   = null;\n\n\t/**\n\t * Set the parameters to search\n\t *\n\t * @param Client $client\n\t * @param Node   $node\n\t * @param mixed  $types a string or array of strings\n\t * @param string $dir\n\t */\n\tpublic function __construct(Client $client, Node $node, $types=array(), $dir=null)\n\t{\n\t\tparent::__construct($client);\n\n\t\tif (empty($dir)) {\n\t\t\t$dir = Relationship::DirectionAll;\n\t\t}\n\t\tif (empty($types)) {\n\t\t\t$types = array();\n\t\t} else if (!is_array($types)) {\n\t\t\t$types = array($types);\n\t\t}\n\n\t\t$this->node = $node;\n\t\t$this->dir = $dir;\n\t\t$this->types = $types;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'get';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->node->hasId()) {\n\t\t\tthrow new Exception('No node id specified');\n\t\t}\n\n\t\t$path = '/node/'.$this->node->getId().'/relationships/'.$this->dir;\n\t\tif (!empty($this->types)) {\n\t\t\t$types = array_map('rawurlencode', $this->types);\n\t\t\t$path .= '/'.join('&', $types);\n\t\t}\n\n\t\treturn $path;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) == 2) {\n\t\t\t$rels = array();\n\t\t\tforeach ($data as $relData) {\n\t\t\t\t$rels[] = $this->getEntityMapper()->makeRelationship($relData);\n\t\t\t}\n\t\t\treturn $rels;\n\t\t} else {\n\t\t\t$this->throwException('Unable to retrieve node relationships', $code, $headers, $data);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/GetNodesForLabel.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Label,\n\tEveryman\\Neo4j\\Query\\Row;\n\n/**\n * Find nodes with the given label\n */\nclass GetNodesForLabel extends Command\n{\n\tprotected $label           = null;\n\tprotected $propertyName    = null;\n\tprotected $propertyValue   = null;\n\n\t/**\n\t * Set the parameters to search\n\t *\n\t * @param Client $client\n\t * @param Label  $label\n\t * @param string $propertyName\n\t * @param mixed  $propertyValue\n\t */\n\tpublic function __construct(Client $client, Label $label, $propertyName=null, $propertyValue=null)\n\t{\n\t\tparent::__construct($client);\n\n\t\t$this->label = $label;\n\t\t$this->propertyName = $propertyName;\n\t\t$this->propertyValue = $propertyValue;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'get';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->client->hasCapability(Client::CapabilityLabel)) {\n\t\t\tthrow new \\RuntimeException('The connected Neo4j version does not have label capability');\n\t\t}\n\n\t\t$labelName = rawurlencode($this->label->getName());\n\t\t$path = \"/label/{$labelName}/nodes\";\n\t\tif ($this->propertyName || $this->propertyValue) {\n\t\t\tif (!$this->propertyName || !$this->propertyValue) {\n\t\t\t\tthrow new \\InvalidArgumentException('Cannot specify a property name without a value, or vice versa');\n\t\t\t}\n\n\t\t\t$propertyName = rawurlencode($this->propertyName);\n\n\t\t\tif (is_numeric($this->propertyValue)) {\n\t\t\t\t$propertyValue = rawurlencode($this->propertyValue);\n\t\t\t} else {\n\t\t\t\t$propertyValue = rawurlencode('\"'.$this->propertyValue.'\"');\n\t\t\t}\n\n\t\t\t$path .= \"?{$propertyName}={$propertyValue}\";\n\t\t}\n\t\treturn $path;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return Row\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to retrieve nodes for label', $code, $headers, $data);\n\t\t}\n\n\t\treturn new Row($this->client, array_keys($data), $data);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/GetPaths.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\PathFinder,\n\tEveryman\\Neo4j\\Path;\n\n/**\n * Find paths from one node to another\n */\nclass GetPaths extends Command\n{\n\tprotected $finder = null;\n\n\t/**\n\t * Set the parameters to search\n\t *\n\t * @param Client     $client\n\t * @param PathFinder $finder\n\t */\n\tpublic function __construct(Client $client, PathFinder $finder)\n\t{\n\t\tparent::__construct($client);\n\n\t\t$this->finder = $finder;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\t$data = array();\n\n\t\t$end = $this->finder->getEndNode();\n\t\tif (!$end || !$end->hasId()) {\n\t\t\tthrow new Exception('No end node id specified');\n\t\t}\n\n\t\t$endUri = $this->getTransport()->getEndpoint().'/node/'.$end->getId();\n\t\t$data['to'] = $endUri;\n\n\t\t$algo = $this->finder->getAlgorithm();\n\t\tif ($algo == PathFinder::AlgoDijkstra) {\n\t\t\t$property = $this->finder->getCostProperty();\n\t\t\tif (!$property) {\n\t\t\t\tthrow new Exception('No cost property specified for Dijkstra path search');\n\t\t\t}\n\t\t\t$data['cost_property'] = $property;\n\t\t\t$data['cost property'] = $property;\n\n\t\t\t$cost = $this->finder->getDefaultCost();\n\t\t\tif ($cost) {\n\t\t\t\t$data['default_cost'] = $cost;\n\t\t\t\t$data['default cost'] = $cost;\n\t\t\t}\n\t\t}\n\t\t$data['algorithm'] = $algo;\n\n\n\n\t\t$max = $this->finder->getMaxDepth();\n\t\tif (!$max) {\n\t\t\t$max = 1;\n\t\t}\n\t\t$data['max_depth'] = $max;\n\t\t$data['max depth'] = $max;\n\n\t\t$type = $this->finder->getType();\n\t\t$dir = $this->finder->getDirection();\n\t\tif ($dir && !$type) {\n\t\t\tthrow new Exception('No relationship type specified');\n\t\t} else if ($type) {\n\t\t\t$rel = array('type'=>$type);\n\t\t\tif ($dir) {\n\t\t\t\t$rel['direction'] = $dir;\n\t\t\t}\n\t\t\t$data['relationships'] = $rel;\n\t\t}\n\n\t\treturn $data;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$start = $this->finder->getStartNode();\n\t\tif (!$start || !$start->hasId()) {\n\t\t\tthrow new Exception('No start node id specified');\n\t\t}\n\n\t\treturn '/node/'.$start->getId().'/paths';\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to retrieve paths', $code, $headers, $data);\n\t\t}\n\n\t\t$paths = array();\n\t\tforeach ($data as $pathData) {\n\t\t\t$paths[] = $this->getEntityMapper()->populatePath(new Path($this->client), $pathData);\n\t\t}\n\t\treturn $paths;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/GetRelationship.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node;\n\n/**\n * Get and populate a relationship\n */\nclass GetRelationship extends Command\n{\n\tprotected $rel = null;\n\n\t/**\n\t * Set the relationship to drive the command\n\t *\n\t * @param Client $client\n\t * @param Relationship $rel\n\t */\n\tpublic function __construct(Client $client, Relationship $rel)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->rel = $rel;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'get';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->rel->hasId()) {\n\t\t\tthrow new Exception('No relationship id specified');\n\t\t}\n\t\treturn '/relationship/'.$this->rel->getId();\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return boolean true on success\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) == 2) {\n\t\t\t$this->rel = $this->getEntityMapper()->populateRelationship($this->rel, $data);\n\t\t\t$this->getEntityCache()->setCachedEntity($this->rel);\n\t\t\treturn true;\n\t\t} else {\n\t\t\t$this->throwException('Unable to retrieve relationship', $code, $headers, $data);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/GetRelationshipTypes.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client;\n\n/**\n * Get all relationship types known by the server\n */\nclass GetRelationshipTypes extends Command\n{\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'get';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\treturn '/relationship/types';\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to retrieve relationship types', $code, $headers, $data);\n\t\t}\n\t\treturn $data;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/GetServerInfo.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client;\n\n/**\n * Get information about the server\n */\nclass GetServerInfo extends Command\n{\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'get';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\treturn '/';\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to retrieve server info', $code, $headers, $data);\n\t\t}\n\t\t$data['version'] = $this->parseVersion($data['neo4j_version']);\n\t\treturn $data;\n\t}\n\n\t/**\n\t * Parse the version into usable bits\n\t *\n\t * @param string $fullVersion\n\t * @return array\n\t */\n\tprotected function parseVersion($fullVersion)\n\t{\n\t\t$parts = explode('.', $fullVersion);\n\t\t$versionInfo = array(\n\t\t\t'full'  => $fullVersion,\n\t\t\t'major' => $parts[0],\n\t\t\t'minor' => $parts[1],\n\t\t);\n\t\tif (empty($parts[2])) {\n\t\t\t$versionInfo['release'] = 'GA';\n\t\t} else {\n\t\t\t$versionInfo['release'] = current(explode('-', $parts[2], 2));\n\t\t}\n\t\treturn $versionInfo;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/QueryIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Index;\n\n/**\n * Queries for entities in an index\n */\nclass QueryIndex extends SearchIndex\n{\n\t/**\n\t * Set the index to drive the command\n\t *\n\t * @param Client $client\n\t * @param Index $index\n\t * @param string $query\n\t */\n\tpublic function __construct(Client $client, Index $index, $query)\n\t{\n\t\tparent::__construct($client, $index, $query, null);\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$path = parent::getPath();\n\t\t$path = join('/', array_slice(explode('/', $path), 0, 4));\n\t\t$query = rawurlencode($this->key);\n\t\treturn $path . '?query=' . $query;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/RemoveFromIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\PropertyContainer,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Index;\n\n/**\n * Removes an entity from an index\n */\nclass RemoveFromIndex extends Command\n{\n\tprotected $index = null;\n\tprotected $entity = null;\n\tprotected $key = null;\n\tprotected $value = null;\n\n\t/**\n\t * Remove an entity from an index\n\t * If $value is not given, all reference of the entity for the key\n\t * are removed.\n\t * If $key is not given, all reference of the entity are removed.\n\t *\n\t * @param Client $client\n\t * @param Index $index\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @return boolean\n\t */\n\tpublic function __construct(Client $client, Index $index, PropertyContainer $entity, $key=null, $value=null)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->index = $index;\n\t\t$this->entity = $entity;\n\t\t$this->key = $key;\n\t\t$this->value = $value;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'delete';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->entity || !$this->entity->hasId()) {\n\t\t\tthrow new Exception('No entity to index specified');\n\t\t}\n\n\t\t$type = trim((string)$this->index->getType());\n\t\tif ($type != Index::TypeNode && $type != Index::TypeRelationship) {\n\t\t\tthrow new Exception('No type specified for index');\n\t\t} else if ($type == Index::TypeNode && !($this->entity instanceof Node)) {\n\t\t\tthrow new Exception('Cannot remove a node from a non-node index');\n\t\t} else if ($type == Index::TypeRelationship && !($this->entity instanceof Relationship)) {\n\t\t\tthrow new Exception('Cannot remove a relationship from a non-relationship index');\n\t\t}\n\n\t\t$name = trim((string)$this->index->getName());\n\t\tif (!$name) {\n\t\t\tthrow new Exception('No name specified for index');\n\t\t}\n\n\t\t$name = rawurlencode($name);\n\t\t$key = trim((string)$this->key);\n\t\t$value = trim((string)$this->value);\n\n\t\t$uri = '/index/'.$type.'/'.$name.'/';\n\t\tif ($key) {\n\t\t\t$uri .= rawurlencode($key).'/';\n\t\t\tif ($value) {\n\t\t\t\t$uri .= rawurlencode($value).'/';\n\t\t\t}\n\t\t}\n\t\t$uri .= $this->entity->getId();\n\n\t\treturn $uri;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to remove entity from index', $code, $headers, $data);\n\t\t}\n\t\treturn true;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/RemoveLabels.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command\\SetLabels,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Label;\n\n/**\n * Remove a set of labels from a node\n */\nclass RemoveLabels extends SetLabels\n{\n\t/**\n\t * Set the labels to remove\n\t *\n\t * @param Client $client\n\t * @param Node   $node\n\t * @param array  $labels\n\t */\n\tpublic function __construct(Client $client, Node $node, $labels)\n\t{\n\t\tparent::__construct($client, $node, $labels, true);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/RollbackTransaction.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Transaction;\n\n/**\n * Rollback an open Cypher transaction\n */\nclass RollbackTransaction extends Command\n{\n\tprotected $transaction = null;\n\n\t/**\n\t * Set the transaction to rollback\n\t *\n\t * @param Client $client\n\t * @param Transaction $transaction\n\t */\n\tpublic function __construct(Client $client, Transaction $transaction)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->transaction = $transaction;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'delete';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->client->hasCapability(Client::CapabilityTransactions)) {\n\t\t\tthrow new Exception('Transactions unavailable');\n\t\t}\n\n\t\t$id = $this->transaction->getId();\n\t\tif (!$id) {\n\t\t\tthrow new Exception('Cannot rollback a transaction without a transaction id');\n\t\t}\n\n\t\t$path = '/transaction/'.$id;\n\n\t\treturn $path;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Error during transaction rollback', $code, $headers, $data);\n\t\t}\n\n\t\treturn true;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/SaveIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Index;\n\n/**\n * Create an index\n */\nclass SaveIndex extends Command\n{\n\tprotected $index = null;\n\n\t/**\n\t * Set the index to drive the command\n\t *\n\t * @param Client $client\n\t * @param Index $index\n\t */\n\tpublic function __construct(Client $client, Index $index)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->index = $index;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\t$name = trim((string)$this->index->getName());\n\t\tif (!$name) {\n\t\t\tthrow new Exception('No name specified for index');\n\t\t}\n\t\t$data = array('name' => $name);\n\n\t\t$config = $this->index->getConfig();\n\t\tif ($config) {\n\t\t\t$data['config'] = $config;\n\t\t}\n\n\t\treturn $data;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'post';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$type = trim((string)$this->index->getType());\n\t\tif ($type != Index::TypeNode && $type != Index::TypeRelationship) {\n\t\t\tthrow new Exception('No type specified for index');\n\t\t}\n\n\t\treturn '/index/'.$type;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to save index', $code, $headers, $data);\n\t\t}\n\t\treturn true;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/SearchIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Index;\n\n/**\n * Search for entities in an index\n */\nclass SearchIndex extends Command\n{\n\tprotected $index = null;\n\tprotected $key = null;\n\tprotected $value = null;\n\n\t/**\n\t * Set the index to drive the command\n\t *\n\t * @param Client $client\n\t * @param Index $index\n\t * @param string $key\n\t * @param string $value\n\t */\n\tpublic function __construct(Client $client, Index $index, $key, $value)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->index = $index;\n\t\t$this->key = $key;\n\t\t$this->value = $value;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn null;\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'get';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\t$type = trim((string)$this->index->getType());\n\t\tif ($type != Index::TypeNode && $type != Index::TypeRelationship) {\n\t\t\tthrow new Exception('No type specified for index');\n\t\t}\n\n\t\t$name = trim((string)$this->index->getName());\n\t\tif (!$name) {\n\t\t\tthrow new Exception('No name specified for index');\n\t\t}\n\n\t\t$key = trim((string)$this->key);\n\t\tif (!$key) {\n\t\t\tthrow new Exception('No key specified to search index');\n\t\t}\n\n\t\t$name = rawurlencode($name);\n\t\t$key = rawurlencode($key);\n\t\t$value = rawurlencode($this->value);\n\n\t\treturn '/index/'.$type.'/'.$name.'/'.$key.'/'.$value;\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return integer on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) != 2) {\n\t\t\t$this->throwException('Unable to search index', $code, $headers, $data);\n\t\t}\n\n\t\t$buildMethod = $this->index->getType() == Index::TypeNode ? 'makeNode' : 'makeRelationship';\n\t\t$results = array();\n\t\tforeach ($data as $entityData) {\n\t\t\t$results[] = $this->getEntityMapper()->$buildMethod($entityData);\n\t\t}\n\t\treturn $results;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/SetLabels.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command\\ExecuteCypherQuery,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Cypher\\Query,\n\tEveryman\\Neo4j\\Label;\n\n/**\n * Add or remove a set of labels on a node\n *\n * @todo: Don't extend ExecuteCypherQuery, extract and use a more generic Command interface\n *        that proxies to an ExecuteCypherQuery command\n */\nclass SetLabels extends ExecuteCypherQuery\n{\n\t/**\n\t * Proxy creation to a cypher query that does what we want\n\t *\n\t * @param Client   $client\n\t * @param Node     $node\n\t * @param array    $labels\n\t * @param boolean  $remove\n\t */\n\tpublic function __construct(Client $client, Node $node, $labels, $remove=false)\n\t{\n\t\tif (!$client->hasCapability(Client::CapabilityLabel)) {\n\t\t\tthrow new \\RuntimeException('The connected Neo4j version does not have label capability');\n\t\t}\n\n\t\t$nodeId = $node->getId();\n\t\tif (!is_numeric($nodeId)) {\n\t\t\tthrow new \\InvalidArgumentException(\"Cannot set labels on an unsaved node\");\n\t\t}\n\n\t\tif (!$labels) {\n\t\t\tthrow new \\InvalidArgumentException(\"No labels given to set on node\");\n\t\t}\n\n\t\t$labelSet = implode(':', array_map(function ($label) {\n\t\t\tif (!($label instanceof Label)) {\n\t\t\t\tthrow new \\InvalidArgumentException(\"Cannot set a non-label\");\n\t\t\t}\n\t\t\t$name = str_replace('`', '``', $label->getName());\n\t\t\treturn \"`{$name}`\";\n\t\t}, $labels));\n\n\t\t$setCommand = $remove ? 'REMOVE' : 'SET';\n\n\t\t$query = \"START n=node({nodeId}) {$setCommand} n:{$labelSet} RETURN labels(n) AS labels\";\n\t\t$params = array('nodeId' => $nodeId);\n\n\t\t$cypher = new Query($client, $query, $params);\n\t\tparent::__construct($client, $cypher);\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return array of Label\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\t$results = parent::handleResult($code, $headers, $data);\n\n\t\t$nodeLabels = array();\n\t\tforeach ($results[0]['labels'] as $labelName) {\n\t\t\t$nodeLabels[] = $this->client->makeLabel($labelName);\n\t\t}\n\t\treturn $nodeLabels;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/UpdateNode.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Node;\n\n/**\n * Update a node\n */\nclass UpdateNode extends Command\n{\n\tprotected $node = null;\n\n\t/**\n\t * Set the node to drive the command\n\t *\n\t * @param Client $client\n\t * @param Node $node\n\t */\n\tpublic function __construct(Client $client, Node $node)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->node = $node;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn $this->node->getProperties();\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'put';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->node->hasId()) {\n\t\t\tthrow new Exception('No node id specified');\n\t\t}\n\t\treturn '/node/'.$this->node->getId().'/properties';\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return boolean true on success\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) == 2) {\n\t\t\t$this->getEntityCache()->setCachedEntity($this->node);\n\t\t\treturn true;\n\t\t} else {\n\t\t\t$this->throwException('Unable to update node', $code, $headers, $data);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command/UpdateRelationship.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Command;\n\nuse Everyman\\Neo4j\\Command,\n\tEveryman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Relationship;\n\n/**\n * Update a relationship's properties\n */\nclass UpdateRelationship extends Command\n{\n\tprotected $rel = null;\n\n\t/**\n\t * Set the relationship to drive the command\n\t *\n\t * @param Client $client\n\t * @param Relationship $rel\n\t */\n\tpublic function __construct(Client $client, Relationship $rel)\n\t{\n\t\tparent::__construct($client);\n\t\t$this->rel = $rel;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tprotected function getData()\n\t{\n\t\treturn $this->rel->getProperties();\n\t}\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tprotected function getMethod()\n\t{\n\t\treturn 'put';\n\t}\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tprotected function getPath()\n\t{\n\t\tif (!$this->rel->hasId()) {\n\t\t\tthrow new Exception('No relationship id specified');\n\t\t}\n\t\treturn '/relationship/'.$this->rel->getId().'/properties';\n\t}\n\n\t/**\n\t * Use the results\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return boolean true on success\n\t * @throws Exception on failure\n\t */\n\tprotected function handleResult($code, $headers, $data)\n\t{\n\t\tif ((int)($code / 100) == 2) {\n\t\t\t$this->getEntityCache()->setCachedEntity($this->rel);\n\t\t\treturn true;\n\t\t} else {\n\t\t\t$this->throwException('Unable to update relationship', $code, $headers, $data);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Command.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Abstract the parameters needed to make a request and parse the response\n */\nabstract class Command\n{\n\tprotected $client;\n\n\t/**\n\t * Set the client\n\t *\n\t * @param Client $client\n\t */\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->client = $client;\n\t}\n\n\t/**\n\t * Return the data to pass\n\t *\n\t * @return mixed\n\t */\n\tabstract protected function getData();\n\n\t/**\n\t * Return the transport method to call\n\t *\n\t * @return string\n\t */\n\tabstract protected function getMethod();\n\n\t/**\n\t * Return the path to use\n\t *\n\t * @return string\n\t */\n\tabstract protected function getPath();\n\n\t/**\n\t * Use the results in some way\n\t *\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @return mixed\n\t * @throws Exception on failure\n\t */\n\tabstract protected function handleResult($code, $headers, $data);\n\n\t/**\n\t * Run the command and return a value signalling the result\n\t *\n\t * @return mixed\n\t * @throws Exception on failure\n\t */\n\tpublic function execute()\n\t{\n\t\t$method = $this->getMethod();\n\t\t$path = $this->getPath();\n\t\t$data = $this->getData();\n\t\t$result = $this->getTransport()->$method($path, $data);\n\n\t\t$resultCode = isset($result['code']) ? $result['code'] : Client::ErrorUnknown;\n\t\t$resultHeaders = isset($result['headers']) ? $result['headers'] : array();\n\t\t$resultData = isset($result['data']) ? $result['data'] : array();\n\t\t$parseResult = $this->handleResult($resultCode, $resultHeaders, $resultData);\n\n\t\treturn $parseResult;\n\t}\n\n\t/**\n\t * Get the entity cache\n\t *\n\t * @return Cache\\EntityCache\n\t */\n\tprotected function getEntityCache()\n\t{\n\t\treturn $this->client->getEntityCache();\n\t}\n\n\t/**\n\t * Get the entity mapper\n\t *\n\t * @return EntityMapper\n\t */\n\tprotected function getEntityMapper()\n\t{\n\t\treturn $this->client->getEntityMapper();\n\t}\n\n\t/**\n\t * Get the transport\n\t *\n\t * @return Transport\n\t */\n\tprotected function getTransport()\n\t{\n\t\treturn $this->client->getTransport();\n\t}\n\n\t/**\n\t * Throw an exception from handling the results\n\t *\n\t * @param string  $message\n\t * @param integer $code\n\t * @param array   $headers\n\t * @param array   $data\n\t * @throws Exception\n\t */\n\tprotected function throwException($message, $code, $headers, $data)\n\t{\n\t\t$message = \"{$message} [{$code}]:\\nHeaders: \" . print_r($headers, true) . \"Body: \" . print_r($data, true);\n\t\tthrow new Exception($message, $code, $headers, $data);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Cypher/Query.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cypher;\n\nuse Everyman\\Neo4j;\n\n/**\n * Represents a Cypher query string and variables\n * Query the database using Cypher. For query syntax, please refer\n * to the Cypher documentation for your server version.\n *\n * Latest documentation:\n * http://docs.neo4j.org/chunked/snapshot/cypher-query-lang.html\n */\nclass Query implements Neo4j\\Query\n{\n\tprotected $client = null;\n\tprotected $template = null;\n\tprotected $vars = array();\n\n\tprotected $result = null;\n\n\t/**\n\t * Set the template to use\n\t *\n\t * @param Neo4j\\Client $client\n\t * @param string $template A Cypher query string or template\n\t * @param array $vars Replacement vars to inject into the query\n\t */\n\tpublic function __construct(Neo4j\\Client $client, $template, $vars=array())\n\t{\n\t\t$this->client = $client;\n\t\t$this->template = $template;\n\t\t$this->vars = $vars;\n\t}\n\n\t/**\n\t * Get the query script\n\t *\n\t * @return string\n\t */\n\tpublic function getQuery()\n\t{\n\t\treturn $this->template;\n\t}\n\n\t/**\n\t * Get the template parameters\n\t *\n\t * @return array\n\t */\n\tpublic function getParameters()\n\t{\n\t\treturn $this->vars;\n\t}\n\n\t/**\n\t * Retrieve the query results\n\t *\n\t * @return Neo4j\\Query\\ResultSet\n\t */\n\tpublic function getResultSet()\n\t{\n\t\tif ($this->result === null) {\n\t\t\t$this->result = $this->client->executeCypherQuery($this);\n\t\t}\n\n\t\treturn $this->result;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/EntityMapper.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Used to convert arbitrary arrays into Nodes and Relationships\n * where appropriate. \n */\nclass EntityMapper\n{\n\tprotected $client = null;\n\n\t/**\n\t * Set the client for retrieving related entities\n\t *\n\t * @param Client $client\n\t */\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->client = $client;\n\t}\n\n\t/**\n\t * Given any object, see if it fulfills the contract\n\t * for being a path, node or relationship data returned by the\n\t * server. If so, return a full Path, Node or Relationship instance.\n\t * Else, return the value untainted.\n\t *\n\t * @param mixed $value\n\t * @return mixed\n\t */\n\tpublic function getEntityFor($value)\n\t{\n\t\tif (is_array($value)) {\n\t\t\tif (array_key_exists('self', $value)) {\n\t\t\t\tif (array_key_exists('type', $value)) {\n\t\t\t\t\t$value = $this->makeRelationship($value);\n\t\t\t\t} else {\n\t\t\t\t\t$value = $this->makeNode($value);\n\t\t\t\t}\n\t\t\t} else if (array_key_exists('nodes', $value) && array_key_exists('relationships', $value)) {\n\t\t\t\t$value = $this->populatePath(new Path($this->client), $value);\n\t\t\t}\n\t\t}\n\t\treturn $value;\n\t}\n\n\t/**\n\t * Get an id from a URI\n\t *\n\t * @param string $uri\n\t * @return mixed\n\t */\n\tpublic function getIdFromUri($uri)\n\t{\n\t\t$uriParts = explode('/', $uri);\n\t\treturn array_pop($uriParts);\n\t}\n\n\t/**\n\t * Generate and populate a node from the given data\n\t *\n\t * @param array $data\n\t * @return Node\n\t */\n\tpublic function makeNode($data)\n\t{\n\t\t$node = $this->getNodeFromUri($data['self']);\n\t\treturn $this->populateNode($node, $data);\n\t}\n\n\t/**\n\t * Generate and populate a relationship from the given data\n\t *\n\t * @param array $data\n\t * @return Relationship\n\t */\n\tpublic function makeRelationship($data)\n\t{\n\t\t$rel = $this->getRelationshipFromUri($data['self']);\n\t\treturn $this->populateRelationship($rel, $data);\n\t}\n\n\t/**\n\t * Fill a node with data\n\t *\n\t * @param Node $node\n\t * @param array $data\n\t * @return Node\n\t */\n\tpublic function populateNode(Node $node, $data)\n\t{\n\t\t$node->useLazyLoad(false);\n\t\t$node->setProperties($data['data']);\n\t\treturn $node;\n\t}\n\n\t/**\n\t * Fill a path with data\n\t *\n\t * @param Path $path\n\t * @param array $data\n\t * @param boolean $full\n\t * @return Path\n\t */\n\tpublic function populatePath(Path $path, $data, $full=false)\n\t{\n\t\tforeach ($data['relationships'] as $relData) {\n\t\t\t$relUri = $full ? $relData['self'] : $relData;\n\t\t\t$rel = $this->getRelationshipFromUri($relUri);\n\t\t\tif ($full) {\n\t\t\t\t$rel = $this->populateRelationship($rel, $relData);\n\t\t\t}\n\t\t\t$path->appendRelationship($rel);\n\t\t}\n\n\t\tforeach ($data['nodes'] as $nodeData) {\n\t\t\t$nodeUri = $full ? $nodeData['self'] : $nodeData;\n\t\t\t$node = $this->getNodeFromUri($nodeUri);\n\t\t\tif ($full) {\n\t\t\t\t$node = $this->populateNode($node, $nodeData);\n\t\t\t}\n\t\t\t$path->appendNode($node);\n\t\t}\n\n\t\treturn $path;\n\t}\n\n\t/**\n\t * Fill a relationship with data\n\t *\n\t * @param Relationship $rel\n\t * @param array $data\n\t * @return Relationship\n\t */\n\tpublic function populateRelationship(Relationship $rel, $data)\n\t{\n\t\t$rel->useLazyLoad(false);\n\t\t$rel->setProperties($data['data']);\n\t\t$rel->setType($data['type']);\n\n\t\t$rel->setStartNode($this->getNodeFromUri($data['start']));\n\t\t$rel->setEndNode($this->getNodeFromUri($data['end']));\n\n\t\treturn $rel;\n\t}\n\n\t/**\n\t * Retrieve a node by it's 'self' uri\n\t *\n\t * @param string $uri\n\t * @return Node\n\t */\n\tprotected function getNodeFromUri($uri)\n\t{\n\t\t$nodeId = $this->getIdFromUri($uri);\n\t\treturn $this->client->getNode($nodeId, true);\n\t}\n\n\t/**\n\t * Retrieve a relationship by it's 'self' uri\n\t *\n\t * @param string $uri\n\t * @return Relationship\n\t */\n\tprotected function getRelationshipFromUri($uri)\n\t{\n\t\t$relId = $this->getIdFromUri($uri);\n\t\treturn $this->client->getRelationship($relId, true);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Exception.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Exception extends \\Exception\n{\n\tprotected $headers;\n\tprotected $data;\n\n\tpublic function __construct($message, $code=0, $headers=array(), $data=array())\n\t{\n\t\t$this->headers = $headers;\n\t\t$this->data = $data;\n\t\tparent::__construct($message, $code);\n\t}\n\n\t/**\n\t * Return response headers\n\t * @return array Response headers\n\t */\n\tpublic function getHeaders()\n\t{\n\t\treturn $this->headers;\n\t}\n\n\t/**\n\t * Return response data\n\t * @return array Response data\n\t */\n\tpublic function getData()\n\t{\n\t\treturn $this->data;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Geoff/Exporter.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Geoff;\n\nuse Everyman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Path;\n\n/**\n * Export an array of Paths to a file\n */\nclass Exporter\n{\n\t/**\n\t * Dump an array of Paths\n\t *\n\t * @param mixed $paths a single Path object or an array of Path objects\n\t * @param stream $handle\n\t */\n\tpublic function dump($paths, $handle)\n\t{\n\t\tif (!is_resource($handle) || get_resource_type($handle) != 'stream') {\n\t\t\tthrow new Exception(\"Not a stream resource\");\n\t\t}\n\n\t\tif (!is_array($paths)) {\n\t\t\t$paths = array($paths);\n\t\t}\n\n\t\t$nodes = array();\n\t\t$rels = array();\n\t\tforeach ($paths as $path) {\n\t\t\tif (!($path instanceof Path)) {\n\t\t\t\tthrow new Exception(\"Not a Path\");\n\t\t\t}\n\n\t\t\t$pathNodes = $path->getNodes();\n\t\t\tforeach ($pathNodes as $node) {\n\t\t\t\t$nodes[$node->getId()] = $node;\n\t\t\t}\n\n\t\t\t$pathRels = $path->getRelationships();\n\t\t\tforeach ($pathRels as $rel) {\n\t\t\t\t$rels[$rel->getId()] = $rel;\n\t\t\t}\n\t\t}\n\n\t\tforeach ($nodes as $id => $node) {\n\t\t\t$properties = $node->getProperties();\n\t\t\t$format = $properties ? \"(%s)\\t%s\\n\" : \"(%s)\\n\";\n\t\t\tfprintf(\n\t\t\t\t$handle,\n\t\t\t\t$format,\n\t\t\t\t$id,\n\t\t\t\tjson_encode($properties)\n\t\t\t);\n\t\t}\n\n\t\tforeach ($rels as $id => $rel) {\n\t\t\t$properties = $rel->getProperties();\n\t\t\t$format = \"(%s)-[%s:%s]->(%s)\";\n\t\t\t$format .= $properties ? \"\\t%s\\n\" : \"\\n\";\n\t\t\tfprintf(\n\t\t\t\t$handle,\n\t\t\t\t$format,\n\t\t\t\t$rel->getStartNode()->getId(),\n\t\t\t\t$id,\n\t\t\t\t$rel->getType(),\n\t\t\t\t$rel->getEndNode()->getId(),\n\t\t\t\tjson_encode($properties)\n\t\t\t);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Geoff/Importer.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Geoff;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Exception,\n\tEveryman\\Neo4j\\Node,\n\tEveryman\\Neo4j\\Relationship,\n\tEveryman\\Neo4j\\Index,\n\tEveryman\\Neo4j\\Batch;\n\n/**\n * Import a GEOFF file into a batch\n */\nclass Importer\n{\n\tprotected $client = null;\n\n\t/**\n\t * Build the importer\n\t *\n\t * @param Client $client\n\t */\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->client = $client;\n\t}\n\n\n\t/**\n\t * Load a GEOFF string from a stream\n\t * If a batch is provided, append imported data to it,\n\t * else, create and return a new batch\n\t *\n\t * @param stream $handle\n\t * @param Batch $batch\n\t * @return Batch\n\t */\n\tpublic function load($handle, Batch $batch=null)\n\t{\n\t\tif (!is_resource($handle) || get_resource_type($handle) != 'stream') {\n\t\t\tthrow new Exception(\"Not a stream resource\");\n\t\t}\n\n\t\tif (!$batch) {\n\t\t\t$batch = new Batch($this->client);\n\t\t}\n\n\t\t$i = 0;\n\t\t$nodes = array();\n\t\t$rels = array();\n\t\twhile (($line = fgets($handle)) !== false) {\n\t\t\t$this->loadLine($line, $batch, $i, $nodes, $rels);\n\t\t\t$i++;\n\t\t}\n\n\t\treturn $batch;\n\t}\n\n\t/**\n\t * Load a single line into the batch\n\t *\n\t * @param string $line\n\t * @param Batch $batch\n\t * @param integer $lineNum\n\t * @param array $nodes\n\t * @param array $rels\n\t */\n\tprotected function loadLine($line, Batch $batch, $lineNum, &$nodes, &$rels)\n\t{\n\t\t$descriptorPattern = \"/^(\n\t\t\t\\((\\w+)\\)\t            # node identifier or relationship start node\n\t\t\t(                       # next two sub expressions signify a relationship line\n\t\t\t\t-\\[(\\w*):(\\w+)\\]    # relationship identifier and type\n\t\t\t\t->\\((\\w+)\\)         # relationship end node\n\t\t)?)(\n\t\t\t\\s+(.*)                 # properties\n\t\t)?/x\";\n\n\t\t$indexPattern = \"/^(\n\t\t\t\\{(\\w+)\\}               # index name\n\t\t\t->(\\(|\\[)\t\t\t\t# ( indicates node index, [ indicates relationship index\n\t\t\t\t(\\w+)               # node identifier to index\n\t\t\t(\\)|\\])                 # must match opening ( or [\n\t\t)(\n\t\t\t\\s+(.*)                 # keys:values to index\n\t\t)?/x\";\n\n\t\t$line = trim($line);\n\t\tif (!$line || $line[0]  == '#') {\n\t\t\treturn;\n\t\t}\n\n\t\t$matches = array();\n\t\t$descriptorMatch = preg_match($descriptorPattern, $line, $matches);\n\n\t\tif ($descriptorMatch && !empty($matches[3])) {\n\t\t\t$startNodeId = $matches[2];\n\t\t\t$relId = $matches[4];\n\t\t\t$type = $matches[5];\n\t\t\t$endNodeId = $matches[6];\n\t\t\tif (!isset($nodes[$startNodeId]) || !isset($nodes[$endNodeId])) {\n\t\t\t\tthrow new Exception(\"Invalid node reference on line {$lineNum}: $line\");\n\t\t\t} else if (!empty($relId) && isset($rels[$relId])) {\n\t\t\t\tthrow new Exception(\"Duplicate relationship on line {$lineNum}: $line\");\n\t\t\t}\n\t\t\t$properties = !empty($matches[8]) ? json_decode($matches[8]) : false;\n\t\t\t$rel = $this->client->makeRelationship();\n\t\t\t$rel->setProperties($properties ?: array())\n\t\t\t\t->setType($type)\n\t\t\t\t->setStartNode($nodes[$startNodeId])\n\t\t\t\t->setEndNode($nodes[$endNodeId]);\n\t\t\tif (!empty($relId)) {\n\t\t\t\t$rels[$relId] = $rel;\n\t\t\t}\n\t\t\t$batch->save($rel);\n\t\t\treturn;\n\n\t\t} else if ($descriptorMatch) {\n\t\t\t$nodeId = $matches[2];\n\t\t\tif (isset($nodes[$nodeId])) {\n\t\t\t\tthrow new Exception(\"Duplicate node on line {$lineNum}: $line\");\n\t\t\t}\n\t\t\t$properties = !empty($matches[7]) ? json_decode($matches[7]) : false;\n\t\t\t$node = $this->client->makeNode();\n\t\t\t$node->setProperties($properties ?: array());\n\t\t\t$nodes[$nodeId] = $node;\n\t\t\t$batch->save($node);\n\t\t\treturn;\n\t\t}\n\n\t\t$matches = array();\n\t\t$indexMatch = preg_match($indexPattern, $line, $matches);\n\t\tif ($indexMatch) {\n\t\t\t$name = $matches[2];\n\t\t\t$openBrace = $matches[3];\n\t\t\t$closeBrace = $matches[5];\n\t\t\t$entityId = $matches[4];\n\t\t\t$properties = !empty($matches[7]) ? json_decode($matches[7]) : false;\n\t\t\tif ($properties) {\n\t\t\t\t$type = null;\n\t\t\t\tif ($openBrace == '(' && $closeBrace == ')') {\n\t\t\t\t\tif (!isset($nodes[$entityId])) {\n\t\t\t\t\t\tthrow new Exception(\"Invalid node reference on line {$lineNum}: $line\");\n\t\t\t\t\t}\n\t\t\t\t\t$entity = $nodes[$entityId];\n\t\t\t\t\t$type = Index::TypeNode;\n\t\t\t\t} else if ($openBrace == '[' && $closeBrace == ']') {\n\t\t\t\t\tif (!isset($rels[$entityId])) {\n\t\t\t\t\t\tthrow new Exception(\"Invalid relationship reference on line {$lineNum}: $line\");\n\t\t\t\t\t}\n\t\t\t\t\t$entity = $rels[$entityId];\n\t\t\t\t\t$type = Index::TypeRelationship;\n\t\t\t\t}\n\n\t\t\t\tif ($type) {\n\t\t\t\t\t$index = new Index($this->client, $type, $name);\n\t\t\t\t\tforeach ($properties as $key => $value) {\n\t\t\t\t\t\t$batch->addToIndex($index, $entity, $key, $value);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Exception(\"Cannot parse line {$lineNum}: $line\");\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Geoff.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Implementation of GEOFF - Graph Export Object File Format\n * From http://py2neo.org/geoff\n * Available at http://github.com/nigelsmall/py2neo\n */\nclass Geoff\n{\n\tprotected $client = null;\n\n\t/**\n\t * Build the importer/exported\n\t *\n\t * @param Client $client\n\t */\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->client = $client;\n\t}\n\n\t/**\n\t * Dump path information to a GEOFF string or file\n\t *\n\t * @param mixed $paths a single Path object or an array of Path objects\n\t * @param stream $handle\n\t * @return mixed stream or string\n\t */\n\tpublic function dump($paths, $handle=null)\n\t{\n\t\t$returnString = false;\n\t\tif (!$handle) {\n\t\t\t$returnString = true;\n\t\t\t$handle = fopen('data:text/plain,', 'w+');\n\t\t}\n\n\t\t$exporter = new Geoff\\Exporter();\n\t\t$exporter->dump($paths, $handle);\n\n\t\tif ($returnString) {\n\t\t\treturn stream_get_contents($handle, -1, 0);\n\t\t}\n\t\treturn $handle;\n\t}\n\n\t/**\n\t * Load a GEOFF string or file\n\t *\n\t * @param mixed $handle\n\t * @param Batch $batch\n\t * @return Batch\n\t */\n\tpublic function load($handle, Batch $batch=null)\n\t{\n\t\tif (is_string($handle)) {\n\t\t\t$handle = fopen('data:text/plain,'.urlencode($handle), 'r');\n\t\t}\n\n\t\t$importer = new Geoff\\Importer($this->client);\n\t\treturn $importer->load($handle, $batch);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Gremlin/Query.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Gremlin;\n\nuse Everyman\\Neo4j;\n\n/**\n * Represents a Gremlin query\n * Query the database using Gremlin syntax. For query syntax, please refer\n * to the Gremlin documentation for your server version.\n *\n * Latest documentation:\n * http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html\n */\nclass Query implements Neo4j\\Query\n{\n\tprotected $client = null;\n\tprotected $script = null;\n\tprotected $vars = array();\n\n\tprotected $result = null;\n\n\t/**\n\t * Set the query script to use\n\t *\n\t * @param Neo4j\\Client $client\n\t * @param string $script A Gremlin query script\n\t * @param array $vars Replacement vars to inject into the query\n\t */\n\tpublic function __construct(Neo4j\\Client $client, $script, $vars=array())\n\t{\n\t\t$this->client = $client;\n\t\t$this->script = $script;\n\t\t$this->vars = $vars;\n\t}\n\n\t/**\n\t * Get the query script\n\t *\n\t * @return string\n\t */\n\tpublic function getQuery()\n\t{\n\t\treturn $this->script;\n\t}\n\n\t/**\n\t * Get the template parameters\n\t *\n\t * @return array\n\t */\n\tpublic function getParameters()\n\t{\n\t\treturn $this->vars;\n\t}\n\n\t/**\n\t * Retrieve the query results\n\t *\n\t * @return Neo4j\\Query\\ResultSet\n\t */\n\tpublic function getResultSet()\n\t{\n\t\tif ($this->result === null) {\n\t\t\t$this->result = $this->client->executeGremlinQuery($this);\n\t\t}\n\n\t\treturn $this->result;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Index/NodeFulltextIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Index;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index\\NodeIndex;\n\n/**\n * Represents a fulltext node index in the database\n */\nclass NodeFulltextIndex extends NodeIndex\n{\n\t/**\n\t * Initialize the index\n\t *\n\t * @param Client $client\n\t * @param string $name\n\t * @param array  $config\n\t */\n\tpublic function __construct(Client $client, $name, $config=array())\n\t{\n\t\tif (empty($config['type'])) {\n\t\t\t$config['type'] = 'fulltext';\n\t\t}\n\t\tif (empty($config['provider'])) {\n\t\t\t$config['provider'] = 'lucene';\n\t\t}\n\n\t\tparent::__construct($client, $name, $config);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Index/NodeIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Index;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index;\n\n/**\n * Represents a node index in the database\n */\nclass NodeIndex extends Index\n{\n\t/**\n\t * Initialize the index\n\t *\n\t * @param Client $client\n\t * @param string $name\n\t * @param array  $config\n\t */\n\tpublic function __construct(Client $client, $name, $config=array())\n\t{\n\t\tparent::__construct($client, Index::TypeNode, $name, $config);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Index/RelationshipIndex.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Index;\n\nuse Everyman\\Neo4j\\Client,\n\tEveryman\\Neo4j\\Index;\n\n/**\n * Represents a relationship index in the database\n */\nclass RelationshipIndex extends Index\n{\n\t/**\n\t * Initialize the index\n\t *\n\t * @param Client $client\n\t * @param string $name\n\t * @param array  $config\n\t */\n\tpublic function __construct(Client $client, $name, $config=array())\n\t{\n\t\tparent::__construct($client, Index::TypeRelationship, $name, $config);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Index.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Represents an index in the database\n */\nclass Index\n{\n\tconst TypeNode = 'node';\n\tconst TypeRelationship = 'relationship';\n\n\tprotected $client = null;\n\tprotected $type = self::TypeNode;\n\tprotected $name = null;\n\tprotected $config = array();\n\n\t/**\n\t * Initialize the index\n\t *\n\t * @param Client $client\n\t * @param string $type\n\t * @param string $name\n\t * @param array  $config\n\t */\n\tpublic function __construct(Client $client, $type, $name, $config=array())\n\t{\n\t\t$this->client = $client;\n\t\t$this->type = $type;\n\t\t$this->name = $name;\n\t\t$this->config = $config;\n\t}\n\n\t/**\n\t * Add an entity to the index\n\t *\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @return boolean\n\t */\n\tpublic function add($entity, $key, $value)\n\t{\n\t\treturn $this->client->addToIndex($this, $entity, $key, $value);\n\t}\n\n\t/**\n\t * Delete this index\n\t *\n\t * @return boolean\n\t */\n\tpublic function delete()\n\t{\n\t\treturn $this->client->deleteIndex($this);\n\t}\n\n\t/**\n\t * Find entities\n\t *\n\t * @param string $key\n\t * @param string $value\n\t * @return array\n\t */\n\tpublic function find($key, $value)\n\t{\n\t\treturn $this->client->searchIndex($this, $key, $value);\n\t}\n\n\t/**\n\t * Find a single entity\n\t *\n\t * @param string $key\n\t * @param string $value\n\t * @return PropertyContainer\n\t */\n\tpublic function findOne($key, $value)\n\t{\n\t\t$entities = $this->client->searchIndex($this, $key, $value);\n\t\treturn $entities ? $entities[0] : null;\n\t}\n\n\t/**\n\t * Get the configuration options for this index\n\t *\n\t * Configuration options are only used during index creation,\n\t * see `save`\n\t *\n\t * @return array\n\t */\n\tpublic function getConfig()\n\t{\n\t\treturn $this->config;\n\t}\n\n\t/**\n\t * Get the index name\n\t *\n\t * @return string\n\t */\n\tpublic function getName()\n\t{\n\t\treturn $this->name;\n\t}\n\n\t/**\n\t * Get the index type\n\t *\n\t * @return string\n\t */\n\tpublic function getType()\n\t{\n\t\treturn $this->type;\n\t}\n\n\t/**\n\t * Query index to find entities\n\t *\n\t * @param string $query\n\t * @return array\n\t */\n\tpublic function query($query)\n\t{\n\t\treturn $this->client->queryIndex($this, $query);\n\t}\n\n\t/**\n\t * Query index to find a single entity\n\t *\n\t * @param string $query\n\t * @return PropertyContainer\n\t */\n\tpublic function queryOne($query)\n\t{\n\t\t$entities = $this->client->queryIndex($this, $query);\n\t\treturn $entities ? $entities[0] : null;\n\t}\n\n\t/**\n\t * Remove an entity from the index\n\t * If $value is not given, all reference of the entity for the key\n\t * are removed.\n\t * If $key is not given, all reference of the entity are removed.\n\t *\n\t * @param PropertyContainer $entity\n\t * @param string $key\n\t * @param string $value\n\t * @return boolean\n\t */\n\tpublic function remove($entity, $key=null, $value=null)\n\t{\n\t\treturn $this->client->removeFromIndex($this, $entity, $key, $value);\n\t}\n\n\t/**\n\t * Save this index\n\t *\n\t * @return boolean\n\t */\n\tpublic function save()\n\t{\n\t\treturn $this->client->saveIndex($this);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Label.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Represents a single label\n *\n * Labels cannot be saved standalone; instead, they are\n * saved when attached to a node\n */\nclass Label\n{\n\t/**\n\t * @var Client Our client\n\t */\n\tprotected $client;\n\t/**\n\t * @var string Our name\n\t */\n\tprotected $name;\n\n\t/**\n\t * Build the label and set its client and name\n\t *\n\t * @param Client $client\n\t * @param string $name\n\t * @throws \\InvalidArgumentException\n\t */\n\tpublic function __construct(Client $client, $name)\n\t{\n\t\tif (empty($name) || !(is_string($name) || is_numeric($name))) {\n\t\t\tthrow new \\InvalidArgumentException(\"Label name must be a string or number\");\n\t\t}\n\n\t\t$this->setClient($client);\n\t\t$this->name = (string)$name;\n\t}\n\n\t/**\n\t * Set the client to use with this Label object\n\t *\n\t * @param Client $client\n\t * @return Label\n\t */\n\tpublic function setClient(Client $client)\n\t{\n\t\t$this->client = $client;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Get our client\n\t *\n\t * @return Client\n\t */\n\tpublic function getClient()\n\t{\n\t\treturn $this->client;\n\t}\n\n\t/**\n\t * Return the label name\n\t *\n\t * @return string\n\t */\n\tpublic function getName()\n\t{\n\t\treturn $this->name;\n\t}\n\n\t/**\n\t * Get the nodes with this label\n\t *\n\t * If a property and value are given, only return\n\t * nodes where the given property equals the value\n\t *\n\t * @param string $propertyName\n\t * @param mixed  $propertyValue\n\t * @return Query\\Row\n\t * @throws Exception on failure\n\t */\n\tpublic function getNodes($propertyName=null, $propertyValue=null)\n\t{\n\t\treturn $this->client->getNodesForLabel($this, $propertyName, $propertyValue);\n\t}\n\n\t/**\n\t * Only serialize our name property\n\t *\n\t * @return array\n\t */\n\tpublic function __sleep()\n\t{\n\t\treturn array('name');\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Node.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Represents a single node in the database\n */\nclass Node extends PropertyContainer\n{\n\t/**\n\t * @var Label[] Our labels, or `null` if not loaded\n\t */\n\tprotected $labels = null;\n\n\n\t/**\n\t * @inheritdoc\n\t * @param Client $client\n\t * @return Node\n\t */\n\tpublic function setClient(Client $client)\n\t{\n\t\tparent::setClient($client);\n\t\t// set the client of each label in case it's not set yet\n\t\tif ($this->labels) {\n\t\t\tforeach ($this->labels as $label) {\n\t\t\t\tif (!$label->getClient()) {\n\t\t\t\t\t$label->setClient($client);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Add labels to this node\n\t *\n\t * @param array $labels\n\t * @return array of all the Labels on this node, including those just added\n\t */\n\tpublic function addLabels($labels)\n\t{\n\t\t$this->labels = $this->client->addLabels($this, $labels);\n\t\treturn $this->labels;\n\t}\n\n\t/**\n\t * Delete this node\n\t *\n\t * @return PropertyContainer\n\t * @throws Exception on failure\n\t */\n\tpublic function delete()\n\t{\n\t\t$this->client->deleteNode($this);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Find paths from this node to the given node\n\t *\n\t * @param Node $to\n\t * @param string $type\n\t * @param string $dir\n\t * @return PathFinder\n\t */\n\tpublic function findPathsTo(Node $to, $type=null, $dir=null)\n\t{\n\t\t$finder = new PathFinder($this->client);\n\t\t$finder->setStartNode($this);\n\t\t$finder->setEndNode($to);\n\t\tif ($dir) {\n\t\t\t$finder->setDirection($dir);\n\t\t}\n\n\t\tif ($type) {\n\t\t\t$finder->setType($type);\n\t\t}\n\n\t\treturn $finder;\n\t}\n\n\t/**\n\t * Get the first relationship of this node that matches the given criteria\n\t *\n\t * @param mixed  $types string or array of strings\n\t * @param string $dir\n\t * @return Relationship\n\t */\n\tpublic function getFirstRelationship($types=array(), $dir=null)\n\t{\n\t\t$rels = $this->client->getNodeRelationships($this, $types, $dir);\n\t\tif (count($rels) < 1) {\n\t\t\treturn null;\n\t\t}\n\t\treturn $rels[0];\n\t}\n\n\t/**\n\t * Get relationships of this node\n\t *\n\t * @param mixed  $types string or array of strings\n\t * @param string $dir\n\t * @return array of Relationship\n\t */\n\tpublic function getRelationships($types=array(), $dir=null)\n\t{\n\t\treturn $this->client->getNodeRelationships($this, $types, $dir);\n\t}\n\n\t/**\n\t * List labels for this node\n\t *\n\t * @return array\n\t * @throws Exception on failure\n\t */\n\tpublic function getLabels()\n\t{\n\t\tif (is_null($this->labels)) {\n\t\t\t$this->labels = $this->client->getLabels($this);\n\t\t}\n\t\treturn $this->labels;\n\t}\n\n\t/**\n\t * Load this node\n\t *\n\t * @return PropertyContainer\n\t * @throws Exception on failure\n\t */\n\tpublic function load()\n\t{\n\t\t$this->client->loadNode($this);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Make a new relationship\n\t *\n\t * @param Node $to\n\t * @param string $type\n\t * @return Relationship\n\t */\n\tpublic function relateTo(Node $to, $type)\n\t{\n\t\t$rel = $this->client->makeRelationship();\n\t\t$rel->setStartNode($this);\n\t\t$rel->setEndNode($to);\n\t\t$rel->setType($type);\n\n\t\treturn $rel;\n\t}\n\n\t/**\n\t * Remove labels from this node\n\t *\n\t * @param array $labels\n\t * @return array of all the Labels on this node, after removing the given labels\n\t */\n\tpublic function removeLabels($labels)\n\t{\n\t\t$this->labels = $this->client->removeLabels($this, $labels);\n\t\treturn $this->labels;\n\t}\n\n\t/**\n\t * Save this node\n\t *\n\t * @return PropertyContainer\n\t * @throws Exception on failure\n\t */\n\tpublic function save()\n\t{\n\t\t$this->client->saveNode($this);\n\t\t$this->useLazyLoad(false);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Be sure to add our properties to the things to serialize\n\t *\n\t * @return array\n\t */\n\tpublic function __sleep()\n\t{\n\t\treturn array_merge(parent::__sleep(), array('labels'));\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Pager.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Holds the parameters for running a paged traversal\n */\nclass Pager\n{\n\tprotected $traversal = null;\n\tprotected $startNode = null;\n\tprotected $returnType = null;\n\n\tprotected $id = null;\n\tprotected $leaseTime = null;\n\tprotected $pageSize = null;\n\n\t/**\n\t * Set the traversal to paginate\n\t *\n\t * @param Traversal $traversal\n\t * @param Node $startNode\n\t * @param string $returnType\n\t */\n\tpublic function __construct(Traversal $traversal, Node $startNode, $returnType)\n\t{\n\t\t$this->traversal = $traversal;\n\t\t$this->startNode = $startNode;\n\t\t$this->returnType = $returnType;\n\t}\n\n\t/**\n\t * Get the paged traversal id\n\t *\n\t * @return string\n\t */\n\tpublic function getId()\n\t{\n\t\treturn $this->id;\n\t}\n\n\t/**\n\t * Get the lease time, in secods\n\t *\n\t * @return integer\n\t */\n\tpublic function getLeaseTime()\n\t{\n\t\treturn $this->leaseTime;\n\t}\n\n\t/**\n\t * Get the next page of results\n\t * If the traversal hasn't been run yet, this will run it\n\t *\n\t * @return array\n\t */\n\tpublic function getNextResults()\n\t{\n\t\treturn $this->traversal->getClient()->executePagedTraversal($this);\n\t}\n\n\t/**\n\t * Get the maximum result page set size\n\t *\n\t * @return integer\n\t */\n\tpublic function getPageSize()\n\t{\n\t\treturn $this->pageSize;\n\t}\n\n\t/**\n\t * Get the return type\n\t *\n\t * @return string\n\t */\n\tpublic function getReturnType()\n\t{\n\t\treturn $this->returnType;\n\t}\n\n\t/**\n\t * Return the start node of the traversal\n\t *\n\t * @return Node\n\t */\n\tpublic function getStartNode()\n\t{\n\t\treturn $this->startNode;\n\t}\n\n\t/**\n\t * Get the traversal being paginated\n\t *\n\t * @return Traversal\n\t */\n\tpublic function getTraversal()\n\t{\n\t\treturn $this->traversal;\n\t}\n\n\t/**\n\t * Set the paged traversal id\n\t *\n\t * @param string $id\n\t * @return Traversal\n\t */\n\tpublic function setId($id)\n\t{\n\t\t$this->id = $id;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the lease time\n\t *\n\t * @param integer $leaseTime\n\t * @return Traversal\n\t */\n\tpublic function setLeaseTime($leaseTime)\n\t{\n\t\t$this->leaseTime = $leaseTime;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the page size\n\t *\n\t * @param integer $pageSize\n\t * @return Traversal\n\t */\n\tpublic function setPageSize($pageSize)\n\t{\n\t\t$this->pageSize = $pageSize;\n\t\treturn $this;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Path.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Represents collection of relationships joining two nodes\n */\nclass Path implements \\Countable, \\IteratorAggregate\n{\n\tconst ContextNode = 'node';\n\tconst ContextRelationship = 'relationship';\n\n\tprotected $relationships = array();\n\tprotected $nodes = array();\n\tprotected $context = self::ContextNode;\n\n\t/**\n\t * Add another node to the end of this path\n\t *\n\t * @param Node $node\n\t * @return Path\n\t */\n\tpublic function appendNode(Node $node)\n\t{\n\t\t$this->nodes[] = $node;\n\t}\n\n\t/**\n\t * Add another relationship to the end of this path\n\t *\n\t * @param Relationship $rel\n\t * @return Path\n\t */\n\tpublic function appendRelationship(Relationship $rel)\n\t{\n\t\t$this->relationships[] = $rel;\n\t}\n\n\t/**\n\t * Get the number of relationships in this path\n\t *\n\t * @return integer\n\t */\n\tpublic function count()\n\t{\n\t\treturn $this->context == self::ContextNode ? count($this->nodes) : count($this->relationships);\n\t}\n\n\t/**\n\t * Get the current context for iteration\n\t *\n\t * @return string\n\t */\n\tpublic function getContext()\n\t{\n\t\treturn $this->context;\n\t}\n\n\t/**\n\t * Get the end node\n\t *\n\t * @return Node\n\t */\n\tpublic function getEndNode()\n\t{\n\t\t$length = count($this->nodes);\n\t\tif ($length) {\n\t\t\treturn $this->nodes[$length-1];\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Get the number of relationships in this path\n\t *\n\t * @return integer\n\t */\n\tpublic function getLength()\n\t{\n\t\treturn $this->count();\n\t}\n\n\t/**\n\t * Return an iterator for iterating through the path\n\t *\n\t * @return Iterator\n\t */\n\tpublic function getIterator()\n\t{\n\t\treturn $this->context == self::ContextNode\n\t\t\t? new \\ArrayIterator($this->nodes)\n\t\t\t\t: new \\ArrayIterator($this->relationships);\n\t}\n\n\t/**\n\t * Get the list of nodes that make up this path\n\t *\n\t * @return array\n\t */\n\tpublic function getNodes()\n\t{\n\t\treturn $this->nodes;\n\t}\n\n\t/**\n\t * Get the list of relationships that make up this path\n\t *\n\t * @return array\n\t */\n\tpublic function getRelationships()\n\t{\n\t\treturn $this->relationships;\n\t}\n\n\t/**\n\t * Get the start node\n\t *\n\t * @return Node\n\t */\n\tpublic function getStartNode()\n\t{\n\t\t$length = count($this->nodes);\n\t\tif ($length) {\n\t\t\treturn $this->nodes[0];\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Set the context for iteration\n\t *\n\t * @param string $context\n\t * @return Path\n\t */\n\tpublic function setContext($context)\n\t{\n\t\tif ($context != self::ContextNode && $context != self::ContextRelationship) {\n\t\t\t$context = self::ContextNode;\n\t\t}\n\t\t$this->context = $context;\n\t\treturn $this;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/PathFinder.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Holds the parameters for finding a path between two nodes\n */\nclass PathFinder\n{\n\tconst AlgoShortest  = 'shortestPath';\n\tconst AlgoAll       = 'allPaths';\n\tconst AlgoAllSimple = 'allSimplePaths';\n\tconst AlgoDijkstra  = 'dijkstra';\n\n\tprotected $client = null;\n\n\tprotected $start = null;\n\tprotected $end = null;\n\tprotected $type = null;\n\tprotected $maxDepth = null;\n\tprotected $dir = null;\n\tprotected $algo = self::AlgoShortest;\n\tprotected $costProperty = null;\n\tprotected $defaultCost = null;\n\n\t/**\n\t * Build the finder and set its client\n\t *\n\t * @param Client $client\n\t */\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->client = $client;\n\t}\n\n\t/**\n\t * Get the current path finding algorithm\n\t *\n\t * @return string\n\t */\n\tpublic function getAlgorithm()\n\t{\n\t\treturn $this->algo;\n\t}\n\n\t/**\n\t * Get the finder's client\n\t *\n\t * @return Client\n\t */\n\tpublic function getClient()\n\t{\n\t\treturn $this->client;\n\t}\n\n\t/**\n\t * Get the cost property name for the Dijkstra search\n\t *\n\t * @return string\n\t */\n\tpublic function getCostProperty()\n\t{\n\t\treturn $this->costProperty;\n\t}\n\n\t/**\n\t * Get the default relationship cost for the Dijkstra search\n\t *\n\t * @return numeric\n\t */\n\tpublic function getDefaultCost()\n\t{\n\t\treturn $this->defaultCost;\n\t}\n\n\t/**\n\t * Get the path direction type\n\t *\n\t * @return string\n\t */\n\tpublic function getDirection()\n\t{\n\t\treturn $this->dir;\n\t}\n\n\t/**\n\t * Get the end node\n\t *\n\t * @return Node\n\t */\n\tpublic function getEndNode()\n\t{\n\t\treturn $this->end;\n\t}\n\n\t/**\n\t * Get the maximum allowed path length\n\t *\n\t * @return integer\n\t */\n\tpublic function getMaxDepth()\n\t{\n\t\treturn $this->maxDepth;\n\t}\n\n\t/**\n\t * Find paths\n\t *\n\t * @return array of Path\n\t */\n\tpublic function getPaths()\n\t{\n\t\treturn $this->client->getPaths($this);\n\t}\n\n\t/**\n\t * Get a single path\n\t *\n\t * @return Path\n\t */\n\tpublic function getSinglePath()\n\t{\n\t\t$paths = $this->getPaths();\n\t\treturn $paths ? $paths[0] : null;\n\t}\n\n\t/**\n\t * Get the start node\n\t *\n\t * @return Node\n\t */\n\tpublic function getStartNode()\n\t{\n\t\treturn $this->start;\n\t}\n\n\t/**\n\t * Get the relationship type\n\t *\n\t * @return string\n\t */\n\tpublic function getType()\n\t{\n\t\treturn $this->type;\n\t}\n\n\t/**\n\t * Set the algorithm to use\n\t *\n\t * @param string $algo\n\t * @return PathFinder\n\t */\n\tpublic function setAlgorithm($algo)\n\t{\n\t\t$this->algo = $algo;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the cost property name for the Dijkstra search\n\t *\n\t * @param string $property\n\t * @return PathFinder\n\t */\n\tpublic function setCostProperty($property)\n\t{\n\t\t$this->costProperty = $property;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the default relationship cost for the Dijkstra search\n\t *\n\t * @param numeric $cost\n\t * @return PathFinder\n\t */\n\tpublic function setDefaultCost($cost)\n\t{\n\t\t$this->defaultCost = $cost;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the direction of the path\n\t *\n\t * @param string $dir\n\t * @return PathFinder\n\t */\n\tpublic function setDirection($dir)\n\t{\n\t\t$this->dir = $dir;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the end node\n\t *\n\t * @param Node $end\n\t * @return PathFinder\n\t */\n\tpublic function setEndNode(Node $end)\n\t{\n\t\t$this->end = $end;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the maximum allowed path length\n\t *\n\t * @param integer $max\n\t * @return PathFinder\n\t */\n\tpublic function setMaxDepth($max)\n\t{\n\t\t$this->maxDepth = $max;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the start node\n\t *\n\t * @param Node $start\n\t * @return PathFinder\n\t */\n\tpublic function setStartNode(Node $start)\n\t{\n\t\t$this->start = $start;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the type\n\t *\n\t * @param string $type\n\t * @return PathFinder\n\t */\n\tpublic function setType($type)\n\t{\n\t\t$this->type = $type;\n\t\treturn $this;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/PropertyContainer.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Represents an entity that is a collection of properties\n */\nabstract class PropertyContainer\n{\n\t/**\n\t * @var int our ID\n\t */\n\tprotected $id = null;\n\t/**\n\t * @var Client Our client\n\t */\n\tprotected $client = null;\n\t/**\n\t * @var array Our properties\n\t */\n\tprotected $properties = array();\n\n\t/**\n\t * @var bool Are we in lazy load mode?\n\t */\n\tprotected $lazyLoad = true;\n\t/**\n\t * @var bool Are we loaded?\n\t */\n\tprotected $loaded = false;\n\n\t/**\n\t * Build the container and set its client\n\t *\n\t * @param Client $client\n\t */\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->setClient($client);\n\t}\n\n\tpublic function __get($key)\n\t{\n\t\treturn $this->getProperty($key);\n\t}\n\n\tpublic function __set($key, $value)\n\t{\n\t\t$this->setProperty($key, $value);\n\t}\n\n\tpublic function __unset($key)\n\t{\n\t\t$this->removeProperty($key);\n\t}\n\n\tpublic function __isset($key)\n\t{\n\t\treturn array_key_exists($key, $this->properties);\n\t}\n\n\tpublic function __sleep()\n\t{\n\t\treturn array('id', 'properties', 'lazyLoad', 'loaded');\n\t}\n\n\t/**\n\t * Delete this entity\n\t *\n\t * @return PropertyContainer\n\t * @throws Exception on failure\n\t */\n\tabstract public function delete();\n\n\t/**\n\t * Load this entity\n\t *\n\t * @return PropertyContainer\n\t * @throws Exception on failure\n\t */\n\tabstract public function load();\n\n\t/**\n\t * Save this entity\n\t *\n\t * @return PropertyContainer\n\t * @throws Exception on failure\n\t */\n\tabstract public function save();\n\n\t/**\n\t * Get the entity's client\n\t *\n\t * @return Client\n\t */\n\tpublic function getClient()\n\t{\n\t\treturn $this->client;\n\t}\n\n\t/**\n\t * Get the entity's id\n\t *\n\t * @return integer\n\t */\n\tpublic function getId()\n\t{\n\t\treturn $this->id;\n\t}\n\n\t/**\n\t * Return all properties\n\t *\n\t * @return array\n\t */\n\tpublic function getProperties()\n\t{\n\t\t$this->loadProperties();\n\t\treturn $this->properties;\n\t}\n\n\t/**\n\t * Return the named property\n\t *\n\t * @param string $property\n\t * @return mixed\n\t */\n\tpublic function getProperty($property)\n\t{\n\t\t$this->loadProperties();\n\t\treturn (isset($this->properties[$property])) ? $this->properties[$property] : null;\n\t}\n\n\t/**\n\t * Is this entity identified?\n\t *\n\t * @return boolean\n\t */\n\tpublic function hasId()\n\t{\n\t\treturn $this->getId() !== null;\n\t}\n\n\t/**\n\t * Remove a property set on the entity\n\t *\n\t * @param string $property\n\t * @return PropertyContainer\n\t */\n\tpublic function removeProperty($property)\n\t{\n\t\t$this->loadProperties();\n\t\tunset($this->properties[$property]);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the entity's client\n\t *\n\t * @param Client $client\n\t * @return PropertyContainer\n\t */\n\tpublic function setClient(Client $client)\n\t{\n\t\t$this->client = $client;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the entity's id\n\t *\n\t * @param integer $id\n\t * @return PropertyContainer\n\t */\n\tpublic function setId($id)\n\t{\n\t\t$this->id = $id === null ? null : (int)$id;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set multiple properties on the entity\n\t *\n\t * @param array $properties\n\t * @return PropertyContainer\n\t */\n\tpublic function setProperties($properties)\n\t{\n\t\t$this->loadProperties();\n\t\tforeach ($properties as $property => $value) {\n\t\t\t$this->setProperty($property, $value);\n\t\t}\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set a property on the entity\n\t *\n\t * @param string $property\n\t * @param mixed $value\n\t * @return PropertyContainer\n\t */\n\tpublic function setProperty($property, $value)\n\t{\n\t\t$this->loadProperties();\n\t\tif ($value === null) {\n\t\t\t$this->removeProperty($property);\n\t\t} else {\n\t\t\t$this->properties[$property] = $value;\n\t\t}\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Should this entity be lazy-loaded if necessary?\n\t *\n\t * @param boolean $lazyLoad\n\t * @return PropertyContainer\n\t */\n\tpublic function useLazyLoad($lazyLoad)\n\t{\n\t\t$this->lazyLoad = (bool)$lazyLoad;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set up the properties array the first time we need it\n\t *\n\t * This includes loading the properties from the server\n\t * if we can get them.\n\t */\n\tprotected function loadProperties()\n\t{\n\t\tif ($this->hasId() && $this->lazyLoad && !$this->loaded) {\n\t\t\t$this->loaded = true;\n\t\t\t$this->load();\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Query/ResultSet.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Query;\n\nuse Everyman\\Neo4j\\Client;\n\n/**\n * This is what you get when you execute a query. Looping\n * over this will give you {@link Row} instances.\n */\nclass ResultSet implements \\Iterator, \\Countable, \\ArrayAccess\n{\n\tprotected $client = null;\n\n\tprotected $rows = array();\n\tprotected $data = array();\n\tprotected $columns = array();\n\tprotected $position = 0;\n\n\t/**\n\t * Set the array of results to represent\n\t *\n\t * @param Client $client\n\t * @param array $result\n\t */\n\tpublic function __construct(Client $client, $result)\n\t{\n\t\t$this->client = $client;\n\t\tif (is_array($result) && array_key_exists('data', $result)) {\n\t\t\t$this->data = $result['data'];\n\t\t\t$this->columns = $result['columns'];\n\t\t}\n\t}\n\n\t/**\n\t * Return the list of column names\n\t *\n\t * @return array\n\t */\n\tpublic function getColumns()\n\t{\n\t\treturn $this->columns;\n\t}\n\n\t// ArrayAccess API\n\n\tpublic function offsetExists($offset)\n\t{\n\t\treturn isset($this->data[$offset]);\n\t}\n\n\tpublic function offsetGet($offset)\n\t{\n\t\tif (!isset($this->rows[$offset])) {\n\t\t\t$this->rows[$offset] = new Row($this->client, $this->columns, $this->data[$offset]);\n\t\t}\n\t\treturn $this->rows[$offset];\n\t}\n\n\tpublic function offsetSet($offset, $value)\n\t{\n\t\tthrow new \\BadMethodCallException(\"You cannot modify a query result.\");\n\t}\n\n\tpublic function offsetUnset($offset)\n\t{\n\t\tthrow new \\BadMethodCallException(\"You cannot modify a query result.\");\n\t}\n\n\n\t// Countable API\n\n\tpublic function count()\n\t{\n\t\treturn count($this->data);\n\t}\n\n\n\t// Iterator API\n\n\tpublic function rewind()\n\t{\n\t\t$this->position = 0;\n\t}\n\n\tpublic function current()\n\t{\n\t\treturn $this[$this->position];\n\t}\n\n\tpublic function key()\n\t{\n\t\treturn $this->position;\n\t}\n\n\tpublic function next()\n\t{\n\t\t++$this->position;\n\t}\n\n\tpublic function valid()\n\t{\n\t\treturn isset($this->data[$this->position]);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Query/Row.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Query;\n\nuse Everyman\\Neo4j\\Client;\n\n/**\n * Represents a single result row from a query.\n * You can loop over this to get each value, or you can\n * use array access ($myRow['columnName'] or $myRow[0])\n * to get specific fields.\n */\nclass Row implements \\Iterator, \\Countable, \\ArrayAccess\n{\n\tprotected $client = null;\n\tprotected $raw = null;\n\tprotected $data = null;\n\tprotected $columns = null;\n\tprotected $position = 0;\n\n\t/**\n\t * Set the raw result data of this row\n\t *\n\t * @param Client $client\n\t * @param array $columns\n\t * @param array $rowData\n\t */\n\tpublic function __construct(Client $client, $columns, $rowData)\n\t{\n\t\t$this->client = $client;\n\t\t$this->raw = $rowData;\n\t\t$this->data = array();\n\t\t$this->columns = $columns;\n\t}\n\n\t// ArrayAccess API\n\n\tpublic function offsetExists($offset)\n\t{\n\t\tif (!is_integer($offset)) {\n\n\t\t\t$rawOffset = array_search($offset, $this->columns);\n\n\t\t\tif ($rawOffset === false) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn isset($this->raw[$rawOffset]);\n\t\t}\n\n\t\treturn isset($this->raw[$offset]);\n\t}\n\n\tpublic function offsetGet($offset)\n\t{\n\t\tif (!is_integer($offset)) {\n\t\t\t$offset = array_search($offset, $this->columns);\n\t\t}\n\n\t\tif (!isset($this->data[$offset])) {\n\t\t\t$raw = $this->raw[$offset];\n\t\t\t$data = $this->client->getEntityMapper()->getEntityFor($raw);\n\t\t\tif (is_array($data)) {\n\t\t\t\t$data = new Row($this->client, array_keys($raw), array_values($raw));\n\t\t\t}\n\t\t\t$this->data[$offset] = $data;\n\t\t}\n\n\t\treturn $this->data[$offset];\n\t}\n\n\tpublic function offsetSet($offset, $value)\n\t{\n\t\tthrow new \\BadMethodCallException(\"You cannot modify a result row.\");\n\t}\n\n\tpublic function offsetUnset($offset)\n\t{\n\t\tthrow new \\BadMethodCallException(\"You cannot modify a result row.\");\n\t}\n\n\n\t// Countable API\n\n\tpublic function count()\n\t{\n\t\treturn count($this->raw);\n\t}\n\n\n\t// Iterator API\n\n\tpublic function rewind()\n\t{\n\t\t$this->position = 0;\n\t}\n\n\tpublic function current()\n\t{\n\t\treturn $this[$this->position];\n\t}\n\n\tpublic function key()\n\t{\n\t\treturn $this->columns[$this->position];\n\t}\n\n\tpublic function next()\n\t{\n\t\t++$this->position;\n\t}\n\n\tpublic function valid()\n\t{\n\t\treturn $this->position < count($this->raw);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Query.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Represents a query (e. g. Gremlin or Cypher)\n */\ninterface Query\n{\n\t/**\n\t * Get the query script\n\t *\n\t * @return string\n\t */\n\tpublic function getQuery();\n\n\t/**\n\t * Retrieve the query results\n\t *\n\t * @return Query\\ResultSet\n\t */\n\tpublic function getResultSet();\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Relationship.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Represents a relationship between two nodes\n */\nclass Relationship extends PropertyContainer\n{\n\tconst DirectionAll       = 'all';\n\tconst DirectionIn        = 'in';\n\tconst DirectionOut       = 'out';\n\n\t/**\n\t * @var Node Our start node\n\t */\n\tprotected $start = null;\n\t/**\n\t * @var Node Our end node\n\t */\n\tprotected $end = null;\n\t/**\n\t * @var string Our type\n\t */\n\tprotected $type = null;\n\n\n\t/**\n\t * @inheritdoc\n\t * @param Client $client\n\t * @return Relationship\n\t */\n\tpublic function setClient(Client $client)\n\t{\n\t\tparent::setClient($client);\n\t\t// set the client of our start and end nodes if they exists and doesn't have client yet\n\t\tif ($this->start && !$this->start->getClient()) {\n\t\t\t$this->start->setClient($client);\n\t\t}\n\t\tif ($this->end && !$this->end->getClient()) {\n\t\t\t$this->end->setClient($client);\n\t\t}\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Delete this relationship\n\t *\n\t * @return PropertyContainer\n\t * @throws Exception on failure\n\t */\n\tpublic function delete()\n\t{\n\t\t$this->client->deleteRelationship($this);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Get the end node\n\t *\n\t * @return Node\n\t */\n\tpublic function getEndNode()\n\t{\n\t\tif (null === $this->end) {\n\t\t\t$this->loadProperties();\n\t\t}\n\t\treturn $this->end;\n\t}\n\n\t/**\n\t * Get the start node\n\t *\n\t * @return Node\n\t */\n\tpublic function getStartNode()\n\t{\n\t\tif (null === $this->start) {\n\t\t\t$this->loadProperties();\n\t\t}\n\t\treturn $this->start;\n\t}\n\n\t/**\n\t * Get the relationship type\n\t *\n\t * @return string\n\t */\n\tpublic function getType()\n\t{\n\t\t$this->loadProperties();\n\t\treturn $this->type;\n\t}\n\n\t/**\n\t * Load this relationship\n\t *\n\t * @return PropertyContainer\n\t * @throws Exception on failure\n\t */\n\tpublic function load()\n\t{\n\t\t$this->client->loadRelationship($this);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Save this node\n\t *\n\t * @return PropertyContainer\n\t * @throws Exception on failure\n\t */\n\tpublic function save()\n\t{\n\t\t$this->client->saveRelationship($this);\n\t\t$this->useLazyLoad(false);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the end node\n\t *\n\t * @param Node $end\n\t * @return Relationship\n\t */\n\tpublic function setEndNode(Node $end)\n\t{\n\t\t$this->end = $end;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the start node\n\t *\n\t * @param Node $start\n\t * @return Relationship\n\t */\n\tpublic function setStartNode(Node $start)\n\t{\n\t\t$this->start = $start;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the type\n\t *\n\t * @param string $type\n\t * @return Relationship\n\t */\n\tpublic function setType($type)\n\t{\n\t\t$this->type = $type;\n\t\treturn $this;\n\t}\n\n\n\t/**\n\t * Be sure to add our properties to the things to serialize\n\t *\n\t * @return array\n\t */\n\tpublic function __sleep()\n\t{\n\t\treturn array_merge(parent::__sleep(), array('start', 'end', 'type'));\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Transaction.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * A transaction context for multiple Cypher statements across multiple requests\n */\nclass Transaction\n{\n\tprotected $client;\n\tprotected $id;\n\tprotected $isClosed = false;\n\tprotected $isError = false;\n\n\t/**\n\t * Build the transaction and set its client\n\t *\n\t * @param Client $client\n\t */\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->client = $client;\n\t}\n\n\t/**\n\t * Add statements to this transaction\n\t *\n\t * @param mixed   $statements a single or list of Cypher\\Query objects to add to the transaction\n\t * @param boolean $commit should this transaction be committed with these statements?\n\t * @return Query\\ResultSet\n\t */\n\tpublic function addStatements($statements, $commit=false)\n\t{\n\t\t$unwrap = false;\n\t\tif (!is_array($statements)) {\n\t\t\t$statements = array($statements);\n\t\t\t$unwrap = true;\n\t\t}\n\n\t\t$result = $this->performClientAction(function ($client, $transaction) use ($statements, $commit) {\n\t\t\treturn $client->addStatementsToTransaction($transaction, $statements, $commit);\n\t\t}, $commit, false);\n\n\t\tif ($unwrap) {\n\t\t\t$result = reset($result);\n\t\t}\n\n\t\treturn $result;\n\t}\n\n\t/**\n\t * Commit this transaction immediately, without adding any new statements\n\t *\n\t * @return Transaction\n\t */\n\tpublic function commit()\n\t{\n\t\t$this->performClientAction(function ($client, $transaction) {\n\t\t\t$client->addStatementsToTransaction($transaction, array(), true);\n\t\t}, true);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Return the transaction id\n\t *\n\t * @return integer\n\t */\n\tpublic function getId()\n\t{\n\t\treturn $this->id;\n\t}\n\n\t/**\n\t * Has this transaction been closed?\n\t *\n\t * @return boolean\n\t */\n\tpublic function isClosed()\n\t{\n\t\treturn $this->isClosed;\n\t}\n\n\t/**\n\t * Has this transaction experienced an error?\n\t *\n\t * @return boolean\n\t */\n\tpublic function isError()\n\t{\n\t\treturn $this->isError;\n\t}\n\n\t/**\n\t * Ask for more time to keep this transaction open\n\t *\n\t * @return Transaction\n\t */\n\tpublic function keepAlive()\n\t{\n\t\t$this->performClientAction(function ($client, $transaction) {\n\t\t\t$client->addStatementsToTransaction($transaction);\n\t\t}, false);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Rollback the transaction\n\t *\n\t * @return Transaction\n\t */\n\tpublic function rollback()\n\t{\n\t\t$this->performClientAction(function ($client, $transaction) {\n\t\t\t$client->rollbackTransaction($transaction);\n\t\t}, true);\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the transaction id\n\t *\n\t * Once an id has been set, the same id can be set again.\n\t * Attempting to set a different id will throw an InvalidArgumentException.\n\t *\n\t * @param integer $id\n\t * @return Transaction\n\t * @throws InvalidArgumentException if an id is given that is different from the existing id\n\t */\n\tpublic function setId($id)\n\t{\n\t\tif ($this->id && $this->id != $id) {\n\t\t\tthrow new \\InvalidArgumentException(\"Cannot set a new id on a transaction once an id has been set\");\n\t\t}\n\n\t\t$this->id = $id;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Perform an action against the client\n\t *\n\t * @param callable $action\n\t * @param boolean  $shouldClose\n\t * @param boolean  $requireId\n\t */\n\tprotected function performClientAction($action, $shouldClose, $requireId=true)\n\t{\n\t\tif ($this->isClosed()) {\n\t\t\tthrow new Exception('Transaction is already closed');\n\t\t}\n\n\t\t$result = null;\n\t\tif (!$requireId || $this->getId()) {\n\t\t\ttry {\n\t\t\t\t$result = $action($this->client, $this);\n\t\t\t} catch (\\Exception $e) {\n\t\t\t\t$this->isClosed = true;\n\t\t\t\t$this->isError = true;\n\t\t\t\tthrow $e;\n\t\t\t}\n\t\t}\n\n\t\t$this->isClosed = $shouldClose;\n\n\t\treturn $result;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Transport/Curl.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Transport;\n\nuse Everyman\\Neo4j\\Transport as BaseTransport,\n\tEveryman\\Neo4j\\Version,\n\tEveryman\\Neo4j\\Exception;\n\n/**\n * Class for communicating with an HTTP JSON endpoint\n */\nclass Curl extends BaseTransport\n{\n\tprotected $handle = null;\n\n\t/**\n\t * @inherit\n\t */\n\tpublic function __construct($host='localhost', $port=7474)\n\t{\n\t\tif (! function_exists('curl_init')) {\n\t\t\tthrow new Exception('cUrl extension not enabled/installed');\n\t\t}\n\n\t\tparent::__construct($host, $port);\n\t}\n\n\t/**\n\t * Make sure the curl handle closes when we are done with the Transport\n\t */\n\tpublic function __destruct()\n\t{\n\t\tif ($this->handle) {\n\t\t\tcurl_close($this->handle);\n\t\t}\n\t}\n\n\t/**\n\t * @inherit\n\t */\n\tpublic function makeRequest($method, $path, $data=array())\n\t{\n\t\t$url = $this->getEndpoint().$path;\n\n\t\t$options = array(\n\t\t\tCURLOPT_URL => $url,\n\t\t\tCURLOPT_RETURNTRANSFER => true,\n\t\t\tCURLOPT_HEADER => true,\n\t\t\tCURLOPT_HTTPHEADER => array(\n\t\t\t\t'Accept: application/json;stream=true',\n\t\t\t\t'Content-type: application/json',\n\t\t\t\t'User-Agent: '.Version::userAgent(),\n\t\t\t\t'X-Stream: true'\n\t\t\t),\n\t\t\tCURLOPT_CUSTOMREQUEST => self::GET,\n\t\t\tCURLOPT_POST => false,\n\t\t\tCURLOPT_POSTFIELDS => null,\n\t\t\tCURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,\n\t\t);\n\n\t\tif ($this->username && $this->password) {\n\t\t\t$options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;\n\t\t\t$options[CURLOPT_USERPWD] = $this->username.':'.$this->password;\n\t\t}\n\n\t\tswitch ($method) {\n\t\t\tcase self::DELETE:\n\t\t\t\t$options[CURLOPT_CUSTOMREQUEST] = self::DELETE;\n\t\t\t\tbreak;\n\n\t\t\tcase self::POST:\n\t\t\tcase self::PUT:\n\t\t\t\t$dataString = $this->encodeData($data);\n\t\t\t\t$options[CURLOPT_CUSTOMREQUEST] = $method;\n\t\t\t\t$options[CURLOPT_POSTFIELDS] = $dataString;\n\t\t\t\t$options[CURLOPT_HTTPHEADER][] = 'Content-Length: '.strlen($dataString);\n\n\t\t\t\tif (self::POST == $method) {\n\t\t\t\t\t$options[CURLOPT_POST] = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\n\t\t$ch = $this->getHandle();\n\t\tcurl_setopt_array($ch, $options);\n\n\t\t$response = curl_exec($ch);\n\t\t$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);\n\t\t$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);\n\n\t\tif ($response === false) {\n\t\t\tthrow new Exception(\"Can't open connection to \".$url);\n\t\t}\n\n\t\tif (!$code) {\n\t\t\t$code = 500;\n\t\t\t$headerSize = 0;\n\t\t\t$response = json_encode(array(\"error\"=>curl_error($ch).' ['.curl_errno($ch).']'));\n\t\t}\n\n\t\t$bodyString = substr($response, $headerSize);\n\t\t$bodyData = json_decode($bodyString, true);\n\n\t\t$headerString = substr($response, 0, $headerSize);\n\t\t$headers = explode(\"\\r\\n\", $headerString);\n\t\tforeach ($headers as $i => $header) {\n\t\t\tunset($headers[$i]);\n\t\t\t$parts = explode(':', $header);\n\t\t\tif (isset($parts[1])) {\n\t\t\t\t$name = trim(array_shift($parts));\n\t\t\t\t$value = join(':', $parts);\n\t\t\t\t$headers[$name] = $value;\n\t\t\t}\n\t\t}\n\n\t\treturn array(\n\t\t\t'code' => $code,\n\t\t\t'headers' => $headers,\n\t\t\t'data' => $bodyData,\n\t\t);\n\t}\n\n\t/**\n\t * Get the cURL handle\n\t *\n\t * @return resource cURL handle\n\t */\n\tprotected function getHandle()\n\t{\n\t\tif (!$this->handle) {\n\t\t\t$this->handle = curl_init();\n\t\t}\n\t\treturn $this->handle;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Transport/Stream.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Transport;\n\nuse Everyman\\Neo4j\\Transport as BaseTransport,\n\tEveryman\\Neo4j\\Version,\n\tEveryman\\Neo4j\\Exception;\n\n/**\n * Class for communicating with an HTTP JSON endpoint over PHP streams\n */\nclass Stream extends BaseTransport\n{\n\t/**\n\t * @inherit\n\t */\n\tpublic function makeRequest($method, $path, $data=array())\n\t{\n\t\t$url = $this->getEndpoint().$path;\n\n\t\t$context_options = array (\n\t\t\t$this->scheme => array (\n\t\t\t\t'method' => 'GET',\n\t\t\t\t'ignore_errors' => true,\n\t\t\t\t'header'=>\n\t\t\t\t\t\"Content-type: application/json\\r\\n\"\n\t\t\t\t\t. \"Accept: application/json;stream=true\\r\\n\"\n\t\t\t\t\t. \"User-Agent: \".Version::userAgent().\"\\r\\n\"\n\t\t\t\t\t. \"X-Stream: true\\r\\n\"\n\t\t\t)\n\t\t);\n\n\t\tif ($this->username && $this->password) {\n\t\t\t$encodedAuth = base64_encode($this->username.':'.$this->password);\n\t\t\t$context_options[$this->scheme]['header'] .= 'Authorization: Basic ' . $encodedAuth . \"\\r\\n\";\n\t\t}\n\n\t\tswitch ($method) {\n\t\t\tcase self::DELETE:\n\t\t\t\t$context_options[$this->scheme]['method'] = self::DELETE;\n\t\t\t\tbreak;\n\n\t\t\tcase self::POST:\n\t\t\tcase self::PUT:\n\t\t\t\t$dataString = $this->encodeData($data);\n\t\t\t\t$context_options[$this->scheme]['method'] = $method;\n\t\t\t\t$context_options[$this->scheme]['content'] = $dataString;\n\t\t\t\t$context_options[$this->scheme]['header'] .= 'Context-Length: ' . strlen($dataString) . \"\\r\\n\";\n\t\t\t\tbreak;\n\t\t}\n\n\t\t$context = stream_context_create($context_options);\n\t\t$response = file_get_contents($url, false, $context);\n\n\t\tif ($response === false) {\n\t\t\tthrow new Exception(\"Can't open connection to \".$url);\n\t\t}\n\n\t\t// $http_response_header is set by file_get_contents with the http:// wrapper\n\n\t\tpreg_match('/^HTTP\\/1\\.[0-1] (\\d{3})/', $http_response_header[0], $parts);\n\t\t$code = $parts[1];\n\n\t\tif (!$code) {\n\t\t\t$code = 500;\n\t\t\t$response = json_encode(array(\"error\"=>'error [' . $code . ']'));\n\t\t}\n\n\t\t$bodyData = json_decode($response, true);\n\n\t\t$headers = array();\n\t\tforeach ($http_response_header as $header) {\n\t\t\t$parts = explode(':', $header, 2);\n\n\t\t\tif (count($parts) == 2) {\n\t\t\t\t$headers[$parts[0]] = $parts[1];\n\t\t\t}\n\t\t}\n\n\t\treturn array(\n\t\t\t'code' => $code,\n\t\t\t'headers' => $headers,\n\t\t\t'data' => $bodyData,\n\t\t);\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Transport.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Class for communicating with an HTTP JSON endpoint\n */\nabstract class Transport\n{\n\tconst GET    = 'GET';\n\tconst POST   = 'POST';\n\tconst PUT    = 'PUT';\n\tconst DELETE = 'DELETE';\n\n\tprotected $scheme = 'http';\n\tprotected $host = 'localhost';\n\tprotected $port = 7474;\n\tprotected $path = '/db/data';\n\tprotected $username = null;\n\tprotected $password = null;\n\n\tprotected $handle = null;\n\n\t/**\n\t * Set the host and port of the endpoint\n\t *\n\t * @param string $host\n\t * @param integer $port\n\t */\n\tpublic function __construct($host='localhost', $port=7474)\n\t{\n\t\t$this->host = $host;\n\t\t$this->port = $port;\n\t}\n\n\t/**\n\t * Return the Neo4j REST endpoint\n\t *\n\t * @return string\n\t */\n\tpublic function getEndpoint()\n\t{\n\t\treturn \"{$this->scheme}://{$this->host}:{$this->port}{$this->path}\";\n\t}\n\n\t/**\n\t * Encode data for transport\n\t *\n\t * @param mixed $data\n\t * @return string\n\t */\n\tpublic function encodeData($data)\n\t{\n\t\t$encoded = '';\n\t\tif (!is_scalar($data)) {\n\t\t\tif ($data) {\n\t\t\t\t$keys = array_keys($data);\n\t\t\t\t$nonNumeric = array_filter($keys, function ($var) {\n\t\t\t\t\treturn !is_int($var);\n\t\t\t\t});\n\t\t\t\tif ($nonNumeric) {\n\t\t\t\t\t$data = (object)$data;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t$data = (object)$data;\n\t\t\t}\n\t\t}\n\n\t\t$encoded = json_encode($data);\n\t\treturn $encoded;\n\t}\n\n\t/**\n\t * Make a request against the endpoint\n\t * Returned array has the following elements:\n\t *   'code' => the HTTP status code returned\n\t *   'headers' => array of HTTP headers, indexed by header name\n\t *   'data' => array return data\n\t *\n\t * @param string $method\n\t * @param string $path\n\t * @param array  $data\n\t * @return array\n\t */\n\tabstract public function makeRequest($method, $path, $data=array());\n\n\t/**\n\t * Make a GET request\n\t *\n\t * @param $path\n\t * @param $data\n\t * @return array see 'makeRequest'\n\t */\n\tpublic function get($path, $data=array())\n\t{\n\t\treturn $this->makeRequest(self::GET, $path, $data);\n\t}\n\n\t/**\n\t * Make a POST request\n\t *\n\t * @param $path\n\t * @param $data\n\t * @return array see 'makeRequest'\n\t */\n\tpublic function post($path, $data=array())\n\t{\n\t\treturn $this->makeRequest(self::POST, $path, $data);\n\t}\n\n\t/**\n\t * Make a PUT request\n\t *\n\t * @param $path\n\t * @param $data\n\t * @return array see 'makeRequest'\n\t */\n\tpublic function put($path, $data=array())\n\t{\n\t\treturn $this->makeRequest(self::PUT, $path, $data);\n\t}\n\n\t/**\n\t * Make a DELETE request\n\t *\n\t * @param $path\n\t * @return array see 'makeRequest'\n\t */\n\tpublic function delete($path)\n\t{\n\t\treturn $this->makeRequest(self::DELETE, $path);\n\t}\n\n\t/**\n\t * Set username and password to use with HTTP Basic Auth\n\t *\n\t * Returns this Trnasport object\n\t *\n\t * @param string $username\n\t * @param string $password\n\t * @return Transport\n\t */\n\tpublic function setAuth($username=null, $password=null)\n\t{\n\t\t$this->username = $username;\n\t\t$this->password = $password;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Turn HTTPS on or off\n\t *\n\t * Returns this Trnasport object\n\t *\n\t * @param boolean $useHttps\n\t * @return Transport\n\t */\n\tpublic function useHttps($useHttps=true)\n\t{\n\t\t$this->scheme = $useHttps ? 'https' : 'http';\n\t\treturn $this;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Traversal.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Holds the parameters for running a traversal\n */\nclass Traversal\n{\n\tconst ReturnTypeNode = 'node';\n\tconst ReturnTypeRelationship = 'relationship';\n\tconst ReturnTypePath = 'path';\n\tconst ReturnTypeFullPath = 'fullpath';\n\n\tconst OrderDepthFirst = 'depth_first';\n\tconst OrderBreadthFirst = 'breadth_first';\n\n\tconst UniquenessNone = 'none';\n\tconst UniquenessNodeGlobal = 'node_global';\n\tconst UniquenessRelationshipGlobal = 'relationship_global';\n\tconst UniquenessNodePath = 'node_path';\n\tconst UniquenessRelationshipPath = 'relationship_path';\n\n\tconst Builtin = 'builtin';\n\n\tconst PruneNone = 'none';\n\n\tconst ReturnAll = 'all';\n\tconst ReturnAllButStart = 'all_but_start_node';\n\n\tprotected $client = null;\n\n\tprotected $order = null;\n\tprotected $uniqueness = null;\n\tprotected $maxDepth = null;\n\tprotected $relationships = array();\n\n\tprotected $pruneEvaluator = null;\n\tprotected $returnFilter = null;\n\n\t/**\n\t * Build the traversal and set its client\n\t *\n\t * @param Client $client\n\t */\n\tpublic function __construct(Client $client)\n\t{\n\t\t$this->client = $client;\n\t}\n\n\t/**\n\t * Add a relationship type and direction\n\t *\n\t * @param string $type\n\t * @param string $direction\n\t * @return Traversal\n\t */\n\tpublic function addRelationship($type, $direction=null)\n\t{\n\t\t$relationship = array('type'=>$type);\n\t\tif ($direction) {\n\t\t\t$relationship['direction'] = $direction;\n\t\t}\n\n\t\t$this->relationships[] = $relationship;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Get the finder's client\n\t *\n\t * @return Client\n\t */\n\tpublic function getClient()\n\t{\n\t\treturn $this->client;\n\t}\n\n\t/**\n\t * Get the maximum allowed path length\n\t *\n\t * @return integer\n\t */\n\tpublic function getMaxDepth()\n\t{\n\t\treturn $this->maxDepth;\n\t}\n\n\t/**\n\t * Return the order in which to traverse\n\t *\n\t * @return string\n\t */\n\tpublic function getOrder()\n\t{\n\t\treturn $this->order;\n\t}\n\n\t/**\n\t * Get the prune evaluator\n\t *\n\t * @return array ('language'=>..., 'body'=>...)\n\t */\n\tpublic function getPruneEvaluator()\n\t{\n\t\treturn $this->pruneEvaluator;\n\t}\n\n\t/**\n\t * Get the relationship type and description\n\t *\n\t * @return array ('type'=>..., 'direction'=>...)\n\t */\n\tpublic function getRelationships()\n\t{\n\t\treturn $this->relationships;\n\t}\n\n\t/**\n\t * Run the traversal, and return the results\n\t *\n\t * @param Node $startNode\n\t * @param string $returnType\n\t * @return array\n\t */\n\tpublic function getResults(Node $startNode, $returnType)\n\t{\n\t\treturn $this->client->executeTraversal($this, $startNode, $returnType);\n\t}\n\n\t/**\n\t * Get the return filter\n\t *\n\t * @return array ('language'=>..., 'body'=>...)\n\t */\n\tpublic function getReturnFilter()\n\t{\n\t\treturn $this->returnFilter;\n\t}\n\n\t/**\n\t * Run the traversal, and return the first result\n\t *\n\t * @param Node $startNode\n\t * @param string $returnType\n\t * @return mixed\n\t */\n\tpublic function getSingleResult(Node $startNode, $returnType)\n\t{\n\t\t$results = $this->getResults($startNode, $returnType);\n\t\treturn $results ? $results[0] : null;\n\t}\n\n\t/**\n\t * Return the uniqueness of the traversal\n\t *\n\t * @return string\n\t */\n\tpublic function getUniqueness()\n\t{\n\t\treturn $this->uniqueness;\n\t}\n\n\t/**\n\t * Set the maximum allowed path length\n\t *\n\t * @param integer $max\n\t * @return Traversal\n\t */\n\tpublic function setMaxDepth($max)\n\t{\n\t\t$this->maxDepth = $max;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the order in which to traverse\n\t *\n\t * @param string $order\n\t * @return Traversal\n\t */\n\tpublic function setOrder($order)\n\t{\n\t\t$this->order = $order;\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the prune evaluator\n\t * If language is one of the special builtin self::Prune* constants,\n\t * the evaluator language will be set to 'builtin' and the body\n\t * will be set to the value of the constant.\n\t *\n\t * @param string $language\n\t * @param string $body\n\t * @return Traversal\n\t */\n\tpublic function setPruneEvaluator($language=null, $body=null)\n\t{\n\t\tif (!$language) {\n\t\t\t$this->pruneEvaluator = null;\n\t\t} else if ($language == self::PruneNone) {\n\t\t\t$this->pruneEvaluator = array(\n\t\t\t\t'language' => self::Builtin,\n\t\t\t\t'body' => $language,\n\t\t\t);\n\t\t} else {\n\t\t\t$this->pruneEvaluator = array(\n\t\t\t\t'language' => $language,\n\t\t\t\t'body' => $body,\n\t\t\t);\n\t\t}\n\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the return filter\n\t * If language is one of the special builtin self::Return* constants,\n\t * the filter language will be set to 'builtin' and the body\n\t * will be set to the value of the constant.\n\t *\n\t * @param string $language\n\t * @param string $body\n\t * @return Traversal\n\t */\n\tpublic function setReturnFilter($language=null, $body=null)\n\t{\n\t\tif (!$language) {\n\t\t\t$this->returnFilter = null;\n\t\t} else if ($language == self::ReturnAll || $language == self::ReturnAllButStart) {\n\t\t\t$this->returnFilter = array(\n\t\t\t\t'language' => self::Builtin,\n\t\t\t\t'body' => $language,\n\t\t\t);\n\t\t} else {\n\t\t\t$this->returnFilter = array(\n\t\t\t\t'language' => $language,\n\t\t\t\t'body' => $body,\n\t\t\t);\n\t\t}\n\n\t\treturn $this;\n\t}\n\n\t/**\n\t * Set the uniquenss\n\t *\n\t * @param string $uniqueness\n\t * @return Traversal\n\t */\n\tpublic function setUniqueness($uniqueness)\n\t{\n\t\t$this->uniqueness = $uniqueness;\n\t\treturn $this;\n\t}\n}\n"
  },
  {
    "path": "lib/Everyman/Neo4j/Version.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\n/**\n * Current library version\n */\nclass Version\n{\n\tconst CURRENT = '0.1.0';\n\n\tpublic static function userAgent()\n\t{\n\t\treturn 'neo4jphp/'.self::CURRENT;\n\t}\n}\n"
  },
  {
    "path": "phpconfig.ini",
    "content": "extension = \"memcache.so\"\nextension = \"memcached.so\""
  },
  {
    "path": "stub.php",
    "content": "<?php\ntrigger_error('The neo4jphp PHAR archive is no longer supported and will be removed in the future. Use Composer to install the library.', E_USER_DEPRECATED);\n\nPhar::mapPhar('neo4jphp.phar');\nspl_autoload_register(function ($className) {\n\tif (strpos($className, 'Everyman\\Neo4j\\\\') !== 0) {\n\t\treturn;\n\t}\n\t$libPath = 'phar://neo4jphp.phar/lib/';\n\t$classFile = str_replace('\\\\',DIRECTORY_SEPARATOR,$className).'.php';\n\t$classPath = $libPath.$classFile;\n\tif (file_exists($classPath)) {\n\t\trequire($classPath);\n\t}\n});\n\nif ('cli' === php_sapi_name() && basename(__FILE__) === basename($_SERVER['argv'][0])) {\n\t$command = empty($_SERVER['argv'][1]) ? '-help' : $_SERVER['argv'][1];\n\t$me = new Phar('neo4jphp.phar');\n\t$meta = $me->getMetaData();\n\n\tif ($command == '-help') {\n\t\techo <<<HELP\nNeo4jPHP version {$meta['version']}\n\n{$_SERVER['argv'][0]} [-help|-license|-readme|-version|<host>] <port>\n    -help            Display help text\n    -license         Display software license\n    -readme          Display README\n    -version         Display version information\n    <host> (<port>)  Test connection to Neo4j instance on host (port defaults to 7474)\n\nHELP;\n\n\t} else if ($command == '-license') {\n\t\techo file_get_contents('phar://neo4jphp.phar/LICENSE').\"\\n\\n\";\n\n\t} else if ($command == '-readme') {\n\t\techo file_get_contents('phar://neo4jphp.phar/README.md').\"\\n\\n\";\n\n\t} else if ($command == '-version') {\n\t\techo \"Neo4jPHP version {$meta['version']}\\n\\n\";\n\n\t} else {\n\t\t$port = empty($_SERVER['argv'][2]) ? 7474 : $_SERVER['argv'][2];\n\t\t$client = new Everyman\\Neo4j\\Client($command, $port);\n\t\tprint_r($client->getServerInfo());\n\t}\n\n\texit(0);\n}\n__HALT_COMPILER();\n"
  },
  {
    "path": "tests/cs/ruleset.xml",
    "content": "<?xml version=\"1.0\"?>\n<ruleset name=\"Neo4jPHP\">\n\t<description>Code style guidelines for the Neo4jPHP library</description>\n\n\t<rule ref=\"PSR2\">\n\t\t<exclude name=\"Generic.WhiteSpace.DisallowTabIndent\" />\n\t\t<exclude name=\"PSR2.ControlStructures.ElseIfDeclaration.NotAllowed\" />\n\t\t<exclude name=\"PSR2.Namespaces.UseDeclaration.MultipleDeclarations\" />\n\t\t<!-- @todo: This should change in a future BC-breaking version -->\n\t\t<exclude name=\"Generic.NamingConventions.UpperCaseConstantName\" />\n\t</rule>\n\n\t<rule ref=\"Generic.WhiteSpace.DisallowSpaceIndent\" />\n\t<rule ref=\"Squiz.ControlStructures.ElseIfDeclaration\" />\n\n\t<rule ref=\"Squiz.Functions.FunctionDeclarationArgumentSpacing\">\n\t\t<properties>\n\t\t\t<property name=\"equalsSpacing\" value=\"0\" />\n\t\t</properties>\n\t</rule>\n\n\t<!-- Fix for tab indenting -->\n\t<rule ref=\"Generic.WhiteSpace.ScopeIndent\">\n\t\t<properties>\n\t\t\t<property name=\"indent\" value=\"1\" />\n\t\t</properties>\n\t</rule>\n\t<rule ref=\"PSR2.ControlStructures.SwitchDeclaration\">\n\t\t<properties>\n\t\t\t<property name=\"indent\" value=\"1\" />\n\t\t</properties>\n\t</rule>\n\t<rule ref=\"PSR2.Methods.FunctionCallSignature\">\n\t\t<properties>\n\t\t\t<property name=\"indent\" value=\"1\" />\n\t\t</properties>\n\t</rule>\n\n\t<!-- No whitespace-only lines -->\n\t<rule ref=\"Squiz.WhiteSpace.SuperfluousWhitespace\">\n\t\t<properties>\n\t\t\t<property name=\"ignoreBlankLines\" value=\"false\"/>\n\t\t</properties>\n\t</rule>\n</ruleset>"
  },
  {
    "path": "tests/phpunit.xml",
    "content": "<phpunit\n\tbootstrap=\"../vendor/autoload.php\"\n\tcolors=\"true\"\n\tconvertErrorsToExceptions=\"true\"\n\tconvertNoticesToExceptions=\"true\"\n\tconvertWarningsToExceptions=\"true\">\n\t<php>\n\t\t<ini name=\"error_reporting\" value=\"-1\" />\n\t\t<ini name=\"display_errors\" value=\"1\" />\n\t</php>\n    <testsuite name=\"Neo4j PHP Test Results\">\n        <directory>./unit</directory>\n    </testsuite>\n</phpunit>\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/BatchTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass BatchTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $batch = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->batch = new Batch($this->client);\n\t}\n\n\tpublic function testGetClient_ClientSetCorrectly_ReturnsClient()\n\t{\n\t\t$this->assertSame($this->client, $this->batch->getClient());\n\t}\n\n\tpublic function testCommit_PassesSelfToClient_Success_ReturnsTrue()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('commitBatch')\n\t\t\t->with($this->batch)\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertTrue($this->batch->commit());\n\t}\n\n\tpublic function testCommit_PassesSelfToClient_Failure_ReturnsFalse()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('commitBatch')\n\t\t\t->with($this->batch)\n\t\t\t->will($this->returnValue(false));\n\n\t\t$this->assertFalse($this->batch->commit());\n\t}\n\n\tpublic function testCommit_CommitMoreThanOnce_ThrowsException()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('commitBatch');\n\n\t\t$this->batch->commit();\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->batch->commit();\n\t}\n\n\tpublic function testSave_PropertyContainerEntities_ReturnsIntegerOperationIndex()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$nodeA->setId(123);\n\n\t\t$nodeB = new Node($this->client);\n\t\t$nodeB->setId(456);\n\n\t\t$nodeC = new Node($this->client);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId(987)\n\t\t\t->setStartNode($nodeA)\n\t\t\t->setEndNode($nodeB);\n\t\t\t\n\t\t$this->assertEquals(0, $this->batch->save($nodeA));\n\t\t$this->assertEquals(1, $this->batch->save($nodeB));\n\t\t$this->assertEquals(2, $this->batch->save($nodeC));\n\t\t$this->assertEquals(3, $this->batch->save($rel));\n\t}\n\n\tpublic function testSave_SameEntityMoreThanOnce_ReturnsIntegerOperationIndex()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t\t\n\t\t$this->assertEquals(0, $this->batch->save($nodeA));\n\t\t$this->assertEquals(0, $this->batch->save($nodeA));\n\t}\n\n\tpublic function testDelete_PropertyContainerEntities_ReturnsIntegerOperationIndex()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$nodeA->setId(123);\n\n\t\t$nodeB = new Node($this->client);\n\t\t$nodeB->setId(456);\n\n\t\t$nodeC = new Node($this->client);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId(987)\n\t\t\t->setStartNode($nodeA)\n\t\t\t->setEndNode($nodeB);\n\t\t\t\n\t\t$this->assertEquals(0, $this->batch->delete($nodeA));\n\t\t$this->assertEquals(1, $this->batch->delete($nodeB));\n\t\t$this->assertEquals(2, $this->batch->delete($nodeC));\n\t\t$this->assertEquals(3, $this->batch->delete($rel));\n\t}\n\n\tpublic function testDelete_SameEntityMoreThanOnce_ReturnsIntegerOperationIndex()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t\t\n\t\t$this->assertEquals(0, $this->batch->delete($nodeA));\n\t\t$this->assertEquals(0, $this->batch->delete($nodeA));\n\t}\n\n\tpublic function testAddToIndex_Index_ReturnsIntegerOperationIndex()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$nodeA->setId(123);\n\t\t$nodeB = new Node($this->client);\n\t\t$nodeB->setId(456);\n\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$this->assertEquals(0, $this->batch->addToIndex($index, $nodeA, 'somekey', 'somevalue'));\n\t\t$this->assertEquals(1, $this->batch->addToIndex($index, $nodeB, 'otherkey', 'othervalue'));\n\t\t$this->assertEquals(2, $this->batch->addToIndex($index, $nodeB, 'diffkey', 'diffvalue'));\n\t}\n\n\tpublic function testAddToIndex_SameEntitySameKeyValueMoreThanOnce_ReturnsIntegerOperationIndex()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t\t\n\t\t$this->assertEquals(0, $this->batch->addToIndex($index, $nodeA, 'somekey', 'somevalue'));\n\t\t$this->assertEquals(0, $this->batch->addToIndex($index, $nodeA, 'somekey', 'somevalue'));\n\t}\n\n\tpublic function testRemoveFromIndex_Index_ReturnsIntegerOperationIndex()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$nodeA->setId(123);\n\t\t$nodeB = new Node($this->client);\n\t\t$nodeB->setId(456);\n\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$this->assertEquals(0, $this->batch->removeFromIndex($index, $nodeA, 'somekey', 'somevalue'));\n\t\t$this->assertEquals(1, $this->batch->removeFromIndex($index, $nodeA, 'otherkey'));\n\t\t$this->assertEquals(2, $this->batch->removeFromIndex($index, $nodeA));\n\t\t$this->assertEquals(3, $this->batch->removeFromIndex($index, $nodeB, 'diffkey', 'diffvalue'));\n\t}\n\n\tpublic function testRemoveFromIndex_SameEntitySameKeyValueMoreThanOnce_ReturnsIntegerOperationIndex()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t\t\n\t\t$this->assertEquals(0, $this->batch->removeFromIndex($index, $nodeA, 'somekey', 'somevalue'));\n\t\t$this->assertEquals(0, $this->batch->removeFromIndex($index, $nodeA, 'somekey', 'somevalue'));\n\t\t\t\n\t\t$this->assertEquals(1, $this->batch->removeFromIndex($index, $nodeA, 'otherkey'));\n\t\t$this->assertEquals(1, $this->batch->removeFromIndex($index, $nodeA, 'otherkey'));\n\t\t\t\n\t\t$this->assertEquals(2, $this->batch->removeFromIndex($index, $nodeA));\n\t\t$this->assertEquals(2, $this->batch->removeFromIndex($index, $nodeA));\n\t}\n\n\tpublic function testGetOperations_MixedOperations_ReturnsOperations()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t\t\n\t\t$this->assertEquals(0, $this->batch->save($nodeA));\n\t\t$this->assertEquals(1, $this->batch->delete($nodeA));\n\n\t\t$operations = $this->batch->getOperations();\n\t\t$this->assertInternalType('array', $operations);\n\t\t$this->assertEquals(2, count($operations));\n\n\t\t$saveMatch = new Batch\\Save($this->batch, $nodeA, 123);\n\t\t$deleteMatch = new Batch\\Delete($this->batch, $nodeA, 456);\n\t\t$this->assertEquals($saveMatch->matchId(), $operations[0]->matchId());\n\t\t$this->assertEquals($deleteMatch->matchId(), $operations[1]->matchId());\n\t}\n\n\tpublic function testReserve_OperationNotReserved_ReturnsOperation()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$opId = $this->batch->save($nodeA);\n\n\t\t$reservation = $this->batch->reserve($opId);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Batch\\Operation', $reservation);\n\n\t\t$saveMatch = new Batch\\Save($this->batch, $nodeA, 123);\n\t\t$this->assertEquals($saveMatch->matchId(), $reservation->matchId());\n\t}\n\n\tpublic function testReserve_OperationAlreadyReserved_ReturnsFalse()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$opId = $this->batch->save($nodeA);\n\n\t\t$temp = $this->batch->reserve($opId);\n\t\t$reservation = $this->batch->reserve($opId);\n\t\t$this->assertFalse($reservation);\n\t}\n\n\tpublic function testReserve_OperationNotExists_ReturnsFalse()\n\t{\n\t\t$reservation = $this->batch->reserve(0);\n\t\t$this->assertFalse($reservation);\n\t}\n}\n\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Cache/MemcacheTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cache;\n\nclass MemcacheTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $memcache = null;\n\tprotected $cache = null;\n\n\tpublic function setUp()\n\t{\n\t\tif (!phpversion('memcache')) {\n\t\t\t$this->markTestSkipped('Memcache extension not enabled/installed');\n\t\t}\n\n\t\t$this->memcache = $this->getMock('\\Memcache');\n\t\t$this->cache = new Memcache($this->memcache);\n\t}\n\n\tpublic function testSet_PassesThroughToMemcache()\n\t{\n\t\t$this->memcache->expects($this->once())\n\t\t\t->method('set')\n\t\t\t->with('somekey', 'somevalue', 0, 12345)\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertTrue($this->cache->set('somekey', 'somevalue', 12345));\n\t}\n\n\tpublic function testGet_PassesThroughToMemcache()\n\t{\n\t\t$this->memcache->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('somekey')\n\t\t\t->will($this->returnValue('somevalue'));\n\n\t\t$this->assertEquals('somevalue', $this->cache->get('somekey'));\n\t}\n\n\tpublic function testDelete_PassesThroughToMemcache()\n\t{\n\t\t$this->memcache->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('somekey')\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertTrue($this->cache->delete('somekey'));\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Cache/MemcachedTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cache;\n\nclass MemcachedTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $memcached = null;\n\tprotected $cache = null;\n\n\tpublic function setUp()\n\t{\n\t\t$memcachedVersion = phpversion('memcached');\n\t\tif (!$memcachedVersion) {\n\t\t\t$this->markTestSkipped('Memcached extension not enabled/installed');\n\t\t} else if (version_compare($memcachedVersion, '2.2.0', '>=')) {\n\t\t\t$this->markTestSkipped('Memcached tests can only be run with memcached extension 2.1.0 or lower');\n\t\t}\n\n\t\t$this->memcached = $this->getMock('\\Memcached');\n\t\t$this->cache = new Memcached($this->memcached);\n\t}\n\n\tpublic function testSet_PassesThroughToMemcached()\n\t{\n\t\t$this->memcached->expects($this->once())\n\t\t\t->method('set')\n\t\t\t->with('somekey', 'somevalue', 12345)\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertTrue($this->cache->set('somekey', 'somevalue', 12345));\n\t}\n\n\tpublic function testGet_PassesThroughToMemcached()\n\t{\n\t\t$this->memcached->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('somekey')\n\t\t\t->will($this->returnValue('somevalue'));\n\n\t\t$this->assertEquals('somevalue', $this->cache->get('somekey'));\n\t}\n\n\tpublic function testDelete_PassesThroughToMemcached()\n\t{\n\t\t$this->memcached->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('somekey')\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertTrue($this->cache->delete('somekey'));\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Cache/NoneTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cache;\n\nclass NoneTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $cache = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->cache = new None();\n\t}\n\n\tpublic function testDelete_ReturnsTrue()\n\t{\n\t\t$this->assertTrue($this->cache->delete('somekey'));\n\t}\n\n\tpublic function testGet_ReturnsFalse()\n\t{\n\t\t$this->assertFalse($this->cache->get('somekey'));\n\t}\n\n\tpublic function testSet_ReturnsTrue()\n\t{\n\t\t$this->assertTrue($this->cache->set('somekey', 'somevalue', 12345));\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Cache/VariableTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cache;\n\nclass VariableTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $cache = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->cache = new Variable();\n\t}\n\n\tpublic function testSet_ReturnsTrue()\n\t{\n\t\t$this->assertTrue($this->cache->set('somekey', 'somevalue', 12345));\n\t}\n\n\tpublic function testGet_KeyDoesNotExist_ReturnsFalse()\n\t{\n\t\t$this->assertFalse($this->cache->get('somekey'));\n\t}\n\n\tpublic function testGet_KeyExists_ReturnsValue()\n\t{\n\t\t$this->cache->set('somekey', 'somevalue', 12345);\n\t\t$this->assertEquals('somevalue', $this->cache->get('somekey'));\n\t}\n\n\tpublic function testGet_ExpiredValue_ReturnsFalse()\n\t{\n\t\t$this->cache->set('somekey', 'somevalue', time()-10000);\n\t\t$this->assertFalse($this->cache->get('somekey'));\n\t}\n\n\tpublic function testDelete_KeyDoesNotExist_ReturnsTrue()\n\t{\n\t\t$this->assertTrue($this->cache->delete('somekey'));\n\t}\n\n\tpublic function testDelete_KeyExists_ReturnsTrue()\n\t{\n\t\t$this->cache->set('somekey', 'somevalue', 12345);\n\t\t$this->assertTrue($this->cache->delete('somekey'));\n\t\t$this->assertFalse($this->cache->get('somekey'));\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/ClientTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass ClientTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\t\t$this->client = new Client($this->transport);\n\t}\n\n\tpublic function testConstruct_TransportGiven_SetsTransport()\n\t{\n\t\t$this->assertSame($this->transport, $this->client->getTransport());\n\t}\n\n\tpublic function testConstruct_NoTransportGiven_SetsCreateTransport()\n\t{\n\t\t$client = new Client();\n\t\t$transport = $client->getTransport();\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Transport', $transport);\n\t\t$this->assertEquals('http://localhost:7474/db/data', $transport->getEndpoint());\n\t}\n\n\tpublic function testConstruct_HostAndPortGiven_SetsCreateTransport()\n\t{\n\t\t$client = new Client('somehost', 7575);\n\t\t$transport = $client->getTransport();\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Transport', $transport);\n\t\t$this->assertEquals('http://somehost:7575/db/data', $transport->getEndpoint());\n\t}\n\n\tpublic function testDeleteNode_NodeDeleted_ReturnsTrue()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/node/123')\n\t\t\t->will($this->returnValue(array('code'=>204)));\n\n\t\t$this->assertTrue($this->client->deleteNode($node));\n\t}\n\n\tpublic function testDeleteNode_NodeNotFound_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/node/123')\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->deleteNode($node);\n\t}\n\n\tpublic function testDeleteNode_TransportError_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/node/123')\n\t\t\t->will($this->returnValue(array('code'=>409)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->deleteNode($node);\n\t}\n\n\tpublic function testDeleteNode_NodeHasNoId_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->deleteNode($node);\n\t}\n\n\tpublic function testSaveNode_Update_NodeHasNoId_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$command = new Command\\UpdateNode($this->client, $node);\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$command->execute();\n\t}\n\n\tpublic function testSaveNode_UpdateNodeFound_ReturnsTrue()\n\t{\n\t\t$properties = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$node = new Node($this->client);\n\t\t$node->useLazyLoad(false)\n\t\t\t->setId(123)\n\t\t\t->setProperties($properties);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/node/123/properties', $properties)\n\t\t\t->will($this->returnValue(array('code'=>204)));\n\n\t\t$this->assertTrue($this->client->saveNode($node));\n\t\t$this->assertEquals(123, $node->getId());\n\t}\n\n\tpublic function testSaveNode_UpdateNodeNotFound_ThrowsException()\n\t{\n\t\t$properties = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$node = new Node($this->client);\n\t\t$node->useLazyLoad(false)\n\t\t\t->setId(123)\n\t\t\t->setProperties($properties);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/node/123/properties', $properties)\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->saveNode($node);\n\t}\n\n\tpublic function testSaveNode_Update_TransportError_ThrowsException()\n\t{\n\t\t$properties = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$node = new Node($this->client);\n\t\t$node->useLazyLoad(false)\n\t\t\t->setId(123)\n\t\t\t->setProperties($properties);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/node/123/properties', $properties)\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->saveNode($node);\n\t}\n\n\tpublic function testSaveNode_Create_ReturnsTrue()\n\t{\n\t\t$properties = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$node = new Node($this->client);\n\t\t$node->setProperties($properties);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node', $properties)\n\t\t\t->will($this->returnValue(array(\n\t\t\t\t'code'=>201,\n\t\t\t\t'headers'=>array('Location'=>'http://foo.com:1234/db/data/node/123')\n\t\t\t)));\n\n\t\t$this->assertTrue($this->client->saveNode($node));\n\t\t$this->assertEquals(123, $node->getId());\n\t}\n\n\tpublic function testSaveNode_Create_TransportError_ThrowsException()\n\t{\n\t\t$properties = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$node = new Node($this->client);\n\t\t$node->setProperties($properties);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node', $properties)\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->saveNode($node);\n\t}\n\n\tpublic function testSaveNode_CreateNoProperties_ReturnsSuccess()\n\t{\n\t\t$node = new Node($this->client);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node',null)\n\t\t\t->will($this->returnValue(array('code'=>201, 'headers'=>array('Location'=>'http://foo.com:1234/db/data/node/123'))));\n\n\t\t$this->assertTrue($this->client->saveNode($node));\n\t\t$this->assertEquals(123, $node->getId());\n\t}\n\n\tpublic function testGetNode_TransportError_ThrowsException()\n\t{\n\t\t$nodeId = 123;\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/'.$nodeId)\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->getNode($nodeId);\n\t}\n\n\tpublic function testGetNode_NotFound_ReturnsNull()\n\t{\n\t\t$nodeId = 123;\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/'.$nodeId)\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->assertNull($this->client->getNode($nodeId));\n\t}\n\n\tpublic function testGetNode_Force_ReturnsNode()\n\t{\n\t\t$nodeId = 123;\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('get');\n\n\t\t$node = $this->client->getNode($nodeId, true);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $node);\n\t\t$this->assertEquals($nodeId, $node->getId());\n\t}\n\n\tpublic function testGetNode_Found_ReturnsNode()\n\t{\n\t\t$nodeId = 123;\n\t\t$properties = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/'.$nodeId)\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array('data'=>$properties))));\n\n\t\t$node = $this->client->getNode($nodeId);\n\t\t$this->assertNotNull($node);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $node);\n\t\t$this->assertEquals($nodeId, $node->getId());\n\t\t$this->assertEquals($properties, $node->getProperties());\n\t}\n\n\tpublic function testLoadNode_NodeNotFound_ThrowsException()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/'.$nodeId)\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->loadNode($node);\n\t}\n\n\tpublic function testLoadNode_NodeHasNoId_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->loadNode($node);\n\t}\n\n\tpublic function testGetRelationship_TransportError_ThrowsException()\n\t{\n\t\t$relId = 123;\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->getRelationship($relId);\n\t}\n\n\tpublic function testGetRelationship_NotFound_ReturnsNull()\n\t{\n\t\t$relId = 123;\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>'404')));\n\n\t\t$this->assertNull($this->client->getRelationship($relId));\n\t}\n\n\tpublic function testGetRelationship_Force_ReturnsRelationship()\n\t{\n\t\t$relId = 123;\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('get');\n\n\t\t$rel = $this->client->getRelationship($relId, true);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rel);\n\t\t$this->assertEquals($relId, $rel->getId());\n\t}\n\n\tpublic function testGetRelationship_Found_ReturnsRelationship()\n\t{\n\t\t$relId = 123;\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'foo' => 'bar',\n\t\t\t\t'baz' => 'qux',\n\t\t\t),\n\t\t\t'start' => 'http://foo:1234/db/data/node/567',\n\t\t\t'end'   => 'http://foo:1234/db/data/node/890',\n\t\t\t'type'  => 'FOOTYPE',\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>'200','data'=>$data)));\n\n\t\t$rel = $this->client->getRelationship($relId);\n\t\t$this->assertNotNull($rel);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rel);\n\t\t$this->assertEquals($relId, $rel->getId());\n\t\t$this->assertEquals($data['data'], $rel->getProperties());\n\t\t$this->assertEquals($data['type'], $rel->getType());\n\n\t\t$start = $rel->getStartNode();\n\t\t$this->assertNotNull($start);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $start);\n\t\t$this->assertEquals(567, $start->getId());\n\n\t\t$end = $rel->getEndNode();\n\t\t$this->assertNotNull($end);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $end);\n\t\t$this->assertEquals(890, $end->getId());\n\t}\n\n\t/**\n\t * Regression test for http://github.com/jadell/neo4jphp/issues/52\n\t */\n\tpublic function testGetRelationship_Found_LazyLoadNodes()\n\t{\n\t\t$relId = 123;\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'foo' => 'bar',\n\t\t\t\t'baz' => 'qux',\n\t\t\t),\n\t\t\t'start' => 'http://foo:1234/db/data/node/567',\n\t\t\t'end'   => 'http://foo:1234/db/data/node/890',\n\t\t\t'type'  => 'FOOTYPE',\n\t\t);\n\n\t\t$this->transport->expects($this->at(0))\n\t\t\t->method('get')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>'200','data'=>$data)));\n\t\t$this->transport->expects($this->at(1))\n\t\t\t->method('get')\n\t\t\t->with('/node/567')\n\t\t\t->will($this->returnValue(array('code'=>'200','data'=>array('data' => array()))));\n\t\t$this->transport->expects($this->at(2))\n\t\t\t->method('get')\n\t\t\t->with('/node/890')\n\t\t\t->will($this->returnValue(array('code'=>'200','data'=>array('data' => array()))));\n\n\t\t$rel = $this->client->getRelationship($relId);\n\t\t$rel->getStartNode()->getProperties();\n\t\t$rel->getEndNode()->getProperties();\n\t}\n\n\tpublic function testLoadRelationship_RelationshipNotFound_ThrowsException()\n\t{\n\t\t$relId = 123;\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId($relId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->loadRelationship($rel);\n\t}\n\n\tpublic function testLoadRelationship_RelationshipHasNoId_ThrowsException()\n\t{\n\t\t$rel = new Relationship($this->client);\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->loadRelationship($rel);\n\t}\n\n\tpublic function testDeleteRelationship_Found_ReturnsTrue()\n\t{\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/relationship/123')\n\t\t\t->will($this->returnValue(array('code'=>204)));\n\n\t\t$this->assertTrue($this->client->deleteRelationship($rel));\n\t}\n\n\tpublic function testDeleteRelationship_NotFound_ThrowsException()\n\t{\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/relationship/123')\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->deleteRelationship($rel);\n\t}\n\n\tpublic function testDeleteRelationship_TransportError_ThrowsException()\n\t{\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/relationship/123')\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->deleteRelationship($rel);\n\t}\n\n\tpublic function testDeleteRelationship_RelationshipHasNoId_ThrowsException()\n\t{\n\t\t$rel = new Relationship($this->client);\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->deleteRelationship($rel);\n\t}\n\n\tpublic function testSaveRelationship_Create_NoStartNode_ThrowsException()\n\t{\n\t\t$rel = new Relationship($this->client);\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->saveRelationship($rel);\n\t}\n\n\tpublic function testSaveRelationship_Create_NoEndNode_ThrowsException()\n\t{\n\t\t$start = new Node($this->client);\n\t\t$start->setId(123);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setStartNode($start);\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->saveRelationship($rel);\n\t}\n\n\tpublic function testSaveRelationship_Create_NoType_ThrowsException()\n\t{\n\t\t$start = new Node($this->client);\n\t\t$start->setId(123);\n\t\t$end = new Node($this->client);\n\t\t$end->setId(456);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setStartNode($start);\n\t\t$rel->setEndNode($end);\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->saveRelationship($rel);\n\t}\n\n\tpublic function testSaveRelationship_Create_ReturnsTrue()\n\t{\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'foo' => 'bar',\n\t\t\t\t'baz' => 'qux',\n\t\t\t),\n\t\t\t'to' => $this->endpoint.'/node/456',\n\t\t\t'type' => 'FOOTYPE',\n\t\t);\n\n\t\t$start = new Node($this->client);\n\t\t$start->setId(123);\n\t\t$end = new Node($this->client);\n\t\t$end->setId(456);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('FOOTYPE')\n\t\t\t->setStartNode($start)\n\t\t\t->setEndNode($end)\n\t\t\t->setProperties($data['data']);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/123/relationships', $data)\n\t\t\t->will($this->returnValue(array('code'=>201, 'headers'=>array('Location'=>'http://foo.com:1234/db/data/relationship/890'))));\n\n\t\t$this->assertTrue($this->client->saveRelationship($rel));\n\t\t$this->assertEquals(890, $rel->getId());\n\t}\n\n\tpublic function testSaveRelationship_CreateNoData_ReturnsTrue()\n\t{\n\t\t$data = array(\n\t\t\t'to' => $this->endpoint.'/node/456',\n\t\t\t'type' => 'FOOTYPE',\n\t\t);\n\n\t\t$start = new Node($this->client);\n\t\t$start->setId(123);\n\t\t$end = new Node($this->client);\n\t\t$end->setId(456);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('FOOTYPE')\n\t\t\t->setStartNode($start)\n\t\t\t->setEndNode($end)\n\t\t\t->setProperties(array());\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/123/relationships', $data)\n\t\t\t->will($this->returnValue(array('code'=>201, 'headers'=>array('Location'=>'http://foo.com:1234/db/data/relationship/890'))));\n\n\t\t$this->assertTrue($this->client->saveRelationship($rel));\n\t\t$this->assertEquals(890, $rel->getId());\n\t}\n\n\tpublic function testSaveRelationship_CreateTransportError_ThrowsException()\n\t{\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'foo' => 'bar',\n\t\t\t\t'baz' => 'qux',\n\t\t\t),\n\t\t\t'to' => $this->endpoint.'/node/456',\n\t\t\t'type' => 'FOOTYPE',\n\t\t);\n\n\t\t$start = new Node($this->client);\n\t\t$start->setId(123);\n\t\t$end = new Node($this->client);\n\t\t$end->setId(456);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('FOOTYPE')\n\t\t\t->setStartNode($start)\n\t\t\t->setEndNode($end)\n\t\t\t->setProperties($data['data']);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/123/relationships', $data)\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->saveRelationship($rel);\n\t}\n\n\tpublic function testSaveRelationship_Update_RelationshipHasNoId_ThrowsException()\n\t{\n\t\t$rel = new Relationship($this->client);\n\t\t$command = new Command\\UpdateRelationship($this->client, $rel);\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$command->execute();\n\t}\n\n\tpublic function testSaveRelationship_UpdateFound_ReturnsTrue()\n\t{\n\t\t$properties = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->useLazyLoad(false)\n\t\t\t->setId(123)\n\t\t\t->setProperties($properties);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/relationship/123/properties', $properties)\n\t\t\t->will($this->returnValue(array('code'=>204)));\n\n\t\t$this->assertTrue($this->client->saveRelationship($rel));\n\t}\n\n\tpublic function testSaveRelationship_UpdateNotFound_ReturnsFalse()\n\t{\n\t\t$properties = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->useLazyLoad(false)\n\t\t\t->setId(123)\n\t\t\t->setProperties($properties);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/relationship/123/properties', $properties)\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->saveRelationship($rel);\n\t}\n\n\tpublic function testSaveRelationship_UpdateTransportError_ThrowsException()\n\t{\n\t\t$properties = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->useLazyLoad(false)\n\t\t\t->setId(123)\n\t\t\t->setProperties($properties);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/relationship/123/properties', $properties)\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->saveRelationship($rel);\n\t}\n\n\tpublic function testGetNodeRelationships_NodeNotPersisted_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$type = 'FOOTYPE';\n\t\t$dir = Relationship::DirectionOut;\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->getNodeRelationships($node, $type, $dir);\n\t}\n\n\tpublic function testGetNodeRelationships_NodeNotFound_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/123/relationships/all')\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->getNodeRelationships($node, array(), null);\n\t}\n\n\tpublic function testGetNodeRelationships_NoRelationships_ReturnsEmptyArray()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\t\t$types = array('FOOTYPE');\n\t\t$dir = Relationship::DirectionIn;\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/123/relationships/in/FOOTYPE')\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array())));\n\n\t\t$this->assertEquals(array(), $this->client->getNodeRelationships($node, $types, $dir));\n\t}\n\n\tpublic function testGetNodeRelationships_Relationships_ReturnsArray()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\t\t$types = array('FOOTYPE','BARTYPE');\n\t\t$dir = Relationship::DirectionOut;\n\n\t\t$data = array(\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/56\",\n\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/123\",\n\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/93\",\n\t\t\t\t\"type\" => \"KNOWS\",\n\t\t\t\t\"data\" => array('foo'=>'bar','baz'=>'qux'),\n\t\t\t),\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/834\",\n\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/32\",\n\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/123\",\n\t\t\t\t\"type\" => \"LOVES\",\n\t\t\t\t\"data\" => array('bar'=>'foo','qux'=>'baz'),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/123/relationships/out/FOOTYPE&BARTYPE')\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$data)));\n\n\t\t$result = $this->client->getNodeRelationships($node, $types, $dir);\n\t\t$this->assertEquals(2, count($result));\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $result[0]);\n\t\t$this->assertEquals(56, $result[0]->getId());\n\t\t$this->assertEquals($data[0]['data'], $result[0]->getProperties());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getStartNode());\n\t\t$this->assertEquals(123, $result[0]->getStartNode()->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getEndNode());\n\t\t$this->assertEquals(93, $result[0]->getEndNode()->getId());\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $result[1]);\n\t\t$this->assertEquals(834, $result[1]->getId());\n\t\t$this->assertEquals($data[1]['data'], $result[1]->getProperties());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[1]->getStartNode());\n\t\t$this->assertEquals(32, $result[1]->getStartNode()->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[1]->getEndNode());\n\t\t$this->assertEquals(123, $result[1]->getEndNode()->getId());\n\t}\n\n\tpublic function testGetNodeRelationships_UrlCharactersInTypeName_EncodesCorrectly()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\t\t$types = array('FOO\\TYPE','BAR?TYPE','BAZ/TYPE');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/123/relationships/all/FOO%5CTYPE&BAR%3FTYPE&BAZ%2FTYPE')\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array())));\n\n\t\t$result = $this->client->getNodeRelationships($node, $types);\n\t}\n\n\tpublic function testGetRelationshipTypes_ServerReturnsErrorCode_ThrowsException()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/relationship/types')\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$result = $this->client->getRelationshipTypes();\n\t}\n\n\tpublic function testGetRelationshipTypes_ServerReturnsArray_ReturnsArray()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/relationship/types')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\"foo\",\"bar\"))));\n\n\t\t$result = $this->client->getRelationshipTypes();\n\t\t$this->assertEquals(array(\"foo\",\"bar\"), $result);\n\t}\n\n\tpublic function testGetServerInfo_ServerReturnsArray_ReturnsArray()\n\t{\n\t\t$returnData = array(\n\t\t\t\"relationship_index\" => \"http://localhost:7474/db/data/index/relationship\",\n\t\t\t\"node\" => \"http://localhost:7474/db/data/node\",\n\t\t\t\"relationship_types\" => \"http://localhost:7474/db/data/relationship/types\",\n\t\t\t\"batch\" => \"http://localhost:7474/db/data/batch\",\n\t\t\t\"extensions_info\" => \"http://localhost:7474/db/data/ext\",\n\t\t\t\"node_index\" => \"http://localhost:7474/db/data/index/node\",\n\t\t\t\"reference_node\" => \"http://localhost:7474/db/data/node/2\",\n\t\t\t\"extensions\" => array(),\n\t\t\t\"neo4j_version\" => \"1.5.M01-793-gc100417-dirty\",\n\t\t);\n\n\t\t$expectedData = $returnData;\n\t\t$expectedData['version'] = array(\n\t\t\t\"full\" => \"1.5.M01-793-gc100417-dirty\",\n\t\t\t\"major\" => \"1\",\n\t\t\t\"minor\" => \"5\",\n\t\t\t\"release\" => \"M01\",\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>$returnData)));\n\n\t\t$result = $this->client->getServerInfo();\n\t\t$this->assertEquals($expectedData, $result);\n\t}\n\n\tpublic function testGetServerInfo_GeneralAvailabilityRelease_ReturnsArray()\n\t{\n\t\t$returnData = array(\n\t\t\t\"relationship_index\" => \"http://localhost:7474/db/data/index/relationship\",\n\t\t\t\"node\" => \"http://localhost:7474/db/data/node\",\n\t\t\t\"neo4j_version\" => \"1.5\",\n\t\t);\n\n\t\t$expectedData = $returnData;\n\t\t$expectedData['version'] = array(\n\t\t\t\"full\" => \"1.5\",\n\t\t\t\"major\" => \"1\",\n\t\t\t\"minor\" => \"5\",\n\t\t\t\"release\" => \"GA\",\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>$returnData)));\n\n\t\t$result = $this->client->getServerInfo();\n\t\t$this->assertEquals($expectedData, $result);\n\t}\n\n\tpublic function testGetServerInfo_UnsuccessfulResponse_ThrowsException()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->getServerInfo();\n\t}\n\n\tpublic function testStartBatch_MultipleCallsWithoutCommit_ReturnsSameBatch()\n\t{\n\t\t$batch = $this->client->startBatch();\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Batch', $batch);\n\n\t\t$batchAgain = $this->client->startBatch();\n\t\t$this->assertSame($batch, $batchAgain);\n\t}\n\n\tpublic function testStartBatch_CommitAndStartAnother_ReturnsNewBatch()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/batch')\n\t\t\t->will($this->returnValue(array('code'=>200)));\n\n\n\t\t$batch = $this->client->startBatch();\n\t\t$batch->save(new Node($this->client));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Batch', $batch);\n\t\t$this->client->commitBatch();\n\n\t\t$batchAgain = $this->client->startBatch();\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Batch', $batchAgain);\n\t\t$this->assertNotSame($batch, $batchAgain);\n\t}\n\n\tpublic function testStartBatch_CommitOpenedBatch_ReturnsNewBatch()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/batch')\n\t\t\t->will($this->returnValue(array('code'=>200)));\n\n\n\t\t$batch = $this->client->startBatch();\n\t\t$batch->save(new Node($this->client));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Batch', $batch);\n\t\t$batch->commit();\n\n\t\t$batchAgain = $this->client->startBatch();\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Batch', $batchAgain);\n\t\t$this->assertNotSame($batch, $batchAgain);\n\t}\n\n\tpublic function testStartBatch_CommitOtherBatch_ReturnsSameBatch()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/batch')\n\t\t\t->will($this->returnValue(array('code'=>200)));\n\n\t\t$openBatch = $this->client->startBatch();\n\t\t$batch = new Batch($this->client);\n\t\t$batch->save(new Node($this->client));\n\t\t$batch->commit();\n\n\t\t$batchAgain = $this->client->startBatch();\n\t\t$this->assertSame($openBatch, $batchAgain);\n\t}\n\n\tpublic function testStartBatch_EndBatch_ReturnsNewBatch()\n\t{\n\t\t$batch = $this->client->startBatch();\n\t\t$this->client->endBatch();\n\n\t\t$batchAgain = $this->client->startBatch();\n\t\t$this->assertNotSame($batch, $batchAgain);\n\t}\n\n\tpublic function testCommitBatch_NoBatchGivenNoOpenBatch_ThrowsException()\n\t{\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->commitBatch();\n\t}\n\n\tpublic function testCommitBatch_NoOperationsInBatch_ReturnsTrue()\n\t{\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$batch = new Batch($this->client);\n\t\t$this->assertTrue($this->client->commitBatch($batch));\n\t}\n\n\tpublic function testMakeNode_ReturnsNode()\n\t{\n\t\t$data = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$node = $this->client->makeNode($data);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $node);\n\t\t$this->assertSame($this->client, $node->getClient());\n\t\t$this->assertEquals($data, $node->getProperties());\n\t}\n\n\tpublic function testMakeRelationship_ReturnsRelationship()\n\t{\n\t\t$data = array(\n\t\t\t'foo' => 'bar',\n\t\t\t'baz' => 'qux',\n\t\t);\n\n\t\t$rel = $this->client->makeRelationship($data);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rel);\n\t\t$this->assertSame($this->client, $rel->getClient());\n\t\t$this->assertEquals($data, $rel->getProperties());\n\t}\n\n\tpublic function testGetReferenceNode_Found_ReturnsNode()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/0')\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array('data'=>array()))));\n\n\t\t$node = $this->client->getReferenceNode();\n\t\t$this->assertNotNull($node);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $node);\n\t\t$this->assertEquals(0, $node->getId());\n\t}\n\n\tpublic function testNodeFactory_SetNodeFactory_ReturnsNodeFromFactory()\n\t{\n\t\t$this->client->setNodeFactory(function (Client $client, $properties=array()) {\n\t\t\treturn new NodeFactoryTestClass_ClientTest($client);\n\t\t});\n\n\t\t$node = $this->client->makeNode();\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\NodeFactoryTestClass_ClientTest', $node);\n\t}\n\n\tpublic function testNodeFactory_SetNodeFactory_NotCallable_ThrowsException()\n\t{\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->setNodeFactory('bar');\n\t}\n\n\tpublic function testNodeFactory_NodeFactoryReturnsNotNode_ThrowsException()\n\t{\n\t\t$this->client->setNodeFactory(function (Client $client, $properties=array()) {\n\t\t\treturn new \\stdClass();\n\t\t});\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$node = $this->client->makeNode();\n\t}\n\n\tpublic function testRelationshipFactory_SetRelationshipFactory_ReturnsRelationshipFromFactory()\n\t{\n\t\t$this->client->setRelationshipFactory(function (Client $client, $properties=array()) {\n\t\t\treturn new RelFactoryTestClass_ClientTest($client);\n\t\t});\n\n\t\t$rel = $this->client->makeRelationship();\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\RelFactoryTestClass_ClientTest', $rel);\n\t}\n\n\tpublic function testRelationshipFactory_SetRelationshipFactory_NotCallable_ThrowsException()\n\t{\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$this->client->setRelationshipFactory('bar');\n\t}\n\n\tpublic function testRelationshipFactory_RelationshipFactoryReturnsNotRelationship_ThrowsException()\n\t{\n\t\t$this->client->setRelationshipFactory(function (Client $client, $properties=array()) {\n\t\t\treturn new \\stdClass();\n\t\t});\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$rel = $this->client->makeRelationship();\n\t}\n}\n\nclass NodeFactoryTestClass_ClientTest extends Node {}\nclass RelFactoryTestClass_ClientTest extends Relationship {}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_Batch_IndexTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_Batch_IndexTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $batch = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\t\t$this->client = new Client($this->transport);\n\n\t\t$this->batch = new Batch($this->client);\n\t}\n\n\tpublic function testCommitBatch_AddToIndex_NodeExists_Success_ReturnsTrue()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$request = array(array('id' => 0, 'method' => 'POST',\n\t\t\t'to' => '/index/node/indexname',\n\t\t\t'body' => array(\n\t\t\t\t'key'   => 'somekey',\n\t\t\t\t'value' => 'somevalue',\n\t\t\t\t'uri'   => $this->endpoint.'/node/123',\n\t\t\t)\n\t\t));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(array('id' => 0)));\n\n\t\t$this->batch->addToIndex($index, $node, 'somekey', 'somevalue');\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\t}\n\n\tpublic function testCommitBatch_AddToIndex_NodeDoesNotExist_Success_ReturnsTrue()\n\t{\n\t\t$node = new Node($this->client);\n\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$request = array(\n\t\t\tarray('id' => 1, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 0, 'method' => 'POST',\n\t\t\t\t'to' => '/index/node/indexname',\n\t\t\t\t'body' => array(\n\t\t\t\t\t'key'   => 'somekey',\n\t\t\t\t\t'value' => 'somevalue',\n\t\t\t\t\t'uri'   => '{1}',\n\t\t\t\t)\n\t\t\t));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\tarray('id' => 1, 'location' => 'http://foo:1234/db/data/node/123'),\n\t\t\tarray('id' => 0)\n\t\t));\n\n\t\t$this->batch->addToIndex($index, $node, 'somekey', 'somevalue');\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\t\t$this->assertEquals(123, $node->getId());\n\t}\n\n\tpublic function testCommitBatch_AddToIndex_RelationshipExists_Success_ReturnsTrue()\n\t{\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId(123);\n\n\t\t$index = new Index($this->client, Index::TypeRelationship, 'indexname');\n\n\t\t$request = array(array('id' => 0, 'method' => 'POST',\n\t\t\t'to' => '/index/relationship/indexname',\n\t\t\t'body' => array(\n\t\t\t\t'key'   => 'somekey',\n\t\t\t\t'value' => 'somevalue',\n\t\t\t\t'uri'   => $this->endpoint.'/relationship/123',\n\t\t\t)\n\t\t));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(array('id' => 0)));\n\n\t\t$this->batch->addToIndex($index, $rel, 'somekey', 'somevalue');\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\t}\n\n\tpublic function testCommitBatch_AddToIndex_NoEntitiesExist_Success_ReturnsTrue()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$nodeB = new Node($this->client);\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('TEST')\n\t\t\t->setStartNode($nodeA)\n\t\t\t->setEndNode($nodeB);\n\n\t\t$index = new Index($this->client, Index::TypeRelationship, 'indexname');\n\n\t\t$request = array(\n\t\t\tarray('id' => 2, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 3, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 1, 'method' => 'POST', 'to' => '{2}/relationships',\n\t\t\t\t'body' => array('to' => '{3}', 'type' => 'TEST')\n\t\t\t),\n\t\t\tarray('id' => 0, 'method' => 'POST',\n\t\t\t\t'to' => '/index/relationship/indexname',\n\t\t\t\t'body' => array(\n\t\t\t\t\t'key'   => 'somekey',\n\t\t\t\t\t'value' => 'somevalue',\n\t\t\t\t\t'uri'   => '{1}',\n\t\t\t\t)\n\t\t\t)\n\t\t);\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\tarray('id' => 2, 'location' => 'http://foo:1234/db/data/node/123'),\n\t\t\tarray('id' => 3, 'location' => 'http://foo:1234/db/data/node/456'),\n\t\t\tarray('id' => 1, 'location' => 'http://foo:1234/db/data/relationship/789'),\n\t\t\tarray('id' => 0)\n\t\t));\n\n\t\t$this->batch->addToIndex($index, $rel, 'somekey', 'somevalue');\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\t\t$this->assertEquals(123, $nodeA->getId());\n\t\t$this->assertEquals(456, $nodeB->getId());\n\t\t$this->assertEquals(789, $rel->getId());\n\t}\n\n\tpublic function testCommitBatch_RemoveFromIndex_Entity_Success_ReturnsTrue()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$request = array(array('id' => 0, 'method' => 'DELETE',\n\t\t\t'to' => '/index/node/indexname/123'));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(array('id' => 0)));\n\n\t\t$this->batch->removeFromIndex($index, $node);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\t}\n\n\tpublic function testCommitBatch_RemoveFromIndex_EntityKey_Success_ReturnsTrue()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$request = array(array('id' => 0, 'method' => 'DELETE',\n\t\t\t'to' => '/index/node/indexname/somekey/123'));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(array('id' => 0)));\n\n\t\t$this->batch->removeFromIndex($index, $node, 'somekey');\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\t}\n\n\tpublic function testCommitBatch_RemoveFromIndex_EntityKeyValue_Success_ReturnsTrue()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$request = array(array('id' => 0, 'method' => 'DELETE',\n\t\t\t'to' => '/index/node/indexname/somekey/somevalue/123'));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(array('id' => 0)));\n\n\t\t$this->batch->removeFromIndex($index, $node, 'somekey', 'somevalue');\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\t}\n\n\tprotected function setupTransportExpectation($request, $will)\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/batch', $request)\n\t\t\t->will($will);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_Batch_NodeTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_Batch_NodeTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $batch = null;\n\tprotected $client = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->client = new Client($this->transport);\n\n\t\t$this->batch = new Batch($this->client);\n\n\t\t$this->client->getEntityCache()->setCache(new Cache\\Variable());\n\t}\n\n\tpublic function testCommitBatch_TransportError_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$request = array(array('id' => 0, 'method' => 'POST', 'to' => '/node', 'body' => null));\n\t\t\n\t\t$this->batch->save($node);\n\t\t$this->setupTransportExpectation($request, $this->returnValue(array('code' => 400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->commitBatch($this->batch);\n\t}\n\n\tpublic function testCommitBatch_CreateNode_Success_ReturnsTrue()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setProperties(array('foo' => 'bar','baz' => 'qux'));\n\n\t\t$request = array(array('id' => 0, 'method' => 'POST', 'to' => '/node',\n\t\t\t'body' => array('foo' => 'bar','baz' => 'qux')));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\t\tarray('id' => 0, 'location' => 'http://foo:1234/db/data/node/123')));\n\n\t\t$this->batch->save($node);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\t\t$this->assertEquals(123, $node->getId());\n\n\t\t$this->assertSame($node, $this->client->getEntityCache()->getCachedEntity(123, 'node'));\n\t}\n\t\n\tpublic function testCommitBatch_UpdateNode_Success_ReturnsTrue()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->useLazyLoad(false)\n\t\t\t->setId(123)\n\t\t\t->setProperties(array('foo' => 'bar','baz' => 'qux'));\n\n\t\t$request = array(array('id' => 0, 'method' => 'PUT', 'to' => '/node/123/properties',\n\t\t\t'body' => array('foo' => 'bar','baz' => 'qux')));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\t\tarray('id' => 0)));\n\n\t\t$this->batch->save($node);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\n\t\t$this->assertSame($node, $this->client->getEntityCache()->getCachedEntity(123, 'node'));\n\t}\n\t\n\tpublic function testCommitBatch_DeleteNode_Success_ReturnsTrue()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\t\t$this->client->getEntityCache()->setCachedEntity($node);\n\n\t\t$request = array(array('id' => 0, 'method' => 'DELETE', 'to' => '/node/123'));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\t\tarray('id' => 0)));\n\n\t\t$this->batch->delete($node);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\n\t\t$this->assertFalse($this->client->getEntityCache()->getCachedEntity(123, 'node'));\n\t}\n\n\tprotected function setupTransportExpectation($request, $will)\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/batch', $request)\n\t\t\t->will($will);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_Batch_RelationshipTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_Batch_RelationshipTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $batch = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\t\t$this->client = new Client($this->transport);\n\n\t\t$this->batch = new Batch($this->client);\n\n\t\t$this->client->getEntityCache()->setCache(new Cache\\Variable());\n\t}\n\n\tpublic function testCommitBatch_CreateRelationship_Success_ReturnsTrue()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$startNode->setId(123);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('TEST')\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode)\n\t\t\t->setProperties(array('foo' => 'bar','baz' => 'qux'));\n\n\t\t$request = array(array('id' => 0, 'method' => 'POST', 'to' => '/node/123/relationships',\n\t\t\t'body' => array('to' => $this->endpoint.'/node/456', 'type' => 'TEST',\n\t\t\t\t'data' => array('foo' => 'bar','baz' => 'qux'))));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\t\tarray('id' => 0, 'location' => 'http://foo:1234/db/data/relationship/789')));\n\n\t\t$this->batch->save($rel);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\t\t$this->assertEquals(789, $rel->getId());\n\n\t\t$this->assertSame($rel, $this->client->getEntityCache()->getCachedEntity(789, 'relationship'));\n\t}\n\n\tpublic function testCommitBatch_CreateRelationship_StartNodeUnidentified_ReturnsTrue()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('TEST')\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode);\n\n\t\t$request = array(\n\t\t\tarray('id' => 1, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 0, 'method' => 'POST', 'to' => '{1}/relationships',\n\t\t\t\t'body' => array('to' => $this->endpoint.'/node/456', 'type' => 'TEST')),\n\t\t);\n\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\tarray('id' => 1, 'location' => 'http://foo:1234/db/data/node/123'),\n\t\t\tarray('id' => 0, 'location' => 'http://foo:1234/db/data/relationship/789'),\n\t\t));\n\n\t\t$this->batch->save($rel);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\n\t\t$this->assertTrue($result);\n\t\t$this->assertEquals(789, $rel->getId());\n\t\t$this->assertEquals(123, $startNode->getId());\n\n\t\t$this->assertSame($rel, $this->client->getEntityCache()->getCachedEntity(789, 'relationship'));\n\t\t$this->assertSame($startNode, $this->client->getEntityCache()->getCachedEntity(123, 'node'));\n\t}\n\n\tpublic function testCommitBatch_CreateRelationship_EndNodeUnidentified_ReturnsTrue()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$startNode->setId(456);\n\t\t$endNode = new Node($this->client);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('TEST')\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode)\n\t\t\t->setProperties(array('foo' => 'bar','baz' => 'qux'));\n\n\t\t$request = array(\n\t\t\tarray('id' => 1, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 0, 'method' => 'POST', 'to' => '/node/456/relationships',\n\t\t\t\t'body' => array('to' => '{1}', 'type' => 'TEST',\n\t\t\t\t\t'data' => array('foo' => 'bar','baz' => 'qux'))),\n\t\t);\n\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\tarray('id' => 1, 'location' => 'http://foo:1234/db/data/node/123'),\n\t\t\tarray('id' => 0, 'location' => 'http://foo:1234/db/data/relationship/789'),\n\t\t));\n\n\t\t$this->batch->save($rel);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\n\t\t$this->assertTrue($result);\n\t\t$this->assertEquals(789, $rel->getId());\n\t\t$this->assertEquals(123, $endNode->getId());\n\n\t\t$this->assertSame($rel, $this->client->getEntityCache()->getCachedEntity(789, 'relationship'));\n\t\t$this->assertSame($endNode, $this->client->getEntityCache()->getCachedEntity(123, 'node'));\n\t}\n\n\tpublic function testCommitBatch_CreateRelationship_NeitherNodeUnidentified_ReturnsTrue()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$endNode = new Node($this->client);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('TEST')\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode)\n\t\t\t->setProperties(array('foo' => 'bar','baz' => 'qux'));\n\n\t\t$request = array(\n\t\t\tarray('id' => 1, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 2, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 0, 'method' => 'POST', 'to' => '{1}/relationships',\n\t\t\t\t'body' => array('to' => '{2}', 'type' => 'TEST',\n\t\t\t\t\t'data' => array('foo' => 'bar','baz' => 'qux'))),\n\t\t);\n\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\tarray('id' => 1, 'location' => 'http://foo:1234/db/data/node/123'),\n\t\t\tarray('id' => 2, 'location' => 'http://foo:1234/db/data/node/456'),\n\t\t\tarray('id' => 0, 'location' => 'http://foo:1234/db/data/relationship/789'),\n\t\t));\n\n\t\t$this->batch->save($rel);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\n\t\t$this->assertTrue($result);\n\t\t$this->assertEquals(789, $rel->getId());\n\t\t$this->assertEquals(123, $startNode->getId());\n\t\t$this->assertEquals(456, $endNode->getId());\n\n\t\t$this->assertSame($rel, $this->client->getEntityCache()->getCachedEntity(789, 'relationship'));\n\t\t$this->assertSame($startNode, $this->client->getEntityCache()->getCachedEntity(123, 'node'));\n\t\t$this->assertSame($endNode, $this->client->getEntityCache()->getCachedEntity(456, 'node'));\n\t}\n\n\tpublic function testCommitBatch_CreateRelationship_UnidentifiedNodeAlreadySavedInBatch_ReturnsTrue()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$endNode = new Node($this->client);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('TEST')\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode)\n\t\t\t->setProperties(array('foo' => 'bar','baz' => 'qux'));\n\n\t\t$request = array(\n\t\t\tarray('id' => 0, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 2, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 1, 'method' => 'POST', 'to' => '{0}/relationships',\n\t\t\t\t'body' => array('to' => '{2}', 'type' => 'TEST',\n\t\t\t\t\t'data' => array('foo' => 'bar','baz' => 'qux'))),\n\t\t);\n\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\tarray('id' => 0, 'location' => 'http://foo:1234/db/data/node/123'),\n\t\t\tarray('id' => 2, 'location' => 'http://foo:1234/db/data/node/456'),\n\t\t\tarray('id' => 1, 'location' => 'http://foo:1234/db/data/relationship/789'),\n\t\t));\n\n\t\t$this->batch->save($startNode);\n\t\t$this->batch->save($rel);\n\t\t$this->batch->save($endNode);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\n\t\t$this->assertTrue($result);\n\t\t$this->assertEquals(789, $rel->getId());\n\t\t$this->assertEquals(123, $startNode->getId());\n\t\t$this->assertEquals(456, $endNode->getId());\n\t}\n\n\tpublic function testCommitBatch_UpdateRelationship_Success_ReturnsTrue()\n\t{\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->useLazyLoad(false)\n\t\t\t->setId(123)\n\t\t\t->setProperties(array('foo' => 'bar','baz' => 'qux'));\n\n\t\t$request = array(array('id' => 0, 'method' => 'PUT', 'to' => '/relationship/123/properties',\n\t\t\t'body' => array('foo' => 'bar','baz' => 'qux')));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\t\tarray('id' => 0)));\n\n\t\t$this->batch->save($rel);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\n\t\t$this->assertSame($rel, $this->client->getEntityCache()->getCachedEntity(123, 'relationship'));\n\t}\n\n\tpublic function testCommitBatch_DeleteRelationship_Success_ReturnsTrue()\n\t{\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId(123);\n\t\t$this->client->getEntityCache()->setCachedEntity($rel);\n\n\t\t$request = array(array('id' => 0, 'method' => 'DELETE', 'to' => '/relationship/123'));\n\t\t\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\t\tarray('id' => 0)));\n\n\t\t$this->batch->delete($rel);\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\t\t$result = $this->client->commitBatch($this->batch);\n\t\t\n\t\t$this->assertTrue($result);\n\n\t\t$this->assertFalse($this->client->getEntityCache()->getCachedEntity(123, 'relationship'));\n\t}\n\n\tpublic function testImplicitBatch_StartBatch_CloseBatch_ExpectedBatchRequest()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456)->useLazyLoad(false);\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setType('TEST')\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode);\n\n\t\t$deleteNode = new Node($this->client);\n\t\t$deleteNode->setId(987);\n\n\t\t$deleteRel = new Relationship($this->client);\n\t\t$deleteRel->setId(321);\n\n\t\t$addIndexNode = new Node($this->client);\n\t\t$addIndexNode->setId(654);\n\t\t$removeIndexNode = new Node($this->client);\n\t\t$removeIndexNode->setId(209);\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$request = array(\n\t\t\tarray('id' => 0, 'method' => 'POST', 'to' => '/node', 'body' => null),\n\t\t\tarray('id' => 1, 'method' => 'PUT', 'to' => '/node/456/properties', 'body' => array()),\n\t\t\tarray('id' => 2, 'method' => 'POST', 'to' => '{0}/relationships',\n\t\t\t\t'body' => array(\n\t\t\t\t\t'to' => $this->endpoint.'/node/456',\n\t\t\t\t\t'type' => 'TEST'\n\t\t\t\t)\n\t\t\t),\n\t\t\tarray('id' => 3, 'method' => 'DELETE', 'to' => '/node/987'),\n\t\t\tarray('id' => 4, 'method' => 'DELETE', 'to' => '/relationship/321'),\n\t\t\tarray('id' => 5, 'method' => 'POST', 'to' => '/index/node/indexname',\n\t\t\t\t'body' => array(\n\t\t\t\t\t'key'   => 'addkey',\n\t\t\t\t\t'value' => 'addvalue',\n\t\t\t\t\t'uri'   => $this->endpoint.'/node/654',\n\t\t\t\t)\n\t\t\t),\n\t\t\tarray('id' => 6, 'method' => 'DELETE', 'to' => '/index/node/indexname/removekey/removevalue/209'),\n\t\t);\n\n\t\t$return = array('code' => 200, 'data' => array(\n\t\t\tarray('id' => 0, 'location' => 'http://foo:1234/db/data/node/123'),\n\t\t\tarray('id' => 1),\n\t\t\tarray('id' => 2, 'location' => 'http://foo:1234/db/data/relationship/789'),\n\t\t\tarray('id' => 3),\n\t\t\tarray('id' => 4),\n\t\t\tarray('id' => 5),\n\t\t\tarray('id' => 6),\n\t\t));\n\n\t\t$this->setupTransportExpectation($request, $this->returnValue($return));\n\n\t\t$batch = $this->client->startBatch();\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Batch', $batch);\n\n\t\t$startNode->save();\n\t\t$endNode->save();\n\t\t$rel->save();\n\t\t$deleteNode->delete();\n\t\t$deleteRel->delete();\n\t\t$index->add($addIndexNode, 'addkey', 'addvalue');\n\t\t$index->remove($removeIndexNode, 'removekey', 'removevalue');\n\n\t\t$this->assertTrue($this->client->commitBatch());\n\t\t$this->assertEquals(789, $rel->getId());\n\t\t$this->assertEquals(123, $startNode->getId());\n\t}\n\n\tprotected function setupTransportExpectation($request, $will)\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/batch', $request)\n\t\t\t->will($will);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_CacheTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_CacheTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $cache = null;\n\tprotected $client = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->cache = new Cache\\Variable();\n\n\t\t$this->client = new Client($this->transport);\n\t\t$this->client->getEntityCache()->setCache($this->cache);\n\t}\n\n\tpublic function testLoadNode_Found_NodeInCache()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$data = array('data' => array(\n\t\t\t\t'name' => 'FOO',\n\t\t));\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/'.$nodeId)\n\t\t\t->will($this->returnValue(array('code'=>'200','data'=>$data)));\n\n\t\t$this->client->loadNode($node);\n\t\t$this->assertSame($node, $this->cache->get(\"node-{$nodeId}\"));\n\t\t\n\t\t$subseq = new Node($this->client);\n\t\t$subseq->setId($nodeId);\n\t\t$this->client->loadNode($subseq);\n\t\t$this->assertEquals($node->getProperties(), $subseq->getProperties());\n\t}\n\n\tpublic function testLoadNode_NotFound_NodeNotInCache()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/'.$nodeId)\n\t\t\t->will($this->returnValue(array('code'=>'404')));\n\n\t\ttry {\n\t\t\t$this->client->loadNode($node);\n\t\t\t$this->fail();\n\t\t} catch (Exception $e) {\n\t\t\t$this->assertFalse($this->cache->get(\"node-{$nodeId}\"));\n\t\t}\n\t}\n\n\tpublic function testLoadRelationship_Found_RelationshipInCache()\n\t{\n\t\t$relId = 123;\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId($relId);\n\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'name' => 'FOO',\n\t\t\t),\n\t\t\t'start' => 'http://foo:1234/db/data/node/567',\n\t\t\t'end'   => 'http://foo:1234/db/data/node/890',\n\t\t\t'type'  => 'FOOTYPE',\n\t\t);\n\t\t\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>'200','data'=>$data)));\n\n\t\t$this->client->loadRelationship($rel);\n\t\t$this->assertSame($rel, $this->cache->get(\"relationship-{$relId}\"));\n\n\t\t$subseq = new Relationship($this->client);\n\t\t$subseq->setId($relId);\n\t\t$this->client->loadRelationship($subseq);\n\t\t$this->assertEquals($rel->getProperties(), $subseq->getProperties());\n\t}\n\n\tpublic function testLoadRelationship_NotFound_RelationshipNotInCache()\n\t{\n\t\t$relId = 123;\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId($relId);\n\t\t\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>'404','data'=>array())));\n\n\n\t\ttry {\n\t\t\t$this->client->loadRelationship($rel);\n\t\t\t$this->fail();\n\t\t} catch (Exception $e) {\n\t\t\t$this->assertFalse($this->cache->get(\"relationship-{$relId}\"));\n\t\t}\n\t}\n\n\tpublic function testGetNode_Found_SubsequentCallsReturnsFromCache()\n\t{\n\t\t$nodeId = 123;\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/node/'.$nodeId)\n\t\t\t->will($this->returnValue(array('code'=>'200','data'=>array('data'=>array()))));\n\n\t\t$node = $this->client->getNode($nodeId);\n\t\t$subseq = $this->client->getNode($nodeId);\n\t\t$this->assertSame($node, $subseq);\n\t}\n\n\tpublic function testGetRelationship_Found_SubsequentCallsReturnsFromCache()\n\t{\n\t\t$relId = 123;\n\t\t$data = array(\n\t\t\t'data' => array(),\n\t\t\t'start' => 'http://foo:1234/db/data/node/567',\n\t\t\t'end'   => 'http://foo:1234/db/data/node/890',\n\t\t\t'type'  => 'FOOTYPE',\n\t\t);\n\t\t\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>'200','data'=>$data)));\n\n\t\t$rel = $this->client->getRelationship($relId);\n\t\t$subseq = $this->client->getRelationship($relId);\n\t\t$this->assertSame($rel, $subseq);\n\t}\n\n\tpublic function testDeleteNode_Success_NodeNotInCache()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/node/'.$nodeId)\n\t\t\t->will($this->returnValue(array('code'=>'200')));\n\n\t\t$this->cache->set(\"node-{$nodeId}\", $node);\n\t\t$this->client->deleteNode($node);\n\t\t$this->assertFalse($this->cache->get(\"node-{$nodeId}\"));\n\t}\n\n\tpublic function testDeleteNode_Failure_NodeRemainsInCache()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/node/'.$nodeId)\n\t\t\t->will($this->returnValue(array('code'=>'400')));\n\n\t\t$this->cache->set(\"node-{$nodeId}\", $node);\n\t\ttry {\n\t\t\t$this->client->deleteNode($node);\n\t\t\t$this->fail();\n\t\t} catch (Exception $e) {\n\t\t\t$this->assertSame($node, $this->cache->get(\"node-{$nodeId}\"));\n\t\t}\n\t}\n\n\tpublic function testDeleteRelationship_Success_RelationshipNotInCache()\n\t{\n\t\t$relId = 123;\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId($relId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>'200')));\n\n\t\t$this->cache->set(\"relationship-{$relId}\", $rel);\n\t\t$this->client->deleteRelationship($rel);\n\t\t$this->assertFalse($this->cache->get(\"relationship-{$relId}\"));\n\t}\n\n\tpublic function testDeleteRelationship_Failure_RelationshipRemainsInCache()\n\t{\n\t\t$relId = 123;\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId($relId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/relationship/'.$relId)\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->cache->set(\"relationship-{$relId}\", $rel);\n\n\t\ttry {\n\t\t\t$this->client->deleteRelationship($rel);\n\t\t\t$this->fail();\n\t\t} catch (Exception $e) {\n\t\t\t$this->assertSame($rel, $this->cache->get(\"relationship-{$relId}\"));\n\t\t}\n\t}\n\n\tpublic function testSaveNode_Success_NodeInCache()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->useLazyLoad(false)\n\t\t\t->setId($nodeId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/node/123/properties', array())\n\t\t\t->will($this->returnValue(array('code'=>204)));\n\n\t\t$this->client->saveNode($node);\n\t\t$this->assertSame($node, $this->cache->get(\"node-{$nodeId}\"));\n\t}\n\n\tpublic function testSaveNode_Failure_NodeNotInCache()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->useLazyLoad(false)\n\t\t\t->setId($nodeId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/node/123/properties', array())\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\ttry {\n\t\t\t$this->client->saveNode($node);\n\t\t\t$this->fail();\n\t\t} catch (Exception $e) {\n\t\t\t$this->assertFalse($this->cache->get(\"node-{$nodeId}\"));\n\t\t}\n\t}\n\n\tpublic function testSaveRelationship_Success_RelationshipInCache()\n\t{\n\t\t$relId = 123;\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->useLazyLoad(false)\n\t\t\t->setId($relId);\n\t\t\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/relationship/123/properties', array())\n\t\t\t->will($this->returnValue(array('code'=>204)));\n\n\t\t$this->client->saveRelationship($rel);\n\t\t$this->assertSame($rel, $this->cache->get(\"relationship-{$relId}\"));\n\t}\n\n\tpublic function testSaveRelationship_Failure_RelationshipNotInCache()\n\t{\n\t\t$relId = 123;\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->useLazyLoad(false)\n\t\t\t->setId($relId);\n\t\t\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('put')\n\t\t\t->with('/relationship/123/properties', array())\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\ttry {\n\t\t\t$this->client->saveRelationship($rel);\n\t\t\t$this->fail();\n\t\t} catch (Exception $e) {\n\t\t\t$this->assertFalse($this->cache->get(\"relationship-{$relId}\"));\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_CypherTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_CypherTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\t\t$this->client = new Client($this->transport);\n\t}\n\n\t/**\n\t * @dataProvider dataProvider_TestCypherQuery\n\t */\n\tpublic function testCypherQuery($returnValue, $resultCount)\n\t{\n\t\t$props = array(\n\t\t\t'query' => 'START a=({start}) MATCH (a)->(b) WHERE b.name = {name} RETURN b',\n\t\t\t'params' => array('start' => 1, 'name' => 'friend name'),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\n\t\t\t\t'neo4j_version' => '1.5.foo',\n\t\t\t\t'extensions' => array('CypherPlugin' => array(\n\t\t\t\t\t'execute_query' => $this->endpoint.'/ext/CypherPlugin/graphdb/execute_query'\n\t\t\t\t)),\n\t\t\t))));\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/ext/CypherPlugin/graphdb/execute_query', $props)\n\t\t\t->will($this->returnValue($returnValue));\n\n\t\t$query = new Cypher\\Query($this->client, $props['query'], $props['params']);\n\n\t\t$result = $this->client->executeCypherQuery($query);\n\t\t$this->assertInstanceOf('\\Everyman\\Neo4j\\Query\\ResultSet', $result);\n\t\t$this->assertEquals(count($result), $resultCount);\n\t}\n\n\t/**\n\t * @dataProvider dataProvider_TestCypherQuery\n\t */\n\tpublic function testCypherQuery_NewEndpoint($returnValue, $resultCount)\n\t{\n\t\t$props = array(\n\t\t\t'query' => 'START a=({start}) MATCH (a)->(b) WHERE b.name = {name} RETURN b',\n\t\t\t'params' => array('start' => 1, 'name' => 'friend name'),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\n\t\t\t\t'neo4j_version' => '1.5.foo',\n\t\t\t\t'cypher' => $this->endpoint.'/cypher',\n\t\t\t))));\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/cypher', $props)\n\t\t\t->will($this->returnValue($returnValue));\n\n\t\t$query = new Cypher\\Query($this->client, $props['query'], $props['params']);\n\n\t\t$result = $this->client->executeCypherQuery($query);\n\t\t$this->assertInstanceOf('\\Everyman\\Neo4j\\Query\\ResultSet', $result);\n\t\t$this->assertEquals(count($result), $resultCount);\n\t}\n\n\t/**\n\t * Test for http://github.com/jadell/neo4jphp/issues/63\n\t * @dataProvider dataProvider_TestCypherQuery\n\t */\n\tpublic function testCypherQuery_ProxyHost($returnValue, $resultCount)\n\t{\n\t\t$proxyEndpoint = 'http://proxy.me:1234/db/data';\n\t\t$transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($proxyEndpoint));\n\t\t$client = new Client($transport);\n\n\t\t$props = array(\n\t\t\t'query' => 'START a=({start}) MATCH (a)->(b) WHERE b.name = {name} RETURN b',\n\t\t\t'params' => array('start' => 1, 'name' => 'friend name'),\n\t\t);\n\n\t\t$transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\n\t\t\t\t'neo4j_version' => '1.5.foo',\n\t\t\t\t'cypher' => $this->endpoint.'/cypher',\n\t\t\t))));\n\t\t$transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/cypher', $props)\n\t\t\t->will($this->returnValue($returnValue));\n\n\t\t$query = new Cypher\\Query($client, $props['query'], $props['params']);\n\n\t\t$result = $client->executeCypherQuery($query);\n\t\t$this->assertInstanceOf('\\Everyman\\Neo4j\\Query\\ResultSet', $result);\n\t\t$this->assertEquals(count($result), $resultCount);\n\t}\n\n\tpublic function dataProvider_TestCypherQuery()\n\t{\n\t\t$return = array(\n\t\t\t'columns' => array('name','age'),\n\t\t\t'data' => array(\n\t\t\t\tarray('Bob', 12),\n\t\t\t\tarray('Lotta', 0),\n\t\t\t\tarray('Brenda', 14)\n\t\t\t)\n\t\t);\n\n\t\treturn array(\n\t\t\tarray(array('code'=>204,'data'=>null), 0),\n\t\t\tarray(array('code'=>200,'data'=>$return), 3),\n\t\t);\n\t}\n\n\tpublic function testCypherQuery_ServerReturnsErrorCode_ThrowsException()\n\t{\n\t\t$props = array(\n\t\t\t'query' => 'START a=(0) RETURN a'\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\n\t\t\t\t'neo4j_version' => '1.5.foo',\n\t\t\t\t'extensions' => array('CypherPlugin' => array(\n\t\t\t\t\t'execute_query' => $this->endpoint.'/ext/CypherPlugin/graphdb/execute_query'\n\t\t\t\t)),\n\t\t\t))));\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/ext/CypherPlugin/graphdb/execute_query', $props)\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$query = new Cypher\\Query($this->client, $props['query']);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->executeCypherQuery($query);\n\t}\n\n\tpublic function testCypherQuery_CypherNotAvailable_ThrowsException()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\n\t\t\t\t'neo4j_version' => '1.5.foo',\n\t\t\t))));\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$query = new Cypher\\Query($this->client, 'query');\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->executeCypherQuery($query);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_GremlinTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_GremlinTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('getServerInfo'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('getServerInfo')\n\t\t\t->will($this->returnValue(array(\n\t\t\t\t'extensions' => array(\n\t\t\t\t\t'GremlinPlugin' => array(\n\t\t\t\t\t\t'execute_script' => $this->endpoint.'/ext/GremlinPlugin/graphdb/execute_script',\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)));\n\t}\n\n\tpublic function testGremlinQuery_ServerReturnsErrorCode_ReturnsFalse()\n\t{\n\t\t$props = array(\n\t\t\t'script' => 'i=g.foo(start);',\n\t\t\t'params' => array('start' => 123),\n\t\t);\n\t\t$query = new Gremlin\\Query($this->client, $props['script'], $props['params']);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/ext/GremlinPlugin/graphdb/execute_script', $props)\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->executeGremlinQuery($query);\n\t}\n\n\tpublic function testGremlinQuery_DataAndColumnsReturned_ReturnsResultSet()\n\t{\n\t\t$props = array(\n\t\t\t'script' => 'i=g.foo(start);',\n\t\t\t'params' => array('start' => 123),\n\t\t);\n\t\t$query = new Gremlin\\Query($this->client, $props['script'], $props['params']);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/ext/GremlinPlugin/graphdb/execute_script', $props)\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array(\n\t\t\t\t'columns' => array('name','age'),\n\t\t\t\t'data' => array(\n\t\t\t\t\tarray('Bob', 12),\n\t\t\t\t\tarray('Lotta', 0),\n\t\t\t\t\tarray('Brenda', 14)\n\t\t\t\t)\n\t\t\t))));\n\n\t\t$result = $this->client->executeGremlinQuery($query);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Query\\ResultSet', $result);\n\t\t$this->assertEquals('Brenda', $result[2]['name']);\n\t}\n\n\tpublic function testGremlinQuery_ListOfEntitiesReturned_ReturnsResultSet()\n\t{\n\t\t$props = array('script' => 'i=g.foo();');\n\t\t$query = new Gremlin\\Query($this->client, $props['script']);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/ext/GremlinPlugin/graphdb/execute_script', $props)\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array(\n\t\t\t\tarray('self' => 'http://foo:1234/db/data/node/1','data'=>array()),\n\t\t\t\tarray('self' => 'http://foo:1234/db/data/node/2','data'=>array()),\n\t\t\t\tarray('self' => 'http://foo:1234/db/data/node/3','data'=>array()),\n\t\t\t))));\n\n\t\t$result = $this->client->executeGremlinQuery($query);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Query\\ResultSet', $result);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[1][0]);\n\t\t$this->assertEquals(2, $result[1][0]->getId());\n\t}\n\n\tpublic function testGremlinQuery_SingleEntityReturned_ReturnsResultSet()\n\t{\n\t\t$props = array('script' => 'i=g.foo();');\n\t\t$query = new Gremlin\\Query($this->client, $props['script']);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/ext/GremlinPlugin/graphdb/execute_script', $props)\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array(\n\t\t\t\t'self' => 'http://foo:1234/db/data/node/2',\n\t\t\t\t'data' => array()\n\t\t\t))));\n\n\t\t$result = $this->client->executeGremlinQuery($query);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Query\\ResultSet', $result);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0][0]);\n\t\t$this->assertEquals(2, $result[0][0]->getId());\n\t}\n\n\tpublic function testGremlinQuery_ScalarValueReturned_ReturnsResultSet()\n\t{\n\t\t$props = array('script' => 'i=g.foo();');\n\t\t$query = new Gremlin\\Query($this->client, $props['script']);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/ext/GremlinPlugin/graphdb/execute_script', $props)\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>\"this is some scalar value\")));\n\n\t\t$result = $this->client->executeGremlinQuery($query);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Query\\ResultSet', $result);\n\t\t$this->assertEquals(\"this is some scalar value\", $result[0][0]);\n\t}\n\n\tpublic function testGremlinQuery_GremlinNotAvailable_ThrowsException()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('getServerInfo'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('getServerInfo')\n\t\t\t->will($this->returnValue(array('extensions' => array())));\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$props = array('script' => 'i=g.foo();');\n\t\t$query = new Gremlin\\Query($this->client, $props['script']);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->executeGremlinQuery($query);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_IndexTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_IndexTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\t\t$this->client = new Client($this->transport);\n\t}\n\n\tpublic function testSaveIndex_UnknownIndexType_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, 'FOO', 'indexname');\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->saveIndex($index);\n\t}\n\n\tpublic function testSaveIndex_NoName_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, null);\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->saveIndex($index);\n\t}\n\n\t/**\n\t * @dataProvider dataProvider_SaveIndexScenarios\n\t */\n\tpublic function testSaveIndex_ReturnsSuccess($type, $name, $config, $result)\n\t{\n\t\t$index = new Index($this->client, $type, $name, $config);\n\t\t$data = array('name' => $name);\n\t\tif ($config) {\n\t\t\t$data['config'] = $config;\n\t\t}\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/index/'.$type, $data)\n\t\t\t->will($this->returnValue($result));\n\n\t\t$this->assertTrue($this->client->saveIndex($index));\n\t}\n\n\tpublic function dataProvider_SaveIndexScenarios()\n\t{\n\t\treturn array(// type, name, config, result\n\t\t\tarray(Index::TypeNode, 'somekey', array(), array('code'=>201)),\n\t\t\tarray(Index::TypeRelationship, 'somekey', array(), array('code'=>201)),\n\t\t\tarray(Index::TypeNode, 'somekey', array('type' => 'fulltext'), array('code'=>201)),\n\t\t);\n\t}\n\n\tpublic function testSaveIndex_ServerError_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'somekey');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/index/node', array(\n\t\t\t\t'name' => 'somekey',\n\t\t\t))\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->saveIndex($index);\n\t}\n\n\tpublic function testDeleteIndex_UnknownIndexType_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, 'FOO', 'indexname');\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->deleteIndex($index);\n\t}\n\n\tpublic function testDeleteIndex_NoName_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, null);\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->deleteIndex($index);\n\t}\n\n\t/**\n\t * @dataProvider dataProvider_SaveIndexScenarios\n\t */\n\tpublic function testDeleteIndex_ReturnsSuccess($type, $name, $config, $result)\n\t{\n\t\t$index = new Index($this->client, $type, $name);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/index/'.$type.'/'.$name)\n\t\t\t->will($this->returnValue($result));\n\n\t\t$this->assertTrue($this->client->deleteIndex($index));\n\t}\n\n\tpublic function testDeleteIndex_ServerError_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'somekey');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/index/node/somekey')\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->deleteIndex($index);\n\t}\n\n\tpublic function testDeleteIndex_UrlEntities_ReturnsCorrectSuccess()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'ind@ex na$me');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/index/node/ind%40ex%20na%24me')\n\t\t\t->will($this->returnValue(array('code'=>200)));\n\n\t\t$this->assertTrue($this->client->deleteIndex($index));\n\t}\n\n\tpublic function testDeleteIndex_NotFound_ReturnsSuccess()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/index/node/indexname')\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->assertTrue($this->client->deleteIndex($index));\n\t}\n\n\tpublic function testAddToIndex_UnknownIndexType_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, 'FOO', 'indexname');\n\t\t$node = new Node($this->client);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->addToIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function dataProvider_AddToIndexScenarios_NoName_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, null);\n\t\t$node = new Node($this->client);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->addToIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function dataProvider_AddToIndexScenarios_WrongEntityType_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeRelationship, 'indexname');\n\t\t$node = new Node($this->client);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->addToIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testAddToIndex_EntityAdded_ReturnsSuccess()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$data = array(\n\t\t\t'key'   => 'somekey',\n\t\t\t'value' => 'somevalue',\n\t\t\t'uri'   => $this->endpoint.'/node/123',\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/index/node/indexname', $data)\n\t\t\t->will($this->returnValue(array('code'=>201)));\n\n\t\t$this->assertTrue($this->client->addToIndex($index, $node, 'somekey', 'somevalue'));\n\t}\n\t\n\tpublic function testAddToIndex_UrlEntities_ReturnsCorrectSuccess()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'index name');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$data = array(\n\t\t\t'key'   => 'some@key',\n\t\t\t'value' => 'some$value',\n\t\t\t'uri'   => $this->endpoint.'/node/123',\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/index/node/index%20name', $data)\n\t\t\t->will($this->returnValue(array('code'=>200)));\n\n\t\t$this->assertTrue($this->client->addToIndex($index, $node, 'some@key', 'some$value'));\n\t}\n\n\tpublic function testAddToIndex_ServerError_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$data = array(\n\t\t\t'key'   => 'somekey',\n\t\t\t'value' => 'somevalue',\n\t\t\t'uri'   => $this->endpoint.'/node/123',\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/index/node/indexname', $data)\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->addToIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testAddToIndex_BadIndexName_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, null);\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->addToIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testAddToIndex_EntityNotPersisted_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$node = new Node($this->client);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->addToIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testAddToIndex_BadType_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, 'FOOTYPE', 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->addToIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testAddToIndex_BadKey_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->addToIndex($index, $node, null, 'somevalue');\n\t}\n\n\tpublic function testAddToIndex_RelationshipTypeMismatch_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeRelationship, 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->addToIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testAddToIndex_NodeTypeMismatch_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId(123);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->addToIndex($index, $rel, 'somekey', 'somevalue');\n\t}\n\n\t/**\n\t * @dataProvider dataProvider_RemoveFromIndexScenarios\n\t */\n\tpublic function testRemoveFromIndex_ReturnsSuccess($key, $value, $path, $result)\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/index/node/indexname'.$path.'/123')\n\t\t\t->will($this->returnValue($result));\n\n\t\t$this->assertTrue($this->client->removeFromIndex($index, $node, $key, $value));\n\t}\n\t\n\tpublic function dataProvider_RemoveFromIndexScenarios()\n\t{\n\t\treturn array(// key, value, path, result\n\t\t\tarray('somekey', 'somevalue', '/somekey/somevalue', array('code'=>201)),\n\t\t\tarray('somekey', null, '/somekey', array('code'=>201)),\n\t\t\tarray(null, null, '', array('code'=>201)),\n\t\t\tarray('some key@', 'som$e value', '/some%20key%40/som%24e%20value', array('code'=>201)),\n\t\t);\n\t}\n\n\tpublic function testRemoveFromIndex_NotFound_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/index/node/indexname/somekey/somevalue/123')\n\t\t\t->will($this->returnValue(array('code'=>404)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->removeFromIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testRemoveFromIndex_ServerError_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/index/node/indexname/somekey/somevalue/123')\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->removeFromIndex($index, $node, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testRemoveFromIndex_BadIndexName_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, null);\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->removeFromIndex($index, $node);\n\t}\n\n\tpublic function testRemoveFromIndex_EntityNotPersisted_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$node = new Node($this->client);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->removeFromIndex($index, $node);\n\t}\n\n\tpublic function testRemoveFromIndex_BadType_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, 'FOOTYPE', 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->removeFromIndex($index, $node);\n\t}\n\n\tpublic function testRemoveFromIndex_RelationshipTypeMismatch_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeRelationship, 'indexname');\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->removeFromIndex($index, $node);\n\t}\n\n\tpublic function testRemoveFromIndex_NodeTypeMismatch_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setId(123);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->removeFromIndex($index, $rel);\n\t}\n\n\tpublic function testSearchIndex_BadType_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, 'badtype', 'indexname');\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->searchIndex($index, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testSearchIndex_NoIndexName_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, null);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->searchIndex($index, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testSearchIndex_NoKeySpecified_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->searchIndex($index, null, 'somevalue');\n\t}\n\n\tpublic function testSearchIndex_Error_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/node/indexname/somekey/somevalue')\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->searchIndex($index, 'somekey', 'somevalue');\n\t}\n\n\tpublic function testSearchIndex_NodesFound_ReturnsArray()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$return = array(\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/123\",\n\t\t\t\t\"data\" => array(\"foo\"=>\"bar\"),\n\t\t\t),\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/456\",\n\t\t\t\t\"data\" => array(\"baz\"=>\"qux\"),\n\t\t\t)\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/node/indexname/somekey/somevalue')\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$return)));\n\n\t\t$result = $this->client->searchIndex($index, 'somekey', 'somevalue');\n\t\t$this->assertEquals(2, count($result));\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]);\n\t\t$this->assertEquals(123, $result[0]->getId());\n\t\t$this->assertEquals(array('foo'=>'bar'), $result[0]->getProperties());\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[1]);\n\t\t$this->assertEquals(456, $result[1]->getId());\n\t\t$this->assertEquals(array('baz'=>'qux'), $result[1]->getProperties());\n\t}\n\n\tpublic function testSearchIndex_RelationshipsFound_ReturnsArray()\n\t{\n\t\t$index = new Index($this->client, Index::TypeRelationship, 'indexname');\n\n\t\t$return = array(\n\t\t\tarray(\n\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/123\",\n\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/456\",\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/789\",\n\t\t\t\t\"type\" => \"FOOTYPE\",\n\t\t\t\t\"data\" => array(\"foo\"=>\"bar\"),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/relationship/indexname/somekey/somevalue')\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$return)));\n\n\t\t$result = $this->client->searchIndex($index, 'somekey', 'somevalue');\n\t\t$this->assertEquals(1, count($result));\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $result[0]);\n\t\t$this->assertEquals(789, $result[0]->getId());\n\t\t$this->assertEquals(array('foo'=>'bar'), $result[0]->getProperties());\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getStartNode());\n\t\t$this->assertEquals(123, $result[0]->getStartNode()->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getEndNode());\n\t\t$this->assertEquals(456, $result[0]->getEndNode()->getId());\n\t}\n\n\tpublic function testSearchIndex_UrlEntities_ReturnsArray()\n\t{\n\t\t$index = new Index($this->client, Index::TypeRelationship, 'index name');\n\n\t\t$return = array(\n\t\t\tarray(\n\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/123\",\n\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/456\",\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/789\",\n\t\t\t\t\"type\" => \"FOOTYPE\",\n\t\t\t\t\"data\" => array(\"foo\"=>\"bar\"),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/relationship/index%20name/some%40key/some%24value')\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$return)));\n\n\t\t$result = $this->client->searchIndex($index, 'some@key', 'some$value');\n\t\t$this->assertEquals(1, count($result));\n\t}\n\n\tpublic function testQueryIndex_BadType_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, 'badtype', 'indexname');\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->queryIndex($index, 'somekey:somevalue*');\n\t}\n\n\n\tpublic function testQueryIndex_NoIndexName_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, null);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->queryIndex($index, 'somekey:somevalue*');\n\t}\n\n\n\tpublic function testQueryIndex_NoQuerySpecified_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->queryIndex($index, null);\n\t}\n\n\n\tpublic function testQueryIndex_Error_ThrowsException()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/node/indexname?query='.rawurlencode('somekey:somevalue*'))\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->queryIndex($index, 'somekey:somevalue*');\n\t}\n\n\n\tpublic function testQueryIndex_NodesFound_ReturnsArray()\n\t{\n\t\t$index = new Index($this->client, Index::TypeNode, 'indexname');\n\n\t\t$return = array(\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/123\",\n\t\t\t\t\"data\" => array(\"foo\"=>\"bar\"),\n\t\t\t),\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/456\",\n\t\t\t\t\"data\" => array(\"baz\"=>\"qux\"),\n\t\t\t)\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/node/indexname?query='.rawurlencode('somekey:somevalue*'))\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$return)));\n\n\t\t$result = $this->client->queryIndex($index, 'somekey:somevalue*');\n\t\t$this->assertEquals(2, count($result));\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]);\n\t\t$this->assertEquals(123, $result[0]->getId());\n\t\t$this->assertEquals(array('foo'=>'bar'), $result[0]->getProperties());\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[1]);\n\t\t$this->assertEquals(456, $result[1]->getId());\n\t\t$this->assertEquals(array('baz'=>'qux'), $result[1]->getProperties());\n\t}\n\n\n\tpublic function testQueryIndex_RelationshipsFound_ReturnsArray()\n\t{\n\t\t$index = new Index($this->client, Index::TypeRelationship, 'indexname');\n\n\t\t$return = array(\n\t\t\tarray(\n\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/123\",\n\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/456\",\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/789\",\n\t\t\t\t\"type\" => \"FOOTYPE\",\n\t\t\t\t\"data\" => array(\"foo\"=>\"bar\"),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/relationship/indexname?query='.rawurlencode('somekey:somevalue*'))\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$return)));\n\n\t\t$result = $this->client->queryIndex($index, 'somekey:somevalue*');\n\t\t$this->assertEquals(1, count($result));\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $result[0]);\n\t\t$this->assertEquals(789, $result[0]->getId());\n\t\t$this->assertEquals(array('foo'=>'bar'), $result[0]->getProperties());\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getStartNode());\n\t\t$this->assertEquals(123, $result[0]->getStartNode()->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getEndNode());\n\t\t$this->assertEquals(456, $result[0]->getEndNode()->getId());\n\t}\n\t\t\n\tpublic function testGetIndexes_ServerError_ThrowsException()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/node')\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$results = $this->client->getIndexes(Index::TypeNode);\n\t}\n\n\tpublic function testGetIndexes_BadType_ThrowsException()\n\t{\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->getIndexes('foo');\n\t}\n\n\tpublic function testGetIndexes_NoIndexes_ReturnsEmptyArray()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/node')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>'')));\n\n\t\t$results = $this->client->getIndexes(Index::TypeNode);\n\t\t$this->assertInternalType('array', $results);\n\t\t$this->assertEquals(0, count($results));\n\t}\n\n\tpublic function testGetIndexes_NodeType_ReturnsArray()\n\t{\n\t\t$favoritesConfig = array(\n\t\t\t'template' =>'http://0.0.0.0:7474/db/data/index/node/favorites/{key}/{value}',\n\t\t\t'provider' =>'lucene',\n\t\t\t'type' =>'exact',\n\t\t);\n\n\t\t$usersConfig = array(\n\t\t\t'template' =>'http://0.0.0.0:7474/db/data/index/node/users/{key}/{value}',\n\t\t\t'provider' =>'lucene',\n\t\t\t'type' =>'fulltext',\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/node')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\n\t\t\t'favorites' => $favoritesConfig,\n\t\t\t'users' => $usersConfig,\n\t\t))));\n\n\t\t$results = $this->client->getIndexes(Index::TypeNode);\n\t\t$this->assertEquals(2, count($results));\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Index', $results[0]);\n\t\t$this->assertEquals(Index::TypeNode, $results[0]->getType());\n\t\t$this->assertEquals('favorites', $results[0]->getName());\n\t\t$this->assertEquals($favoritesConfig, $results[0]->getConfig());\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Index', $results[1]);\n\t\t$this->assertEquals(Index::TypeNode, $results[1]->getType());\n\t\t$this->assertEquals('users', $results[1]->getName());\n\t\t$this->assertEquals($usersConfig, $results[1]->getConfig());\n\t}\n\n\tpublic function testGetIndexes_RelationshipType_ReturnsArray()\n\t{\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with('/index/relationship')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\n\t\t\t'favorites' => array('template' =>'http://0.0.0.0:7474/db/data/index/relationship/favorites/{key}/{value}'),\n\t\t\t'users' => array('template' =>'http://0.0.0.0:7474/db/data/index/relationship/users/{key}/{value}'),\n\t\t))));\n\n\t\t$results = $this->client->getIndexes(Index::TypeRelationship);\n\t\t$this->assertEquals(2, count($results));\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Index', $results[0]);\n\t\t$this->assertEquals(Index::TypeRelationship, $results[0]->getType());\n\t\t$this->assertEquals('favorites', $results[0]->getName());\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Index', $results[1]);\n\t\t$this->assertEquals(Index::TypeRelationship, $results[1]->getType());\n\t\t$this->assertEquals('users', $results[1]->getName());\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_LabelTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_LabelTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('getServerInfo'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('getServerInfo')\n\t\t\t->will($this->returnValue(array(\n\t\t\t\t'cypher' => $this->endpoint.'/cypher',\n\t\t\t\t'version' => array(\n\t\t\t\t\t\"full\" => \"2.0.0-M06\",\n\t\t\t\t\t\"major\" => \"2\",\n\t\t\t\t\t\"minor\" => \"0\",\n\t\t\t\t)\n\t\t\t)));\n\t}\n\n\tpublic function testMakeLabel_ReturnsLabel()\n\t{\n\t\t$labelNameA = 'FOOBAR';\n\t\t$labelNameB = 'BAZQUX';\n\n\t\t$labelA = $this->client->makeLabel($labelNameA);\n\t\t$labelB = $this->client->makeLabel($labelNameB);\n\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Label', $labelA);\n\t\tself::assertEquals($labelNameA, $labelA->getName());\n\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Label', $labelB);\n\t\tself::assertEquals($labelNameB, $labelB->getName());\n\t}\n\n\tpublic function testMakeLabel_SameName_ReturnsSameLabelInstance()\n\t{\n\t\t$labelName = 'FOOBAR';\n\n\t\t$labelA = $this->client->makeLabel($labelName);\n\t\t$labelB = $this->client->makeLabel($labelName);\n\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Label', $labelA);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Label', $labelB);\n\t\tself::assertSame($labelA, $labelB);\n\t}\n\n\tpublic function testGetNodesForLabel_NodesExistForLabel_ReturnsRow()\n\t{\n\t\t$labelName = 'FOOBAR';\n\t\t$label = new Label($this->client, $labelName);\n\n\t\t$returnData = array(\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/56\",\n\t\t\t\t\"data\" => array(),\n\t\t\t),\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/834\",\n\t\t\t\t\"data\" => array(),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with(\"/label/{$labelName}/nodes\")\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\n\t\t$nodes = $this->client->getNodesForLabel($label);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Query\\Row', $nodes);\n\t\tself::assertEquals(2, count($nodes));\n\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[1]);\n\t\tself::assertEquals(56,  $nodes[0]->getId());\n\t\tself::assertEquals(834, $nodes[1]->getId());\n\t}\n\n\tpublic function testGetNodesForLabel_NodesExistForLabelAndProperty_ReturnsRow()\n\t{\n\t\t$labelName = 'FOOBAR';\n\t\t$propertyName = 'baz';\n\t\t$propertyValue = 'qux';\n\t\t$label = new Label($this->client, $labelName);\n\n\t\t$returnData = array(\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/56\",\n\t\t\t\t\"data\" => array($propertyName => $propertyValue),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with(\"/label/{$labelName}/nodes?{$propertyName}=%22{$propertyValue}%22\")\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\n\t\t$nodes = $this->client->getNodesForLabel($label, $propertyName, $propertyValue);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Query\\Row', $nodes);\n\t\tself::assertEquals(1, count($nodes));\n\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\tself::assertEquals(56,  $nodes[0]->getId());\n\t}\n\n\tpublic function testGetNodesForLabel_NoNodesExist_ReturnsEmptyRow()\n\t{\n\t\t$labelName = 'FOOBAR';\n\t\t$label = new Label($this->client, $labelName);\n\n\t\t$returnData = array();\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with(\"/label/{$labelName}/nodes\")\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\n\t\t$nodes = $this->client->getNodesForLabel($label);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Query\\Row', $nodes);\n\t\tself::assertEquals(0, count($nodes));\n\t}\n\n\tpublic function testGetNodesForLabel_ProperlyUrlEncodesPath()\n\t{\n\t\t$labelName = 'FOO+Bar /Baz';\n\t\t$propertyName = 'ba$! \"z qux\"';\n\t\t$propertyValue = 'f @oo !B\"/+%20ar ';\n\t\t$label = new Label($this->client, $labelName);\n\n\t\t$expectedLabel = rawurlencode($labelName);\n\t\t$expectedName = rawurlencode($propertyName);\n\t\t$expectedValue = rawurlencode('\"'.$propertyValue.'\"');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with(\"/label/{$expectedLabel}/nodes?{$expectedName}={$expectedValue}\")\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array())));\n\n\t\t$this->client->getNodesForLabel($label, $propertyName, $propertyValue);\n\t}\n\n\tpublic function testGetNodesForLabel_PropertyWithIntegerValueGiven_CallsClientMethod()\n\t{\n\t\t$labelName = 'FOOBAR';\n\t\t$propertyName = 'baz';\n\t\t$propertyValue = 1;\n\t\t$label = new Label($this->client, $labelName);\n\n\t\t$returnData = array(\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/56\",\n\t\t\t\t\"data\" => array($propertyName => $propertyValue),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with(\"/label/{$labelName}/nodes?{$propertyName}={$propertyValue}\")\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\n\t\t$nodes = $this->client->getNodesForLabel($label, $propertyName, $propertyValue);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Query\\Row', $nodes);\n\t\tself::assertEquals(1, count($nodes));\n\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\tself::assertEquals(56,  $nodes[0]->getId());\n\t}\n\n\tpublic function testGetNodesForLabel_PropertyNameWithoutValue_ThrowsException()\n\t{\n\t\t$labelName = 'FOOBAR';\n\t\t$label = new Label($this->client, $labelName);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('get');\n\n\t\t$this->setExpectedException('InvalidArgumentException');\n\t\t$this->client->getNodesForLabel($label, 'prop', null);\n\t}\n\n\tpublic function testGetNodesForLabel_PropertyValueWithoutName_ThrowsException()\n\t{\n\t\t$labelName = 'FOOBAR';\n\t\t$label = new Label($this->client, $labelName);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('get');\n\n\t\t$this->setExpectedException('InvalidArgumentException');\n\t\t$this->client->getNodesForLabel($label, null, 'val');\n\t}\n\n\tpublic function testGetNodesForLabel_NoLabelCapability_ThrowsException()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('getServerInfo'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('getServerInfo')\n\t\t\t->will($this->returnValue(array(\n\t\t\t\t'cypher' => $this->endpoint.'/cypher',\n\t\t\t\t'version' => array(\n\t\t\t\t\t\"full\" => \"1.9.0\",\n\t\t\t\t\t\"major\" => \"1\",\n\t\t\t\t\t\"minor\" => \"9\",\n\t\t\t\t)\n\t\t\t)));\n\n\t\t$labelName = 'FOOBAR';\n\t\t$label = new Label($this->client, $labelName);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('get');\n\n\t\t$this->setExpectedException('RuntimeException', 'label capability');\n\t\t$this->client->getNodesForLabel($label);\n\t}\n\n\tpublic function testGetLabels_NoNode_ReturnsArrayOfLabelsAttachedToNodesOnTheServer()\n\t{\n\t\t$labelAlreadyInstantiated = $this->client->makeLabel('BAZQUX');\n\n\t\t$returnData = array('FOOBAR', $labelAlreadyInstantiated->getName(), 'LOREMIPSUM');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with(\"/labels\")\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\n\t\t$labels = $this->client->getLabels();\n\t\tself::assertEquals(count($returnData), count($labels));\n\t\tforeach ($labels as $i => $label) {\n\t\t\tself::assertInstanceOf('Everyman\\Neo4j\\Label', $label);\n\t\t\tself::assertEquals($returnData[$i], $label->getName());\n\t\t}\n\n\t\tself::assertSame($labelAlreadyInstantiated, $labels[1]);\n\t}\n\n\tpublic function testGetLabels_NodeSpecified_ReturnsArrayOfLabelsAttachedToNode()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$returnData = array('FOOBAR', 'BAZQUX');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with(\"/node/{$nodeId}/labels\")\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\n\t\t$labels = $this->client->getLabels($node);\n\t\tself::assertEquals(count($returnData), count($labels));\n\t\tforeach ($labels as $i => $label) {\n\t\t\tself::assertInstanceOf('Everyman\\Neo4j\\Label', $label);\n\t\t\tself::assertEquals($returnData[$i], $label->getName());\n\t\t}\n\t}\n\n\tpublic function testGetLabels_NodeIdZero_ReturnsArrayOfLabelsAttachedToNode()\n\t{\n\t\t$nodeId = 0;\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$returnData = array('FOOBAR', 'BAZQUX');\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('get')\n\t\t\t->with(\"/node/{$nodeId}/labels\")\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\n\t\t$labels = $this->client->getLabels($node);\n\t\tself::assertEquals(count($returnData), count($labels));\n\t\tforeach ($labels as $i => $label) {\n\t\t\tself::assertInstanceOf('Everyman\\Neo4j\\Label', $label);\n\t\t\tself::assertEquals($returnData[$i], $label->getName());\n\t\t}\n\t}\n\n\tpublic function testGetLabels_NoNodeId_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('get');\n\n\t\t$this->setExpectedException('InvalidArgumentException');\n\t\t$labels = $this->client->getLabels($node);\n\t}\n\n\tpublic function testGetLabels_NoLabelCapabiltiy_ThrowsException()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('getServerInfo'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('getServerInfo')\n\t\t\t->will($this->returnValue(array(\n\t\t\t\t'cypher' => $this->endpoint.'/cypher',\n\t\t\t\t'version' => array(\n\t\t\t\t\t\"full\" => \"1.9.0\",\n\t\t\t\t\t\"major\" => \"1\",\n\t\t\t\t\t\"minor\" => \"9\",\n\t\t\t\t)\n\t\t\t)));\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('get');\n\n\t\t$this->setExpectedException('RuntimeException', 'label capability');\n\t\t$this->client->getLabels();\n\t}\n\n\tpublic function testAddLabels_SendsCorrectCypherQuery()\n\t{\n\t\t$nodeId = 123;\n\t\t$labelAName = 'FOOBAR';\n\t\t$labelBName = 'BAZ QUX';\n\t\t$labelCName = 'HACK`THIS';\n\n\t\t$escapedCName = 'HACK``THIS';\n\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$labelA = $this->client->makeLabel($labelAName);\n\t\t$labelB = $this->client->makeLabel($labelBName);\n\t\t$labelC = $this->client->makeLabel($labelCName);\n\n\t\t$expectedLabels = array('LOREMIPSUM', $labelAName, $labelBName, $labelCName);\n\n\t\t$expectedQuery = \"START n=node({nodeId}) SET n:`{$labelAName}`:`{$labelBName}`:`{$escapedCName}` RETURN labels(n) AS labels\";\n\t\t$expectedParams = array(\"nodeId\" => $nodeId);\n\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\n\t\t\t\t'neo4j_version' => '2.0.foo',\n\t\t\t\t'cypher' => $this->endpoint.'/cypher',\n\t\t\t))));\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/cypher', array(\n\t\t\t\t'query'  => $expectedQuery,\n\t\t\t\t'params' => $expectedParams,\n\t\t\t))\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array(\n\t\t\t\t'columns' => array('labels'),\n\t\t\t\t'data' => array(array($expectedLabels)),\n\t\t\t))));\n\n\t\t$resultLabels = $this->client->addLabels($node, array($labelA, $labelB, $labelC));\n\t\tself::assertEquals(count($expectedLabels), count($resultLabels));\n\t\tforeach ($resultLabels as $i => $label) {\n\t\t\tself::assertInstanceOf('Everyman\\Neo4j\\Label', $label);\n\t\t\tself::assertEquals($expectedLabels[$i], $label->getName());\n\t\t}\n\t}\n\n\tpublic function testAddLabels_NoLabelCapability_ThrowsException()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$labelAName = 'FOOBAR';\n\t\t$labelA = $this->client->makeLabel($labelAName);\n\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('getServerInfo'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('getServerInfo')\n\t\t\t->will($this->returnValue(array(\n\t\t\t\t'cypher' => $this->endpoint.'/cypher',\n\t\t\t\t'version' => array(\n\t\t\t\t\t\"full\" => \"1.9.0\",\n\t\t\t\t\t\"major\" => \"1\",\n\t\t\t\t\t\"minor\" => \"9\",\n\t\t\t\t)\n\t\t\t)));\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('get');\n\n\t\t$this->setExpectedException('RuntimeException');\n\t\t$this->client->addLabels($node, array($labelA));\n\t}\n\n\tpublic function testAddLabels_NoNodeId_ThrowsException()\n\t{\n\t\t$labelAName = 'FOOBAR';\n\t\t$labelA = $this->client->makeLabel($labelAName);\n\n\t\t$node = new Node($this->client);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$this->setExpectedException('InvalidArgumentException', 'unsaved node');\n\t\t$this->client->addLabels($node, array($labelA));\n\t}\n\n\tpublic function testAddLabels_NodeIdZero_DoesNotThrowException()\n\t{\n\t\t$nodeId = 0;\n\t\t$labelAName = 'FOOBAR';\n\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$labelA = $this->client->makeLabel($labelAName);\n\n\t\t$expectedQuery = \"START n=node({nodeId}) SET n:`{$labelAName}` RETURN labels(n) AS labels\";\n\t\t$expectedParams = array(\"nodeId\" => $nodeId);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/cypher', array(\n\t\t\t\t'query'  => $expectedQuery,\n\t\t\t\t'params' => $expectedParams,\n\t\t\t))\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array(\n\t\t\t\t'columns' => array('labels'),\n\t\t\t\t'data' => array(array(array($labelAName))),\n\t\t\t))));\n\n\t\t$resultLabels = $this->client->addLabels($node, array($labelA));\n\t\tself::assertEquals(1, count($resultLabels));\n\t\tself::assertEquals($labelAName, $resultLabels[0]->getName());\n\t}\n\n\tpublic function testAddLabels_NonLabelGiven_ThrowsException()\n\t{\n\t\t$labelAName = 'FOOBAR';\n\t\t$labelA = $this->client->makeLabel($labelAName);\n\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$this->setExpectedException('InvalidArgumentException', 'non-label');\n\t\t$this->client->addLabels($node, array($labelA, 'not-a-label'));\n\t}\n\n\tpublic function testAddLabels_NoLabelsGiven_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$this->setExpectedException('InvalidArgumentException', 'No labels');\n\t\t$this->client->addLabels($node, array());\n\t}\n\n\tpublic function testRemoveLabels_SendsCorrectCypherQuery()\n\t{\n\t\t$nodeId = 123;\n\t\t$labelAName = 'FOOBAR';\n\t\t$labelBName = 'BAZ QUX';\n\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$labelA = $this->client->makeLabel($labelAName);\n\t\t$labelB = $this->client->makeLabel($labelBName);\n\n\t\t$expectedLabels = array('LOREMIPSUM', $labelAName, $labelBName);\n\n\t\t$expectedQuery = \"START n=node({nodeId}) REMOVE n:`{$labelAName}`:`{$labelBName}` RETURN labels(n) AS labels\";\n\t\t$expectedParams = array(\"nodeId\" => $nodeId);\n\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('get')\n\t\t\t->with('/')\n\t\t\t->will($this->returnValue(array('code'=>200, 'data'=>array(\n\t\t\t\t'neo4j_version' => '2.0.foo',\n\t\t\t\t'cypher' => $this->endpoint.'/cypher',\n\t\t\t))));\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/cypher', array(\n\t\t\t\t'query'  => $expectedQuery,\n\t\t\t\t'params' => $expectedParams,\n\t\t\t))\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>array(\n\t\t\t\t'columns' => array('labels'),\n\t\t\t\t'data' => array(array($expectedLabels)),\n\t\t\t))));\n\n\t\t$resultLabels = $this->client->removeLabels($node, array($labelA, $labelB));\n\t\tself::assertEquals(count($expectedLabels), count($resultLabels));\n\t\tforeach ($resultLabels as $i => $label) {\n\t\t\tself::assertInstanceOf('Everyman\\Neo4j\\Label', $label);\n\t\t\tself::assertEquals($expectedLabels[$i], $label->getName());\n\t\t}\n\t}\n\n\tpublic function testRemoveLabels_NoLabelCapability_ThrowsException()\n\t{\n\t\t$nodeId = 123;\n\t\t$node = new Node($this->client);\n\t\t$node->setId($nodeId);\n\n\t\t$labelAName = 'FOOBAR';\n\t\t$labelA = $this->client->makeLabel($labelAName);\n\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('getServerInfo'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('getServerInfo')\n\t\t\t->will($this->returnValue(array(\n\t\t\t\t'cypher' => $this->endpoint.'/cypher',\n\t\t\t\t'version' => array(\n\t\t\t\t\t\"full\" => \"1.9.0\",\n\t\t\t\t\t\"major\" => \"1\",\n\t\t\t\t\t\"minor\" => \"9\",\n\t\t\t\t)\n\t\t\t)));\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('get');\n\n\t\t$this->setExpectedException('RuntimeException');\n\t\t$this->client->removeLabels($node, array($labelA));\n\t}\n\n\tpublic function testRemoveLabels_NoNodeId_ThrowsException()\n\t{\n\t\t$labelAName = 'FOOBAR';\n\t\t$labelA = $this->client->makeLabel($labelAName);\n\n\t\t$node = new Node($this->client);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$this->setExpectedException('InvalidArgumentException', 'unsaved node');\n\t\t$this->client->removeLabels($node, array($labelA));\n\t}\n\n\tpublic function testRemoveLabels_NonLabelGiven_ThrowsException()\n\t{\n\t\t$labelAName = 'FOOBAR';\n\t\t$labelA = $this->client->makeLabel($labelAName);\n\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$this->setExpectedException('InvalidArgumentException', 'non-label');\n\t\t$this->client->removeLabels($node, array($labelA, 'not-a-label'));\n\t}\n\n\tpublic function testRemoveLabels_NoLabelsGiven_ThrowsException()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(123);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$this->setExpectedException('InvalidArgumentException', 'No labels');\n\t\t$this->client->removeLabels($node, array());\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_PathTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_PathTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\t\t$this->client = new Client($this->transport);\n\t}\n\n\tpublic function testGetPaths_PathsExist_ReturnsArray()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$startNode->setId(123);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456);\n\t\t\n\t\t$finder = new PathFinder($this->client);\n\t\t$finder->setType('FOOTYPE')\n\t\t\t->setDirection(Relationship::DirectionOut)\n\t\t\t->setMaxDepth(3)\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode);\n\t\t\n\t\t$data = array(\n\t\t\t'to' => $this->endpoint.'/node/456',\n\t\t\t'relationships' => array('type'=>'FOOTYPE', 'direction'=>Relationship::DirectionOut),\n\t\t\t'max_depth' => 3,\n\t\t\t'max depth' => 3,\n\t\t\t'algorithm' => 'shortestPath'\n\t\t);\n\t\t\n\t\t$returnData = array(\n\t\t\tarray(\n\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/123\",\n\t\t\t\t\"nodes\" => array(\"http://localhost:7474/db/data/node/123\", \"http://localhost:7474/db/data/node/341\", \"http://localhost:7474/db/data/node/456\"),\n\t\t\t\t\"length\" => 2,\n\t\t\t\t\"relationships\" => array(\"http://localhost:7474/db/data/relationship/564\", \"http://localhost:7474/db/data/relationship/32\"),\n\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/456\"\n\t\t\t),\n\t\t\tarray(\n\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/123\",\n\t\t\t\t\"nodes\" => array(\"http://localhost:7474/db/data/node/123\", \"http://localhost:7474/db/data/node/41\", \"http://localhost:7474/db/data/node/456\"),\n\t\t\t\t\"length\" => 2,\n\t\t\t\t\"relationships\" => array(\"http://localhost:7474/db/data/relationship/437\", \"http://localhost:7474/db/data/relationship/97\"),\n\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/456\"\n\t\t\t),\n\t\t);\n\t\t\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/123/paths', $data)\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\t\t\t\n\t\t$paths = $this->client->getPaths($finder);\n\t\t$this->assertEquals(2, count($paths));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Path', $paths[0]);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Path', $paths[1]);\n\t\t\n\t\t$rels = $paths[0]->getRelationships();\n\t\t$this->assertEquals(2, count($rels));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[0]);\n\t\t$this->assertEquals(564, $rels[0]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[1]);\n\t\t$this->assertEquals(32, $rels[1]->getId());\n\n\t\t$nodes = $paths[0]->getNodes();\n\t\t$this->assertEquals(3, count($nodes));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\t$this->assertEquals(123, $nodes[0]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[1]);\n\t\t$this->assertEquals(341, $nodes[1]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[2]);\n\t\t$this->assertEquals(456, $nodes[2]->getId());\n\t\t\n\t\t$rels = $paths[1]->getRelationships();\n\t\t$this->assertEquals(2, count($rels));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[0]);\n\t\t$this->assertEquals(437, $rels[0]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[1]);\n\t\t$this->assertEquals(97, $rels[1]->getId());\n\n\t\t$nodes = $paths[1]->getNodes();\n\t\t$this->assertEquals(3, count($nodes));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\t$this->assertEquals(123, $nodes[0]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[1]);\n\t\t$this->assertEquals(41, $nodes[1]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[2]);\n\t\t$this->assertEquals(456, $nodes[2]->getId());\n\t}\n\t\n\tpublic function testGetPaths_NoMaxDepth_MaxDepthDefaultsToOne_ReturnsArray()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$startNode->setId(123);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456);\n\t\t\n\t\t$finder = new PathFinder($this->client);\n\t\t$finder->setType('FOOTYPE')\n\t\t\t->setDirection(Relationship::DirectionOut)\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode);\n\t\t\n\t\t$data = array(\n\t\t\t'to' => $this->endpoint.'/node/456',\n\t\t\t'relationships' => array('type'=>'FOOTYPE', 'direction'=>Relationship::DirectionOut),\n\t\t\t'max_depth' => 1,\n\t\t\t'max depth' => 1,\n\t\t\t'algorithm' => 'shortestPath'\n\t\t);\n\t\t\n\t\t$returnData = array();\n\t\t\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/123/paths', $data)\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\t\t\t\n\t\t$paths = $this->client->getPaths($finder);\n\t\t$this->assertEquals(0, count($paths));\n\t}\n\n\tpublic function testGetPaths_DirectionGivenButNoType_ThrowsException()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$startNode->setId(123);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456);\n\t\t\n\t\t$finder = new PathFinder($this->client);\n\t\t$finder->setDirection(Relationship::DirectionOut)\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode);\n\t\t\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$paths = $this->client->getPaths($finder);\n\t}\n\t\n\tpublic function testGetPaths_StartNodeNotPersisted_ThrowsException()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456);\n\t\t\n\t\t$finder = new PathFinder($this->client);\n\t\t$finder->setStartNode($startNode)\n\t\t\t->setEndNode($endNode);\n\t\t\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$paths = $this->client->getPaths($finder);\n\t}\n\t\n\tpublic function testGetPaths_EndNodeNotPersisted_ThrowsException()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$startNode->setId(123);\n\t\t$endNode = new Node($this->client);\n\t\t\n\t\t$finder = new PathFinder($this->client);\n\t\t$finder->setStartNode($startNode)\n\t\t\t->setEndNode($endNode);\n\t\t\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$paths = $this->client->getPaths($finder);\n\t}\n\t\n\tpublic function testGetPaths_DijkstraSearchNoCostProperty_ThrowsException()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$startNode->setId(123);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456);\n\t\t\n\t\t$finder = new PathFinder($this->client);\n\t\t$finder->setStartNode($startNode)\n\t\t\t->setEndNode($endNode)\n\t\t\t->setAlgorithm(PathFinder::AlgoDijkstra);\n\t\t\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$paths = $this->client->getPaths($finder);\n\t}\n\t\n\tpublic function testGetPaths_DijkstraSearch_ReturnsResult()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$startNode->setId(123);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456);\n\t\t\n\t\t$finder = new PathFinder($this->client);\n\t\t$finder->setStartNode($startNode)\n\t\t\t->setEndNode($endNode)\n\t\t\t->setAlgorithm(PathFinder::AlgoDijkstra)\n\t\t\t->setCostProperty('distance')\n\t\t\t->setDefaultCost(2);\n\t\t\n\t\t$data = array(\n\t\t\t'to' => $this->endpoint.'/node/456',\n\t\t\t'max_depth' => 1,\n\t\t\t'max depth' => 1,\n\t\t\t'algorithm' => 'dijkstra',\n\t\t\t'cost_property' => 'distance',\n\t\t\t'cost property' => 'distance',\n\t\t\t'default_cost' => 2,\n\t\t\t'default cost' => 2,\n\t\t);\n\t\t\n\t\t$returnData = array();\n\t\t\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/123/paths', $data)\n\t\t\t->will($this->returnValue(array('code'=>200,'data'=>$returnData)));\n\t\t\t\n\t\t$paths = $this->client->getPaths($finder);\n\t\t$this->assertEquals(0, count($paths));\n\t}\n\t\n\tpublic function testGetPaths_TransportFails_ThrowsException()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$startNode->setId(123);\n\t\t$endNode = new Node($this->client);\n\t\t$endNode->setId(456);\n\t\t\n\t\t$finder = new PathFinder($this->client);\n\t\t$finder->setType('FOOTYPE')\n\t\t\t->setDirection(Relationship::DirectionOut)\n\t\t\t->setMaxDepth(3)\n\t\t\t->setStartNode($startNode)\n\t\t\t->setEndNode($endNode);\n\t\t\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('post')\n\t\t\t->will($this->returnValue(array('code'=>400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\t\t\t\n\t\t$this->client->getPaths($finder);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_TransactionTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_TransactionTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('hasCapability'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('hasCapability')\n\t\t\t->will($this->returnValue(true));\n\t}\n\n\tpublic function testBeginTransaction_ReturnsNewTransactionWithNoId()\n\t{\n\t\t$result = $this->client->beginTransaction();\n\t\tself::assertInstanceOf('\\Everyman\\Neo4j\\Transaction', $result);\n\t\tself::assertNull($result->getId());\n\t}\n\n\tpublic function testAddStatements_NewTransaction_ReturnsResultSetAndSetsTransactionId()\n\t{\n\t\t$queryTemplateA = \"This is the query template\";\n\t\t$queryParamsA = array('foo' => 'bar', 'baz' => 123);\n\t\t$queryA = new Cypher\\Query($this->client, $queryTemplateA, $queryParamsA);\n\n\t\t$queryTemplateB = \"This is the query template B\";\n\t\t$queryParamsB = array('foo' => 'barB', 'bazB' => 456);\n\t\t$queryB = new Cypher\\Query($this->client, $queryTemplateB, $queryParamsB);\n\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$expectedRequest = array(\n\t\t\t'statements' => array(\n\t\t\t\tarray(\n\t\t\t\t\t'statement'  => $queryTemplateA,\n\t\t\t\t\t'parameters' => (object)$queryParamsA,\n\t\t\t\t\t'resultDataContents' => array('rest'),\n\t\t\t\t),\n\t\t\t\tarray(\n\t\t\t\t\t'statement'  => $queryTemplateB,\n\t\t\t\t\t'parameters' => (object)$queryParamsB,\n\t\t\t\t\t'resultDataContents' => array('rest'),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\t$expectedResponse = array(\n\t\t\t\"commit\" => $this->endpoint . '/transaction/987/commit',\n\t\t\t\"transaction\" => array(\"expires\" => \"Wed, 16 Oct 2013 23:07:12 +0000\"),\n\t\t\t\"errors\" => array(),\n\t\t\t\"results\" => array(\n\t\t\t\t// Result of queryA\n\t\t\t\tarray(\n\t\t\t\t\t'columns' => array('name','age'),\n\t\t\t\t\t'data' => array(\n\t\t\t\t\t\tarray(\"rest\" => array('Bob', 12)),\n\t\t\t\t\t\tarray(\"rest\" => array('Lotta', 0)),\n\t\t\t\t\t\tarray(\"rest\" => array('Brenda', 14)),\n\t\t\t\t\t)\n\t\t\t\t),\n\t\t\t\t// Result of queryB\n\t\t\t\tarray(\n\t\t\t\t\t'columns' => array('count','somenode'),\n\t\t\t\t\t'data' => array(\n\t\t\t\t\t\tarray(\"rest\" => array(\n\t\t\t\t\t\t\t5,\n\t\t\t\t\t\t\tarray(\n\t\t\t\t\t\t\t\t\"self\" => $this->endpoint.'/node/34',\n\t\t\t\t\t\t\t\t\"data\" => array(\"baz\" => \"qux\"),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)),\n\t\t\t\t\t\tarray(\"rest\" => array(\n\t\t\t\t\t\t\t2,\n\t\t\t\t\t\t\tarray(\n\t\t\t\t\t\t\t\t\"self\" => $this->endpoint.'/node/21',\n\t\t\t\t\t\t\t\t\"data\" => array(\"lorem\" => \"ipsum\"),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)),\n\t\t\t\t\t)\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/transaction', $expectedRequest)\n\t\t\t->will($this->returnValue(array(\"code\" => 201, \"data\" => $expectedResponse)));\n\n\t\t$result = $this->client->addStatementsToTransaction($transaction, array($queryA, $queryB));\n\t\tself::assertInternalType('array', $result);\n\t\tself::assertEquals(2, count($result));\n\n\t\t$resultA = $result[0];\n\t\tself::assertInstanceOf('\\Everyman\\Neo4j\\Query\\ResultSet', $resultA);\n\t\tself::assertEquals(3, count($resultA));\n\t\tself::assertEquals('Bob', $resultA[0]['name']);\n\t\tself::assertEquals(12, $resultA[0]['age']);\n\n\t\t$resultB = $result[1];\n\t\tself::assertInstanceOf('\\Everyman\\Neo4j\\Query\\ResultSet', $resultB);\n\t\tself::assertEquals(2, count($resultB));\n\t\tself::assertEquals(2, $resultB[1]['count']);\n\t\tself::assertInstanceOf('\\Everyman\\Neo4j\\Node', $resultB[1]['somenode']);\n\t\tself::assertEquals(21, $resultB[1]['somenode']->getId());\n\t\tself::assertEquals('ipsum', $resultB[1]['somenode']->getProperty('lorem'));\n\n\t\tself::assertEquals(987, $transaction->getId());\n\t\tself::assertFalse($transaction->isClosed());\n\t\tself::assertFalse($transaction->isError());\n\t}\n\n\tpublic function testAddStatements_NoParams_ParamsSentAsEmptyObject()\n\t{\n\t\t$queryTemplateA = \"This is the query template\";\n\t\t$queryA = new Cypher\\Query($this->client, $queryTemplateA);\n\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$expectedRequest = array(\n\t\t\t'statements' => array(\n\t\t\t\tarray(\n\t\t\t\t\t'statement'  => $queryTemplateA,\n\t\t\t\t\t'parameters' => (object)array(),\n\t\t\t\t\t'resultDataContents' => array('rest'),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\t$expectedResponse = array(\n\t\t\t\"commit\" => $this->endpoint . '/transaction/987/commit',\n\t\t\t\"transaction\" => array(\"expires\" => \"Wed, 16 Oct 2013 23:07:12 +0000\"),\n\t\t\t\"errors\" => array(),\n\t\t\t\"results\" => array(\n\t\t\t\t// Result of queryA\n\t\t\t\tarray(\n\t\t\t\t\t'columns' => array('name'),\n\t\t\t\t\t'data' => array(\n\t\t\t\t\t\tarray(\"rest\" => array('Brenda')),\n\t\t\t\t\t)\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/transaction', $expectedRequest)\n\t\t\t->will($this->returnValue(array(\"code\" => 201, \"data\" => $expectedResponse)));\n\n\t\t$result = $this->client->addStatementsToTransaction($transaction, array($queryA));\n\t\tself::assertInternalType('array', $result);\n\t\tself::assertEquals(1, count($result));\n\t}\n\n\tpublic function testAddStatements_ExistingTransactionId_ReturnsResultSet()\n\t{\n\t\t$queryA = new Cypher\\Query($this->client, 'foobar');\n\n\t\t$transaction = new Transaction($this->client);\n\t\t$transaction->setId(321);\n\n\t\t$expectedResponse = array(\n\t\t\t\"commit\" => $this->endpoint . '/transaction/321/commit',\n\t\t\t\"transaction\" => array(\"expires\" => \"Wed, 16 Oct 2013 23:07:12 +0000\"),\n\t\t\t\"errors\" => array(),\n\t\t\t\"results\" => array(),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/transaction/'.$transaction->getId())\n\t\t\t->will($this->returnValue(array(\"code\" => 200, \"data\" => $expectedResponse)));\n\n\t\t$this->client->addStatementsToTransaction($transaction, array($queryA));\n\t\tself::assertFalse($transaction->isClosed());\n\t\tself::assertFalse($transaction->isError());\n\t}\n\n\tpublic function testAddStatements_TransactionFailed_ThrowsException()\n\t{\n\t\t$queryA = new Cypher\\Query($this->client, 'foobar');\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$expectedResponse = array(\n\t\t\t\"commit\" => $this->endpoint . '/transaction/321/commit',\n\t\t\t\"transaction\" => array(\"expires\" => \"Wed, 16 Oct 2013 23:07:12 +0000\"),\n\t\t\t\"errors\" => array(),\n\t\t\t\"results\" => array(),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/transaction')\n\t\t\t->will($this->returnValue(array(\"code\" => 400)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->addStatementsToTransaction($transaction, array($queryA));\n\t}\n\n\tpublic function testAddStatements_ErrorsGiven_ThrowsException()\n\t{\n\t\t$queryA = new Cypher\\Query($this->client, 'foobar');\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$expectedResponse = array(\n\t\t\t\"commit\" => $this->endpoint . '/transaction/321/commit',\n\t\t\t\"transaction\" => array(\"expires\" => \"Wed, 16 Oct 2013 23:07:12 +0000\"),\n\t\t\t\"errors\" => array(\"foo bar error\"),\n\t\t\t\"results\" => array(),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/transaction')\n\t\t\t->will($this->returnValue(array(\"code\" => 200, \"data\" => $expectedResponse)));\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->addStatementsToTransaction($transaction, array($queryA));\n\t}\n\n\tpublic function testAddStatements_NewTransactionWithCommit_ReturnsResulSet()\n\t{\n\t\t$queryA = new Cypher\\Query($this->client, 'foobar');\n\t\t$transaction = new Transaction($this->client);\n\t\t$commit = true;\n\n\t\t$expectedResponse = array(\n\t\t\t\"errors\" => array(),\n\t\t\t\"results\" => array(),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/transaction/commit')\n\t\t\t->will($this->returnValue(array(\"code\" => 200, \"data\" => $expectedResponse)));\n\n\t\t$this->client->addStatementsToTransaction($transaction, array($queryA), $commit);\n\t}\n\n\tpublic function testAddStatements_ExistingTransactionWithCommit_ReturnsResulSet()\n\t{\n\t\t$queryA = new Cypher\\Query($this->client, 'foobar');\n\t\t$transaction = new Transaction($this->client);\n\t\t$transaction->setId(321);\n\t\t$commit = true;\n\n\t\t$expectedResponse = array(\n\t\t\t\"commit\" => $this->endpoint . '/transaction/321/commit',\n\t\t\t\"transaction\" => array(\"expires\" => \"Wed, 16 Oct 2013 23:07:12 +0000\"),\n\t\t\t\"errors\" => array(),\n\t\t\t\"results\" => array(),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/transaction/'.$transaction->getId().'/commit')\n\t\t\t->will($this->returnValue(array(\"code\" => 200, \"data\" => $expectedResponse)));\n\n\t\t$this->client->addStatementsToTransaction($transaction, array($queryA), $commit);\n\t}\n\n\tpublic function testAddStatements_KeepAlive_HasTransactionId_SendsToTransportWithoutStatements()\n\t{\n\t\t$transaction = new Transaction($this->client);\n\t\t$transaction->setId(321);\n\n\t\t$expectedRequest = array(\n\t\t\t'statements' => array(),\n\t\t);\n\n\t\t$expectedResponse = array(\n\t\t\t\"commit\" => $this->endpoint . '/transaction/321/commit',\n\t\t\t\"transaction\" => array(\"expires\" => \"Wed, 16 Oct 2013 23:07:12 +0000\"),\n\t\t\t\"errors\" => array(),\n\t\t\t\"results\" => array(),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/transaction/'.$transaction->getId(), $expectedRequest)\n\t\t\t->will($this->returnValue(array(\"code\" => 200, \"data\" => $expectedResponse)));\n\n\t\t$this->client->addStatementsToTransaction($transaction, array());\n\t}\n\n\tpublic function testAddStatements_KeepAlive_NoTransactionId_ThrowsException()\n\t{\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->addStatementsToTransaction($transaction, array());\n\t}\n\n\tpublic function testAddStatements_NoTransactionCapability_ThrowsException()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('hasCapability'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('hasCapability')\n\t\t\t->will($this->returnValue(false));\n\n\t\t$queryA = new Cypher\\Query($this->client, 'foobar');\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('post');\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->addStatementsToTransaction($transaction, array($queryA));\n\t}\n\n\tpublic function testRollback_HasTransactionId_SendsDelete()\n\t{\n\t\t$transaction = new Transaction($this->client);\n\t\t$transaction->setId(321);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('delete')\n\t\t\t->with('/transaction/'.$transaction->getId())\n\t\t\t->will($this->returnValue(array(\"code\" => 200)));\n\n\t\t$this->client->rollbackTransaction($transaction);\n\t}\n\n\tpublic function testRollback_NoTransactionId_ThrowsException()\n\t{\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('delete');\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->rollbackTransaction($transaction);\n\t}\n\n\tpublic function testRollback_NoTransactionCapability_ThrowsException()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('hasCapability'), array($this->transport));\n\t\t$this->client->expects($this->any())\n\t\t\t->method('hasCapability')\n\t\t\t->will($this->returnValue(false));\n\n\t\t$transaction = new Transaction($this->client);\n\t\t$transaction->setId(321);\n\n\t\t$this->transport->expects($this->never())\n\t\t\t->method('delete');\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->rollbackTransaction($transaction);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Client_TraversalTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass Client_TraversalTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $transport = null;\n\tprotected $client = null;\n\tprotected $endpoint = 'http://foo:1234/db/data';\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\t\t$this->client = new Client($this->transport);\n\t}\n\t\n\tpublic function testTraversal_NoNodeId_ThrowsException()\n\t{\n\t\t$traversal = new Traversal($this->client);\n\t\t$node = new Node($this->client);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->executeTraversal($traversal, $node, Traversal::ReturnTypeNode);\n\t}\n\n\tpublic function testTraversal_BadReturnType_ThrowsException()\n\t{\n\t\t$traversal = new Traversal($this->client);\n\t\t$node = new Node($this->client);\n\t\t$node->setId(1);\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception');\n\t\t$this->client->executeTraversal($traversal, $node, 'FOOTYPE');\n\t}\n\n\t/**\n\t * @dataProvider dataProvider_TestTraversal\n\t */\n\tpublic function testTraversal_TraversalOptions_PassesThroughCorrectDataToTransport($traversal, $expectedData)\n\t{\n\t\t$node = new Node($this->client);\n\t\t$node->setId(1);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/1/traverse/node', $expectedData)\n\t\t\t->will($this->returnValue(array(\"code\"=>200,\"data\"=>array())));\n\n\t\t$result = $this->client->executeTraversal($traversal, $node, Traversal::ReturnTypeNode);\n\t\t$this->assertEquals(array(), $result);\n\t}\n\t\n\tpublic function dataProvider_TestTraversal()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->transport->expects($this->any())\n\t\t\t->method('getEndpoint')\n\t\t\t->will($this->returnValue($this->endpoint));\n\t\t$this->client = new Client($this->transport);\n\n\t\t$scenarios = array();\n\n\t\t$traversal = new Traversal($this->client);\n\t\t$scenarios[] = array($traversal, array());\n\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->setOrder(Traversal::OrderDepthFirst);\n\t\t$scenarios[] = array($traversal, array(\n\t\t\t\"order\" => \"depth_first\",\n\t\t));\n\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->setUniqueness(Traversal::UniquenessNodePath);\n\t\t$scenarios[] = array($traversal, array(\n\t\t\t\"uniqueness\" => \"node_path\",\n\t\t));\n\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->setMaxDepth(2);\n\t\t$scenarios[] = array($traversal, array(\n\t\t\t\"max_depth\" => 2,\n\t\t));\n\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->addRelationship('FOOTYPE')\n\t\t\t->addRelationship('BARTYPE', Relationship::DirectionIn);\n\t\t$scenarios[] = array($traversal, array(\n\t\t\t\"relationships\" => array(\n\t\t\t\tarray('type'=>'FOOTYPE'),\n\t\t\t\tarray('type'=>'BARTYPE', 'direction' => 'in'),\n\t\t\t),\n\t\t));\n\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->setPruneEvaluator('javascript', \"position.endNode().getProperty('date')>1234567;\");\n\t\t$scenarios[] = array($traversal, array(\n\t\t\t\"prune_evaluator\" => array(\n\t\t\t\t\"language\" => \"javascript\",\n\t\t\t\t\"body\" => \"position.endNode().getProperty('date')>1234567;\",\n\t\t\t),\n\t\t));\n\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->setPruneEvaluator(Traversal::PruneNone);\n\t\t$scenarios[] = array($traversal, array(\n\t\t\t\"prune_evaluator\" => array(\n\t\t\t\t\"language\" => \"builtin\",\n\t\t\t\t\"name\" => \"none\",\n\t\t\t),\n\t\t));\n\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->setReturnFilter('javascript', \"position.endNode().getProperty('date')>1234567;\");\n\t\t$scenarios[] = array($traversal, array(\n\t\t\t\"return_filter\" => array(\n\t\t\t\t\"language\" => \"javascript\",\n\t\t\t\t\"body\" => \"position.endNode().getProperty('date')>1234567;\",\n\t\t\t),\n\t\t));\n\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->setReturnFilter(Traversal::ReturnAll);\n\t\t$scenarios[] = array($traversal, array(\n\t\t\t\"return_filter\" => array(\n\t\t\t\t\"language\" => \"builtin\",\n\t\t\t\t\"name\" => \"all\",\n\t\t\t),\n\t\t));\n\n\t\treturn $scenarios;\n\t}\n\n\tpublic function testTraversal_ReturnTypeNode_ReturnsArrayOfNodes()\n\t{\n\t\t$traversal = new Traversal($this->client);\n\t\t$node = new Node($this->client);\n\t\t$node->setId(1);\n\n\t\t$data = array(\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/2\",\n\t\t\t\t\"data\" => array(\n\t\t\t\t\t\"name\" => \"foo\",\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/1/traverse/node', array())\n\t\t\t->will($this->returnValue(array(\"code\"=>200,\"data\"=>$data)));\n\n\t\t$result = $this->client->executeTraversal($traversal, $node, Traversal::ReturnTypeNode);\n\t\t$this->assertEquals(1, count($result));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]);\n\t\t$this->assertEquals(2, $result[0]->getId());\n\t\t$this->assertEquals('foo', $result[0]->getProperty('name'));\n\t}\n\n\tpublic function testTraversal_ReturnTypeRelationship_ReturnsArrayOfRelationships()\n\t{\n\t\t$traversal = new Traversal($this->client);\n\t\t$node = new Node($this->client);\n\t\t$node->setId(1);\n\n\t\t$data = array(\n\t\t\tarray(\n\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/2\",\n\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/1\",\n\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/3\",\n\t\t\t\t\"type\" => \"FOOTYPE\",\n\t\t\t\t\"data\" => array(\n\t\t\t\t\t\"name\" => \"foo\",\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/1/traverse/relationship', array())\n\t\t\t->will($this->returnValue(array(\"code\"=>200,\"data\"=>$data)));\n\n\t\t$result = $this->client->executeTraversal($traversal, $node, Traversal::ReturnTypeRelationship);\n\t\t$this->assertEquals(1, count($result));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $result[0]);\n\t\t$this->assertEquals(2, $result[0]->getId());\n\t\t$this->assertEquals('foo', $result[0]->getProperty('name'));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getStartNode());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getEndNode());\n\t\t$this->assertEquals(1, $result[0]->getStartNode()->getId());\n\t\t$this->assertEquals(3, $result[0]->getEndNode()->getId());\n\t}\n\n\tpublic function testTraversal_ReturnTypePath_ReturnsArrayOfPaths()\n\t{\n\t\t$traversal = new Traversal($this->client);\n\t\t$node = new Node($this->client);\n\t\t$node->setId(1);\n\n\t\t$data = array(\n\t\t\tarray(\n\t\t\t\t\"relationships\" => array(\"http://localhost:7474/db/data/relationship/2\"),\n\t\t\t\t\"nodes\" => array(\"http://localhost:7474/db/data/node/1\",\"http://localhost:7474/db/data/node/3\"),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/1/traverse/path', array())\n\t\t\t->will($this->returnValue(array(\"code\"=>200,\"data\"=>$data)));\n\n\t\t$result = $this->client->executeTraversal($traversal, $node, Traversal::ReturnTypePath);\n\t\t$this->assertEquals(1, count($result));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Path', $result[0]);\n\t\t\n\t\t$rels = $result[0]->getRelationships();\n\t\t$this->assertEquals(1, count($rels));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[0]);\n\t\t$this->assertEquals(2, $rels[0]->getId());\n\n\t\t$nodes = $result[0]->getNodes();\n\t\t$this->assertEquals(2, count($nodes));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\t$this->assertEquals(1, $nodes[0]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[1]);\n\t\t$this->assertEquals(3, $nodes[1]->getId());\n\t}\n\n\tpublic function testTraversal_ReturnTypeFullPath_ReturnsArrayOfPaths()\n\t{\n\t\t$traversal = new Traversal($this->client);\n\t\t$node = new Node($this->client);\n\t\t$node->setId(1);\n\n\t\t$data = array(\n\t\t\tarray(\n\t\t\t\t\"relationships\" => array(\n\t\t\t\t\tarray(\n\t\t\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/2\",\n\t\t\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/1\",\n\t\t\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/3\",\n\t\t\t\t\t\t\"type\" => \"FOOTYPE\",\n\t\t\t\t\t\t\"data\" => array(\n\t\t\t\t\t\t\t\"name\" => \"baz\",\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\t\"nodes\" => array(\n\t\t\t\t\tarray(\n\t\t\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/1\",\n\t\t\t\t\t\t\"data\" => array(\n\t\t\t\t\t\t\t\"name\" => \"foo\",\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t\tarray(\n\t\t\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/3\",\n\t\t\t\t\t\t\"data\" => array(\n\t\t\t\t\t\t\t\"name\" => \"bar\",\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/1/traverse/fullpath', array())\n\t\t\t->will($this->returnValue(array(\"code\"=>200,\"data\"=>$data)));\n\n\t\t$result = $this->client->executeTraversal($traversal, $node, Traversal::ReturnTypeFullPath);\n\t\t$this->assertEquals(1, count($result));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Path', $result[0]);\n\t\t\n\t\t$rels = $result[0]->getRelationships();\n\t\t$this->assertEquals(1, count($rels));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[0]);\n\t\t$this->assertEquals(2, $rels[0]->getId());\n\t\t$this->assertEquals('FOOTYPE', $rels[0]->getType());\n\t\t$this->assertEquals('baz', $rels[0]->getProperty('name'));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rels[0]->getStartNode());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rels[0]->getEndNode());\n\t\t$this->assertEquals(1, $rels[0]->getStartNode()->getId());\n\t\t$this->assertEquals(3, $rels[0]->getEndNode()->getId());\n\n\t\t$nodes = $result[0]->getNodes();\n\t\t$this->assertEquals(2, count($nodes));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\t$this->assertEquals(1, $nodes[0]->getId());\n\t\t$this->assertEquals('foo', $nodes[0]->getProperty('name'));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[1]);\n\t\t$this->assertEquals(3, $nodes[1]->getId());\n\t\t$this->assertEquals('bar', $nodes[1]->getProperty('name'));\n\t}\n\n\tpublic function testTraversal_ServerReturnsErrorCode_ThrowsException()\n\t{\n\t\t$traversal = new Traversal($this->client);\n\t\t$node = new Node($this->client);\n\t\t$node->setId(1);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/1/traverse/node', array())\n\t\t\t->will($this->returnValue(array(\"code\"=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$result = $this->client->executeTraversal($traversal, $node, Traversal::ReturnTypeNode);\n\t}\n\n\tpublic function testPagedTraversal_TraversalGiven_ReturnsResultSets()\n\t{\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->setOrder(Traversal::OrderDepthFirst);\n\n\t\t$node = new Node($this->client);\n\t\t$node->setId(1);\n\n\t\t$pager = new Pager($traversal, $node, Traversal::ReturnTypeNode);\n\t\t$pager->setPageSize(1)\n\t\t\t->setLeaseTime(30);\n\n\t\t$data = array(\n\t\t\t// First results page\n\t\t\tarray(\n\t\t\t\tarray(\n\t\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/2\",\n\t\t\t\t\t\"data\" => array(\n\t\t\t\t\t\t\"name\" => \"foo\",\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\n\t\t\t// Second results page\n\t\t\tarray(\n\t\t\t\tarray(\n\t\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/3\",\n\t\t\t\t\t\"data\" => array(\n\t\t\t\t\t\t\"name\" => \"bar\",\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t\t\n\t\t$this->transport->expects($this->at(0))\n\t\t\t->method('post')\n\t\t\t->with('/node/1/paged/traverse/node?pageSize=1&leaseTime=30',array(\"order\" => \"depth_first\"))\n\t\t\t->will($this->returnValue(array(\"code\"=>200,\"data\"=>$data[0],\"headers\"=>array('Location' => \"http://localhost:7474/db/data/node/1/paged/traverse/node/a1b2c3\"))));\n\n\t\t$this->transport->expects($this->at(1))\n\t\t\t->method('get')\n\t\t\t->with('/node/1/paged/traverse/node/a1b2c3', null)\n\t\t\t->will($this->returnValue(array(\"code\"=>200,\"data\"=>$data[1])));\n\n\t\t$this->transport->expects($this->at(2))\n\t\t\t->method('get')\n\t\t\t->with('/node/1/paged/traverse/node/a1b2c3', null)\n\t\t\t->will($this->returnValue(array(\"code\"=>404)));\n\n\t\t$result = $this->client->executePagedTraversal($pager);\n\t\t$this->assertEquals(1, count($result));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]);\n\t\t$this->assertEquals(2, $result[0]->getId());\n\t\t$this->assertEquals('foo', $result[0]->getProperty('name'));\n\n\t\t$result = $this->client->executePagedTraversal($pager);\n\t\t$this->assertEquals(1, count($result));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]);\n\t\t$this->assertEquals(3, $result[0]->getId());\n\t\t$this->assertEquals('bar', $result[0]->getProperty('name'));\n\n\t\t$result = $this->client->executePagedTraversal($pager);\n\t\t$this->assertNull($result);\n\t}\n\n\tpublic function testPagedTraversal_ServerReturnsError_ThrowsException()\n\t{\n\t\t$traversal = new Traversal($this->client);\n\t\t$traversal->setOrder(Traversal::OrderDepthFirst);\n\n\t\t$node = new Node($this->client);\n\t\t$node->setId(1);\n\n\t\t$pager = new Pager($traversal, $node, Traversal::ReturnTypeNode);\n\t\t$pager->setPageSize(1)\n\t\t\t->setLeaseTime(30);\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('post')\n\t\t\t->with('/node/1/paged/traverse/node?pageSize=1&leaseTime=30',array(\"order\" => \"depth_first\"))\n\t\t\t->will($this->returnValue(array(\"code\"=>400)));\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$result = $this->client->executePagedTraversal($pager);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Cypher/QueryTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Cypher;\n\nclass QueryTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $query = null;\n\n\tprotected $template = null;\n\tprotected $vars = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->template = 'START a=({start}) RETURN a';\n\t\t$this->vars = array('start' => 0);\n\n\t\t$this->query = new Query($this->client, $this->template, $this->vars);\n\t}\n\n\tpublic function testGetQuery_ReturnsString()\n\t{\n\t\t$result = $this->query->getQuery();\n\t\t$this->assertEquals($result, $this->template);\n\t}\n\n\tpublic function testGetParameters_ReturnsArray()\n\t{\n\t\t$result = $this->query->getParameters();\n\t\t$this->assertEquals($result, $this->vars);\n\t}\n\n\tpublic function testGetResultSet_OnlyExecutesOnce_ReturnsResultSet()\n\t{\n\t\t$return = $this->getMock('Everyman\\Neo4j\\Query\\ResultSet', array(), array(), '', false);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('executeCypherQuery')\n\t\t\t->will($this->returnValue($return));\n\n\t\t$this->assertSame($return, $this->query->getResultSet());\n\t\t$this->assertSame($return, $this->query->getResultSet());\n\t}\n\n\tpublic function testGetResultSet_ClientReturnsFalse_ReturnsFalse()\n\t{\n\t\t$return = false;\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('executeCypherQuery')\n\t\t\t->will($this->returnValue($return));\n\n\t\t$this->assertFalse($this->query->getResultSet());\n\t\t$this->assertFalse($this->query->getResultSet());\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/EntityMapperTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass EntityMapperTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $mapper = null;\n\t\n\tpublic function setUp()\n\t{\n\t\t$transport = $this->getMock('Everyman\\Neo4j\\Transport');\n\t\t$this->client = new Client($transport);\n\t\t$this->mapper = new EntityMapper($this->client);\n\t}\n\t\n\tpublic function testGetIdFromUri_UriGiven_ReturnsInteger()\n\t{\n\t\t$uri = 'http://localhost:7474/db/data/node/1';\n\t\t$this->assertEquals(1, $this->mapper->getIdFromUri($uri));\n\t}\n\n\tpublic function testMakeNode_NodeDataGiven_ReturnsNode()\n\t{\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'name' => 'Bob'\n\t\t\t),\n\t\t\t'self' => 'http://localhost:7474/db/data/node/1',\n\t\t);\n\n\t\t$node = $this->mapper->makeNode($data);\n\t\t\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $node);\n\t\t$this->assertEquals(1, $node->getId());\n\t\t$this->assertEquals('Bob', $node->getProperty('name'));\n\t}\n\t\n\tpublic function testMakeRelationship_RelationshipDataGiven_ReturnsRelationship()\n\t{\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'name' => 'Bob'\n\t\t\t),\n\t\t\t'type' => 'KNOWS',\n\t\t\t'start' => 'http://localhost/db/data/node/1', \n\t\t\t'end' => 'http://localhost/db/data/node/2', \n\t\t\t'self' => 'http://localhost:7474/db/data/relationship/3',\n\t\t);\n\n\t\t$rel = $this->mapper->makeRelationship($data);\n\t\t\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rel);\n\t\t$this->assertEquals(3, $rel->getId());\n\t\t$this->assertEquals('KNOWS', $rel->getType());\n\t\t$this->assertEquals('Bob', $rel->getProperty('name'));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rel->getStartNode());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rel->getEndNode());\n\t\t$this->assertEquals(1, $rel->getStartNode()->getId());\n\t\t$this->assertEquals(2, $rel->getEndNode()->getId());\n\t}\n\n\tpublic function testPopulateNode_NodeGiven_ReturnsNode()\n\t{\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'name' => 'Bob'\n\t\t\t),\n\t\t);\n\n\t\t$node = new Node($this->client);\n\t\t$this->mapper->populateNode($node, $data);\n\t\t\n\t\t$this->assertEquals('Bob', $node->getProperty('name'));\n\t}\n\t\n\tpublic function testPopulateRelationship_RelationshipGiven_ReturnsRelationship()\n\t{\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'name' => 'Bob'\n\t\t\t),\n\t\t\t'type' => 'KNOWS',\n\t\t\t'start' => 'http://localhost/db/data/node/1', \n\t\t\t'end' => 'http://localhost/db/data/node/2', \n\t\t);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$this->mapper->populateRelationship($rel, $data);\n\t\t\n\t\t$this->assertEquals('KNOWS', $rel->getType());\n\t\t$this->assertEquals('Bob', $rel->getProperty('name'));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rel->getStartNode());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rel->getEndNode());\n\t\t$this->assertEquals(1, $rel->getStartNode()->getId());\n\t\t$this->assertEquals(2, $rel->getEndNode()->getId());\n\t}\n\n\tpublic function testPopulatePath_PathGiven_ReturnsPath()\n\t{\n\t\t$data = array(\n\t\t\t\"nodes\" => array(\"http://localhost:7474/db/data/node/123\", \"http://localhost:7474/db/data/node/341\", \"http://localhost:7474/db/data/node/456\"),\n\t\t\t\"relationships\" => array(\"http://localhost:7474/db/data/relationship/564\", \"http://localhost:7474/db/data/relationship/32\"),\n\t\t);\n\t\t\n\t\t$path = new Path($this->client);\n\t\t$this->mapper->populatePath($path, $data);\n\t\t\n\t\t$rels = $path->getRelationships();\n\t\t$this->assertEquals(2, count($rels));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[0]);\n\t\t$this->assertEquals(564, $rels[0]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[1]);\n\t\t$this->assertEquals(32, $rels[1]->getId());\n\n\t\t$nodes = $path->getNodes();\n\t\t$this->assertEquals(3, count($nodes));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\t$this->assertEquals(123, $nodes[0]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[1]);\n\t\t$this->assertEquals(341, $nodes[1]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[2]);\n\t\t$this->assertEquals(456, $nodes[2]->getId());\n\t}\n\n\tpublic function testPopulatePath_FullPath_ReturnsPath()\n\t{\n\t\t$data = array(\n\t\t\t\"relationships\" => array(\n\t\t\t\tarray(\n\t\t\t\t\t\"self\" => \"http://localhost:7474/db/data/relationship/2\",\n\t\t\t\t\t\"start\" => \"http://localhost:7474/db/data/node/1\",\n\t\t\t\t\t\"end\" => \"http://localhost:7474/db/data/node/3\",\n\t\t\t\t\t\"type\" => \"FOOTYPE\",\n\t\t\t\t\t\"data\" => array(\n\t\t\t\t\t\t\"name\" => \"baz\",\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t\t\"nodes\" => array(\n\t\t\t\tarray(\n\t\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/1\",\n\t\t\t\t\t\"data\" => array(\n\t\t\t\t\t\t\"name\" => \"foo\",\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tarray(\n\t\t\t\t\t\"self\" => \"http://localhost:7474/db/data/node/3\",\n\t\t\t\t\t\"data\" => array(\n\t\t\t\t\t\t\"name\" => \"bar\",\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\t$path = new Path($this->client);\n\t\t$this->mapper->populatePath($path, $data, true);\n\t\t\n\t\t$rels = $path->getRelationships();\n\t\t$this->assertEquals(1, count($rels));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[0]);\n\t\t$this->assertEquals(2, $rels[0]->getId());\n\t\t$this->assertEquals('FOOTYPE', $rels[0]->getType());\n\t\t$this->assertEquals('baz', $rels[0]->getProperty('name'));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rels[0]->getStartNode());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rels[0]->getEndNode());\n\t\t$this->assertEquals(1, $rels[0]->getStartNode()->getId());\n\t\t$this->assertEquals(3, $rels[0]->getEndNode()->getId());\n\n\t\t$nodes = $path->getNodes();\n\t\t$this->assertEquals(2, count($nodes));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\t$this->assertEquals(1, $nodes[0]->getId());\n\t\t$this->assertEquals('foo', $nodes[0]->getProperty('name'));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[1]);\n\t\t$this->assertEquals(3, $nodes[1]->getId());\n\t\t$this->assertEquals('bar', $nodes[1]->getProperty('name'));\n\t}\n\t\n\tpublic function testGetEntityFor_RelationshipData_ReturnsRelationship()\n\t{\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'name' => 'Bob'\n\t\t\t),\n\t\t\t'type' => 'KNOWS',\n\t\t\t'start' => 'http://localhost/db/data/node/1', \n\t\t\t'end' => 'http://localhost/db/data/node/2', \n\t\t\t'self' => 'http://localhost/db/data/relationship/0'\n\t\t);\n\n\t\t$rel = $this->mapper->getEntityFor($data);\n\t\t\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rel);\n\t\t$this->assertEquals(0, $rel->getId());\n\t\t$this->assertEquals('KNOWS', $rel->getType());\n\t\t$this->assertEquals('Bob', $rel->getProperty('name'));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rel->getStartNode());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $rel->getEndNode());\n\t\t$this->assertEquals(1, $rel->getStartNode()->getId());\n\t\t$this->assertEquals(2, $rel->getEndNode()->getId());\n\t}\n\n\tpublic function testGetEntityFor_NodeData_ReturnsNode()\n\t{\n\t\t$data = array(\n\t\t\t'data' => array(\n\t\t\t\t'name' => 'Bob'\n\t\t\t),\n\t\t\t'self' => 'http://localhost/db/data/node/0'\n\t\t);\n\n\t\t$node = $this->mapper->getEntityFor($data);\n\t\t\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $node);\n\t\t$this->assertEquals(0, $node->getId());\n\t\t$this->assertEquals('Bob', $node->getProperty('name'));\n\t}\n\n\tpublic function testGetEntityFor_PathData_ReturnsPath()\n\t{\n\t\t$data = array(\n\t\t\t\"relationships\" => array(\n\t\t\t\t\"http://localhost:7474/db/data/relationship/2\",\n\t\t\t),\n\t\t\t\"nodes\" => array(\n\t\t\t\t\"http://localhost:7474/db/data/node/1\",\n\t\t\t\t\"http://localhost:7474/db/data/node/3\",\n\t\t\t),\n\t\t);\n\n\t\t$path = $this->mapper->getEntityFor($data);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Path', $path);\n\t\t$this->assertEquals(1, $path->getStartNode()->getId());\n\t\t$this->assertEquals(3, $path->getEndNode()->getId());\n\n\t\t$rels = $path->getRelationships();\n\t\t$this->assertEquals(1, count($rels));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rels[0]);\n\t\t$this->assertEquals(2, $rels[0]->getId());\n\n\t\t$nodes = $path->getNodes();\n\t\t$this->assertEquals(2, count($nodes));\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[0]);\n\t\t$this->assertEquals(1, $nodes[0]->getId());\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $nodes[1]);\n\t\t$this->assertEquals(3, $nodes[1]->getId());\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/GeoffTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass GeoffTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $geoff = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array('runCommand'));\n\t\t$this->geoff = new Geoff($this->client);\n\n\t}\n\n\tpublic function testLoad_NotAStreamOrString_ThrowsException()\n\t{\n\t\t$geoffString = 123;\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->load($geoffString);\n\t}\n\n\tpublic function testLoad_IgnoreEmptyLines_ReturnsBatch()\n\t{\n\t\t$geoffString = \"\\n \\n\\t\\n   \t\\n\t\\n\";\n\n\t\t$batch = $this->geoff->load($geoffString);\n\t\tself::assertEquals(0, count($batch->getOperations()));\n\t}\n\n\tpublic function testLoad_IgnoreCommentLines_ReturnsBatch()\n\t{\n\t\t$geoffString = \"#this is a comment\\n\"\n\t\t\t\t\t . \"\t#so is this\\n\"\n\t\t\t\t\t . \"# this too   \t\\n\";\n\n\t\t$batch = $this->geoff->load($geoffString);\n\t\tself::assertEquals(0, count($batch->getOperations()));\n\t}\n\n\tpublic function testLoad_LoadNodeLines_ReturnsBatch()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Phil)\t{\"name\": \"Philip\", \"title\": \"Duke of Edinburgh\", \"birth.date\": \"1921-06-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Chaz)';\n\n\t\t$batch = $this->geoff->load($geoffString);\n\t\t$ops = $batch->getOperations();\n\t\tself::assertEquals(3, count($ops));\n\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\Save', $ops[0]);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $ops[0]->getEntity());\n\t\tself::assertFalse($ops[0]->getEntity()->hasId());\n\t\tself::assertEquals('Elizabeth', $ops[0]->getEntity()->getProperty('name'));\n\t\tself::assertEquals('Queen of the Commonwealth Realms', $ops[0]->getEntity()->getProperty('title'));\n\t\tself::assertEquals('1926-04-21', $ops[0]->getEntity()->getProperty('birth.date'));\n\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\Save', $ops[1]);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $ops[1]->getEntity());\n\t\tself::assertFalse($ops[1]->getEntity()->hasId());\n\t\tself::assertEquals('Philip', $ops[1]->getEntity()->getProperty('name'));\n\t\tself::assertEquals('Duke of Edinburgh', $ops[1]->getEntity()->getProperty('title'));\n\t\tself::assertEquals('1921-06-21', $ops[1]->getEntity()->getProperty('birth.date'));\n\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\Save', $ops[2]);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $ops[2]->getEntity());\n\t\tself::assertFalse($ops[2]->getEntity()->hasId());\n\t\tself::assertEquals(array(), $ops[2]->getEntity()->getProperties());\n\t}\n\n\tpublic function testLoad_DuplicateNodeLines_ThrowsException()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL;\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->load($geoffString);\n\t}\n\n\tpublic function testLoad_RelationshipEndpointsDefined_ReturnsBatch()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Phil)\t{\"name\": \"Philip\", \"title\": \"Duke of Edinburgh\", \"birth.date\": \"1921-06-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Chaz)\t{\"name\": \"Charles\", \"title\": \"Prince of Wales\", \"birth.date\": \"1948-11-14\"}'.PHP_EOL\n\t\t\t\t\t . '(Liz)-[:MARRIED]->(Phil)    {\"marriage.place\": \"Westminster Abbey\", \"marriage.date\": \"1947-11-20\"}'.PHP_EOL\n\t\t\t\t\t . '(Phil)-[:FATHER_OF]->(Chaz)';\n\t\t\n\t\t$batch = $this->geoff->load($geoffString);\n\t\t$ops = $batch->getOperations();\n\t\tself::assertEquals(5, count($ops));\n\n\t\t$op = $ops[3];\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\Save', $op);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Relationship', $op->getEntity());\n\t\tself::assertFalse($op->getEntity()->hasId());\n\t\tself::assertSame($ops[0]->getEntity(), $op->getEntity()->getStartNode());\n\t\tself::assertSame($ops[1]->getEntity(), $op->getEntity()->getEndNode());\n\t\tself::assertEquals('MARRIED', $op->getEntity()->getType());\n\t\tself::assertEquals('Westminster Abbey', $op->getEntity()->getProperty('marriage.place'));\n\t\tself::assertEquals('1947-11-20', $op->getEntity()->getProperty('marriage.date'));\n\n\t\t$op = $ops[4];\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\Save', $op);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Relationship', $op->getEntity());\n\t\tself::assertFalse($op->getEntity()->hasId());\n\t\tself::assertSame($ops[1]->getEntity(), $op->getEntity()->getStartNode());\n\t\tself::assertSame($ops[2]->getEntity(), $op->getEntity()->getEndNode());\n\t\tself::assertEquals('FATHER_OF', $op->getEntity()->getType());\n\t\tself::assertEquals(array(), $op->getEntity()->getProperties());\n\t}\n\n\tpublic function testLoad_RelationshipUndefinedStart_ThrowsException()\n\t{\n\t\t$geoffString = '(Chaz)\t{\"name\": \"Charles\", \"title\": \"Prince of Wales\", \"birth.date\": \"1948-11-14\"}'.PHP_EOL\n\t\t\t\t\t . '(Phil)-[:FATHER_OF]->(Chaz)';\n\t\t\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->load($geoffString);\n\t}\n\n\tpublic function testLoad_RelationshipUndefinedEnd_ThrowsException()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Liz)-[:MARRIED]->(Phil)    {\"marriage.place\": \"Westminster Abbey\", \"marriage.date\": \"1947-11-20\"}';\n\t\t\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->load($geoffString);\n\t}\n\n\tpublic function testLoad_DuplicateRelationshipLines_ThrowsException()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Phil)\t{\"name\": \"Philip\", \"title\": \"Duke of Edinburgh\", \"birth.date\": \"1921-06-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Liz)-[LizNPhil:MARRIED]->(Phil)'.PHP_EOL\n\t\t\t\t\t . '(Liz)-[LizNPhil:MARRIED]->(Phil)';\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->load($geoffString);\n\t}\n\n\tpublic function testLoad_IndexLines_ReturnsBatch()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Phil)\t{\"name\": \"Philip\", \"title\": \"Duke of Edinburgh\", \"birth.date\": \"1921-06-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Liz)-[LizNPhil:MARRIED]->(Phil)    {\"marriage.place\": \"Westminster Abbey\", \"marriage.date\": \"1947-11-20\"}'.PHP_EOL\n\t\t\t\t\t . '{People}->(Liz)     {\"name\": \"Elizabeth\"}'.PHP_EOL\n\t\t\t\t\t . '{People}->(Phil)    {\"name\": \"Philip\", \"title\":\"Duke\"}'.PHP_EOL\n\t\t\t\t\t . '{Marriages}->[LizNPhil]    {\"wife\": \"Elizabeth\", \"husband\": \"Philip\"}';\n\n\t\t$batch = $this->geoff->load($geoffString);\n\t\t$ops = $batch->getOperations();\n\t\tself::assertEquals(8, count($ops));\n\n\t\t$op = $ops[3];\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\AddTo', $op);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $op->getEntity());\n\t\tself::assertEquals('Elizabeth', $op->getEntity()->getProperty('name'));\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Index', $op->getIndex());\n\t\tself::assertEquals('People', $op->getIndex()->getName());\n\t\tself::assertEquals(Index::TypeNode, $op->getIndex()->getType());\n\t\tself::assertEquals('name', $op->getKey());\n\t\tself::assertEquals('Elizabeth', $op->getValue());\n\n\t\t$op = $ops[4];\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\AddTo', $op);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $op->getEntity());\n\t\tself::assertEquals('Philip', $op->getEntity()->getProperty('name'));\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Index', $op->getIndex());\n\t\tself::assertEquals('People', $op->getIndex()->getName());\n\t\tself::assertEquals(Index::TypeNode, $op->getIndex()->getType());\n\t\tself::assertEquals('name', $op->getKey());\n\t\tself::assertEquals('Philip', $op->getValue());\n\n\t\t$op = $ops[5];\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\AddTo', $op);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Node', $op->getEntity());\n\t\tself::assertEquals('Philip', $op->getEntity()->getProperty('name'));\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Index', $op->getIndex());\n\t\tself::assertEquals('People', $op->getIndex()->getName());\n\t\tself::assertEquals(Index::TypeNode, $op->getIndex()->getType());\n\t\tself::assertEquals('title', $op->getKey());\n\t\tself::assertEquals('Duke', $op->getValue());\n\n\t\tself::assertSame($ops[4]->getEntity(), $ops[5]->getEntity());\n\n\t\t$op = $ops[6];\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\AddTo', $op);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Relationship', $op->getEntity());\n\t\tself::assertSame($ops[2]->getEntity(), $op->getEntity());\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Index', $op->getIndex());\n\t\tself::assertEquals('Marriages', $op->getIndex()->getName());\n\t\tself::assertEquals(Index::TypeRelationship, $op->getIndex()->getType());\n\t\tself::assertEquals('wife', $op->getKey());\n\t\tself::assertEquals('Elizabeth', $op->getValue());\n\n\t\t$op = $ops[7];\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Batch\\AddTo', $op);\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Relationship', $op->getEntity());\n\t\tself::assertSame($ops[2]->getEntity(), $op->getEntity());\n\t\tself::assertInstanceOf('Everyman\\Neo4j\\Index', $op->getIndex());\n\t\tself::assertEquals('Marriages', $op->getIndex()->getName());\n\t\tself::assertEquals(Index::TypeRelationship, $op->getIndex()->getType());\n\t\tself::assertEquals('husband', $op->getKey());\n\t\tself::assertEquals('Philip', $op->getValue());\n\t}\n\n\tpublic function testLoad_IndexLinesInvalidNode_ThrowsException()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . '{People}->(Phil)    {\"name\": \"Philip\", \"title\":\"Duke\"}';\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->load($geoffString);\n\t}\n\n\tpublic function testLoad_IndexLinesInvalidRelationship_ThrowsException()\n\t{\n\t\t$geoffString = '{Marriages}->[LizNPhil]    {\"wife\": \"Elizabeth\", \"husband\": \"Philip\"}';\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->load($geoffString);\n\t}\n\n\tpublic function testLoad_IndexBracketMismatch_ThrowsException()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Phil)\t{\"name\": \"Philip\", \"title\": \"Duke of Edinburgh\", \"birth.date\": \"1921-06-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Liz)-[LizNPhil:MARRIED]->(Phil)    {\"marriage.place\": \"Westminster Abbey\", \"marriage.date\": \"1947-11-20\"}'.PHP_EOL\n\t\t\t\t\t . '{Marriages}->[LizNPhil)    {\"wife\": \"Elizabeth\", \"husband\": \"Philip\"}';\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->load($geoffString);\n\t}\n\n\tpublic function testLoad_InvalidLine_ThrowsException()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . 'this line is total gibberish'.PHP_EOL\n\t\t\t\t\t . '{People}->(Liz)    {\"name\": \"Elizabeth\"}';\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->load($geoffString);\n\t}\n\n\tpublic function testLoad_UseTheSameBatch_ReturnsBatch()\n\t{\n\t\t$geoffString = '(Liz)\t{\"name\": \"Elizabeth\", \"title\": \"Queen of the Commonwealth Realms\", \"birth.date\": \"1926-04-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Phil)\t{\"name\": \"Philip\", \"title\": \"Duke of Edinburgh\", \"birth.date\": \"1921-06-21\"}'.PHP_EOL\n\t\t\t\t\t . '(Chaz)';\n\n\t\t$initBatch = new Batch($this->client);\n\n\t\t$batch = $this->geoff->load($geoffString, $initBatch);\n\t\tself::assertSame($initBatch, $batch);\n\t\t$ops = $batch->getOperations();\n\t\tself::assertEquals(3, count($ops));\n\n\t\t$batch2 = $this->geoff->load($geoffString, $batch);\n\t\tself::assertSame($batch, $batch2);\n\t\t$ops = $batch->getOperations();\n\t\tself::assertEquals(6, count($ops));\n\t}\n\n\tpublic function testDump_PathsGiven_NoFileDescriptor_ReturnsString()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$nodeA->setId(123)->setProperties(array('foo' => 'bar','baz' => 'qux'));\n\t\t\n\t\t$nodeB = new Node($this->client);\n\t\t$nodeB->setId(456)->setProperties(array('somekey' => 'somevalue'));\n\t\t\n\t\t$nodeC = new Node($this->client);\n\t\t$nodeC->setId(789);\n\n\t\t$relA = new Relationship($this->client);\n\t\t$relA->setId(987)->setType('TEST')\n\t\t\t->setStartNode($nodeA)->setEndNode($nodeB)\n\t\t\t->setProperties(array('anotherkey' => 'anothervalue'));\n\n\t\t$relB = new Relationship($this->client);\n\t\t$relB->setId(654)->setType('TSET')\n\t\t\t->setStartNode($nodeB)->setEndNode($nodeC);\n\n\t\t$path = new Path();\n\t\t$path->appendNode($nodeA);\n\t\t$path->appendNode($nodeB);\n\t\t$path->appendNode($nodeC);\n\t\t$path->appendRelationship($relA);\n\t\t$path->appendRelationship($relB);\n\n\t\t$expected =<<<GEOFF\n(123)\t{\"foo\":\"bar\",\"baz\":\"qux\"}\n(456)\t{\"somekey\":\"somevalue\"}\n(789)\n(123)-[987:TEST]->(456)\t{\"anotherkey\":\"anothervalue\"}\n(456)-[654:TSET]->(789)\n\nGEOFF;\n\n\t\t$result = $this->geoff->dump($path);\n\t\tself::assertEquals($expected, $result);\n\t}\n\n\tpublic function testDump_PathsGiven_FileDescriptor_ReturnsDescriptor()\n\t{\n\t\t$nodeA = new Node($this->client);\n\t\t$nodeA->setId(123)->setProperties(array('foo' => 'bar','baz' => 'qux'));\n\t\t$nodeB = new Node($this->client);\n\t\t$nodeB->setId(456)->setProperties(array('somekey' => 'somevalue'));\n\t\t$relA = new Relationship($this->client);\n\t\t$relA->setId(987)->setType('TEST')\n\t\t\t->setStartNode($nodeA)->setEndNode($nodeB)\n\t\t\t->setProperties(array('anotherkey' => 'anothervalue'));\n\t\t$path = new Path();\n\t\t$path->appendNode($nodeA);\n\t\t$path->appendNode($nodeB);\n\t\t$path->appendRelationship($relA);\n\n\t\t$expected =<<<GEOFF\n(123)\t{\"foo\":\"bar\",\"baz\":\"qux\"}\n(456)\t{\"somekey\":\"somevalue\"}\n(123)-[987:TEST]->(456)\t{\"anotherkey\":\"anothervalue\"}\n\nGEOFF;\n\n\t\t$handle = fopen('data:text/plain,', 'w+');\n\t\t$resultHandle = $this->geoff->dump($path, $handle);\n\t\tself::assertSame($handle, $resultHandle);\n\t\tself::assertEquals($expected, stream_get_contents($resultHandle, -1, 0));\n\t}\n\n\tpublic function testDump_NotAStreamOrString_ThrowsException()\n\t{\n\t\t$handle = 123;\n\t\t$path = new Path();\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->dump($path, $handle);\n\t}\n\n\tpublic function testDump_NotAPath_ThrowsException()\n\t{\n\t\t$handle = \"file\";\n\t\t$notPath = \"blah\";\n\n\t\t$this->setExpectedException('Everyman\\Neo4j\\Exception');\n\t\t$batch = $this->geoff->dump($notPath);\n\t}\n}\n\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Gremlin/QueryTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Gremlin;\n\nclass QueryTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $query = null;\n\n\tprotected $queryString = null;\n\tprotected $params = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->queryString = 'i = g.v(start);i.outE.inV';\n\t\t$this->params = array('start' => 123);\n\n\t\t$this->query = new Query($this->client, $this->queryString, $this->params);\n\t}\n\n\tpublic function testGetQuery_ReturnsString()\n\t{\n\t\t$result = $this->query->getQuery();\n\t\t$this->assertEquals($result, $this->queryString);\n\t}\n\n\tpublic function testGetParameters_ReturnsArray()\n\t{\n\t\t$result = $this->query->getParameters();\n\t\t$this->assertEquals($result, $this->params);\n\t}\n\n\tpublic function testGetResultSet_OnlyExecutesOnce_ReturnsResultSet()\n\t{\n\t\t$return = $this->getMock('Everyman\\Neo4j\\Query\\ResultSet', array(), array(), '', false);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('executeGremlinQuery')\n\t\t\t->will($this->returnValue($return));\n\n\t\t$this->assertSame($return, $this->query->getResultSet());\n\t\t$this->assertSame($return, $this->query->getResultSet());\n\t}\n\n\tpublic function testGetResultSet_ClientReturnsFalse_ReturnsFalse()\n\t{\n\t\t$return = false;\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('executeGremlinQuery')\n\t\t\t->will($this->returnValue($return));\n\n\t\t$this->assertFalse($this->query->getResultSet());\n\t\t$this->assertFalse($this->query->getResultSet());\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/IndexTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass IndexTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $index = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->index = new Index($this->client, Index::TypeNode, 'indexname');\n\t}\n\n\tpublic function testSave_SavesSelfUsingClient()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('saveIndex')\n\t\t\t->with($this->index)\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertTrue($this->index->save());\n\t}\n\n\tpublic function testDelete_DeletesSelfUsingClient()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('deleteIndex')\n\t\t\t->with($this->index)\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertTrue($this->index->delete());\n\t}\n\n\tpublic function testAdd_AddsEntityUsingClient()\n\t{\n\t\t$node = new Node($this->client);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('addToIndex')\n\t\t\t->with($this->index, $node, 'somekey', 'somevalue')\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertTrue($this->index->add($node, 'somekey', 'somevalue'));\n\t}\n\n\tpublic function testRemove_RemovesEntityUsingClient()\n\t{\n\t\t$node = new Node($this->client);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('removeFromIndex')\n\t\t\t->with($this->index, $node, 'somekey', 'somevalue')\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertTrue($this->index->remove($node, 'somekey', 'somevalue'));\n\t}\n\n\tpublic function testFind_FindsNodesUsingClient()\n\t{\n\t\t$node = new Node($this->client);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('searchIndex')\n\t\t\t->with($this->index, 'somekey', 'somevalue')\n\t\t\t->will($this->returnValue(array($node)));\n\n\t\t$result = $this->index->find('somekey', 'somevalue');\n\t\t$this->assertEquals(1, count($result));\n\t\t$this->assertSame($node, $result[0]);\n\t}\n\n\tpublic function testFindOne_FindsNodesUsingClient()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$nodes = array($node, new Node($this->client));\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('searchIndex')\n\t\t\t->with($this->index, 'somekey', 'somevalue')\n\t\t\t->will($this->returnValue($nodes));\n\n\t\t$result = $this->index->findOne('somekey', 'somevalue');\n\t\t$this->assertSame($node, $result);\n\t}\n\n\tpublic function testFindOne_NoNode_ReturnsNull()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('searchIndex')\n\t\t\t->with($this->index, 'somekey', 'somevalue')\n\t\t\t->will($this->returnValue(array()));\n\n\t\t$result = $this->index->findOne('somekey', 'somevalue');\n\t\t$this->assertNull($result);\n\t}\n\n\tpublic function testQuery_QueriesUsingClient()\n\t{\n\t\t$node = new Node($this->client);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('queryIndex')\n\t\t\t->with($this->index, 'somekey:somevalue*')\n\t\t\t->will($this->returnValue(array($node)));\n\n\t\t$result = $this->index->query('somekey:somevalue*');\n\t\t$this->assertEquals(1, count($result));\n\t\t$this->assertSame($node, $result[0]);\n\t}\n\n\tpublic function testQueryOne_QueriesUsingClient()\n\t{\n\t\t$node = new Node($this->client);\n\t\t$nodes = array($node, new Node($this->client));\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('queryIndex')\n\t\t\t->with($this->index, 'somekey:somevalue*')\n\t\t\t->will($this->returnValue($nodes));\n\n\t\t$result = $this->index->queryOne('somekey:somevalue*');\n\t\t$this->assertSame($node, $result);\n\t}\n\n\tpublic function testQueryOne_NoNode_ReturnsNull()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('queryIndex')\n\t\t\t->with($this->index, 'somekey:somevalue*')\n\t\t\t->will($this->returnValue(array()));\n\n\t\t$result = $this->index->queryOne('somekey:somevalue*');\n\t\t$this->assertNull($result);\n\t}\n\n\tpublic function testNodeIndex_CreatesNodeIndex()\n\t{\n\t\t$index = new Index\\NodeIndex($this->client, 'testindex', array('foo'=>'bar'));\n\t\t$this->assertEquals(Index::TypeNode, $index->getType());\n\t\t$this->assertEquals('testindex', $index->getName());\n\t\t$this->assertEquals(array('foo'=>'bar'), $index->getConfig());\n\t}\n\n\tpublic function testNodeFulltextIndex_CreatesNodeFulltextIndex()\n\t{\n\t\t$index = new Index\\NodeFulltextIndex($this->client, 'testindex');\n\t\t$this->assertEquals(Index::TypeNode, $index->getType());\n\t\t$this->assertEquals('testindex', $index->getName());\n\t\t$this->assertEquals(array(\n\t\t\t'type'=>'fulltext',\n\t\t\t'provider'=>'lucene',\n\t\t), $index->getConfig());\n\t}\n\n\tpublic function testRelationshipIndex_CreatesRelationshipIndex()\n\t{\n\t\t$index = new Index\\RelationshipIndex($this->client, 'testindex', array('foo'=>'bar'));\n\t\t$this->assertEquals(Index::TypeRelationship, $index->getType());\n\t\t$this->assertEquals('testindex', $index->getName());\n\t\t$this->assertEquals(array('foo'=>'bar'), $index->getConfig());\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/LabelTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass LabelTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client');\n\t}\n\n\tpublic function dataProvider_ValidNames()\n\t{\n\t\treturn array(\n\t\t\tarray('TEST LABEL NAME'),\n\t\t\tarray(123),\n\t\t\tarray(123.45),\n\t\t);\n\t}\n\n\t/**\n\t * @dataProvider dataProvider_ValidNames\n\t */\n\tpublic function testContruct_ValidNameGiven_SetsNameCastAsString($name)\n\t{\n\t\t$label = new Label($this->client, $name);\n\t\tself::assertEquals($name, $label->getName());\n\t\tself::assertInternalType('string', $label->getName());\n\t}\n\n\tpublic function dataProvider_InvalidNames()\n\t{\n\t\treturn array(\n\t\t\tarray(null),\n\t\t\tarray(''),\n\t\t\tarray(true),\n\t\t\tarray(array()),\n\t\t\tarray(array('foo')),\n\t\t\tarray(new \\stdClass()),\n\t\t);\n\t}\n\n\t/**\n\t * @dataProvider dataProvider_InvalidNames\n\t */\n\tpublic function testContruct_InvalidNameGiven_ThrowsException($name)\n\t{\n\t\t$this->setExpectedException('InvalidArgumentException');\n\t\t$label = new Label($this->client, $name);\n\t}\n\n\tpublic function testGetNodes_NoPropertyGiven_CallsClientMethod()\n\t{\n\t\t$label = new Label($this->client, 'foobar');\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('getNodesForLabel')\n\t\t\t->with($label, null, null);\n\n\t\t$label->getNodes();\n\t}\n\n\tpublic function testGetNodes_PropertyGiven_CallsClientMethod()\n\t{\n\t\t$label = new Label($this->client, 'foobar');\n\t\t$property = 'baz';\n\t\t$value = 'qux';\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('getNodesForLabel')\n\t\t\t->with($label, $property, $value);\n\n\t\t$label->getNodes($property, $value);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/NodeTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass NodeTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $node = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(\n\t\t\t'saveNode',\n\t\t\t'deleteNode',\n\t\t\t'addLabels',\n\t\t\t'removeLabels',\n\t\t\t'getLabels',\n\t\t\t'loadNode',\n\t\t\t'getNodeRelationships',\n\t\t\t'runCommand',\n\t\t));\n\t\t$this->node = new Node($this->client);\n\t}\n\n\tpublic function testSave_SavesSelfUsingClient()\n\t{\n\t\t$expected = $this->node;\n\t\t$matched = false;\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('saveNode')\n\t\t\t// Have to do it this way because PHPUnit clones object parameters\n\t\t\t->will($this->returnCallback(function (Node $actual) use ($expected, &$matched) {\n\t\t\t\t$matched = $expected->getId() == $actual->getId();\n\t\t\t\treturn true;\n\t\t\t}));\n\n\t\t$this->node->setId(123);\n\t\t$this->assertSame($this->node, $this->node->save());\n\t\t$this->assertTrue($matched);\n\t}\n\n\tpublic function testGetLabels_DelegatesToClient()\n\t{\n\t\t$expected = $this->node;\n\t\t$matched = false;\n\n\t\t$label = new Label($this->client, 'FOOBAR');\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('getLabels')\n\t\t\t// Have to do it this way because PHPUnit clones object parameters\n\t\t\t->will($this->returnCallback(function (Node $actual) use ($expected, $label, &$matched) {\n\t\t\t\t$matched = $expected->getId() == $actual->getId();\n\t\t\t\treturn array($label);\n\t\t\t}));\n\n\t\t$labels = $this->node->getLabels();\n\t\t$this->assertEquals(1, count($labels));\n\t\t$this->assertSame($label, $labels[0]);\n\t}\n\n\tpublic function testAddLabels_DelegatesToClient()\n\t{\n\t\t$expected = $this->node;\n\t\t$expected->setId(123);\n\t\t$matched = false;\n\n\t\t$label = new Label($this->client, 'FOOBAR');\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('addLabels')\n\t\t\t// Have to do it this way because PHPUnit clones object parameters\n\t\t\t->will($this->returnCallback(function (Node $actual, $labels) use ($expected, $label, &$matched) {\n\t\t\t\t$matched = $expected->getId() == $actual->getId();\n\t\t\t\t$matched = $matched && $label->getName() == $labels[0]->getName();\n\t\t\t\treturn array($label);\n\t\t\t}));\n\n\t\t$labels = $this->node->addLabels(array($label));\n\t\t$this->assertEquals(1, count($labels));\n\t\t$this->assertSame($label, $labels[0]);\n\t}\n\n\tpublic function testRemoveLabels_DelegatesToClient()\n\t{\n\t\t$expected = $this->node;\n\t\t$expected->setId(123);\n\t\t$matched = false;\n\n\t\t$label = new Label($this->client, 'FOOBAR');\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('removeLabels')\n\t\t\t// Have to do it this way because PHPUnit clones object parameters\n\t\t\t->will($this->returnCallback(function (Node $actual, $labels) use ($expected, $label, &$matched) {\n\t\t\t\t$matched = $expected->getId() == $actual->getId();\n\t\t\t\t$matched = $matched && $label->getName() == $labels[0]->getName();\n\t\t\t\treturn array($label);\n\t\t\t}));\n\n\t\t$labels = $this->node->removeLabels(array($label));\n\t\t$this->assertEquals(1, count($labels));\n\t\t$this->assertSame($label, $labels[0]);\n\t}\n\n\t/**\n\t * Test for https://github.com/jadell/neo4jphp/issues/58\n\t */\n\tpublic function testSave_FollowedByPropertyGet_DoesNotLazyLoad()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('saveNode')\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->client->expects($this->never())\n\t\t\t->method('loadNode');\n\n\t\t$this->node->setId(123);\n\t\t$this->node->save();\n\t\t$this->node->getProperty('foo');\n\t}\n\n\tpublic function testDelete_DeletesSelfUsingClient()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('deleteNode')\n\t\t\t->with($this->node)\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertSame($this->node, $this->node->delete());\n\t}\n\n\tpublic function testLoad_LoadsSelfUsingClient()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('loadNode')\n\t\t\t->with($this->node)\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertSame($this->node, $this->node->load());\n\t}\n\n\tpublic function testGetRelationships_ReturnsArrayOfRelationships()\n\t{\n\t\t$dir = Relationship::DirectionOut;\n\t\t$types = array('FOOTYPE','BARTYPE');\n\n\t\t$returnRels = array(\n\t\t\tnew Relationship($this->client),\n\t\t\tnew Relationship($this->client),\n\t\t);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('getNodeRelationships')\n\t\t\t->with($this->node, $types, $dir)\n\t\t\t->will($this->returnValue($returnRels));\n\n\t\t$rels = $this->node->getRelationships($types, $dir);\n\t\t$this->assertEquals($returnRels, $rels);\n\t}\n\n\tpublic function testGetFirstRelationship_ReturnsRelationship()\n\t{\n\t\t$dir = Relationship::DirectionOut;\n\t\t$types = array('FOOTYPE','BARTYPE');\n\n\t\t$returnRels = array(\n\t\t\tnew Relationship($this->client),\n\t\t\tnew Relationship($this->client),\n\t\t);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('getNodeRelationships')\n\t\t\t->with($this->node, $types, $dir)\n\t\t\t->will($this->returnValue($returnRels));\n\n\t\t$rel = $this->node->getFirstRelationship($types, $dir);\n\t\t$this->assertSame($returnRels[0], $rel);\n\t}\n\n\tpublic function testGetFirstRelationship_NoneFound_ReturnsNull()\n\t{\n\t\t$dir = Relationship::DirectionOut;\n\t\t$types = array('FOOTYPE','BARTYPE');\n\n\t\t$returnRels = array();\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('getNodeRelationships')\n\t\t\t->with($this->node, $types, $dir)\n\t\t\t->will($this->returnValue($returnRels));\n\n\t\t$rel = $this->node->getFirstRelationship($types, $dir);\n\t\t$this->assertNull($rel);\n\t}\n\n\tpublic function testRelateTo_ReturnsRelationship()\n\t{\n\t\t$toNode = new Node($this->client);\n\t\t$type = 'FOOTYPE';\n\n\t\t$rel = $this->node->relateTo($toNode, $type);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $rel);\n\t\t$this->assertSame($this->client, $rel->getClient());\n\t\t$this->assertSame($this->node, $rel->getStartNode());\n\t\t$this->assertSame($toNode, $rel->getEndNode());\n\t\t$this->assertEquals($type, $rel->getType());\n\t}\n\n\tpublic function testFindPathsTo_ReturnsPathFinder()\n\t{\n\t\t$toNode = new Node($this->client);\n\t\t$type = 'FOOTYPE';\n\t\t$dir = Relationship::DirectionOut;\n\n\t\t$finder = $this->node->findPathsTo($toNode, $type, $dir);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\PathFinder', $finder);\n\t\t$this->assertSame($this->node, $finder->getStartNode());\n\t\t$this->assertSame($toNode, $finder->getEndNode());\n\t\t$this->assertEquals($dir, $finder->getDirection());\n\t\t$this->assertEquals($type, $finder->getType());\n\t}\n\n\tpublic function testSerialize_KeepsLabels()\n\t{\n\t\t$fooLabel = $this->client->makeLabel('foo');\n\t\t$barLabel = $this->client->makeLabel('bar');\n\t\t$expectedLabels = array($fooLabel, $barLabel);\n\t\t$this->client->expects($this->once())\n\t\t\t->method('addLabels')\n\t\t\t->with($this->node, $expectedLabels)\n\t\t\t->will($this->returnValue($expectedLabels));\n\n\t\t$this->node->addLabels($expectedLabels);\n\n\t\t$data = serialize($this->node);\n\t\t$node = unserialize($data);\n\t\t// we must reset the client\n\t\t$node->setClient($this->client);\n\n\t\t$this->assertEquals($this->node, $node, 'The node is restored by unserialize');\n\t\t$this->assertEquals($expectedLabels, $node->getLabels(), 'The labels should be restored by unserialize');\n\t\t$this->assertSame($this->client, $expectedLabels[0]->getClient(), 'The labels should have their client set');\n\t\t$this->assertSame($this->client, $expectedLabels[1]->getClient(), 'The labels should have their client set');\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/PagerTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass PagerTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $traversal = null;\n\tprotected $node = null;\n\tprotected $returnType = null;\n\tprotected $pager = null;\n\t\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->traversal = new Traversal($this->client);\n\n\t\t$this->node = new Node($this->client);\n\t\t$this->node->setId(123);\n\n\t\t$this->returnType = Traversal::ReturnTypeNode;\n\n\t\t$this->pager = new Pager($this->traversal, $this->node, $this->returnType);\n\t}\n\n\tpublic function testConstruct_SetsParametersCorrectly_ReturnsCorrectValues()\n\t{\n\t\t$this->assertSame($this->traversal, $this->pager->getTraversal());\n\t\t$this->assertSame($this->node, $this->pager->getStartNode());\n\t\t$this->assertEquals($this->returnType, $this->pager->getReturnType());\n\t}\n\n\tpublic function testPageSize_NoneGiven_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->pager->getPageSize());\n\t}\n\n\tpublic function testPageSize_PageSizeGiven_ReturnsInteger()\n\t{\n\t\t$this->pager->setPageSize(10);\n\t\t$this->assertEquals(10, $this->pager->getPageSize());\n\t}\n\n\tpublic function testLeaseTime_NoneGiven_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->pager->getLeaseTime());\n\t}\n\n\tpublic function testLeaseTime_LeaseTimeGiven_ReturnsInteger()\n\t{\n\t\t$this->pager->setLeaseTime(30);\n\t\t$this->assertEquals(30, $this->pager->getLeaseTime());\n\t}\n\n\tpublic function testId_NoneGiven_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->pager->getId());\n\t}\n\n\tpublic function testId_IdGiven_ReturnsString()\n\t{\n\t\t$this->pager->setId('thisistheid');\n\t\t$this->assertEquals('thisistheid', $this->pager->getId());\n\t}\n\n\tpublic function testGetNextResults_PassesThroughToClient()\n\t{\n\t\t$expectedNodes = array(new Node($this->client), new Node($this->client));\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('executePagedTraversal')\n\t\t\t->with($this->pager)\n\t\t\t->will($this->returnValue($expectedNodes));\n\n\t\t$nodes = $this->pager->getNextResults();\n\t\t$this->assertEquals($expectedNodes, $nodes);\n\t}\n}\n\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/PathFinderTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass PathFinderTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $finder = null;\n\t\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->finder = new PathFinder($this->client);\n\t}\n\n\tpublic function testGetClient_ClientSetCorrectly_ReturnsClient()\n\t{\n\t\t$this->assertSame($this->client, $this->finder->getClient());\n\t}\n\n\tpublic function testGetPaths_PassesThroughToClient()\n\t{\n\t\t$expectedPaths = array(new Path($this->client), new Path($this->client));\n\t\n\t\t$this->client->expects($this->once())\n\t\t\t->method('getPaths')\n\t\t\t->with($this->finder)\n\t\t\t->will($this->returnValue($expectedPaths));\n\n\t\t$paths = $this->finder->getPaths();\n\t\t$this->assertEquals($expectedPaths, $paths);\n\t}\n\n\tpublic function testGetSinglePath_PassesThroughToClient()\n\t{\n\t\t$firstPath = new Path($this->client);\n\t\t$expectedPaths = array($firstPath, new Path($this->client));\n\t\n\t\t$this->client->expects($this->once())\n\t\t\t->method('getPaths')\n\t\t\t->with($this->finder)\n\t\t\t->will($this->returnValue($expectedPaths));\n\n\t\t$path = $this->finder->getSinglePath();\n\t\t$this->assertEquals($firstPath, $path);\n\t}\n\n\tpublic function testGetSinglePath_NoPaths_ReturnsNull()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('getPaths')\n\t\t\t->with($this->finder)\n\t\t\t->will($this->returnValue(array()));\n\n\t\t$path = $this->finder->getSinglePath();\n\t\t$this->assertNull($path);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/PathTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass PathTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $path = null;\n\n\tprotected $rels = array();\n\tprotected $nodes = array();\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->path = new Path($this->client);\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setStartNode(new Node($this->client));\n\t\t$rel->setEndNode(new Node($this->client));\n\t\t$this->path->appendRelationship($rel);\n\t\t$this->rels[0] = $rel;\n\n\t\t$rel = new Relationship($this->client);\n\t\t$rel->setStartNode(new Node($this->client));\n\t\t$rel->setEndNode(new Node($this->client));\n\t\t$this->path->appendRelationship($rel);\n\t\t$this->rels[1] = $rel;\n\t\t\n\t\t$node = new Node($this->client);\n\t\t$this->path->appendNode($node);\n\t\t$this->nodes[0] = $node;\n\t\t\n\t\t$node = new Node($this->client);\n\t\t$this->path->appendNode($node);\n\t\t$this->nodes[1] = $node;\n\t\t\n\t\t$node = new Node($this->client);\n\t\t$this->path->appendNode($node);\n\t\t$this->nodes[2] = $node;\n\t\t\n\t\t$node = new Node($this->client);\n\t\t$this->path->appendNode($node);\n\t\t$this->nodes[3] = $node;\n\t}\n\n\tpublic function testGetLength_ReturnsInteger()\n\t{\n\t\t$this->assertEquals(count($this->nodes), $this->path->getLength());\n\t\t$this->assertEquals(count($this->nodes), count($this->path));\n\t\t\n\t\t$this->path->setContext(Path::ContextRelationship);\n\n\t\t$this->assertEquals(count($this->rels), $this->path->getLength());\n\t\t$this->assertEquals(count($this->rels), count($this->path));\n\t}\n\n\tpublic function testEndpoints_ReturnsCorrectNodes()\n\t{\n\t\t$this->assertSame($this->nodes[0], $this->path->getStartNode());\n\t\t$this->assertSame($this->nodes[3], $this->path->getEndNode());\n\t}\n\n\tpublic function testEndpoints_NoRelationship_ReturnsNull()\n\t{\n\t\t$this->path = new Path($this->client);\n\t\t$this->assertNull($this->path->getStartNode());\n\t\t$this->assertNull($this->path->getEndNode());\n\t}\n\n\tpublic function testGetRelationships_ReturnsArray()\n\t{\n\t\t$rels = $this->path->getRelationships();\n\t\t$this->assertEquals(count($this->rels), count($rels));\n\t\t$this->assertSame($this->rels[0], $rels[0]);\n\t\t$this->assertSame($this->rels[1], $rels[1]);\n\t}\n\n\tpublic function testGetNodes_ReturnsArray()\n\t{\n\t\t$nodes = $this->path->getNodes();\n\t\t$this->assertEquals(count($this->nodes), count($nodes));\n\t\t$this->assertSame($this->nodes[0], $nodes[0]);\n\t\t$this->assertSame($this->nodes[1], $nodes[1]);\n\t\t$this->assertSame($this->nodes[2], $nodes[2]);\n\t\t$this->assertSame($this->nodes[3], $nodes[3]);\n\t}\n\n\tpublic function testIteration_PathCanBeIteratedOver()\n\t{\n\t\t$this->assertInstanceOf('Traversable', $this->path);\n\t\tforeach ($this->path as $i => $node) {\n\t\t\t$this->assertSame($this->nodes[$i], $node);\n\t\t}\n\n\t\t$this->path->setContext(Path::ContextRelationship);\n\t\tforeach ($this->path as $i => $rel) {\n\t\t\t$this->assertSame($this->rels[$i], $rel);\n\t\t}\n\t}\n\n\tpublic function testContext_UnknownContextSet_SetsContextToNode()\n\t{\n\t\t$this->path->setContext('FOO');\n\t\t$this->assertEquals(Path::ContextNode, $this->path->getContext());\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/PropertyContainerTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass PropertyContainerTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $entity = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->entity = $this->getMock('Everyman\\Neo4j\\PropertyContainer',\n\t\t\tarray('delete','save','load'), array($this->client));\n\t}\n\t\n\tpublic function testProperties_MagicNotSet_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->entity->notset);\n\t}\n\n\tpublic function testProperties_MagicSet_ReturnsValue()\n\t{\n\t\t$this->entity->somekey = 'someval';\n\t\t$this->assertEquals('someval', $this->entity->getProperty('somekey'));\n\t}\n\n\tpublic function testProperties_MagicRemoved_ReturnsNull()\n\t{\n\t\t$this->entity->setProperty('somekey', 'someval');\n\t\tunset($this->entity->somekey);\n\t\t$this->assertNull($this->entity->getProperty('somekey'));\n\t}\n\n\tpublic function testProperties_PropertyNotSet_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->entity->getProperty('notset'));\n\t}\n\n\tpublic function testProperties_PropertySet_ReturnsValue()\n\t{\n\t\t$this->entity->setProperty('somekey','someval');\n\t\t$this->assertEquals('someval', $this->entity->getProperty('somekey'));\n\t}\n\n\tpublic function testProperties_PropertyRemoved_ReturnsNull()\n\t{\n\t\t$this->entity->setProperty('somekey','someval');\n\t\t$this->entity->removeProperty('somekey');\n\t\t$this->assertNull($this->entity->getProperty('somekey'));\n\t}\n\n\tpublic function testProperties_BatchSet_ReturnsValues()\n\t{\n\t\t$this->entity->setProperties(array(\n\t\t\t'somekey' => 'someval',\n\t\t\t'yakey' => 'yaval',\n\t\t));\n\t\t$this->assertEquals('someval', $this->entity->getProperty('somekey'));\n\t\t$this->assertEquals('yaval', $this->entity->getProperty('yakey'));\n\t}\n\n\tpublic function testProperties_GetAllProperties_ReturnsValues()\n\t{\n\t\t$this->entity->setProperties(array(\n\t\t\t'somekey' => 'someval',\n\t\t\t'yakey' => 'yaval',\n\t\t));\n\t\t$this->assertEquals(array(\n\t\t\t'somekey' => 'someval',\n\t\t\t'yakey' => 'yaval',\n\t\t), $this->entity->getProperties());\n\t}\n\n\tpublic function testProperties_SetPropertyNullValue_ReturnsNullAndPropertyRemoved()\n\t{\n\t\t$this->entity->setProperties(array(\n\t\t\t'somekey' => 'someval',\n\t\t\t'yakey' => 'yaval',\n\t\t));\n\n\t\t$this->entity->setProperty('somekey', null);\n\t\t$this->assertNull($this->entity->getProperty('somekey'));\n\n\t\t$this->assertEquals(array(\n\t\t\t'yakey' => 'yaval',\n\t\t), $this->entity->getProperties());\n\t}\n\n\tpublic function testProperties_LazyLoad_OnlyLoadsTheFirstTime()\n\t{\n\t\t$this->entity->expects($this->once())\n\t\t\t->method('load');\n\t\t\n\t\t$this->entity->setId(123);\n\t\t$this->entity->getProperties();\n\t\t$this->entity->getProperties();\n\t}\n\n\tpublic function testSetGetId_IntegerId_ReturnsInteger()\n\t{\n\t\t$this->entity->setId(123);\n\t\t$this->assertTrue($this->entity->hasId());\n\t\t$this->assertEquals(123, $this->entity->getId());\n\t}\n\n\tpublic function testSetGetId_ZeroIdIsValid_ReturnsInteger()\n\t{\n\t\t$this->entity->setId(0);\n\t\t$this->assertTrue($this->entity->hasId());\n\t\t$this->assertEquals(0, $this->entity->getId());\n\t}\n\n\tpublic function testSetGetId_NullValid_ReturnsNull()\n\t{\n\t\t$this->entity->setId(null);\n\t\t$this->assertFalse($this->entity->hasId());\n\t\t$this->assertNull($this->entity->getId());\n\t}\n\n\tpublic function testSetGetId_NonIntegerCastToInteger_ReturnsInteger()\n\t{\n\t\t$this->entity->setId('temp');\n\t\t$this->assertTrue($this->entity->hasId());\n\t\t$this->assertEquals(0, $this->entity->getId());\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Query/ResultSetTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Query;\n\nuse Everyman\\Neo4j\\Client;\n\nclass ResultSetTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = new Client($this->getMock('Everyman\\Neo4j\\Transport'));\n\t}\n\n\tpublic function testCount()\n\t{\n\t\t$data = array(\n\t\t\t'columns' => array('name','age'),\n\t\t\t'data' => array(\n\t\t\t\tarray('Bob', 12),\n\t\t\t\tarray('Lotta', 0),\n\t\t\t\tarray('Brenda', 14)\n\t\t\t)\n\t\t);\n\n\t\t$result = new ResultSet($this->client, $data);\n\t\t$this->assertEquals(3, count($result));\n\t}\n\n\tpublic function testIterate()\n\t{\n\t\t$data = array(\n\t\t\t'columns' => array('name','age'),\n\t\t\t'data' => array(\n\t\t\t\tarray('Bob', 12),\n\t\t\t\tarray('Lotta', 0),\n\t\t\t\tarray('Brenda', 14)\n\t\t\t)\n\t\t);\n\n\t\t$result = new ResultSet($this->client, $data);\n\t\tforeach($result as $index => $row) {\n\t\t\t$this->assertEquals($data['data'][$index][0], $row['name']);\n\t\t\t$this->assertEquals($data['data'][$index][0], $row[0]);\n\t\t\t$this->assertTrue($row instanceof Row);\n\t\t}\n\t}\n\n\tpublic function testArrayAccess()\n\t{\n\t\t$data = array(\n\t\t\t'columns' => array('name','age'),\n\t\t\t'data' => array(\n\t\t\t\tarray('Bob', 12),\n\t\t\t\tarray('Lotta', 0),\n\t\t\t\tarray('Brenda', 14),\n\t\t\t\tarray('Jimmy', null)\n\t\t\t)\n\t\t);\n\n\t\t$result = new ResultSet($this->client, $data);\n\t\tfor($i=0,$l=4; $i<$l; $i++) {\n\t\t\t$this->assertEquals(true, isset($result[$i]));\n\t\t\t$this->assertEquals($data['data'][$i][0], $result[$i][0]);\n\t\t}\n\n\t\t//issue #83\n\t\t$this->assertFalse(isset($result[3]['age']));\n\t\t$this->assertTrue(is_null($result[3]['age']));\n\t\t$this->assertEquals(null, $result[3]['age']);\n\n\t\t$this->assertEquals(false, isset($result[4]));\n\t}\n\n\tpublic function testArrayAccess_CacheResultRows()\n\t{\n\t\t$data = array(\n\t\t\t'columns' => array('name','age'),\n\t\t\t'data' => array(\n\t\t\t\tarray('Bob', 12),\n\t\t\t\tarray('Lotta', 0),\n\t\t\t\tarray('Brenda', 14)\n\t\t\t)\n\t\t);\n\n\t\t$result = new ResultSet($this->client, $data);\n\t\t$row = $result[0];\n\t\t$again = $result[0];\n\t\t$this->assertSame($row, $again);\n\t}\n\n\tpublic function testArrayAccess_Set_ThrowsException()\n\t{\n\t\t$data = array(\n\t\t\t'columns' => array('name','age'),\n\t\t\t'data' => array(\n\t\t\t\tarray('Bob', 12),\n\t\t\t\tarray('Lotta', 0),\n\t\t\t\tarray('Brenda', 14)\n\t\t\t)\n\t\t);\n\n\t\t$result = new ResultSet($this->client, $data);\n\n\t\t$this->setExpectedException('BadMethodCallException');\n\t\t$result[3] = 'value';\n\t}\n\n\tpublic function testArrayAccess_Unset_ThrowsException()\n\t{\n\t\t$data = array(\n\t\t\t'columns' => array('name','age'),\n\t\t\t'data' => array(\n\t\t\t\tarray('Bob', 12),\n\t\t\t\tarray('Lotta', 0),\n\t\t\t\tarray('Brenda', 14)\n\t\t\t)\n\t\t);\n\n\t\t$result = new ResultSet($this->client, $data);\n\n\t\t$this->setExpectedException('BadMethodCallException');\n\t\tunset($result[0]);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/Query/RowTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j\\Query;\n\nuse Everyman\\Neo4j\\Client,\n    Everyman\\Neo4j\\Node,\n    Everyman\\Neo4j\\Relationship;\n\nclass RowTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = new Client($this->getMock('Everyman\\Neo4j\\Transport', array(), array(), '', false));\n\t}\n\t\n\tpublic function testCount()\n\t{\n\t\t$columns = array('name','age');\n\t\t$data = array('Brenda', 14);\n\n\t\t$row = new Row($this->client, $columns, $data);\n\t\t$this->assertEquals(2, count($row));\n\t}\n\t\n\tpublic function testIterate()\n\t{\n\t\t$columns = array('name','age');\n\t\t$data = array('Brenda', 14);\n\n\t\t$row = new Row($this->client, $columns, $data);\n\t\t$i = 0;\n\t\tforeach($row as $columnName => $fieldValue) {\n\t\t\t$this->assertEquals($columns[$i], $columnName);\n\t\t\t$this->assertEquals($data[$i], $fieldValue);\n\t\t\t$i++;\n\t\t}\n\t}\n\n\tpublic function testIterateWithNull()\n\t{\n\t\t$columns = array('name', 'undefined content', 'age');\n\t\t$data = array('Brenda', NULL, 14);\n\n\t\t$row = new Row($this->client, $columns, $data);\n\t\t$i = 0;\n\t\tforeach($row as $columnName => $fieldValue) {\n\t\t\t$this->assertEquals($columns[$i], $columnName);\n\t\t\t$this->assertEquals($data[$i], $fieldValue);\n\t\t\t$i++;\n\t\t}\n\t\t$this->assertEquals(count($columns), $i, 'did not iterate over all data');\n\t}\n\n\tpublic function testArrayAccess()\n\t{\n\t\t$columns = array('name','age');\n\t\t$data = array('Brenda', 14);\n\n\t\t$row = new Row($this->client, $columns, $data);\n\t\t$i = 0;\n\t\tforeach($columns as $column) {\n\t\t\t$this->assertEquals(true, isset($row[$column]));\n\t\t\t$this->assertEquals(true, isset($row[$i]));\n\t\t\t$this->assertEquals($row[$column], $data[$i]);\n\t\t\t$this->assertEquals($row[$i], $data[$i]);\n\t\t\t$i++;\n\t\t}\n\t\t\n\t\t$this->assertEquals(false, isset($row['blah']));\n\t\t$this->assertEquals(false, isset($row[3]));\n\t}\n\n\tpublic function testArrayAccess_Set_ThrowsException()\n\t{\n\t\t$columns = array('name','age');\n\t\t$data = array('Brenda', 14);\n\t\t$row = new Row($this->client, $columns, $data);\n\n\t\t$this->setExpectedException('BadMethodCallException');\n\t\t$row['test'] = 'value';\n\t}\n\n\tpublic function testArrayAccess_Unset_ThrowsException()\n\t{\n\t\t$columns = array('name','age');\n\t\t$data = array('Brenda', 14);\n\t\t$row = new Row($this->client, $columns, $data);\n\n\t\t$this->setExpectedException('BadMethodCallException');\n\t\tunset($row['name']);\n\t}\n\t\n\tpublic function testNodeCasting()\n\t{\n\t\t$columns = array('user');\n\t\t$data = array(\n\t\t\tarray(\n\t\t\t\t'data' => array(\n\t\t\t\t\t'name' => 'Bob'\n\t\t\t\t),\n\t\t\t\t'self' => 'http://localhost/db/data/node/0'\n\t\t\t));\n\n\t\t\n\t\t$row = new Row($this->client, $columns, $data);\n\t\t$i = 0;\n\t\t\n\t\t$this->assertTrue($row['user'] instanceof Node);\n\t}\n\t\n\tpublic function testRelationshipCasting()\n\t{\n\t\t$columns = array('user');\n\t\t$data = array(\n\t\t\tarray(\n\t\t\t\t'data' => array(\n\t\t\t\t\t'name' => 'Bob'\n\t\t\t\t),\n\t\t\t\t'type' => 'KNOWS',\n\t\t\t\t'start' => 'http://localhost/db/data/node/0', \n\t\t\t\t'end' => 'http://localhost/db/data/node/1', \n\t\t\t\t'self' => 'http://localhost/db/data/relationship/0'\n\t\t\t));\n\n\t\t\n\t\t$row = new Row($this->client, $columns, $data);\n\t\t\n\t\t$this->assertTrue($row['user'] instanceof Relationship);\n\t}\n\n\tpublic function testValueArray_ReturnsAsANewRowObject()\n\t{\n\t\t$columns = array('a', 'b');\n\t\t$data = array(\n\t\t\t// 'a' is a node value\n\t\t\tarray(\n\t\t\t\t'data' => array('name' => 'Alice'),\n\t\t\t\t'self' => 'http://localhost/db/data/node/0'\n\t\t\t),\n\n\t\t\t// 'b' is a collection of node values\n\t\t\tarray(\n\t\t\t\tarray(\n\t\t\t\t\t'data' => array('name' => 'Bob'),\n\t\t\t\t\t'self' => 'http://localhost/db/data/node/1'\n\t\t\t\t),\n\t\t\t\tarray(\n\t\t\t\t\t'data' => array('name' => 'Cathy'),\n\t\t\t\t\t'self' => 'http://localhost/db/data/node/2'\n\t\t\t\t),\n\t\t\t\tarray(\n\t\t\t\t\t'data' => array('name' => 'David'),\n\t\t\t\t\t'self' => 'http://localhost/db/data/node/3'\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\t$row = new Row($this->client, $columns, $data);\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $row['a']);\n\n\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Query\\Row', $row['b']);\n\t\tforeach ($row['b'] as $innerValue) {\n\t\t\t$this->assertInstanceOf('Everyman\\Neo4j\\Node', $innerValue);\n\t\t}\n\n\t\t$this->assertEquals($data[1][1]['data']['name'], $row['b'][1]->getProperty('name'));\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/RelationshipTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass RelationshipTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $relationship = null;\n\tprotected $type = 'FOOTYPE';\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->relationship = new Relationship($this->client);\n\t}\n\n\tpublic function testSave_SavesSelfUsingClient()\n\t{\n\t\t$expected = $this->relationship;\n\t\t$matched = false;\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('saveRelationship')\n\t\t\t// Have to do it this way because PHPUnit clones object parameters\n\t\t\t->will($this->returnCallback(function (Relationship $actual) use ($expected, &$matched) {\n\t\t\t\t$matched = $expected->getId() == $actual->getId();\n\t\t\t\treturn true;\n\t\t\t}));\n\n\t\t$this->assertSame($this->relationship, $this->relationship->save());\n\t\t$this->assertTrue($matched);\n\t}\n\n\t/**\n\t * Test for https://github.com/jadell/neo4jphp/issues/58\n\t */\n\tpublic function testSave_FollowedByPropertyGet_DoesNotLazyLoad()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('saveRelationship')\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->client->expects($this->never())\n\t\t\t->method('loadRelationship');\n\n\t\t$this->relationship->setId(123);\n\t\t$this->relationship->save();\n\t\t$this->relationship->getProperty('foo');\n\t}\n\n\tpublic function testDelete_DeletesSelfUsingClient()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('deleteRelationship')\n\t\t\t->with($this->relationship)\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertSame($this->relationship, $this->relationship->delete());\n\t}\n\n\tpublic function testLoad_LoadsSelfUsingClient()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('loadRelationship')\n\t\t\t->with($this->relationship)\n\t\t\t->will($this->returnValue(true));\n\n\t\t$this->assertSame($this->relationship, $this->relationship->load());\n\t}\n\n\tpublic function testGetStartNode_NodeNotSet_LazyLoad()\n\t{\n\t\t$this->relationship->setId(123);\n\t\t$this->client->expects($this->once())\n\t\t\t->method('loadRelationship');\n\n\t\t$this->relationship->getStartNode();\n\t}\n\n\tpublic function testGetEndNode_NodeNotSet_LazyLoad()\n\t{\n\t\t$this->relationship->setId(123);\n\t\t$this->client->expects($this->once())\n\t\t\t->method('loadRelationship');\n\n\t\t$this->relationship->getEndNode();\n\t}\n\n\tpublic function testGetStartAndEndNode_NodesSet_DoesNotLazyLoad()\n\t{\n\t\t$startNode = new Node($this->client);\n\t\t$endNode = new Node($this->client);\n\n\t\t$this->relationship->setId(123);\n\t\t$this->relationship->setStartNode($startNode);\n\t\t$this->relationship->setEndNode($endNode);\n\n\t\t$this->client->expects($this->never())\n\t\t\t->method('loadRelationship');\n\n\t\t$this->assertSame($startNode, $this->relationship->getStartNode());\n\t\t$this->assertSame($endNode, $this->relationship->getEndNode());\n\t}\n\n\tpublic function testSerialize_KeepsStartEndAndType()\n\t{\n\t\t$expectedStart = new Node($this->client);\n\t\t$expectedStart->setId(123);\n\t\t$expectedEnd = new Node($this->client);\n\t\t$expectedEnd->setId(456);\n\t\t$this->relationship\n\t\t\t->setType($this->type)\n\t\t\t->setStartNode($expectedStart)\n\t\t\t->setEndNode($expectedEnd);\n\n\t\t// serialize and unserialize\n\t\t$data = serialize($this->relationship);\n\t\t$rel = unserialize($data);\n\t\t// we must reset the client\n\t\t$rel->setClient($this->client);\n\t\t$start = $rel->getStartNode();\n\t\t$end = $rel->getEndNode();\n\n\t\t$this->assertEquals($this->relationship, $rel, 'The relationship is restored by unserialize');\n\t\t$this->assertEquals($expectedStart, $start, 'The start node should be restored by unserialize');\n\t\t$this->assertEquals($expectedEnd, $end, 'The end node should be restored by unserialize');\n\t\t$this->assertEquals($this->type, $rel->getType(), 'The type should be restored by unserialize');\n\t\t$this->assertEquals($this->client, $start->getClient(), 'The client should be restored in the start node by setClient on the relation');\n\t\t$this->assertEquals($this->client, $end->getClient(), 'The client should be restored in the end node by setClient on the relation');\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/TransactionTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nuse Everyman\\Neo4j\\Cypher\\Query,\n    Everyman\\Neo4j\\Query\\ResultSet;\n\nclass TransactionTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $transaction = null;\n\tprotected $transactionId = 123;\n\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client');\n\t\t$this->transaction = new Transaction($this->client);\n\t\t$this->transaction->setId($this->transactionId);\n\t}\n\n\tpublic function testSetId_CorrectlySetsId()\n\t{\n\t\tself::assertEquals($this->transactionId, $this->transaction->getId());\n\t}\n\n\tpublic function testSetId_SameIdSetAgain_CorrectlySetsId()\n\t{\n\t\t$result = $this->transaction->setId($this->transactionId);\n\t\tself::assertEquals($this->transactionId, $this->transaction->getId());\n\t\tself::assertSame($this->transaction, $result);\n\t}\n\n\tpublic function testSetId_DifferentIdSet_ThrowsException()\n\t{\n\t\t$idDifferent = $this->transactionId+1000;\n\t\t$this->setExpectedException('InvalidArgumentException', 'new id');\n\t\t$this->transaction->setId($idDifferent);\n\t}\n\n\tpublic function testCommit_DelegatesToClient()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('addStatementsToTransaction')\n\t\t\t->with($this->transaction, array(), true);\n\n\t\t$result = $this->transaction->commit();\n\t\tself::assertSame($this->transaction, $result);\n\t\tself::assertTrue($this->transaction->isClosed());\n\t}\n\n\tpublic function testCommit_NoId_NoopAndMarksTransactionClosed()\n\t{\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$this->client->expects($this->never())\n\t\t\t->method('addStatementsToTransaction');\n\n\t\t$result = $transaction->commit();\n\t\tself::assertSame($transaction, $result);\n\t\tself::assertTrue($transaction->isClosed());\n\t}\n\n\tpublic function testCommit_ClosedTransaction_ThrowsException()\n\t{\n\t\t$result = $this->transaction->commit();\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception', 'already closed');\n\t\t$this->transaction->commit();\n\t}\n\n\tpublic function testCommit_ClientException_MarksTransactionClosedAndErrorAndThrowsException()\n\t{\n\t\t$exception = new \\Everyman\\Neo4j\\Exception('some client error');\n\n\t\t$this->client->expects($this->any())\n\t\t\t->method('addStatementsToTransaction')\n\t\t\t->will($this->throwException($exception));\n\n\t\ttry {\n\t\t\t$this->transaction->commit();\n\t\t\t$this->fail('Expected exception not thrown');\n\t\t} catch (\\Everyman\\Neo4j\\Exception $e) {\n\t\t\tself::assertSame($exception, $e);\n\t\t\tself::assertTrue($this->transaction->isClosed());\n\t\t\tself::assertTrue($this->transaction->isError());\n\t\t}\n\t}\n\n\tpublic function testRollback_DelegatesToClient()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('rollbackTransaction')\n\t\t\t->with($this->transaction);\n\n\t\t$result = $this->transaction->rollback();\n\t\tself::assertSame($this->transaction, $result);\n\t\tself::assertTrue($this->transaction->isClosed());\n\t}\n\n\tpublic function testRollback_NoTransactionId_NoopAndMarksTransactionClosed()\n\t{\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$this->client->expects($this->never())\n\t\t\t->method('rollbackTransaction');\n\n\t\t$result = $transaction->rollback();\n\t\tself::assertSame($transaction, $result);\n\t\tself::assertTrue($transaction->isClosed());\n\t}\n\n\tpublic function testRollback_ClosedTransaction_ThrowsException()\n\t{\n\t\t$result = $this->transaction->commit();\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception', 'already closed');\n\t\t$this->transaction->rollback();\n\t}\n\n\tpublic function testRollback_ClientException_MarksTransactionClosedAndErrorAndThrowsException()\n\t{\n\t\t$exception = new \\Everyman\\Neo4j\\Exception('some client error');\n\n\t\t$this->client->expects($this->any())\n\t\t\t->method('rollbackTransaction')\n\t\t\t->will($this->throwException($exception));\n\n\t\ttry {\n\t\t\t$this->transaction->rollback();\n\t\t\t$this->fail('Expected exception not thrown');\n\t\t} catch (\\Everyman\\Neo4j\\Exception $e) {\n\t\t\tself::assertSame($exception, $e);\n\t\t\tself::assertTrue($this->transaction->isClosed());\n\t\t\tself::assertTrue($this->transaction->isError());\n\t\t}\n\t}\n\n\tpublic function testKeepAlive_DelegatesToClient()\n\t{\n\t\t$this->client->expects($this->once())\n\t\t\t->method('addStatementsToTransaction')\n\t\t\t->with($this->transaction, array(), false);\n\n\t\t$result = $this->transaction->keepAlive();\n\t\tself::assertSame($this->transaction, $result);\n\t\tself::assertFalse($this->transaction->isClosed());\n\t}\n\n\tpublic function testKeepAlive_NoTransactionId_Noop()\n\t{\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$this->client->expects($this->never())\n\t\t\t->method('addStatementsToTransaction');\n\n\t\t$result = $transaction->keepAlive();\n\t\tself::assertSame($transaction, $result);\n\t\tself::assertFalse($transaction->isClosed());\n\t}\n\n\tpublic function testKeepAlive_ClosedTransaction_ThrowsException()\n\t{\n\t\t$result = $this->transaction->commit();\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception', 'already closed');\n\t\t$this->transaction->keepAlive();\n\t}\n\n\tpublic function testKeepAlive_ClientException_MarksTransactionClosedAndErrorAndThrowsException()\n\t{\n\t\t$exception = new \\Everyman\\Neo4j\\Exception('some client error');\n\n\t\t$this->client->expects($this->any())\n\t\t\t->method('addStatementsToTransaction')\n\t\t\t->will($this->throwException($exception));\n\n\t\ttry {\n\t\t\t$this->transaction->keepAlive();\n\t\t\t$this->fail('Expected exception not thrown');\n\t\t} catch (\\Everyman\\Neo4j\\Exception $e) {\n\t\t\tself::assertSame($exception, $e);\n\t\t\tself::assertTrue($this->transaction->isClosed());\n\t\t\tself::assertTrue($this->transaction->isError());\n\t\t}\n\t}\n\n\tpublic function testAddStatements_NoId_DelegatesToClient()\n\t{\n\t\t$transaction = new Transaction($this->client);\n\n\t\t$statements = array(\n\t\t\tnew Query($this->client, 'foo'),\n\t\t\tnew Query($this->client, 'bar'),\n\t\t);\n\t\t$commit = false;\n\n\t\t$expectedResult = new ResultSet($this->client, array());\n\t\t$expected = array($expectedResult);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('addStatementsToTransaction')\n\t\t\t->with($transaction, $statements, $commit)\n\t\t\t->will($this->returnValue($expected));\n\n\t\t$result = $transaction->addStatements($statements, $commit);\n\t\tself::assertSame($expected[0], $result[0]);\n\t\tself::assertFalse($transaction->isClosed());\n\t}\n\n\tpublic function testAddStatements_DelegatesToClient()\n\t{\n\t\t$statements = array(\n\t\t\tnew Query($this->client, 'foo'),\n\t\t\tnew Query($this->client, 'bar'),\n\t\t);\n\t\t$commit = true;\n\n\t\t$expectedResult = new ResultSet($this->client, array());\n\t\t$expected = array($expectedResult);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('addStatementsToTransaction')\n\t\t\t->with($this->transaction, $statements, $commit)\n\t\t\t->will($this->returnValue($expected));\n\n\t\t$result = $this->transaction->addStatements($statements, $commit);\n\t\tself::assertSame($expected[0], $result[0]);\n\t\tself::assertTrue($this->transaction->isClosed());\n\t}\n\n\tpublic function testAddStatements_SingleQuery_WrapsQueryInArrayBeforeSendingToClient()\n\t{\n\t\t$statement = new Query($this->client, 'foo');\n\n\t\t$expectedResult = new ResultSet($this->client, array());\n\t\t$expected = array($expectedResult);\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('addStatementsToTransaction')\n\t\t\t->with($this->transaction, array($statement))\n\t\t\t->will($this->returnValue($expected));\n\n\t\t$result = $this->transaction->addStatements($statement);\n\t\tself::assertSame($expected[0], $result);\n\t}\n\n\tpublic function testAddStatements_NoCommit_TransactionOpen()\n\t{\n\t\t$statements = array(new Query($this->client, 'foo'));\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('addStatementsToTransaction')\n\t\t\t->with($this->transaction, $statements, false);\n\n\t\t$this->transaction->addStatements($statements);\n\t\tself::assertFalse($this->transaction->isClosed());\n\t}\n\n\tpublic function testAddStatements_ClosedTransaction_ThrowsException()\n\t{\n\t\t$result = $this->transaction->commit();\n\n\t\t$this->setExpectedException('\\Everyman\\Neo4j\\Exception', 'already closed');\n\t\t$this->transaction->addStatements(array(\n\t\t\tnew Query($this->client, 'foo'),\n\t\t\tnew Query($this->client, 'bar'),\n\t\t));\n\t}\n\n\tpublic function testAddStatements_ClientException_MarksTransactionClosedAndErrorAndThrowsException()\n\t{\n\t\t$exception = new \\Everyman\\Neo4j\\Exception('some client error');\n\n\t\t$this->client->expects($this->any())\n\t\t\t->method('addStatementsToTransaction')\n\t\t\t->will($this->throwException($exception));\n\n\t\ttry {\n\t\t\t$this->transaction->addStatements(array(new Query($this->client, 'foo')));\n\t\t\t$this->fail('Expected exception not thrown');\n\t\t} catch (\\Everyman\\Neo4j\\Exception $e) {\n\t\t\tself::assertSame($exception, $e);\n\t\t\tself::assertTrue($this->transaction->isClosed());\n\t\t\tself::assertTrue($this->transaction->isError());\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/TransportTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass TransportTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $host = 'foo.com';\n\tprotected $port = 1234;\n\n\tprotected $transport = null;\n\n\tpublic function setUp()\n\t{\n\t\t$this->transport = $this->getMock('Everyman\\Neo4j\\Transport', array('makeRequest'), array($this->host, $this->port));\n\t}\n\n\tpublic function testConstants_MakeSureNothingSillyHappensLikeMisnamingTheConstants_ReturnsCorrectString()\n\t{\n\t\t$this->assertEquals('GET', Transport::GET);\n\t\t$this->assertEquals('POST', Transport::POST);\n\t\t$this->assertEquals('PUT', Transport::PUT);\n\t\t$this->assertEquals('DELETE', Transport::DELETE);\n\t}\n\n\tpublic function testGetEndpoint_ReturnsCorrectEndpointUrl()\n\t{\n\t\t$this->assertEquals(\"http://{$this->host}:{$this->port}/db/data\", $this->transport->getEndpoint());\n\t}\n\n\tpublic function testGetEndpoint_UseHttps_ReturnsCorrectEndpointUrl()\n\t{\n\t\t$this->transport->useHttps();\n\t\t$this->assertEquals(\"https://{$this->host}:{$this->port}/db/data\", $this->transport->getEndpoint());\n\t}\n\n\tpublic function testDelete_MakesRequestWithCorrectParams()\n\t{\n\t\t$expected = array('code'=>200,'headers'=>array('Location'=>'somewhere'),'data'=>array('key'=>'val'));\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('makeRequest')\n\t\t\t->with(Transport::DELETE, '/path')\n\t\t\t->will($this->returnValue($expected));\n\n\t\t$this->assertEquals($expected, $this->transport->delete('/path'));\n\t}\n\n\tpublic function testPut_MakesRequestWithCorrectParams()\n\t{\n\t\t$expected = array('code'=>200,'headers'=>array('Location'=>'somewhere'),'data'=>array('key'=>'val'));\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('makeRequest')\n\t\t\t->with(Transport::PUT, '/path', 'somedata')\n\t\t\t->will($this->returnValue($expected));\n\n\t\t$this->assertEquals($expected, $this->transport->put('/path','somedata'));\n\t}\n\n\tpublic function testPost_MakesRequestWithCorrectParams()\n\t{\n\t\t$expected = array('code'=>200,'headers'=>array('Location'=>'somewhere'),'data'=>array('key'=>'val'));\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('makeRequest')\n\t\t\t->with(Transport::POST, '/path', 'somedata')\n\t\t\t->will($this->returnValue($expected));\n\n\t\t$this->assertEquals($expected, $this->transport->post('/path','somedata'));\n\t}\n\n\tpublic function testGet_MakesRequestWithCorrectParams()\n\t{\n\t\t$expected = array('code'=>200,'headers'=>array('Location'=>'somewhere'),'data'=>array('key'=>'val'));\n\n\t\t$this->transport->expects($this->once())\n\t\t\t->method('makeRequest')\n\t\t\t->with(Transport::GET, '/path', 'somedata')\n\t\t\t->will($this->returnValue($expected));\n\n\t\t$this->assertEquals($expected, $this->transport->get('/path','somedata'));\n\t}\n\t\n\tpublic function testEncodeData_StringGiven_ReturnsString()\n\t{\n\t\t$data = 'http://localhost:7474/db/data/node/19';\n\t\t$expected = '\"http:\\/\\/localhost:7474\\/db\\/data\\/node\\/19\"';\n\t\t$result = $this->transport->encodeData($data);\n\t\t$this->assertEquals($expected, $result);\n\t}\n\t\n\tpublic function testEncodeData_ArrayWithNonNumericKeys_ReturnsString()\n\t{\n\t\t$obj = new \\stdClass();\n\t\t$obj->s = \"hi\";\n\t\t$obj->i = 9;\n\t\t$obj->a = array(7,8);\n\t\n\t\t$data = array(\n\t\t\t'string' => 'http://localhost:7474/db/data/node/19',\n\t\t\t'int' => 123,\n\t\t\t'array' => array(4,5,6),\n\t\t\t'object' => $obj,\n\t\t);\n\t\t$expected = '{\"string\":\"http:\\/\\/localhost:7474\\/db\\/data\\/node\\/19\",\"int\":123,\"array\":[4,5,6],\"object\":{\"s\":\"hi\",\"i\":9,\"a\":[7,8]}}';\n\t\t$result = $this->transport->encodeData($data);\n\t\t$this->assertEquals($expected, $result);\n\t}\n\t\n\tpublic function testEncodeData_ArrayWithNumericKeys_ReturnsString()\n\t{\n\t\t$obj = new \\stdClass();\n\t\t$obj->s = \"hi\";\n\t\t$obj->i = 9;\n\t\t$obj->a = array(7,8);\n\n\t\t$data = array(\n\t\t\t'http://localhost:7474/db/data/node/19',\n\t\t\t123,\n\t\t\tarray(4,5,6),\n\t\t\t$obj,\n\t\t);\n\t\t$expected = '[\"http:\\/\\/localhost:7474\\/db\\/data\\/node\\/19\",123,[4,5,6],{\"s\":\"hi\",\"i\":9,\"a\":[7,8]}]';\n\t\t$result = $this->transport->encodeData($data);\n\t\t$this->assertEquals($expected, $result);\n\t}\n\t\n\tpublic function testEncodeData_EmptyArray_ReturnsString()\n\t{\n\t\t$data = array();\n\t\t$expected = '{}';\n\t\t$result = $this->transport->encodeData($data);\n\t\t$this->assertEquals($expected, $result);\n\t}\n}\n"
  },
  {
    "path": "tests/unit/lib/Everyman/Neo4j/TraversalTest.php",
    "content": "<?php\nnamespace Everyman\\Neo4j;\n\nclass TraversalTest extends \\PHPUnit_Framework_TestCase\n{\n\tprotected $client = null;\n\tprotected $traversal = null;\n\t\n\tpublic function setUp()\n\t{\n\t\t$this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);\n\t\t$this->traversal = new Traversal($this->client);\n\t}\n\n\tpublic function testGetClient_ClientSetCorrectly_ReturnsClient()\n\t{\n\t\t$this->assertSame($this->client, $this->traversal->getClient());\n\t}\n\n\tpublic function testOrder_NoneGiven_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->traversal->getOrder());\n\t}\n\n\tpublic function testOrder_OrderGiven_ReturnsString()\n\t{\n\t\t$this->traversal->setOrder(Traversal::OrderDepthFirst);\n\t\t$this->assertEquals(Traversal::OrderDepthFirst, $this->traversal->getOrder());\n\t}\n\n\tpublic function testUniqueness_NoneGiven_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->traversal->getUniqueness());\n\t}\n\n\tpublic function testUniqueness_UniquenessGiven_ReturnsString()\n\t{\n\t\t$this->traversal->setUniqueness(Traversal::UniquenessNodeGlobal);\n\t\t$this->assertEquals(Traversal::UniquenessNodeGlobal, $this->traversal->getUniqueness());\n\t}\n\n\tpublic function testMaxDepth_NoneGiven_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->traversal->getMaxDepth());\n\t}\n\n\tpublic function testMaxDepth_MaxDepthGiven_ReturnsInteger()\n\t{\n\t\t$this->traversal->setMaxDepth(3);\n\t\t$this->assertEquals(3, $this->traversal->getMaxDepth());\n\t}\n\n\tpublic function testRelationships_NoneGiven_ReturnsEmptyArray()\n\t{\n\t\t$relationships = $this->traversal->getRelationships();\n\t\t$this->assertEquals(array(), $relationships);\n\t}\n\n\tpublic function testRelationships_TypeGivenAndDirectionGiven_ReturnsArray()\n\t{\n\t\t$this->traversal->addRelationship('FOOTYPE');\n\t\t$this->traversal->addRelationship('BARTYPE', Relationship::DirectionOut);\n\n\t\t$relationships = $this->traversal->getRelationships();\n\t\t$this->assertEquals(array(\n\t\t\tarray('type'=>'FOOTYPE'),\n\t\t\tarray('type'=>'BARTYPE', 'direction'=>Relationship::DirectionOut),\n\t\t), $relationships);\n\t}\n\n\tpublic function testPruneEvaluator_NoneGiven_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->traversal->getPruneEvaluator());\n\t}\n\n\tpublic function testPruneEvaluator_LanguageAndBody_ReturnsArray()\n\t{\n\t\t$this->traversal->setPruneEvaluator('javascript', 'return true;');\n\n\t\t$evaluator = $this->traversal->getPruneEvaluator();\n\t\t$this->assertEquals('javascript', $evaluator['language']);\n\t\t$this->assertEquals('return true;', $evaluator['body']);\n\t}\n\n\tpublic function testPruneEvaluator_BuiltIn_ReturnsArray()\n\t{\n\t\t$this->traversal->setPruneEvaluator(Traversal::PruneNone);\n\n\t\t$evaluator = $this->traversal->getPruneEvaluator();\n\t\t$this->assertEquals('builtin', $evaluator['language']);\n\t\t$this->assertEquals(Traversal::PruneNone, $evaluator['body']);\n\t}\n\n\tpublic function testPruneEvaluator_Reset_ReturnsNull()\n\t{\n\t\t$this->traversal->setPruneEvaluator('javascript', 'return true;');\n\t\t$this->traversal->setPruneEvaluator();\n\n\t\t$this->assertNull($this->traversal->getPruneEvaluator());\n\t}\n\n\tpublic function testReturnFilter_NoneGiven_ReturnsNull()\n\t{\n\t\t$this->assertNull($this->traversal->getReturnFilter());\n\t}\n\n\tpublic function testReturnFilter_LanguageAndBody_ReturnsArray()\n\t{\n\t\t$this->traversal->setReturnFilter('javascript', 'return true;');\n\n\t\t$filter = $this->traversal->getReturnFilter();\n\t\t$this->assertEquals('javascript', $filter['language']);\n\t\t$this->assertEquals('return true;', $filter['body']);\n\t}\n\n\tpublic function testReturnFilter_BuiltIn_ReturnsArray()\n\t{\n\t\t$this->traversal->setReturnFilter(Traversal::ReturnAllButStart);\n\n\t\t$filter = $this->traversal->getReturnFilter();\n\t\t$this->assertEquals('builtin', $filter['language']);\n\t\t$this->assertEquals(Traversal::ReturnAllButStart, $filter['body']);\n\t}\n\n\tpublic function testReturnFilter_Reset_ReturnsNull()\n\t{\n\t\t$this->traversal->setReturnFilter('javascript', 'return true;');\n\t\t$this->traversal->setReturnFilter();\n\n\t\t$this->assertNull($this->traversal->getPruneEvaluator());\n\t}\n\n\tpublic function testGetResults_PassesThroughToClient()\n\t{\n\t\t$startNode = new Node($this->client);\n\n\t\t$expectedNodes = array(new Node($this->client), new Node($this->client));\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('executeTraversal')\n\t\t\t->with($this->traversal, $startNode, Traversal::ReturnTypeNode)\n\t\t\t->will($this->returnValue($expectedNodes));\n\n\t\t$nodes = $this->traversal->getResults($startNode, Traversal::ReturnTypeNode);\n\t\t$this->assertEquals($expectedNodes, $nodes);\n\t}\n\n\tpublic function testGetSingleResult_PassesThroughToClient()\n\t{\n\t\t$startNode = new Node($this->client);\n\n\t\t$firstResult = new Node($this->client);\n\t\t$expectedNodes = array($firstResult, new Node($this->client));\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('executeTraversal')\n\t\t\t->with($this->traversal, $startNode, Traversal::ReturnTypeNode)\n\t\t\t->will($this->returnValue($expectedNodes));\n\n\t\t$result = $this->traversal->getSingleResult($startNode, Traversal::ReturnTypeNode);\n\t\t$this->assertSame($firstResult, $result);\n\t}\n\n\tpublic function testGetSingleResult_NoResults_ReturnsNull()\n\t{\n\t\t$startNode = new Node($this->client);\n\n\t\t$expectedNodes = array();\n\n\t\t$this->client->expects($this->once())\n\t\t\t->method('executeTraversal')\n\t\t\t->with($this->traversal, $startNode, Traversal::ReturnTypeNode)\n\t\t\t->will($this->returnValue($expectedNodes));\n\n\t\t$result = $this->traversal->getSingleResult($startNode, Traversal::ReturnTypeNode);\n\t\t$this->assertNull($result);\n\t}\n}\n\n"
  }
]