/**
  * @test
  */
 public function shouldUpdateModelOneTimeOnLastStackLevelOnException()
 {
     $expectedModel = new \stdClass();
     $storageMock = $this->createStorageMock();
     $storageMock->expects($this->atLeastOnce())->method('supportModel')->with($this->identicalTo($expectedModel))->will($this->returnValue(true));
     $storageMock->expects($this->once())->method('updateModel')->with($this->identicalTo($expectedModel));
     $modelRequestMock = $this->getMock('Payum\\Core\\Request\\ModelRequestInterface');
     $modelRequestMock->expects($this->any())->method('getModel')->will($this->returnValue($expectedModel));
     $extension = new StorageExtension($storageMock);
     $extension->onPreExecute($modelRequestMock);
     $extension->onPreExecute($modelRequestMock);
     $extension->onPreExecute($modelRequestMock);
     //guard
     $this->assertAttributeEquals(3, 'stackLevel', $extension);
     $this->assertAttributeNotEmpty('scheduledForUpdateModels', $extension);
     $extension->onException(new \Exception(), new \stdClass(), $this->createActionMock());
     $this->assertAttributeNotEmpty('scheduledForUpdateModels', $extension);
     $extension->onException(new \Exception(), new \stdClass(), $this->createActionMock());
     $this->assertAttributeNotEmpty('scheduledForUpdateModels', $extension);
     $extension->onException(new \Exception(), new \stdClass(), $this->createActionMock());
     $this->assertAttributeEmpty('scheduledForUpdateModels', $extension);
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function shouldNotUpdateModelIfNotLatestOnPostExecute()
 {
     //when previous is NOT empty
     $expectedModel = new \stdClass();
     $storageMock = $this->createStorageMock();
     $storageMock->expects($this->atLeastOnce())->method('support')->with($this->identicalTo($expectedModel))->will($this->returnValue(true));
     $storageMock->expects($this->never())->method('update')->with($this->identicalTo($expectedModel));
     $requestMock = $this->getMock('Payum\\Core\\Model\\ModelAggregateInterface');
     $requestMock->expects($this->any())->method('getModel')->will($this->returnValue($expectedModel));
     $extension = new StorageExtension($storageMock);
     $previousContext = new Context($this->createGatewayMock(), $requestMock, array());
     $context = new Context($this->createGatewayMock(), $requestMock, array($previousContext));
     $extension->onPreExecute($context);
     //guard
     $this->assertAttributeNotEmpty('scheduledForUpdateModels', $extension);
     $extension->onPostExecute($context);
     $this->assertAttributeNotEmpty('scheduledForUpdateModels', $extension);
 }