Skip to content

Commit 3a7419f

Browse files
committed
Merge branch 'fix-duplicate-limit' into 3.0
* fix-duplicate-limit: Add a unit test for the double limit fix in PrettyDataCollector.php Test the limitNum key when appending the limit
2 parents 7aef657 + 146aba8 commit 3a7419f

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

DataCollector/PrettyDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function collect(Request $request, Response $response, \Exception $except
110110
$query .= ')';
111111
} elseif (isset($log['skip'])) {
112112
$query .= '.skip('.$log['skipNum'].')';
113-
} elseif (isset($log['limit'])) {
113+
} elseif (isset($log['limit']) && isset($log['limitNum'])) {
114114
$query .= '.limit('.$log['limitNum'].')';
115115
} elseif (isset($log['createCollection'])) {
116116
$query .= '.createCollection()';

Tests/DataCollector/PrettyDataCollectorTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,78 @@ public function getQueries()
5050
)
5151
);
5252
}
53+
54+
public function testCollectLimit()
55+
{
56+
$queries = array(
57+
array(
58+
'find' => true,
59+
'query' => array(
60+
'path' => '/',
61+
),
62+
'fields' => array(),
63+
'db' => 'foo',
64+
'collection' => 'Route',
65+
),
66+
array(
67+
'find' => true,
68+
'query' => array('_id' => 'foo'),
69+
'fields' => array(),
70+
'db' => 'foo',
71+
'collection' => 'User',
72+
),
73+
array(
74+
'limit' => true,
75+
'limitNum' => 1,
76+
'query' => array('_id' => 'foo'),
77+
'fields' => array(),
78+
),
79+
array(
80+
'limit' => true,
81+
'limitNum' => NULL,
82+
'query' => array('_id' => 'foo'),
83+
'fields' => array(),
84+
),
85+
array(
86+
'find' => true,
87+
'query' => array(
88+
'_id' => '5506fa1580c7e1ee3c8b4c60',
89+
),
90+
'fields' => array(),
91+
'db' => 'foo',
92+
'collection' => 'Group',
93+
),
94+
array(
95+
'limit' => true,
96+
'limitNum' => 1,
97+
'query' => array(
98+
'_id' => '5506fa1580c7e1ee3c8b4c60',
99+
),
100+
'fields' => array(),
101+
),
102+
array(
103+
'limit' => true,
104+
'limitNum' => NULL,
105+
'query' => array(
106+
'_id' => '5506fa1580c7e1ee3c8b4c60',
107+
),
108+
'fields' => array(),
109+
),
110+
);
111+
$formatted = array(
112+
'use foo;',
113+
'db.Route.find({ "path": "/" });',
114+
'db.User.find({ "_id": "foo" }).limit(1);',
115+
'db.Group.find({ "_id": "5506fa1580c7e1ee3c8b4c60" }).limit(1);'
116+
);
117+
118+
$collector = new PrettyDataCollector();
119+
foreach ($queries as $query) {
120+
$collector->logQuery($query);
121+
}
122+
$collector->collect(new Request(), new Response());
123+
124+
$this->assertEquals(3, $collector->getQueryCount());
125+
$this->assertEquals($formatted, $collector->getQueries());
126+
}
53127
}

0 commit comments

Comments
 (0)