Skip to content

Commit

Permalink
Continue testing
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Feb 12, 2024
1 parent 8a46ae0 commit 68f12c4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
6 changes: 6 additions & 0 deletions lib/GaletteAuto/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ public function store(bool $new = false): bool
$insert = $this->zdb->insert(AUTO_PREFIX . self::TABLE);
$insert->values($values);
$this->zdb->execute($insert);
/** @phpstan-ignore-next-line */
$this->id = (int)$this->zdb->driver->getLastGeneratedValue(
$this->zdb->isPostgres() ?
PREFIX_DB . self::TABLE . '_id_seq'
: null
);
} else {
$update = $this->zdb->update(AUTO_PREFIX . self::TABLE);
$update->set($values)->where(
Expand Down
51 changes: 37 additions & 14 deletions tests/GaletteAuto/tests/units/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,46 @@ public function testCrud(): void
$this->assertCount(1, $models->getList($first_brand_id));
$this->assertCount(0, $models->getList($second_brand_id));

/*$this->assertCount(2, $brand->getList());
$this->assertSame('2 brands', $brand->displayCount());
$model = new \GaletteAuto\Model($this->zdb);
$data = [
'model' => 'A',
'brand' => $first_brand_id,
];
$this->assertTrue($model->check($data));
$this->assertTrue($model->store(true));
$id_model = $model->id;

$brand = new \GaletteAuto\Brand($this->zdb);
$this->assertTrue($brand->load($id));
$brand->value = 'Mercedes';
$this->assertTrue($brand->store());
$this->assertCount(2, $models->getList());

$this->assertCount(2, $brand->getList());
$this->assertSame('2 brands', $brand->displayCount());
$data = [
'model' => 'A5',
'brand' => $first_brand_id
];
$this->assertTrue($model->check($data));
$this->assertTrue($model->store());

$brand = new \GaletteAuto\Brand($this->zdb);
$this->assertTrue($brand->delete([$first_id]));
$list = $brand->getList();
$this->assertCount(1, $list);
$last_brand = $list[0];
$this->assertSame($id, $last_brand->id_brand);*/
$this->assertCount(2, $models->getList());
$this->assertCount(2, $models->getList($first_brand_id));
$this->assertCount(0, $models->getList($second_brand_id));

$model = new \GaletteAuto\Model($this->zdb);
$data = [
'model' => 'Class S',
'brand' => $second_brand_id,
];
$this->assertTrue($model->check($data));
$this->assertTrue($model->store(true));

$this->assertCount(3, $models->getList());
$this->assertCount(2, $models->getList($first_brand_id));
$this->assertCount(1, $models->getList($second_brand_id));

$model = new \GaletteAuto\Model($this->zdb);
$this->assertTrue($model->delete([$id_model]));

$this->assertCount(2, $models->getList());
$this->assertCount(1, $models->getList($first_brand_id));
$this->assertCount(1, $models->getList($second_brand_id));
}

/**
Expand Down

0 comments on commit 68f12c4

Please sign in to comment.