PHP code example of graphaware / neo4j-graphunit

1. Go to this page and download the library: Download graphaware/neo4j-graphunit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

graphaware / neo4j-graphunit example snippets



namespace MyVendor\MyApp\Tests;

use GraphAware\Neo4j\GraphUnit\Neo4jGraphDatabaseTestCase;

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

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

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

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

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');
	}

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

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

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);
}


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.