Esempio n. 1
0
 public function testResponseFromCache()
 {
     $this->commandMetricsFactory->expects($this->atLeastOnce())->method('get')->with('Tests\\Odesk\\Phystrix\\CommandMock')->will($this->returnValue($this->commandMetrics));
     $requestCache = $this->getMock('Odesk\\Phystrix\\RequestCache');
     $requestCache->expects($this->once())->method('get')->with('Tests\\Odesk\\Phystrix\\CommandMock', 'test-cache-key')->will($this->returnValue('result from cache'));
     $this->command->cacheKey = 'test-cache-key';
     $this->command->setRequestCache($requestCache);
     $this->circuitBreakerFactory->expects($this->never())->method('get');
     $this->commandMetrics->expects($this->once())->method('markResponseFromCache');
     $this->assertEquals('result from cache', $this->command->execute());
     $this->assertEquals(array(AbstractCommand::EVENT_RESPONSE_FROM_CACHE), $this->command->getExecutionEvents());
 }
Esempio n. 2
0
 /**
  * Test case for cache miss scenario
  */
 public function testRequestCacheMiss()
 {
     $this->setUpCommonExpectations();
     /** @var RequestCache|\PHPUnit_Framework_MockObject_MockObject $requestCache */
     $requestCache = $this->getMock('Odesk\\Phystrix\\RequestCache');
     $requestCache->expects($this->once())->method('exists')->with('Tests\\Odesk\\Phystrix\\CommandMock', 'test-cache-key')->will($this->returnValue(false));
     $requestCache->expects($this->never())->method('get');
     $requestCache->expects($this->once())->method('put')->with('Tests\\Odesk\\Phystrix\\CommandMock', 'test-cache-key', 'run result');
     $this->command->cacheKey = 'test-cache-key';
     $this->command->setRequestCache($requestCache);
     $this->commandMetrics->expects($this->never())->method('markResponseFromCache');
     $this->assertEquals('run result', $this->command->execute());
     $this->assertEquals(array('SUCCESS'), $this->command->getExecutionEvents());
 }