コード例 #1
0
ファイル: ArachnidTest.php プロジェクト: lrezek/arachnid
 function testRelationRemoval()
 {
     $usr1 = new Entity\User();
     $usr2 = new Entity\User();
     $rel = new Entity\FriendsWith();
     $usr1->setFirstName('Arnold');
     $usr1->setLastName('Schwarzenegger');
     $usr1->setTestId($this->id);
     $usr2->setFirstName('Sean');
     $usr2->setLastName('Connery');
     $usr2->setTestId($this->id);
     $rel->setTo($usr2);
     $rel->setFrom($usr1);
     $rel->setSince("1989");
     ArachnidTest::$arachnid->persist($rel);
     ArachnidTest::$arachnid->flush();
     //Get the relation with everyman
     $id = $this->id;
     $queryString = "MATCH (n {firstName:'Arnold', testId:'{$id}'})-[r {since:'1989'}]->(m {firstName:'Sean'}) RETURN r;";
     $query = new EM_QUERY(ArachnidTest::$arachnid->getClient(), $queryString);
     $d = $query->getResultSet();
     //Check the property
     $i = 0;
     foreach ($d as $row) {
         //Check the since property
         $this->assertEquals($row['x']->getProperty("since"), "1989");
         $i++;
     }
     $this->assertEquals(1, $i);
     //Get relation
     $rel = ArachnidTest::$arachnid->reload($rel);
     //Remove it
     $t = microtime(true);
     ArachnidTest::$arachnid->remove($rel);
     ArachnidTest::$arachnid->flush();
     $this->printTime(__FUNCTION__, microtime(true) - $t);
     //Query for it again
     $id = $this->id;
     $queryString = "MATCH (n {firstName:'Arnold', testId:'{$id}'})-[r {since:'1989'}]->(m {firstName:'Sean'}) RETURN r;";
     $query = new EM_QUERY(ArachnidTest::$arachnid->getClient(), $queryString);
     $d = $query->getResultSet();
     //Check the property
     foreach ($d as $row) {
         $this->fail();
     }
 }
コード例 #2
0
ファイル: RepositoryTest.php プロジェクト: lrezek/arachnid
 function testRelationFindAll()
 {
     $mov1 = new Entity\User();
     $mov1->setFirstName('Owen');
     $mov1->setLastName('Wilson');
     $mov1->setTestId($this->id);
     $mov2 = new Entity\User();
     $mov2->setFirstName('Morgan');
     $mov2->setLastName('Freeman');
     $mov2->setTestId($this->id);
     $mov3 = new Entity\User();
     $mov3->setFirstName('Katy');
     $mov3->setLastName('Perry');
     $mov3->setTestId($this->id);
     //Create relation from David to Lukas
     $relation = new Entity\Likes();
     $relation->setTo($mov1);
     $relation->setFrom($mov2);
     $relation->setSince("2060");
     //Create relation from David to Nicole
     $relation2 = new Entity\Likes();
     $relation2->setTo($mov3);
     $relation2->setFrom($mov2);
     $relation2->setSince("2061");
     self::$arachnid->persist($relation);
     self::$arachnid->persist($relation2);
     self::$arachnid->flush();
     $t = microtime(true);
     $rels = self::$arachnid->getRepository('LRezek\\Arachnid\\Tests\\Entity\\Likes')->find_all()->toArray();
     $this->printTime(__FUNCTION__, microtime(true) - $t);
     $this->assertEquals(count($rels), 2);
 }
コード例 #3
0
ファイル: QueryTest.php プロジェクト: lrezek/arachnid
 function testCypherQueryMatchNodeGet_Result()
 {
     $p1 = new User();
     $p1->setFirstName("Angelina");
     $p1->setLastName("Pitt");
     $p1->setTestId($this->id);
     self::$arachnid->persist($p1);
     self::$arachnid->flush();
     $t = microtime(true);
     $set = self::$arachnid->create_cypher_query()->match('(movie:`LRezek\\Arachnid\\Tests\\Entity\\User`)')->where('movie.testId="' . $this->id . '"', 'movie.firstName="Angelina"')->end('movie')->get_result();
     $this->printTime(__FUNCTION__, microtime(true) - $t);
     $this->assertEquals(count($set), 2);
     foreach ($set[0] as $node) {
         $this->assertEquals($node->getFirstName(), 'Angelina');
     }
     //Remove temp node
     self::$arachnid->reload($p1);
     self::$arachnid->remove($p1);
     self::$arachnid->flush();
 }
コード例 #4
0
ファイル: RepositoryTest.php プロジェクト: lrezek/arachnid
 function setUp()
 {
     //Generate a ID, so nodes can easily be found and deleted after tests
     $this->id = uniqid();
     //Create users
     $p1 = new User();
     $p2 = new User();
     $p3 = new User();
     $p4 = new User();
     $p5 = new User();
     //Brad -> 1990 -> Christian
     //Brad -> 1991 -> Scarlett
     //Brad -> 1992 -> Liam
     //Brad -> 1993 -> Ellen
     //Christian -> 1994 -> Brad
     //Christian -> 1995 -> Scarlett
     //Christian -> 1996 -> Liam
     //Christian -> 1997 -> Ellen
     //Scarlett -> 1998 -> Brad
     //Scarlett -> 1999 -> Christian
     //Scarlett -> 2000 -> Liam
     //Scarlett -> 2001 -> Ellen
     //Liam -> 2002 -> Brad
     //Liam -> 2003 -> Christian
     //Liam -> 2004 -> Scarlett
     //Liam -> 2005 -> Ellen
     //Ellen -> 2006 -> Brad
     //Ellen -> 2007 -> Christian
     //Ellen -> 2008 -> Scarlett
     //Ellen -> 2009 -> Liam
     //Write their properties
     $p1->setFirstName("Brad");
     $p1->setLastName("Pitt");
     $p1->setTestId($this->id);
     $p2->setFirstName("Christian");
     $p2->setLastName("Bale");
     $p2->setTestId($this->id);
     $p3->setFirstName("Scarlett");
     $p3->setLastName("Johansson");
     $p3->setTestId($this->id);
     $p4->setFirstName("Liam");
     $p4->setLastName("Neeson");
     $p4->setTestId($this->id);
     $p5->setFirstName("Ellen");
     $p5->setLastName("Page");
     $p5->setTestId($this->id);
     $nodes = array($p1, $p2, $p3, $p4, $p5);
     $year = 1990;
     //Create 20 relations
     $test_rels = array();
     for ($i = 0; $i < 5; $i++) {
         $test_rels[$i] = array();
         for ($j = 0; $j < 5; $j++) {
             if ($j != $i) {
                 $test_rels[$i][$j] = new FriendsWith();
                 $test_rels[$i][$j]->setSince($year++);
                 $test_rels[$i][$j]->setFrom($nodes[$i]);
                 $test_rels[$i][$j]->setTo($nodes[$j]);
                 self::$arachnid->persist($test_rels[$i][$j]);
             }
         }
     }
     self::$arachnid->flush();
 }
コード例 #5
0
ファイル: ProxyTest.php プロジェクト: lrezek/arachnid
 function testTypedAndArrayParameters()
 {
     $rel = new RelationDifferentMethodTypes();
     $u1 = new User();
     $u2 = new User();
     $u1->setFirstName('Lukas');
     $u1->setTestId($this->id);
     $u2->setFirstName('Bruce');
     $u2->setTestId($this->id);
     $rel->set_from($u1);
     $rel->set_to(array($u2, 3));
     self::$arachnid->persist($rel);
     self::$arachnid->flush();
     $u1_proxy = self::$arachnid->reload($u1);
     $u2_proxy = self::$arachnid->reload($u2);
     $rel_proxy = self::$arachnid->reload($rel);
     //I now have 3 proxies.
     //Assert that everything is as expected coming back
     $this->assertEquals('Bruce', $u2_proxy->getFirstName());
     $this->assertEquals('Lukas', $u1_proxy->getFirstName());
     $this->assertEquals(3, $rel_proxy->getExtra());
     //Pass an unmatching node to the start
     $person = new Person();
     try {
         $rel_proxy->set_from($person);
         $this->fail();
     } catch (\Exception $e) {
         //Not an exception we threw, All good
         $this->assertFalse($e instanceof Exception);
     }
     //Pass a non-array value to the proxy
     try {
         $rel_proxy->set_to($u2);
         $this->fail();
     } catch (\Exception $e) {
         //Not an exception we threw, All good
         $this->assertFalse($e instanceof Exception);
     }
 }