graphaware / neo4j-graphunit
该软件包已被放弃且不再维护。未建议替代软件包。
Neo4j 图形数据库断言工具
1.0.8
2015-08-04 23:19 UTC
Requires
- graphaware/neo4j-response-formatter: ^1.0
- neoxygen/neoclient: ^3.0
- phpunit/phpunit: ^4.7
README
Neo4j 图形数据库断言工具。
使用方法
在您的开发依赖中要求库
composer require --dev graphaware/neo4j-graphunit
创建您的 BaseTestCase
,它将扩展 GraphAware\Neo4j\GraphUnit\Neo4jGraphDatabaseTestCase
,并声明应返回 Client
实例的 getConnection
方法。
为了让事情变得简单,您可以直接调用父类的 createConnection
方法来引导连接。
namespace MyVendor\MyApp\Tests; use GraphAware\Neo4j\GraphUnit\Neo4jGraphDatabaseTestCase; abstract class MyAppBaseTestCase extends Neo4jGraphDatabaseTestCase { public function getConnection() { return $this->createConnection('localhost', 7474, 'neo4j', 'password'); } }
断言
assertNodeWithLabelExist
public function testNodeWillExist() { $q = 'CREATE (n:TestNode)'; $this->getConnection()->sendCypherQuery($q); $this->assertNodeWithLabelExist('TestNode'); }
assertNodesWithLabelCount
public function testMultipleNodesAreCreated() { $q = 'CREATE (n:TestNode), (n2:TestNode); $this->getConnection()->sendCypherQuery($q); $this->assertNodesWithLabelCount(2, 'TestNode'); }
assertNodesCount
public function testMultipleNodesAreCreated() { $q = 'CREATE (n:TestNode), (n2:TestNode); $this->getConnection()->sendCypherQuery($q); $this->assertNodesCount(2); }
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'); }
重置数据库状态
您可以在 setUp
事件期间轻松重置数据库状态(删除所有节点、关系、模式索引和约束)
public function setUp() { $this->resetDatabase(); }
如果您不想删除模式索引和约束,只需调用 emptyDatabase
方法
public function setUp() { $this->emptyDatabase(); }
准备数据库状态
您只需传递一个 Cypher 模式即可准备您的数据库
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); }
断言相同的图
库可以断言实际数据库中的图与您通过 Cypher 模式传递的图匹配,例如
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.
许可
此库根据 MIT 许可发布,请参阅库附带的相关 LICENSE
文件。
作者
Christophe Willemsen
Github: https://github.com/ikwattro
Twitter: https://twitter.com/ikwattro
致谢
GraphAware Limited