protected function execute(InputInterface $input, OutputInterface $output)
 {
     $decorator = new Decorator(new TestService(), 'test_service');
     $lock = new Lock();
     $lock->setDriver(new File('lock'))->setMethod('sleep');
     $decorator->addLock($lock);
     $decorator->sleep((int) $input->getOption('seconds'));
     $output->write('done');
 }
Ejemplo n.º 2
0
 private function getLockName(Lock $lock, $arguments)
 {
     $lockName = $this->lockPrefix . '_' . $lock->getMethod();
     if (array_key_exists($lock->getArgumentIndex(), $arguments)) {
         $argumentHash = $this->getHashFromValue($arguments[$lock->getArgumentIndex()]);
         $lockName .= sprintf('_%s_%s', $lock->getArgumentIndex(), $argumentHash);
     }
     return $lockName;
 }
Ejemplo n.º 3
0
 public function testLogger()
 {
     $decorator = new Decorator(new TestService(), 'test_service');
     $lock = new Lock();
     $lock->setDriver(new Debug())->setMethod('doNothing');
     $decorator->addLock($lock);
     $logger = new TestLogger();
     $decorator->setLogger($logger);
     $decorator->doNothing();
     $this->assertEquals($this->expectedLogs, $logger->getLogs());
 }
Ejemplo n.º 4
0
 public function testFileDriverWithArrayArgument()
 {
     $fileLock = new File('lock');
     $fileLock->clearLocks();
     $p = new Process('/usr/bin/php Tests/FileLockCommand.php test:file -s 1');
     $p->start();
     $decorator = new Decorator(new TestService(), 'test_service');
     $lock = new Lock();
     $lock->setDriver($fileLock)->setMethod('sleep')->setArgumentIndex(1);
     $decorator->addLock($lock);
     $decorator->sleep(1, array(1));
     $p->stop();
     return $this->assertTrue(true);
 }