From e503ad1c4d3a26f023b40dbc9627ea6355899948 Mon Sep 17 00:00:00 2001 From: Manuel Reinhard Date: Mon, 3 Aug 2020 19:10:32 +0200 Subject: [PATCH] Adjust QrPaymentReferenceGenerator to match RfCreditorReferenceGenerator structure --- src/Reference/QrPaymentReferenceGenerator.php | 15 +++++++++------ .../Reference/QrPaymentReferenceGeneratorTest.php | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Reference/QrPaymentReferenceGenerator.php b/src/Reference/QrPaymentReferenceGenerator.php index b01cd83d..e1c9279c 100644 --- a/src/Reference/QrPaymentReferenceGenerator.php +++ b/src/Reference/QrPaymentReferenceGenerator.php @@ -22,14 +22,17 @@ class QrPaymentReferenceGenerator implements SelfValidatableInterface public static function generate(?string $customerIdentificationNumber, string $referenceNumber): string { - $qrPaymentReferenceGenerator = new self(); + $qrPaymentReferenceGenerator = new self($customerIdentificationNumber, $referenceNumber); + return $qrPaymentReferenceGenerator->doGenerate(); + } + + public function __construct(?string $customerIdentificationNumber, string $referenceNumber) + { if (null !== $customerIdentificationNumber) { - $qrPaymentReferenceGenerator->customerIdentificationNumber = StringModifier::stripWhitespace($customerIdentificationNumber); + $this->customerIdentificationNumber = StringModifier::stripWhitespace($customerIdentificationNumber); } - $qrPaymentReferenceGenerator->referenceNumber = StringModifier::stripWhitespace($referenceNumber); - - return $qrPaymentReferenceGenerator->doGenerate(); + $this->referenceNumber = StringModifier::stripWhitespace($referenceNumber); } public function getCustomerIdentificationNumber(): ?string @@ -42,7 +45,7 @@ public function getReferenceNumber(): ?string return $this->referenceNumber; } - private function doGenerate(): string + public function doGenerate(): string { if (!$this->isValid()) { throw new InvalidQrPaymentReferenceException( diff --git a/tests/Reference/QrPaymentReferenceGeneratorTest.php b/tests/Reference/QrPaymentReferenceGeneratorTest.php index 178b93cd..51efba6c 100644 --- a/tests/Reference/QrPaymentReferenceGeneratorTest.php +++ b/tests/Reference/QrPaymentReferenceGeneratorTest.php @@ -22,7 +22,20 @@ public function setUp() /** * @dataProvider qrPaymentReferenceProvider */ - public function testQrPaymentReference($customerIdentification, $referenceNumber, $expectedResult) + public function testMakesResultsViaConstructor($customerIdentification, $referenceNumber, $expectedResult) + { + $qrReference = new QrPaymentReferenceGenerator( + $customerIdentification, + $referenceNumber + ); + + $this->assertSame($expectedResult, $qrReference->doGenerate()); + } + + /** + * @dataProvider qrPaymentReferenceProvider + */ + public function testMakesResultsViaFacade($customerIdentification, $referenceNumber, $expectedResult) { $qrReference = QrPaymentReferenceGenerator::generate( $customerIdentification,