paymentDOMock = $this->createMock(PaymentDataObjectInterface::class); $this->paymentMock = $this->getMockBuilder(Payment::class) ->disableOriginalConstructor() ->getMock(); $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class) ->disableOriginalConstructor() ->getMock(); $this->orderMock = $this->createMock(OrderAdapterInterface::class); /** @var Config $config */ $config = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->getMock(); $this->builder = new PaymentDataBuilder($config, $this->subjectReaderMock); } /** * @return void * @expectedException \InvalidArgumentException */ public function testBuildReadPaymentException(): void { $buildSubject = []; $this->subjectReaderMock->expects(self::once()) ->method('readPayment') ->with($buildSubject) ->willThrowException(new \InvalidArgumentException()); $this->builder->build($buildSubject); } /** * @return void * @expectedException \InvalidArgumentException */ public function testBuildReadAmountException(): void { $buildSubject = [ 'payment' => $this->paymentDOMock, 'amount' => null, ]; $this->subjectReaderMock->expects(self::once()) ->method('readPayment') ->with($buildSubject) ->willReturn($this->paymentDOMock); $this->subjectReaderMock->expects(self::once()) ->method('readAmount') ->with($buildSubject) ->willThrowException(new \InvalidArgumentException()); $this->builder->build($buildSubject); } /** * @return void */ public function testBuild(): void { $additionalData = [ [ DataAssignObserver::PAYMENT_METHOD_NONCE, self::PAYMENT_METHOD_NONCE, ], ]; $expectedResult = [ PaymentDataBuilder::AMOUNT => 10.00, PaymentDataBuilder::PAYMENT_METHOD_NONCE => self::PAYMENT_METHOD_NONCE, PaymentDataBuilder::ORDER_ID => '000000101' ]; $buildSubject = [ 'payment' => $this->paymentDOMock, 'amount' => 10.00, ]; $this->paymentMock->expects(self::exactly(count($additionalData))) ->method('getAdditionalInformation') ->willReturnMap($additionalData); $this->paymentDOMock->expects(self::once()) ->method('getPayment') ->willReturn($this->paymentMock); $this->paymentDOMock->expects(self::once()) ->method('getOrder') ->willReturn($this->orderMock); $this->subjectReaderMock->expects(self::once()) ->method('readPayment') ->with($buildSubject) ->willReturn($this->paymentDOMock); $this->subjectReaderMock->expects(self::once()) ->method('readAmount') ->with($buildSubject) ->willReturn(10.00); $this->orderMock->expects(self::once()) ->method('getOrderIncrementId') ->willReturn('000000101'); self::assertEquals( $expectedResult, $this->builder->build($buildSubject) ); } }