Permalink
Browse files

Fixed paginator tests

  • Loading branch information...
1 parent d96d155 commit ea713659ddf665bdf9e909ffb59541903b1a314a @lorenzo lorenzo committed Jan 23, 2014
@@ -173,8 +173,6 @@ public function paginate($object, array $settings = []) {
if (!$numResults) {
$count = 0;
} else {
- $parameters = compact('conditions');
- $query = $object->find($type, array_merge($parameters, $extra));
$count = $query->count();
}
@@ -116,7 +116,7 @@ public function testPaginateExtraParams() {
);
$table = $this->_getMockPosts(['find']);
$query = $this->_getMockFindQuery();
- $table->expects($this->at(0))
+ $table->expects($this->once())
->method('find')
->with('all', [
'conditions' => [],
@@ -129,15 +129,6 @@ public function testPaginateExtraParams() {
])
->will($this->returnValue($query));
- $table->expects($this->at(1))
- ->method('find')
- ->with('all', [
- 'conditions' => [],
- 'contain' => ['PaginatorAuthor'],
- 'group' => 'PaginatorPosts.published',
- ])
- ->will($this->returnValue($query));
-
$this->Paginator->paginate($table, $settings);
}
@@ -180,7 +171,7 @@ public function testDefaultPaginateParams() {
$table = $this->_getMockPosts(['find']);
$query = $this->_getMockFindQuery();
- $table->expects($this->at(0))
+ $table->expects($this->once())
->method('find')
->with('all', [
'conditions' => [],
@@ -191,10 +182,6 @@ public function testDefaultPaginateParams() {
])
->will($this->returnValue($query));
- $table->expects($this->at(1))
- ->method('find')
- ->will($this->returnValue($query));
-
$this->Paginator->paginate($table, $settings);
}
@@ -351,7 +338,7 @@ public function testValidateSortInvalid() {
$table = $this->_getMockPosts(['find']);
$query = $this->_getMockFindQuery();
- $table->expects($this->at(0))
+ $table->expects($this->once())
->method('find')
->with('all', [
'fields' => null,
@@ -362,10 +349,6 @@ public function testValidateSortInvalid() {
])
->will($this->returnValue($query));
- $table->expects($this->at(1))
- ->method('find')
- ->will($this->returnValue($query));
-
$this->request->query = [
'page' => 1,
'sort' => 'id',
@@ -682,7 +665,7 @@ public function testPaginateCustomFindCount() {
);
$table = $this->_getMockPosts(['find']);
$query = $this->_getMockFindQuery();
- $table->expects($this->at(0))
+ $table->expects($this->once())
->method('find')
->with('published', [
'conditions' => [],
@@ -693,13 +676,6 @@ public function testPaginateCustomFindCount() {
])
->will($this->returnValue($query));
- $table->expects($this->at(1))
- ->method('find')
- ->with('published', [
- 'conditions' => [],
- ])
- ->will($this->returnValue($query));
-
$this->Paginator->paginate($table, $settings);
}
@@ -722,10 +698,13 @@ protected function _getMockPosts($methods = []) {
* @return Query
*/
protected function _getMockFindQuery() {
- $query = $this->getMock('Cake\ORM\Query', ['total', 'all'], [], '', false);
+ $query = $this->getMockBuilder('Cake\ORM\Query')
+ ->setMethods(['total', 'all', 'count'])
+ ->disableOriginalConstructor()
+ ->getMock();
$results = $this->getMock('Cake\ORM\ResultSet', [], [], '', false);
- $results->expects($this->any())
+ $query->expects($this->any())
->method('count')
->will($this->returnValue(2));

0 comments on commit ea71365

Please sign in to comment.