ajout retour en collection, modification des tests en conséquences

This commit is contained in:
Gregory Letellier
2023-10-31 10:47:11 +01:00
parent 42d3d38a0a
commit fe6d2f27b8
2 changed files with 18 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
<?php
use Kletellier\PdoWrapper\Collection;
use Kletellier\PdoWrapper\Db;
use Kletellier\PdoWrapper\EventDispatcher;
use Kletellier\PdoWrapper\Model;
@@ -45,23 +46,23 @@ test("querybuilder", function() {
$qb->reset();
$rows = $qb->where("id",1)->columns("*")->get();
expect($rows)->toBeArray();
expect($rows)->toBeInstanceOf(Collection::class);
expect(count($rows))->toBe(1);
$qb->reset();
$rows = $qb->where("id",">",2)->columns("*")->get();
expect($rows)->toBeArray();
expect($rows)->toBeInstanceOf(Collection::class);
expect(count($rows))->toBe(0);
$qb->reset();
$rows = $qb->whereRaw("id = 1")->columns("*")->get();
expect($rows)->toBeArray();
expect($rows)->toBeInstanceOf(Collection::class);
expect(count($rows))->toBe(1);
$qb->reset();
$rows = $qb->whereRaw("id = 1")->get();
expect($rows)->toBeArray();
expect($rows)->toBeInstanceOf(Collection::class);
expect(count($rows))->toBe(1);
});
@@ -69,25 +70,25 @@ test("order by", function(){
$qb = new QueryBuilder("test");
$rows = $qb->orderBy("id","DESC")->get();
expect($rows)->toBeArray();
expect($rows)->toBeInstanceOf(Collection::class);
expect(count($rows))->toBe(2);
expect($rows[0]->col1)->toBe("test2");
expect($rows->first()->col1)->toBe("test2");
});
test("group by", function(){
$qb = new QueryBuilder("test");
$rows = $qb->columns("COUNT(*) as Nb")->get();
expect($rows)->toBeArray();
expect($rows)->toBeInstanceOf(Collection::class);
expect(count($rows))->toBe(1);
expect($rows[0]->Nb)->toBe(2);
expect($rows->first()->Nb)->toBe(2);
$qb->reset();
$rows = $qb->columns("COUNT(*) as Nb")->groupBy("id")->get();
expect($rows)->toBeArray();
expect($rows)->toBeInstanceOf(Collection::class);
expect(count($rows))->toBe(2);
expect($rows[0]->Nb)->toBe(1);
expect($rows->first()->Nb)->toBe(1);
});
test("update row", function() {
@@ -99,9 +100,9 @@ test("update row", function() {
$qb->reset();
$rows = $qb->where("id",1)->columns("*")->get();
expect($rows)->toBeArray();
expect($rows)->toBeInstanceOf(Collection::class);
expect(count($rows))->toBe(1);
expect($rows[0]->col1)->toBe("testupdate");
expect($rows->first()->col1)->toBe("testupdate");
});
test("event", function() {
@@ -134,12 +135,12 @@ test("where array", function() {
$between = $qb->whereBetween("id",2,3)->get();
expect(count($between))->toBe(2);
expect($between[0]->id)->toBe(2);
expect($between->first()->id)->toBe(2);
$qb->reset();
$in = $qb->whereIn("id",[2,3])->get();
expect(count($in))->toBe(2);
expect($in[0]->id)->toBe(2);
expect($in->first()->id)->toBe(2);
});
@@ -164,6 +165,6 @@ test("second connection", function() {
$qb = new QueryBuilder("test","id","contwo");
$rows = $qb->get();
expect($rows)->toBeArray();
expect($rows)->toBeInstanceOf(Collection::class);
expect(count($rows))->toBe(2);
});