paymentDOMock = $this->createMock(PaymentDataObjectInterface::class); $this->configMock = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->getMock(); $this->paymentMock = $this->getMockBuilder(Payment::class) ->disableOriginalConstructor() ->getMock(); $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class) ->disableOriginalConstructor() ->getMock(); $this->builder = new KountPaymentDataBuilder($this->configMock, $this->subjectReaderMock); } /** * @expectedException \InvalidArgumentException */ public function testBuildReadPaymentException() { $buildSubject = []; $this->configMock->expects(self::never()) ->method('hasFraudProtection') ->willReturn(true); $this->subjectReaderMock->expects(self::once()) ->method('readPayment') ->with($buildSubject) ->willThrowException(new \InvalidArgumentException()); $this->builder->build($buildSubject); } public function testBuild() { $additionalData = [ DataAssignObserver::DEVICE_DATA => self::DEVICE_DATA, ]; $expectedResult = [ KountPaymentDataBuilder::DEVICE_DATA => self::DEVICE_DATA, ]; $order = $this->createMock(OrderAdapterInterface::class); $this->paymentDOMock->expects(self::once())->method('getOrder')->willReturn($order); $buildSubject = ['payment' => $this->paymentDOMock]; $this->paymentMock->expects(self::exactly(count($additionalData))) ->method('getAdditionalInformation') ->willReturn($additionalData); $this->configMock->expects(self::once()) ->method('hasFraudProtection') ->willReturn(true); $this->paymentDOMock->expects(self::once()) ->method('getPayment') ->willReturn($this->paymentMock); $this->subjectReaderMock->expects(self::once()) ->method('readPayment') ->with($buildSubject) ->willReturn($this->paymentDOMock); static::assertEquals( $expectedResult, $this->builder->build($buildSubject) ); } }