2
2
3
3
namespace MongoDB \Laravel \Tests \Eloquent ;
4
4
5
+ use Illuminate \Support \Facades \DB ;
5
6
use MongoDB \Laravel \Eloquent \Model ;
6
7
use MongoDB \Laravel \Tests \TestCase ;
7
8
9
+ use function count ;
10
+
8
11
/** Copied from {@see \Illuminate\Tests\Integration\Database\EloquentWithCountTest\EloquentWithCountTest} */
9
12
class EloquentWithCountTest extends TestCase
10
13
{
@@ -37,6 +40,7 @@ public function testItBasic()
37
40
38
41
public function testWithMultipleResults ()
39
42
{
43
+ $ connection = DB ::connection ('mongodb ' );
40
44
$ ones = [
41
45
EloquentWithCountModel1::create (['id ' => 1 ]),
42
46
EloquentWithCountModel1::create (['id ' => 2 ]),
@@ -50,6 +54,7 @@ public function testWithMultipleResults()
50
54
$ ones [2 ]->twos ()->create (['value ' => 1 ]);
51
55
$ ones [2 ]->twos ()->create (['value ' => 2 ]);
52
56
57
+ $ connection ->enableQueryLog ();
53
58
$ results = EloquentWithCountModel1::withCount ([
54
59
'twos ' => function ($ query ) {
55
60
$ query ->where ('value ' , '>= ' , 2 );
@@ -61,6 +66,9 @@ public function testWithMultipleResults()
61
66
['id ' => 2 , 'twos_count ' => 0 ],
62
67
['id ' => 3 , 'twos_count ' => 1 ],
63
68
], $ results ->get ()->toArray ());
69
+
70
+ $ connection ->disableQueryLog ();
71
+ $ this ->assertEquals (2 , count ($ connection ->getQueryLog ()));
64
72
}
65
73
66
74
public function testGlobalScopes ()
0 commit comments