Exemple #1
0
 /**
  * Dispatch request
  *
  * @return ResultInterface|ResponseInterface
  * @throws NotFoundException
  */
 public function execute()
 {
     $request = $this->_request;
     if (!$request instanceof Http) {
         return $this->createErrorResponse(self::WRONG_REQUEST);
     }
     if (!$this->fkValidator->validate($request)) {
         return $this->createErrorResponse(self::WRONG_REQUEST);
     }
     $paymentToken = $this->getPaymentToken($request);
     if ($paymentToken === null) {
         return $this->createErrorResponse(self::WRONG_TOKEN);
     }
     try {
         $this->tokenRepository->delete($paymentToken);
     } catch (\Exception $e) {
         return $this->createErrorResponse(self::ACTION_EXCEPTION);
     }
     return $this->createSuccessMessage();
 }
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessageRegExp You must implement this operation\. \([^:]+::delete\)
  */
 public function testNullRepositoryExceptionDelete()
 {
     /** @var PaymentTokenFactory|\PHPUnit_Framework_MockObject_MockObject $tokenFactoryMock */
     $tokenFactoryMock = $this->getMockBuilder(PaymentTokenFactory::class)->disableOriginalConstructor()->getMockForAbstractClass();
     /** @var PaymentTokenSearchResultsInterfaceFactory
      * |\PHPUnit_Framework_MockObject_MockObject $searchResultFactoryMock */
     $searchResultFactoryMock = $this->getMockBuilder(PaymentTokenSearchResultsInterfaceFactory::class)->disableOriginalConstructor()->getMockForAbstractClass();
     /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */
     $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass();
     $proxy = new PaymentTokenRepositoryProxy(new \Magento\Vault\Model\PaymentTokenNullRepository($tokenFactoryMock, $searchResultFactoryMock), $this->vaultPaymentMock, $this->configMock, $this->objectManagerMock, []);
     $proxy->delete($tokenMock);
 }
 /**
  * Run test for default repository
  */
 public function testDefaultRepository()
 {
     /** @var SearchCriteria|\PHPUnit_Framework_MockObject_MockObject $searchCriteriaMock */
     $searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->getMockForAbstractClass();
     /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */
     $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass();
     /** @var PaymentTokenSearchResultsInterface|\PHPUnit_Framework_MockObject_MockObject $searchResultMock */
     $searchResultMock = $this->getMockBuilder(PaymentTokenSearchResultsInterface::class)->getMockForAbstractClass();
     $this->objectManagerMock->expects(self::never())->method('get');
     $proxy = new PaymentTokenRepositoryProxy($this->defaultRepository, $this->configMock, $this->objectManagerMock, []);
     $this->defaultRepository->expects(self::once())->method('getById')->with(1)->willReturn($tokenMock);
     $this->defaultRepository->expects(self::once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultMock);
     self::assertEquals($tokenMock, $proxy->getById(1));
     self::assertEquals($searchResultMock, $proxy->getList($searchCriteriaMock));
 }