public function testClearExpiredLock() { $this->assertNotEmpty($this->gateway->select(['key' => 'past'])); $this->assertNotEmpty($this->gateway->select(['key' => 'past2'])); $this->throttleDbAdapter->clearExpiredLock('past'); $this->assertEmpty($this->gateway->select(['key' => 'past'])); $this->assertNotEmpty($this->gateway->select(['key' => 'past2'])); $this->throttleDbAdapter->clearExpiredLock(); $this->assertEmpty($this->gateway->select(['key' => 'past2'])); $this->assertNotEmpty($this->gateway->select(['key' => 'forever'])); }
public function testSetLockReturnsFalse() { $adapterMock = $this->getMock('BeaucalLongThrottle\\Adapter\\Db', ['setLock'], [$this->gateway, $this->throttleDbAdapter->getOptions(), new LockHandleFactory()]); $adapterMock->expects($this->any())->method('setLock')->will($this->returnValue(false)); $throttle = new Throttle($adapterMock, new ThrottleOptions()); $this->assertFalse($throttle->takeLock('setLockReturnsFalse', new DateTimeUnit(3, 'minutes'))); }
/** * @param string $key */ public function clearExpiredLock($key = null) { parent::clearExpiredLock($key); if ($key) { $currDate = date($this->options->getDbDateTimeFormat()); $delete = $this->gateway->getSql()->delete(); $delete->where->lessThanOrEqualTo('end_datetime', $currDate)->and->like('key', "%{$this->separator}{$key}"); $this->gateway->deleteWith($delete); } }