{"id":21273476,"url":"https://github.com/graphaware/php-graphunit","last_synced_at":"2025-07-11T06:33:21.337Z","repository":{"id":35643808,"uuid":"39918353","full_name":"graphaware/php-graphunit","owner":"graphaware","description":"Neo4j Graph Database Assertion Tool for PHPUnit","archived":false,"fork":false,"pushed_at":"2015-08-04T23:19:34.000Z","size":156,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-11-14T14:27:58.867Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Xwards/Xwards_Careers","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/graphaware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-29T21:58:13.000Z","updated_at":"2021-07-28T11:23:01.000Z","dependencies_parsed_at":"2022-08-21T09:10:42.664Z","dependency_job_id":null,"html_url":"https://github.com/graphaware/php-graphunit","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphaware%2Fphp-graphunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphaware%2Fphp-graphunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphaware%2Fphp-graphunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphaware%2Fphp-graphunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graphaware","download_url":"https://codeload.github.com/graphaware/php-graphunit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225700876,"owners_count":17510448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-21T09:14:55.805Z","updated_at":"2024-11-21T09:14:56.529Z","avatar_url":"https://github.com/graphaware.png","language":"PHP","readme":"## Neo4j GraphUnit for PHP\n\nNeo4j Graph Database Assertion Tool.\n\n[![Build Status](https://travis-ci.org/graphaware/php-graphunit.svg?branch=master)](https://travis-ci.org/graphaware/php-graphunit)\n\n### Usage\n\nRequire the library in your dev dependencies :\n\n```bash\ncomposer require --dev graphaware/neo4j-graphunit\n```\n\nCreate your `BaseTestCase` that will extend `GraphAware\\Neo4j\\GraphUnit\\Neo4jGraphDatabaseTestCase` and declare the \n`getConnection` method that should return a `Client` instance.\n\nTo make things easier, you can just call the `createConnection` method of the parent class to bootstrap the connection.\n\n```php\n\nnamespace MyVendor\\MyApp\\Tests;\n\nuse GraphAware\\Neo4j\\GraphUnit\\Neo4jGraphDatabaseTestCase;\n\nabstract class MyAppBaseTestCase extends Neo4jGraphDatabaseTestCase\n{\n\tpublic function getConnection()\n\t{\n\t\treturn $this-\u003ecreateConnection('localhost', 7474, 'neo4j', 'password');\n\t}\n}\n```\n\n### Assertions\n\n#### assertNodeWithLabelExist\n\n```php\npublic function testNodeWillExist()\n\t{\n\t\t$q = 'CREATE (n:TestNode)';\n\t\t$this-\u003egetConnection()-\u003esendCypherQuery($q);\n\t\t\n\t\t$this-\u003eassertNodeWithLabelExist('TestNode');\n\t}\n```\n\n#### assertNodesWithLabelCount\n\n```php\npublic function testMultipleNodesAreCreated()\n\t{\n\t\t$q = 'CREATE (n:TestNode), (n2:TestNode);\n\t\t$this-\u003egetConnection()-\u003esendCypherQuery($q);\n\t\t\n\t\t$this-\u003eassertNodesWithLabelCount(2, 'TestNode');\n\t}\n```\n\n#### assertNodesCount\n\n```php\npublic function testMultipleNodesAreCreated()\n\t{\n\t\t$q = 'CREATE (n:TestNode), (n2:TestNode);\n\t\t$this-\u003egetConnection()-\u003esendCypherQuery($q);\n\t\t\n\t\t$this-\u003eassertNodesCount(2);\n\t}\n```\n\n#### assertNodeHasRelationship\n\n```php\npublic function testMultipleNodesAreCreated()\n\t{\n\t\t$q = 'CREATE (n:User {name: \"john\"}), (n2:User {name: \"mary\"})-[:WORKS_AT]-\u003e(:Company {name:\"Acme\"}) RETURN n2;\n\t\t$result = $this-\u003egetConnection()-\u003esendCypherQuery($q);\n\t\t\n\t\t$this-\u003eassertNodeHasRelationship($result-\u003eget('n2'), 'WORKS_AT', 'OUT');\n\t}\n```\n\n### Reseting database states\n\nYou can easily reset the database state (deleting all nodes, relationships, schema indexes and constraints) during your `setUp` events :\n\n```php\npublic function setUp()\n{\n\t$this-\u003eresetDatabase();\n}\n```\n\nIf you don't want to delete the schema indexes and constraints, just call the `emptyDatabase` method :\n\n```php\npublic function setUp()\n{\n\t$this-\u003eemptyDatabase();\n}\n```\n\n### Preparing database states\n\nYou can just pass a Cypher pattern for preparing your database :\n\n```php\npublic function setUp()\n{\n\t$state = \"(a:User {name:'Abed'})-[:WORKS_AT]-\u003e(:Company {name:'Vinelab'})\n\t(c:User {name:'Chris'})-[:WORKS_AT]-\u003e(:Company {name:'GraphAware'})\n\t(a)-[:FRIEND]-\u003e(c)\";\n\t$this-\u003eprepareDatabase($state);\n}\n```\n\n### Asserting same graphs\n\nThe library can assert that the actual graph in the database matches a graph you pass as a Cypher pattern, example : \n\n```php\n\npublic function testMyGraphIsGood()\n{\n\t$this-\u003eassertSameGraph(\"(:User {name:'John'})-[:WORKS_AT]-\u003e(c:Company {name:'Acme'})\");\n}\n\n// Returns true if the actual graph is identical, otherwise show errors in PHPUnit\n\n//1) GraphAware\\Neo4j\\GraphUnit\\Tests\\Integration\\SimpleIntegrationTest::testAssertSame\n//Failed asserting that the expected graph is the same as the actual graph.\n```\n\n---\n\n### License\n\nThis library is released under the MIT License, please refer to the `LICENSE` file shipped with the library.\n\n### Author\n\nChristophe Willemsen\n\nGithub: https://github.com/ikwattro\n\nTwitter: https://twitter.com/ikwattro\n\n### Credits\n\nGraphAware Limited","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphaware%2Fphp-graphunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraphaware%2Fphp-graphunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphaware%2Fphp-graphunit/lists"}