Skip to content

Commit

Permalink
Add created field to Tags table, and check for correct types on BTM
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Aug 15, 2016
1 parent 17f9d13 commit b158e59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 4 additions & 3 deletions tests/Fixture/TagsFixture.php
Expand Up @@ -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']]]
];

Expand All @@ -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']
];
}
15 changes: 10 additions & 5 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -1269,16 +1269,20 @@ public function testHydrateBelongsToMany()
'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);
}

/**
Expand All @@ -1303,7 +1307,6 @@ public function testFormatResultsBelongsToMany()
});
}, 'Model.beforeFind');


$query = new Query($this->connection, $table);

$results = $query
Expand All @@ -1322,18 +1325,20 @@ public function testFormatResultsBelongsToMany()
'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);
}

/**
Expand Down

0 comments on commit b158e59

Please sign in to comment.