@@ -46,7 +46,9 @@ public function setUp()
4646 {
4747 parent ::setUp ();
4848
49- $ this ->carbon = m::mock (Carbon::class);
49+ $ this ->carbon = new Carbon ();
50+ $ this ->carbon ->setTestNow ();
51+
5052 $ this ->keyUpdateService = m::mock (DaemonKeyUpdateService::class);
5153 $ this ->repository = m::mock (DaemonKeyRepositoryInterface::class);
5254
@@ -65,9 +67,6 @@ public function testKeyIsReturned()
6567 ['server_id ' , '= ' , $ key ->server_id ],
6668 ])->once ()->andReturn ($ key );
6769
68- $ this ->carbon ->shouldReceive ('now ' )->withNoArgs ()->once ()->andReturnSelf ();
69- $ this ->carbon ->shouldReceive ('diffInSeconds ' )->with ($ key ->expires_at , false )->once ()->andReturn (100 );
70-
7170 $ response = $ this ->service ->handle ($ key ->server_id , $ key ->user_id );
7271 $ this ->assertNotEmpty ($ response );
7372 $ this ->assertEquals ($ key ->secret , $ response );
@@ -78,16 +77,15 @@ public function testKeyIsReturned()
7877 */
7978 public function testExpiredKeyIsUpdated ()
8079 {
81- $ key = factory (DaemonKey::class)->make ();
80+ $ key = factory (DaemonKey::class)->make ([
81+ 'expires_at ' => $ this ->carbon ->subHour (),
82+ ]);
8283
8384 $ this ->repository ->shouldReceive ('findFirstWhere ' )->with ([
8485 ['user_id ' , '= ' , $ key ->user_id ],
8586 ['server_id ' , '= ' , $ key ->server_id ],
8687 ])->once ()->andReturn ($ key );
8788
88- $ this ->carbon ->shouldReceive ('now ' )->withNoArgs ()->once ()->andReturnSelf ();
89- $ this ->carbon ->shouldReceive ('diffInSeconds ' )->with ($ key ->expires_at , false )->once ()->andReturn (-100 );
90-
9189 $ this ->keyUpdateService ->shouldReceive ('handle ' )->with ($ key ->id )->once ()->andReturn (true );
9290
9391 $ response = $ this ->service ->handle ($ key ->server_id , $ key ->user_id );
@@ -100,7 +98,9 @@ public function testExpiredKeyIsUpdated()
10098 */
10199 public function testExpiredKeyIsNotUpdated ()
102100 {
103- $ key = factory (DaemonKey::class)->make ();
101+ $ key = factory (DaemonKey::class)->make ([
102+ 'expires_at ' => $ this ->carbon ->subHour (),
103+ ]);
104104
105105 $ this ->repository ->shouldReceive ('findFirstWhere ' )->with ([
106106 ['user_id ' , '= ' , $ key ->user_id ],
0 commit comments