OSDN Git Service

Изменён тест модели типов. Добавлен тест модели состояний.
authorDmitry Dobryshin <dimkainc@mail.ru>
Tue, 24 Nov 2020 05:06:29 +0000 (08:06 +0300)
committerDmitry Dobryshin <dimkainc@mail.ru>
Tue, 24 Nov 2020 05:06:29 +0000 (08:06 +0300)
tests/unit/models/StatusTest.php [new file with mode: 0644]
tests/unit/models/TypesTest.php

diff --git a/tests/unit/models/StatusTest.php b/tests/unit/models/StatusTest.php
new file mode 100644 (file)
index 0000000..019a94b
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+
+namespace tests\unit\models;
+
+use app\models\Status;
+
+class StatusTest extends \Codeception\Test\Unit
+{
+    private $model;
+    /**
+     * @var \UnitTester
+     */
+    protected $tester;
+
+    protected function _before()
+    {
+
+    }
+
+    protected function _after()
+    {
+    }
+
+    // tests
+    public function testEnterNull()
+    {
+        $this->model = new Status();
+    
+        // Пустое значение недопустимо
+        $this->model->name = NULL;
+        $this->assertFalse($this->model->validate([ 'name' ]));
+    }
+
+    public function testEnterLong()
+    {
+        $this->model = new Status();
+
+        // Больше 100 символов недопустимо
+        $this->model->name = '**** aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrsssss ****';
+        $this->assertFalse($this->model->validate([ 'name' ]));
+    }
+
+    public function testEnterData()
+    {
+        $this->model = new Status();
+
+        $validName = '--TEST STATUS--';
+        // Допустимая комбинация
+        $this->model->name = $validName;
+        $this->assertTrue($this->model->validate([ 'name' ]));
+
+        // Сохранение данных в базу
+        $this->assertTrue($this->model->save());
+        $count = count(Status::find()->where([ 'name' => $validName ])->all());
+        $this->assertGreaterThan(0, $count);
+        $this->assertEquals(1, $count);
+    }
+}
\ No newline at end of file
index e14b11d..86ea793 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace tests\unit\models;
 
-use app\models\LoginForm;
 use app\models\Types;
 
 class TypesTest extends \Codeception\Test\Unit
@@ -20,21 +19,30 @@ class TypesTest extends \Codeception\Test\Unit
 
     protected function _after()
     {
-        \Yii::$app->user->logout();
     }
 
-    // tests
-    public function testEnterType()
+    public function testEnterNull()
     {
         $this->types = new Types();
-
+    
         // Пустое значение недопустимо
         $this->types->name = NULL;
         $this->assertFalse($this->types->validate([ 'name' ]));
-
+    }
+    
+    public function testEnterLong()
+    {
+        $this->types = new Types();
+    
         // Больше 100 символов недопустимо
         $this->types->name = '**** aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrsssss ****';
         $this->assertFalse($this->types->validate([ 'name' ]));
+    }
+
+    // tests
+    public function testEnterData()
+    {
+        $this->types = new Types();
 
         $validName = '--TEST TYPE--';
         // Допустимая комбинация