phpstan
This commit is contained in:
@@ -16,11 +16,17 @@ use Domframework\Dbjson;
|
||||
*/
|
||||
class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $DBFILE;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->DBFILE = "/tmp/dbjson-" . time();
|
||||
}
|
||||
|
||||
public function testInsertOne1()
|
||||
{
|
||||
// Document #0
|
||||
define("dbfile", "/tmp/dbjson-" . time());
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->insertOne(
|
||||
"collection",
|
||||
["key1" => "val1", "key2" => "val2"]
|
||||
@@ -31,7 +37,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
public function testInsertOne2()
|
||||
{
|
||||
// Document #1
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->insertOne(
|
||||
"collection",
|
||||
["key1" => "val1", "key2" => "val2"]
|
||||
@@ -43,7 +49,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://" . $this->DBFILE);
|
||||
$res = $dbjson->insertMany(
|
||||
"collection",
|
||||
["key1" => "val1", "key2" => "val2"]
|
||||
@@ -53,7 +59,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
public function testInsertMany2()
|
||||
{
|
||||
// Document #2 and #3
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->insertMany(
|
||||
"collection",
|
||||
[["key1" => "val3", "key2" => "val2"],
|
||||
@@ -65,21 +71,21 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFilter1()
|
||||
{
|
||||
// Return all the keys (filter = array ())
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->filter("collection", []);
|
||||
$this->assertSame(array_keys($res), [0,1,2,3]);
|
||||
}
|
||||
public function testFilter2()
|
||||
{
|
||||
// Return the keys where filter = array ("key2"=>"val2"))
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->filter("collection", ["key2" => "val2"]);
|
||||
$this->assertSame(array_keys($res), [0,1,2]);
|
||||
}
|
||||
public function testFilter3()
|
||||
{
|
||||
// Return the keys where filter = array ("key1"=>"val3","key2"=>"val2"))
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->filter("collection", ["key1" => "val3",
|
||||
"key2" => "val2"]);
|
||||
$this->assertSame(count($res), 1);
|
||||
@@ -88,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://" . $this->DBFILE);
|
||||
$res = $dbjson->filter("collection", ["key1" => ["val3", "=="],
|
||||
"key2" => ["val2", "=="]]);
|
||||
$this->assertSame(count($res), 1);
|
||||
@@ -97,7 +103,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://" . $this->DBFILE);
|
||||
$res = $dbjson->filter("collection", ["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", "=="]]);
|
||||
$this->assertSame(array_keys($res), [0,1,2]);
|
||||
@@ -106,7 +112,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://" . $this->DBFILE);
|
||||
$res = $dbjson->filter("collection", ["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", ">"]]);
|
||||
$this->assertSame(count($res), 1);
|
||||
@@ -114,7 +120,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFind1()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find("collection", ["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", ">"]]);
|
||||
$res = array_values($res);
|
||||
@@ -125,7 +131,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind2()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -142,7 +148,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Exception : fields not an array
|
||||
$this->setExpectedException("Exception");
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -152,7 +158,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind4()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -166,7 +172,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind5()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -181,7 +187,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind6()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -202,7 +208,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind7()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -220,7 +226,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind8()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -236,7 +242,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testDeleteOne1()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->deleteOne(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -247,7 +253,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind9()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -264,7 +270,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testDeleteMany1()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->deleteMany(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -275,7 +281,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind10()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
["key1" => ["val3", "<="],
|
||||
@@ -290,7 +296,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFind11()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
@@ -299,13 +305,13 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testReplace1()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->replace("collection", [], ["key2" => "val5"]);
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
public function testFind12()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
@@ -314,14 +320,14 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testUpdate1()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->update("collection", [], ["key2" => "val6",
|
||||
"key5" => "val5"]);
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
public function testFind13()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
@@ -331,7 +337,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
public function testInsertOne3()
|
||||
{
|
||||
// Document #4
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->insertOne(
|
||||
"collection",
|
||||
["key1" => "val1", "key2" => "val2"]
|
||||
@@ -340,7 +346,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind14()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
@@ -353,14 +359,14 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testUpdate2()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->update("collection", [], ["key2" => "val7",
|
||||
"key5" => "val8"]);
|
||||
$this->assertSame($res, 2);
|
||||
}
|
||||
public function testFind15()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
@@ -374,7 +380,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testUpdate3()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = $dbjson->update(
|
||||
"collection",
|
||||
[],
|
||||
@@ -386,7 +392,7 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testFind16()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
@@ -399,8 +405,8 @@ class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
// Concurrency tests
|
||||
public function testConcurrency1()
|
||||
{
|
||||
$dbjson1 = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson2 = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson1 = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$dbjson2 = new Dbjson("dbjson://" . $this->DBFILE);
|
||||
$dbjson1->insertOne(
|
||||
"collection",
|
||||
["key1" => "val1", "key2" => "val2"]
|
||||
|
||||
Reference in New Issue
Block a user