22
33namespace Illuminate \Tests \Console \Scheduling ;
44
5+ use Illuminate \Cache \ArrayStore ;
56use Illuminate \Console \Scheduling \CacheEventMutex ;
67use Illuminate \Console \Scheduling \CacheSchedulingMutex ;
78use Illuminate \Console \Scheduling \Event ;
@@ -52,13 +53,15 @@ protected function setUp(): void
5253
5354 public function testMutexReceivesCorrectCreate ()
5455 {
56+ $ this ->cacheRepository ->shouldReceive ('getStore ' )->andReturn (new \stdClass );
5557 $ this ->cacheRepository ->shouldReceive ('add ' )->once ()->with ($ this ->event ->mutexName ().$ this ->time ->format ('Hi ' ), true , 3600 )->andReturn (true );
5658
5759 $ this ->assertTrue ($ this ->cacheMutex ->create ($ this ->event , $ this ->time ));
5860 }
5961
6062 public function testCanUseCustomConnection ()
6163 {
64+ $ this ->cacheRepository ->shouldReceive ('getStore ' )->andReturn (new \stdClass );
6265 $ this ->cacheFactory ->shouldReceive ('store ' )->with ('test ' )->andReturn ($ this ->cacheRepository );
6366 $ this ->cacheRepository ->shouldReceive ('add ' )->once ()->with ($ this ->event ->mutexName ().$ this ->time ->format ('Hi ' ), true , 3600 )->andReturn (true );
6467 $ this ->cacheMutex ->useStore ('test ' );
@@ -68,22 +71,58 @@ public function testCanUseCustomConnection()
6871
6972 public function testPreventsMultipleRuns ()
7073 {
74+ $ this ->cacheRepository ->shouldReceive ('getStore ' )->andReturn (new \stdClass );
7175 $ this ->cacheRepository ->shouldReceive ('add ' )->once ()->with ($ this ->event ->mutexName ().$ this ->time ->format ('Hi ' ), true , 3600 )->andReturn (false );
7276
7377 $ this ->assertFalse ($ this ->cacheMutex ->create ($ this ->event , $ this ->time ));
7478 }
7579
7680 public function testChecksForNonRunSchedule ()
7781 {
82+ $ this ->cacheRepository ->shouldReceive ('getStore ' )->andReturn (new \stdClass );
7883 $ this ->cacheRepository ->shouldReceive ('has ' )->once ()->with ($ this ->event ->mutexName ().$ this ->time ->format ('Hi ' ))->andReturn (false );
7984
8085 $ this ->assertFalse ($ this ->cacheMutex ->exists ($ this ->event , $ this ->time ));
8186 }
8287
8388 public function testChecksForAlreadyRunSchedule ()
8489 {
90+ $ this ->cacheRepository ->shouldReceive ('getStore ' )->andReturn (new \stdClass );
8591 $ this ->cacheRepository ->shouldReceive ('has ' )->with ($ this ->event ->mutexName ().$ this ->time ->format ('Hi ' ))->andReturn (true );
8692
8793 $ this ->assertTrue ($ this ->cacheMutex ->exists ($ this ->event , $ this ->time ));
8894 }
95+
96+ public function testMutexReceivesCorrectCreateWithLockProvider ()
97+ {
98+ $ this ->cacheRepository ->shouldReceive ('getStore ' )->andReturn (new ArrayStore );
99+
100+ $ this ->assertTrue ($ this ->cacheMutex ->create ($ this ->event , $ this ->time ));
101+ }
102+
103+ public function testPreventsMultipleRunsWithLockProvider ()
104+ {
105+ $ this ->cacheRepository ->shouldReceive ('getStore ' )->andReturn (new ArrayStore );
106+
107+ // first create the lock, so we can test that the next call fails.
108+ $ this ->cacheMutex ->create ($ this ->event , $ this ->time );
109+
110+ $ this ->assertFalse ($ this ->cacheMutex ->create ($ this ->event , $ this ->time ));
111+ }
112+
113+ public function testChecksForNonRunScheduleWithLockProvider ()
114+ {
115+ $ this ->cacheRepository ->shouldReceive ('getStore ' )->andReturn (new ArrayStore );
116+
117+ $ this ->assertFalse ($ this ->cacheMutex ->exists ($ this ->event , $ this ->time ));
118+ }
119+
120+ public function testChecksForAlreadyRunScheduleWithLockProvider ()
121+ {
122+ $ this ->cacheRepository ->shouldReceive ('getStore ' )->andReturn (new ArrayStore );
123+
124+ $ this ->cacheMutex ->create ($ this ->event , $ this ->time );
125+
126+ $ this ->assertTrue ($ this ->cacheMutex ->exists ($ this ->event , $ this ->time ));
127+ }
89128}
0 commit comments