DBGroup)->call('App\Database\Seeds\TestDatabaseBootstrapSeeder'); Config::connect($this->DBGroup)->close(); self::$doneBootstrap = true; } parent::setUp(); $this->jobThrottle = model(JobThrottle::class); $this->db->table('job_throttles')->truncate(); } public function testExistsReturnsFalseForUnknownId(): void { $this->assertFalse($this->jobThrottle->exists(999999)); } public function testSaveValueInsertsWhenThrottleDoesNotExist(): void { $this->assertSame(1, $this->jobThrottle->saveValue(['max_count' => 10, 'period' => 'hour'], 1)); $this->seeInDatabase('job_throttles', [ 'throttle_id' => 1, 'max_count' => 10, 'period' => 'hour', 'deleted' => 0, ]); } public function testSaveValueUpdatesWhenThrottleExists(): void { $this->jobThrottle->saveValue(['max_count' => 10, 'period' => 'hour'], 1); $this->assertTrue($this->jobThrottle->exists(1)); $this->assertSame(1, $this->jobThrottle->saveValue(['max_count' => 25, 'period' => 'day'], 1)); $this->seeInDatabase('job_throttles', [ 'throttle_id' => 1, 'max_count' => 25, 'period' => 'day', ]); $this->assertEquals(1, $this->db->table('job_throttles')->countAllResults()); } public function testGetAllExcludesDeletedThrottles(): void { $this->jobThrottle->saveValue(['max_count' => 5, 'period' => 'minute'], 1); $this->jobThrottle->saveValue(['max_count' => 15, 'period' => 'day'], 2); $this->jobThrottle->delete(2); $results = $this->jobThrottle->getAll()->getResultArray(); $this->assertCount(1, $results); $this->assertSame('1', (string) $results[0]['throttle_id']); } public function testDeleteSoftDeletesThrottle(): void { $this->jobThrottle->saveValue(['max_count' => 5, 'period' => 'minute'], 1); $this->assertTrue($this->jobThrottle->delete(1)); $this->seeInDatabase('job_throttles', ['throttle_id' => 1, 'deleted' => 1]); $this->assertCount(0, $this->jobThrottle->getAll()->getResultArray()); } }