6
6
use Illuminate \Database \Connection ;
7
7
use Illuminate \Events \Dispatcher ;
8
8
use Illuminate \Support \Arr ;
9
+ use Illuminate \Support \Carbon ;
9
10
use PDO ;
10
11
use PHPUnit \Framework \TestCase ;
11
12
12
13
class QueryDurationThresholdTest extends TestCase
13
14
{
15
+ /**
16
+ * @var \Illuminate\Support\Carbon
17
+ */
18
+ protected $ now ;
19
+
14
20
public function testItCanHandleReachingADurationThresholdInTheDb ()
15
21
{
16
22
$ connection = new Connection (new PDO ('sqlite::memory: ' ));
@@ -46,10 +52,12 @@ public function testItIsOnlyCalledOnce()
46
52
47
53
public function testItIsOnlyCalledOnceWhenGivenDateTime ()
48
54
{
55
+ Carbon::setTestNow ($ this ->now = Carbon::create (2017 , 6 , 27 , 13 , 14 , 15 , 'UTC ' ));
56
+
49
57
$ connection = new Connection (new PDO ('sqlite::memory: ' ));
50
58
$ connection ->setEventDispatcher (new Dispatcher ());
51
59
$ called = 0 ;
52
- $ connection ->whenQueryingForLongerThan (now () ->addMilliseconds (1 ), function () use (&$ called ) {
60
+ $ connection ->whenQueryingForLongerThan ($ this -> now ->addMilliseconds (1 ), function () use (&$ called ) {
53
61
$ called ++;
54
62
});
55
63
@@ -58,6 +66,8 @@ public function testItIsOnlyCalledOnceWhenGivenDateTime()
58
66
$ connection ->logQuery ('xxxx ' , [], 1 );
59
67
60
68
$ this ->assertSame (1 , $ called );
69
+
70
+ Carbon::setTestNow (null );
61
71
}
62
72
63
73
public function testItCanSpecifyMultipleHandlersWithTheSameIntervals ()
0 commit comments