Skip to content
Permalink
Browse files

Adding test for json type and moving another test

  • Loading branch information...
lorenzo committed Mar 19, 2016
1 parent cd5fee1 commit 20d59085f6be725deb3164265238997b269e7e86
Showing with 58 additions and 27 deletions.
  1. +58 −27 tests/TestCase/Database/QueryTest.php
@@ -3595,6 +3595,37 @@ public function testSelectTypeConversion()
$this->assertInstanceOf('DateTime', $result[0]['the_date']);
}
/**
* Tests that the json type can save and get data symetrically
*
* @return void
*/
public function testSymetricJsonType()
{
$query = new Query($this->connection);
$id = $query
->insert(['comment', 'article_id', 'user_id'], ['comment' => 'json'])
->into('comments')
->values([
'comment' => ['a' => 'b', 'c' => true],
'article_id' => 1,
'user_id' => 1
])
->execute()
->lastInsertId('id');
$query = new Query($this->connection);
$query
->select(['comment'])
->from('comments')
->where(['id' => $id])
->selectTypeMap()->types(['comment' => 'json']);
$result = $query->execute()->fetchAll('assoc')[0]['comment'];
$this->assertSame(['a' => 'b', 'c' => true], $result);
}
/**
* Test removeJoin().
*
@@ -3744,6 +3775,33 @@ public function testDeleteModifiers()
);
}
/**
* Tests that fetch returns an anonymous object when the string 'obj'
* is passed as an argument
*
* @return void
*/
public function testSelectWithObjFetchType()
{
$query = new Query($this->connection);
$result = $query
->select(['id'])
->from('comments')
->where(['id' => '1'])
->execute();
$obj = (object)['id' => 1];
$this->assertEquals($obj, $result->fetch('obj'));
$query = new Query($this->connection);
$result = $query
->select(['id'])
->from('comments')
->where(['id' => '1'])
->execute();
$rows = $result->fetchAll('obj');
$this->assertEquals($obj, $rows[0]);
}
/**
* Assertion for comparing a table's contents with what is in it.
*
@@ -3784,31 +3842,4 @@ public function assertQuotedQuery($pattern, $query, $optional = false)
$pattern = str_replace('>', '[`"\]]' . $optional, $pattern);
$this->assertRegExp('#' . $pattern . '#', $query);
}
/**
* Tests that fetch returns an anonymous object when the string 'obj'
* is passed as an argument
*
* @return void
*/
public function testSelectWithObjFetchType()
{
$query = new Query($this->connection);
$result = $query
->select(['id'])
->from('comments')
->where(['id' => '1'])
->execute();
$obj = (object)['id' => 1];
$this->assertEquals($obj, $result->fetch('obj'));
$query = new Query($this->connection);
$result = $query
->select(['id'])
->from('comments')
->where(['id' => '1'])
->execute();
$rows = $result->fetchAll('obj');
$this->assertEquals($obj, $rows[0]);
}
}

0 comments on commit 20d5908

Please sign in to comment.
You can’t perform that action at this time.