Browse Source

Add created field to Tags table, and check for correct types on BTM

Walther Lalk 9 years ago
parent
commit
b158e59b2c
2 changed files with 14 additions and 8 deletions
  1. 4 3
      tests/Fixture/TagsFixture.php
  2. 10 5
      tests/TestCase/ORM/QueryTest.php

+ 4 - 3
tests/Fixture/TagsFixture.php

@@ -32,6 +32,7 @@ class TagsFixture extends TestFixture
         'id' => ['type' => 'integer', 'null' => false],
         'name' => ['type' => 'string', 'null' => false],
         'description' => ['type' => 'text', 'length' => Table::LENGTH_MEDIUM],
+        'created' => ['type' => 'datetime', 'null' => true, 'default' => null],
         '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
     ];
 
@@ -41,8 +42,8 @@ class TagsFixture extends TestFixture
      * @var array
      */
     public $records = [
-        ['name' => 'tag1', 'description' => 'A big description'],
-        ['name' => 'tag2', 'description' => 'Another big description'],
-        ['name' => 'tag3', 'description' => 'Yet another one']
+        ['name' => 'tag1', 'description' => 'A big description', 'created' => '2016-01-01 00:00'],
+        ['name' => 'tag2', 'description' => 'Another big description', 'created' => '2016-01-01 00:00'],
+        ['name' => 'tag3', 'description' => 'Yet another one', 'created' => '2016-01-01 00:00']
     ];
 }

+ 10 - 5
tests/TestCase/ORM/QueryTest.php

@@ -1269,16 +1269,20 @@ class QueryTest extends TestCase
             'name' => 'tag1',
             '_joinData' => ['article_id' => 1, 'tag_id' => 1],
             'description' => 'A big description',
+            'created' => new Time('2016-01-01 00:00'),
         ];
         $this->assertEquals($expected, $first->tags[0]->toArray());
+        $this->assertInstanceOf(Time::class, $first->tags[0]->created);
 
         $expected = [
             'id' => 2,
             'name' => 'tag2',
             '_joinData' => ['article_id' => 1, 'tag_id' => 2],
-            'description' => 'Another big description'
+            'description' => 'Another big description',
+            'created' => new Time('2016-01-01 00:00'),
         ];
         $this->assertEquals($expected, $first->tags[1]->toArray());
+        $this->assertInstanceOf(Time::class, $first->tags[1]->created);
     }
 
     /**
@@ -1303,7 +1307,6 @@ class QueryTest extends TestCase
                 });
             }, 'Model.beforeFind');
 
-
         $query = new Query($this->connection, $table);
 
         $results = $query
@@ -1322,18 +1325,20 @@ class QueryTest extends TestCase
             'name' => 'tag1',
             '_joinData' => ['article_id' => 1, 'tag_id' => 1],
             'description' => 'A big description',
+            'created' => new Time('2016-01-01 00:00'),
         ];
         $this->assertEquals($expected, $first->tags[0]->toArray());
-        $this->assertSame(1, $first->tags[0]->id);
+        $this->assertInstanceOf(Time::class, $first->tags[0]->created);
 
         $expected = [
             'id' => 2,
             'name' => 'tag2',
             '_joinData' => ['article_id' => 1, 'tag_id' => 2],
-            'description' => 'Another big description'
+            'description' => 'Another big description',
+            'created' => new Time('2016-01-01 00:00'),
         ];
         $this->assertEquals($expected, $first->tags[1]->toArray());
-        $this->assertSame(2, $first->tags[1]->id);
+        $this->assertInstanceOf(Time::class, $first->tags[0]->created);
     }
 
     /**