PHPackages                             graphaware/neo4j-graphunit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. graphaware/neo4j-graphunit

AbandonedLibrary[Testing &amp; Quality](/categories/testing)

graphaware/neo4j-graphunit
==========================

Graph Database Assertion Tool for Neo4j

1.0.8(10y ago)63961[1 issues](https://github.com/graphaware/php-graphunit/issues)MITPHP

Since Jul 29Pushed 10y ago21 watchersCompare

[ Source](https://github.com/graphaware/php-graphunit)[ Packagist](https://packagist.org/packages/graphaware/neo4j-graphunit)[ RSS](/packages/graphaware-neo4j-graphunit/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (10)Used By (0)

Neo4j GraphUnit for PHP
-----------------------

[](#neo4j-graphunit-for-php)

Neo4j Graph Database Assertion Tool.

[![Build Status](https://camo.githubusercontent.com/45f8d77b561b1d47657f25fdeeaa4e1b2f1a8854d44ac8f0050c48262e15e479/68747470733a2f2f7472617669732d63692e6f72672f677261706861776172652f7068702d6772617068756e69742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/graphaware/php-graphunit)

### Usage

[](#usage)

Require the library in your dev dependencies :

```
composer require --dev graphaware/neo4j-graphunit
```

Create your `BaseTestCase` that will extend `GraphAware\Neo4j\GraphUnit\Neo4jGraphDatabaseTestCase` and declare the `getConnection` method that should return a `Client` instance.

To make things easier, you can just call the `createConnection` method of the parent class to bootstrap the connection.

```
namespace MyVendor\MyApp\Tests;

use GraphAware\Neo4j\GraphUnit\Neo4jGraphDatabaseTestCase;

abstract class MyAppBaseTestCase extends Neo4jGraphDatabaseTestCase
{
	public function getConnection()
	{
		return $this->createConnection('localhost', 7474, 'neo4j', 'password');
	}
}
```

### Assertions

[](#assertions)

#### assertNodeWithLabelExist

[](#assertnodewithlabelexist)

```
public function testNodeWillExist()
	{
		$q = 'CREATE (n:TestNode)';
		$this->getConnection()->sendCypherQuery($q);

		$this->assertNodeWithLabelExist('TestNode');
	}
```

#### assertNodesWithLabelCount

[](#assertnodeswithlabelcount)

```
public function testMultipleNodesAreCreated()
	{
		$q = 'CREATE (n:TestNode), (n2:TestNode);
		$this->getConnection()->sendCypherQuery($q);

		$this->assertNodesWithLabelCount(2, 'TestNode');
	}
```

#### assertNodesCount

[](#assertnodescount)

```
public function testMultipleNodesAreCreated()
	{
		$q = 'CREATE (n:TestNode), (n2:TestNode);
		$this->getConnection()->sendCypherQuery($q);

		$this->assertNodesCount(2);
	}
```

#### assertNodeHasRelationship

[](#assertnodehasrelationship)

```
public function testMultipleNodesAreCreated()
	{
		$q = 'CREATE (n:User {name: "john"}), (n2:User {name: "mary"})-[:WORKS_AT]->(:Company {name:"Acme"}) RETURN n2;
		$result = $this->getConnection()->sendCypherQuery($q);

		$this->assertNodeHasRelationship($result->get('n2'), 'WORKS_AT', 'OUT');
	}
```

### Reseting database states

[](#reseting-database-states)

You can easily reset the database state (deleting all nodes, relationships, schema indexes and constraints) during your `setUp` events :

```
public function setUp()
{
	$this->resetDatabase();
}
```

If you don't want to delete the schema indexes and constraints, just call the `emptyDatabase` method :

```
public function setUp()
{
	$this->emptyDatabase();
}
```

### Preparing database states

[](#preparing-database-states)

You can just pass a Cypher pattern for preparing your database :

```
public function setUp()
{
	$state = "(a:User {name:'Abed'})-[:WORKS_AT]->(:Company {name:'Vinelab'})
	(c:User {name:'Chris'})-[:WORKS_AT]->(:Company {name:'GraphAware'})
	(a)-[:FRIEND]->(c)";
	$this->prepareDatabase($state);
}
```

### Asserting same graphs

[](#asserting-same-graphs)

The library can assert that the actual graph in the database matches a graph you pass as a Cypher pattern, example :

```
public function testMyGraphIsGood()
{
	$this->assertSameGraph("(:User {name:'John'})-[:WORKS_AT]->(c:Company {name:'Acme'})");
}

// Returns true if the actual graph is identical, otherwise show errors in PHPUnit

//1) GraphAware\Neo4j\GraphUnit\Tests\Integration\SimpleIntegrationTest::testAssertSame
//Failed asserting that the expected graph is the same as the actual graph.
```

---

### License

[](#license)

This library is released under the MIT License, please refer to the `LICENSE` file shipped with the library.

### Author

[](#author)

Christophe Willemsen

Github:

Twitter:

### Credits

[](#credits)

GraphAware Limited

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

9

Last Release

3931d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c66009f0f147bb7dfcfbbd6837176b2fe6c6e2cdcf82d9ad07ab7d7aa47735f4?d=identicon)[ikwattro](/maintainers/ikwattro)

---

Top Contributors

[![ikwattro](https://avatars.githubusercontent.com/u/1222009?v=4)](https://github.com/ikwattro "ikwattro (20 commits)")

---

Tags

databasetestsassertionnosqlneo4jgraph

### Embed Badge

![Health badge](/badges/graphaware-neo4j-graphunit/health.svg)

```
[![Health](https://phpackages.com/badges/graphaware-neo4j-graphunit/health.svg)](https://phpackages.com/packages/graphaware-neo4j-graphunit)
```

###  Alternatives

[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M774](/packages/typo3-testing-framework)[vinelab/neoeloquent

Laravel wrapper for the Neo4j graph database REST interface

65393.1k1](/packages/vinelab-neoeloquent)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)[fr3d/swagger-assertions

Test your API requests and responses against your swagger definition

138850.9k5](/packages/fr3d-swagger-assertions)[stefanak-michal/bolt

PHP library to provide connectivity to graph database over TCP socket with Bolt specification

79655.8k8](/packages/stefanak-michal-bolt)[aik099/phpunit-mink

Library for using Mink in PHPUnit tests. Supports session sharing between tests in a test case.

72136.2k1](/packages/aik099-phpunit-mink)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
