Commits

Jiří Knesl  committed d8ac8ae

Rename test of index manager

  • Participants
  • Parent commits 50c813c

Comments (0)

Files changed (2)

File tests/IndexManagerTest.php

+<?php
+
+require_once "bootstrap.php";
+// require_once "PHPUnit/Framework.php";
+
+/**
+ * Tests index based on value
+ */
+class IndexManagerTest extends PHPUnit_Framework_TestCase
+{
+	/**
+	 * @var PHPersist_Index_Value
+	 */
+	private $object;
+
+	/**
+	 * 
+	 */
+	protected function setUp()
+	{
+		$this->storage = new PHPersist_Storage(new PHPersist_Storage_File(dirname(__FILE__) . "/ValueIndexTest"), new PHPersist_IndexManager);
+	}
+
+	/**
+	 * 
+	 */
+	public function testAddIndex()
+	{
+		$this->storage->getIndexManager()->addIndex("articles", "seo", function($row) {
+			return $row->seo;
+		});
+		
+		$obja = (object)array("seo"=>"ab", "id"=>1);
+		$this->storage->save("articles", $obja->id, $obja);
+		
+		$objb = (object)array("seo"=>"ab", "id"=>2);
+		$this->storage->save("articles", $objb->id, $objb);
+		
+		$objc = (object)array("seo"=>"abc", "id"=>3);
+		$this->storage->save("articles", $objc->id, $objc);
+		
+		$result = $this->storage->getIndexManager()->loadFromIndex("articles", "seo", "ab");
+		$this->assertEquals(2, sizeof($result));
+		foreach ($result as $item)
+			$this->assertTrue(1 === $item->id || 2 === $item->id);
+	}
+	
+	/**
+	 * Test remove from index
+	 *
+	 * @return void
+	 * @author Jiří Knesl
+	 **/
+	public function testRemoveIndex()
+	{
+		$this->storage->getIndexManager()->addIndex("articles", "seo", function($row) {
+			return $row->seo;
+		});
+		
+		$obja = (object)array("seo"=>"ab", "id"=>1);
+		$this->storage->save("articles", $obja->id, $obja);
+		
+		$objb = (object)array("seo"=>"ab", "id"=>2);
+		$this->storage->save("articles", $objb->id, $objb);
+
+		$this->storage->del("articles", 1);
+		// var_dump($this->storage);
+		$result = $this->storage->getIndexManager()->loadFromIndex("articles", "seo", "ab");
+
+		$this->assertEquals(1, sizeof($result));
+		foreach ($result as $item)
+			$this->assertTrue(2 === $item->id);
+		
+	}
+
+	/**
+	 * Test regenerate index
+	 *
+	 * @return void
+	 * @author Jiří Knesl
+	 **/
+	public function testRegenerateIndex()
+	{
+		$indexFunction = function($row) {
+			return $row->seo;
+		};
+		
+		$this->storage->getIndexManager()->addIndex("articles", "seo", $indexFunction);
+		
+		$obja = (object)array("seo"=>"ab", "id"=>1);
+		$this->storage->save("articles", $obja->id, $obja);
+		
+		$objb = (object)array("seo"=>"ab", "id"=>2);
+		$this->storage->save("articles", $objb->id, $objb);
+
+		$this->storage->getIndexManager()->removeIndex("articles", "seo");
+
+		$this->storage->del("articles", 1);
+
+		$this->storage->getIndexManager()->addIndex("articles", "seo", $indexFunction);
+		$this->storage->getIndexManager()->regenerateIndex("articles", "seo");
+		
+		$result = $this->storage->getIndexManager()->loadFromIndex("articles", "seo", "ab");
+		
+		// var_dump($result);
+		
+		$this->assertEquals(1, sizeof($result));
+		foreach ($result as $item)
+			$this->assertTrue(2 === $item->id);
+	}
+}

File tests/ValueIndexTest.php

-<?php
-
-require_once "bootstrap.php";
-// require_once "PHPUnit/Framework.php";
-
-/**
- * Tests index based on value
- */
-class IndexManagerTest extends PHPUnit_Framework_TestCase
-{
-	/**
-	 * @var PHPersist_Index_Value
-	 */
-	private $object;
-
-	/**
-	 * 
-	 */
-	protected function setUp()
-	{
-		$this->storage = new PHPersist_Storage(new PHPersist_Storage_File(dirname(__FILE__) . "/ValueIndexTest"), new PHPersist_IndexManager);
-	}
-
-	/**
-	 * 
-	 */
-	public function testAddIndex()
-	{
-		$this->storage->getIndexManager()->addIndex("articles", "seo", function($row) {
-			return $row->seo;
-		});
-		
-		$obja = (object)array("seo"=>"ab", "id"=>1);
-		$this->storage->save("articles", $obja->id, $obja);
-		
-		$objb = (object)array("seo"=>"ab", "id"=>2);
-		$this->storage->save("articles", $objb->id, $objb);
-		
-		$objc = (object)array("seo"=>"abc", "id"=>3);
-		$this->storage->save("articles", $objc->id, $objc);
-		
-		$result = $this->storage->getIndexManager()->loadFromIndex("articles", "seo", "ab");
-		$this->assertEquals(2, sizeof($result));
-		foreach ($result as $item)
-			$this->assertTrue(1 === $item->id || 2 === $item->id);
-	}
-	
-	/**
-	 * Test remove from index
-	 *
-	 * @return void
-	 * @author Jiří Knesl
-	 **/
-	public function testRemoveIndex()
-	{
-		$this->storage->getIndexManager()->addIndex("articles", "seo", function($row) {
-			return $row->seo;
-		});
-		
-		$obja = (object)array("seo"=>"ab", "id"=>1);
-		$this->storage->save("articles", $obja->id, $obja);
-		
-		$objb = (object)array("seo"=>"ab", "id"=>2);
-		$this->storage->save("articles", $objb->id, $objb);
-
-		$this->storage->del("articles", 1);
-		// var_dump($this->storage);
-		$result = $this->storage->getIndexManager()->loadFromIndex("articles", "seo", "ab");
-
-		$this->assertEquals(1, sizeof($result));
-		foreach ($result as $item)
-			$this->assertTrue(2 === $item->id);
-		
-	}
-
-	/**
-	 * Test regenerate index
-	 *
-	 * @return void
-	 * @author Jiří Knesl
-	 **/
-	public function testRegenerateIndex()
-	{
-		$indexFunction = function($row) {
-			return $row->seo;
-		};
-		
-		$this->storage->getIndexManager()->addIndex("articles", "seo", $indexFunction);
-		
-		$obja = (object)array("seo"=>"ab", "id"=>1);
-		$this->storage->save("articles", $obja->id, $obja);
-		
-		$objb = (object)array("seo"=>"ab", "id"=>2);
-		$this->storage->save("articles", $objb->id, $objb);
-
-		$this->storage->getIndexManager()->removeIndex("articles", "seo");
-
-		$this->storage->del("articles", 1);
-
-		$this->storage->getIndexManager()->addIndex("articles", "seo", $indexFunction);
-		$this->storage->getIndexManager()->regenerateIndex("articles", "seo");
-		
-		$result = $this->storage->getIndexManager()->loadFromIndex("articles", "seo", "ab");
-		
-		// var_dump($result);
-		
-		$this->assertEquals(1, sizeof($result));
-		foreach ($result as $item)
-			$this->assertTrue(2 === $item->id);
-	}
-}