Passage en Namespace et tous les tests fonctionnels OK
This commit is contained in:
@@ -7,14 +7,16 @@
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
/** Test the dbjson database */
|
||||
class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
use Domframework\Dbjson;
|
||||
|
||||
/** Test the Dbjson database */
|
||||
class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_insertOne1 ()
|
||||
{
|
||||
// Document #0
|
||||
define ("dbfile", "/tmp/dbjson-".time());
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->insertOne ("collection",
|
||||
array ("key1"=>"val1", "key2"=>"val2"));
|
||||
$this->assertSame ($res, 1);
|
||||
@@ -23,7 +25,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
public function test_insertOne2 ()
|
||||
{
|
||||
// Document #1
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->insertOne ("collection",
|
||||
array ("key1"=>"val1", "key2"=>"val2"));
|
||||
$this->assertSame ($res, 1);
|
||||
@@ -33,7 +35,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Error : Invalid array provided (not array of array)
|
||||
$this->setExpectedException ("Exception");
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->insertMany ("collection",
|
||||
array ("key1"=>"val1", "key2"=>"val2"));
|
||||
}
|
||||
@@ -41,7 +43,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
public function test_insertMany2 ()
|
||||
{
|
||||
// Document #2 and #3
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->insertMany ("collection",
|
||||
array (array ("key1"=>"val3", "key2"=>"val2"),
|
||||
array ("key1"=>"val3", "key2"=>"val4")));
|
||||
@@ -51,21 +53,21 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
public function test_filter1 ()
|
||||
{
|
||||
// Return all the keys (filter = array ())
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->filter ("collection", array ());
|
||||
$this->assertSame (array_keys ($res), array (0,1,2,3));
|
||||
}
|
||||
public function test_filter2 ()
|
||||
{
|
||||
// Return the keys where filter = array ("key2"=>"val2"))
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->filter ("collection", array ("key2"=>"val2"));
|
||||
$this->assertSame (array_keys ($res), array (0,1,2));
|
||||
}
|
||||
public function test_filter3 ()
|
||||
{
|
||||
// Return the keys where filter = array ("key1"=>"val3","key2"=>"val2"))
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->filter ("collection", array ("key1"=>"val3",
|
||||
"key2"=>"val2"));
|
||||
$this->assertSame (count ($res), 1);
|
||||
@@ -74,7 +76,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Return the keys where filter = array ("key1"=>array ("val3", "=="),
|
||||
// "key2"=>array ("val2", "=="))
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->filter ("collection",array ("key1"=>array ("val3", "=="),
|
||||
"key2"=>array ("val2", "==")));
|
||||
$this->assertSame (count ($res), 1);
|
||||
@@ -83,7 +85,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Return the keys where filter = array ("key1"=>array ("val3", "<="),
|
||||
// "key2"=>array ("val2", "=="))
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->filter ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", "==")));
|
||||
$this->assertSame (array_keys ($res), array (0,1,2));
|
||||
@@ -92,7 +94,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Return the keys where filter = array ("key1"=>array ("val3", "<="),
|
||||
// "key2"=>array ("val2", ">"))
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->filter ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", ">")));
|
||||
$this->assertSame (count ($res), 1);
|
||||
@@ -100,7 +102,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_find1 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", ">")));
|
||||
$res = array_values ($res);
|
||||
@@ -111,7 +113,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function test_find2 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", ">")),
|
||||
"*");
|
||||
@@ -125,14 +127,14 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Exception : fields not an array
|
||||
$this->setExpectedException ("Exception");
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", ">")),
|
||||
"key1");
|
||||
}
|
||||
public function test_find4 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", ">")),
|
||||
array ("key1"));
|
||||
@@ -143,7 +145,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function test_find5 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", ">")),
|
||||
array ("key1", "key2"));
|
||||
@@ -155,7 +157,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function test_find6 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", "==")),
|
||||
array ("key1", "key2"));
|
||||
@@ -173,7 +175,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function test_find7 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", "==")),
|
||||
array ("key2"));
|
||||
@@ -188,7 +190,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function test_find8 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", "==")),
|
||||
array ("key2"), 1);
|
||||
@@ -200,7 +202,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_deleteOne1 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->deleteOne ("collection",
|
||||
array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", "==")));
|
||||
@@ -208,7 +210,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function test_find9 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", "==")),
|
||||
array ("key2"));
|
||||
@@ -222,7 +224,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_deleteMany1 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->deleteMany ("collection",
|
||||
array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", "==")));
|
||||
@@ -230,7 +232,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function test_find10 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->find ("collection", array ("key1"=>array ("val3", "<="),
|
||||
"key2"=>array ("val2", "==")),
|
||||
array ("key2"));
|
||||
@@ -242,7 +244,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_find11 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = array_values ($dbjson->find ("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset ($res[0]["_id"]);
|
||||
@@ -251,13 +253,13 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_replace1 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->replace ("collection", array (), array ("key2"=>"val5"));
|
||||
$this->assertSame ($res, 1);
|
||||
}
|
||||
public function test_find12 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = array_values ($dbjson->find ("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset ($res[0]["_id"]);
|
||||
@@ -266,14 +268,14 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_update1 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->update ("collection", array (), array ("key2"=>"val6",
|
||||
"key5"=>"val5"));
|
||||
$this->assertSame ($res, 1);
|
||||
}
|
||||
public function test_find13 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = array_values ($dbjson->find ("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset ($res[0]["_id"]);
|
||||
@@ -283,14 +285,14 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
public function test_insertOne3 ()
|
||||
{
|
||||
// Document #4
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->insertOne ("collection",
|
||||
array ("key1"=>"val1", "key2"=>"val2"));
|
||||
$this->assertSame ($res, 1);
|
||||
}
|
||||
public function test_find14 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = array_values ($dbjson->find ("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset ($res[0]["_id"]);
|
||||
@@ -303,14 +305,14 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_update2 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->update ("collection", array (), array ("key2"=>"val7",
|
||||
"key5"=>"val8"));
|
||||
$this->assertSame ($res, 2);
|
||||
}
|
||||
public function test_find15 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = array_values ($dbjson->find ("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset ($res[0]["_id"]);
|
||||
@@ -324,7 +326,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_update3 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = $dbjson->update ("collection", array (),
|
||||
array ("key2"=>"val9",
|
||||
"key5"=>"val7",
|
||||
@@ -333,7 +335,7 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function test_find16 ()
|
||||
{
|
||||
$dbjson = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson = new Dbjson ("dbjson://".dbfile);
|
||||
$res = array_values ($dbjson->find ("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset ($res[0]["_id"]);
|
||||
@@ -346,8 +348,8 @@ class dbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
// Concurrency tests
|
||||
public function test_concurrency1 ()
|
||||
{
|
||||
$dbjson1 = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson2 = new dbjson ("dbjson://".dbfile);
|
||||
$dbjson1 = new Dbjson ("dbjson://".dbfile);
|
||||
$dbjson2 = new Dbjson ("dbjson://".dbfile);
|
||||
$dbjson1->insertOne ("collection",
|
||||
array ("key1"=>"val1", "key2"=>"val2"));
|
||||
$res = array_values ($dbjson2->find ("collection"));
|
||||
|
||||
Reference in New Issue
Block a user