aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-11-17 18:15:30 +0100
committerWilly Micieli <micieli@laposte.net>2019-11-17 18:15:30 +0100
commitab045c8d24450a730868a523dfd56ebe3f83c57b (patch)
tree98a9bdb0475dcaab21d0e69d69e85cba8e0b5d1c
parentda0d926dd746abe22a4ea022e96b7365045f2ba8 (diff)
downloadimperium-develop.zip
imperium-develop.tar.gz
clean modelsdevelop
-rw-r--r--imperium/Html/Form/Form.php2
-rw-r--r--imperium/Model/Model.php25
-rw-r--r--imperium/Query/Query.php5
-rw-r--r--tests/Model/ModelTest.php19
4 files changed, 47 insertions, 4 deletions
diff --git a/imperium/Html/Form/Form.php b/imperium/Html/Form/Form.php
index 327dbad..c05973a 100644
--- a/imperium/Html/Form/Form.php
+++ b/imperium/Html/Form/Form.php
@@ -292,7 +292,7 @@ namespace Imperium\Html\Form {
$this->add($column,'textarea',['placeholder' => $column,'rows'=> 10,'required'=>'required']);
elseif(has($type,App::DATE_TYPES))
$this->add($column,'datetime',['value'=> date("Y-m-d H:i:s")]);
-
+
}
return $this->get(config('form','create_text'));
}
diff --git a/imperium/Model/Model.php b/imperium/Model/Model.php
index b38966d..3c63b06 100644
--- a/imperium/Model/Model.php
+++ b/imperium/Model/Model.php
@@ -199,7 +199,7 @@
* @throws NotFoundException
*
*/
- public static function seed(int $records): bool
+ public static function seed(int $records = 200): bool
{
$table = static::query()->table();
@@ -539,6 +539,29 @@
return static::query()->find($id);
}
+
+ /**
+ *
+ * Find a record or fail
+ *
+ * @param int $id
+ *
+ * @return object
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
+ public static function find_or_fail(int $id): object
+ {
+ $x = self::find($id);
+
+ is_false(def($x),true,"The record with $id id was not found in the table");
+
+ return $x;
+ }
+
/**
*
* Use a different where clause
diff --git a/imperium/Query/Query.php b/imperium/Query/Query.php
index 2994c2b..0af872d 100644
--- a/imperium/Query/Query.php
+++ b/imperium/Query/Query.php
@@ -405,10 +405,11 @@
*/
public function find(int $id)
{
-
return $this->where($this->key(), EQUAL, $id)->fetch(true)->all();
}
-
+
+
+
/**
*
* Get values was different of expected
diff --git a/tests/Model/ModelTest.php b/tests/Model/ModelTest.php
index 66b5cbc..243f15d 100644
--- a/tests/Model/ModelTest.php
+++ b/tests/Model/ModelTest.php
@@ -4,6 +4,7 @@ namespace Testing\Model;
use DI\DependencyException;
use DI\NotFoundException;
+use http\Client\Curl\User;
use Imperium\Dump\Dump;
use Imperium\Exception\Kedavra;
use Imperium\Import\Import;
@@ -47,6 +48,24 @@ class ModelTest extends Unit
$this->assertNotEmpty(Users::between(10,50)->paginate([$this,'records'],1,10));
}
+
+ public function test_seed()
+ {
+ $this->assertTrue(Users::seed());
+ }
+
+
+ public function test_update()
+ {
+ $this->assertTrue(Users::update(200,obj(Users::find_or_fail(200))));
+ }
+
+ public function test_update_exec()
+ {
+ $this->expectException(Kedavra::class);
+ Users::find_or_fail(20);
+
+ }
/**
* @throws Kedavra