From 9965d16ff2ae63ecafe8fc9e17465e456a55c485 Mon Sep 17 00:00:00 2001 From: dyurchenko-epam Date: Thu, 28 Nov 2019 14:45:36 +0200 Subject: [PATCH 1/4] corrected setDateOfBirth method --- src/Hyperwallet/Model/BankAccount.php | 8 +++++--- src/Hyperwallet/Model/BankCard.php | 19 ++++++++++++++++--- src/Hyperwallet/Model/Payment.php | 8 +++++--- src/Hyperwallet/Model/TransferMethod.php | 8 +++++--- src/Hyperwallet/Model/User.php | 8 +++++--- .../Hyperwallet/Tests/Model/ModelTestCase.php | 4 ++-- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/Hyperwallet/Model/BankAccount.php b/src/Hyperwallet/Model/BankAccount.php index 5ace32fa..f65e0cb4 100644 --- a/src/Hyperwallet/Model/BankAccount.php +++ b/src/Hyperwallet/Model/BankAccount.php @@ -784,11 +784,13 @@ public function getDateOfBirth() { /** * Set the date of birth * - * @param \DateTime|null $dateOfBirth + * @param string $dateOfBirth |null * @return BankAccount */ - public function setDateOfBirth(\DateTime $dateOfBirth = null) { - $this->dateOfBirth = $dateOfBirth == null ? null : $dateOfBirth->format('Y-m-d'); + public function setDateOfBirth($dateOfBirth = null) + { + $stringToDate = $dateOfBirth === null ? null : new \DateTime($dateOfBirth); + $this->dateOfBirth = $stringToDate == null ? null : $stringToDate->format('Y-m-d'); return $this; } diff --git a/src/Hyperwallet/Model/BankCard.php b/src/Hyperwallet/Model/BankCard.php index 143023be..476c2162 100644 --- a/src/Hyperwallet/Model/BankCard.php +++ b/src/Hyperwallet/Model/BankCard.php @@ -222,14 +222,27 @@ public function getDateOfExpiry() { return $this->dateOfExpiry ? new \DateTime($this->dateOfExpiry) : null; } + /* /** + * Set the bank card expiry date + * + * @param \DateTime $dateOfExpiry + * @return BankCard + */ + /*public function setDateOfExpiry(\DateTime $dateOfExpiry = null) { + $this->dateOfExpiry = $dateOfExpiry == null ? null : $dateOfExpiry->format('Y-m-d'); + return $this; + }*/ + /** * Set the bank card expiry date * - * @param \DateTime $dateOfExpiry + * @param string $dateOfExpiry |null * @return BankCard */ - public function setDateOfExpiry(\DateTime $dateOfExpiry = null) { - $this->dateOfExpiry = $dateOfExpiry == null ? null : $dateOfExpiry->format('Y-m-d'); + public function setDateOfExpiry($dateOfExpiry = null) + { + $stringToDate = $dateOfExpiry === null ? null : new \DateTime($dateOfExpiry); + $this->dateOfExpiry = $stringToDate == null ? null : $stringToDate->format('Y-m-d'); return $this; } diff --git a/src/Hyperwallet/Model/Payment.php b/src/Hyperwallet/Model/Payment.php index 7662de4a..9c73c887 100644 --- a/src/Hyperwallet/Model/Payment.php +++ b/src/Hyperwallet/Model/Payment.php @@ -201,11 +201,13 @@ public function getReleaseOn() { /** * Set the payment release date * - * @param \DateTime $releaseOn + * @param string $releaseOn |null * @return Payment */ - public function setReleaseOn(\DateTime $releaseOn = null) { - $this->releaseOn = $releaseOn == null ? null : $releaseOn->format('Y-m-d\TH:i:s'); + public function setReleaseOn($releaseOn = null) + { + $stringToDate = $releaseOn === null ? null : new \DateTime($releaseOn); + $this->releaseOn = $stringToDate == null ? null : $stringToDate->format('Y-m-d\TH:i:s'); return $this; } diff --git a/src/Hyperwallet/Model/TransferMethod.php b/src/Hyperwallet/Model/TransferMethod.php index b7ce38d2..9c046216 100644 --- a/src/Hyperwallet/Model/TransferMethod.php +++ b/src/Hyperwallet/Model/TransferMethod.php @@ -861,11 +861,13 @@ public function getDateOfBirth() { /** * Set the date of birth * - * @param \DateTime|null $dateOfBirth + * @param string $dateOfBirth |null * @return TransferMethod */ - public function setDateOfBirth(\DateTime $dateOfBirth = null) { - $this->dateOfBirth = $dateOfBirth == null ? null : $dateOfBirth->format('Y-m-d'); + public function setDateOfBirth($dateOfBirth = null) + { + $stringToDate = $dateOfBirth === null ? null : new \DateTime($dateOfBirth); + $this->dateOfBirth = $stringToDate == null ? null : $stringToDate->format('Y-m-d'); return $this; } diff --git a/src/Hyperwallet/Model/User.php b/src/Hyperwallet/Model/User.php index 1e5a2094..e7b1dc1d 100644 --- a/src/Hyperwallet/Model/User.php +++ b/src/Hyperwallet/Model/User.php @@ -362,11 +362,13 @@ public function getDateOfBirth() { /** * Set the date of birth * - * @param \DateTime|null $dateOfBirth + * @param string $dateOfBirth |null * @return User */ - public function setDateOfBirth(\DateTime $dateOfBirth = null) { - $this->dateOfBirth = $dateOfBirth == null ? null : $dateOfBirth->format('Y-m-d'); + public function setDateOfBirth($dateOfBirth = null) + { + $stringToDate = $dateOfBirth === null ? null : new \DateTime($dateOfBirth); + $this->dateOfBirth = $stringToDate == null ? null : $stringToDate->format('Y-m-d'); return $this; } diff --git a/tests/Hyperwallet/Tests/Model/ModelTestCase.php b/tests/Hyperwallet/Tests/Model/ModelTestCase.php index a6ec84ca..301c209c 100644 --- a/tests/Hyperwallet/Tests/Model/ModelTestCase.php +++ b/tests/Hyperwallet/Tests/Model/ModelTestCase.php @@ -130,7 +130,7 @@ protected function performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDef $setter = $this->clazz->getMethod($setterName); $this->assertEquals($valType, $getter->invoke($instance)); - $this->assertEquals($instance, $setter->invoke($instance, $newValParam)); + $this->assertEquals($instance, $setter->invoke($instance, $newVal)); $this->assertEquals($newValParam, $getter->invoke($instance)); $data2 = array(); @@ -173,7 +173,7 @@ protected function performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDef $setter = $this->clazz->getMethod($setterName); $this->assertNull($getter->invoke($instance)); - $this->assertEquals($instance, $setter->invoke($instance, $newValParam)); + $this->assertEquals($instance, $setter->invoke($instance, $newVal)); $this->assertEquals($newValParam, $getter->invoke($instance)); $data2 = array(); From cc5781b9d54be1b2758693c33322c6ffa6adc38f Mon Sep 17 00:00:00 2001 From: dyurchenko-epam Date: Thu, 28 Nov 2019 14:53:03 +0200 Subject: [PATCH 2/4] deleted extra comments --- src/Hyperwallet/Model/BankCard.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Hyperwallet/Model/BankCard.php b/src/Hyperwallet/Model/BankCard.php index 476c2162..4abb1432 100644 --- a/src/Hyperwallet/Model/BankCard.php +++ b/src/Hyperwallet/Model/BankCard.php @@ -222,17 +222,6 @@ public function getDateOfExpiry() { return $this->dateOfExpiry ? new \DateTime($this->dateOfExpiry) : null; } - /* /** - * Set the bank card expiry date - * - * @param \DateTime $dateOfExpiry - * @return BankCard - */ - /*public function setDateOfExpiry(\DateTime $dateOfExpiry = null) { - $this->dateOfExpiry = $dateOfExpiry == null ? null : $dateOfExpiry->format('Y-m-d'); - return $this; - }*/ - /** * Set the bank card expiry date * From d58b91e92f6ba80339fb5e03f14915e8ee4ef6c9 Mon Sep 17 00:00:00 2001 From: dyurchenko-epam Date: Thu, 28 Nov 2019 17:28:52 +0200 Subject: [PATCH 3/4] added converter --- src/Hyperwallet/Model/BankAccount.php | 5 +++-- src/Hyperwallet/Model/BankCard.php | 5 +++-- src/Hyperwallet/Model/Payment.php | 7 ++++--- src/Hyperwallet/Model/TransferMethod.php | 7 ++++--- src/Hyperwallet/Model/User.php | 5 +++-- src/Hyperwallet/Util/StringToDataConverter.php | 14 ++++++++++++++ 6 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 src/Hyperwallet/Util/StringToDataConverter.php diff --git a/src/Hyperwallet/Model/BankAccount.php b/src/Hyperwallet/Model/BankAccount.php index f65e0cb4..5cf081bb 100644 --- a/src/Hyperwallet/Model/BankAccount.php +++ b/src/Hyperwallet/Model/BankAccount.php @@ -1,6 +1,8 @@ dateOfBirth = $stringToDate == null ? null : $stringToDate->format('Y-m-d'); + $this->dateOfBirth = StringToDataConverter::convertStringToDate($dateOfBirth, 'Y-m-d'); return $this; } diff --git a/src/Hyperwallet/Model/BankCard.php b/src/Hyperwallet/Model/BankCard.php index 4abb1432..d58952bf 100644 --- a/src/Hyperwallet/Model/BankCard.php +++ b/src/Hyperwallet/Model/BankCard.php @@ -1,6 +1,8 @@ dateOfExpiry = $stringToDate == null ? null : $stringToDate->format('Y-m-d'); + $this->dateOfExpiry = StringToDataConverter::convertStringToDate($dateOfExpiry, 'Y-m-d'); return $this; } diff --git a/src/Hyperwallet/Model/Payment.php b/src/Hyperwallet/Model/Payment.php index 9c73c887..e9e699bb 100644 --- a/src/Hyperwallet/Model/Payment.php +++ b/src/Hyperwallet/Model/Payment.php @@ -1,6 +1,8 @@ releaseOn = $stringToDate == null ? null : $stringToDate->format('Y-m-d\TH:i:s'); + $this->releaseOn = StringToDataConverter::convertStringToDate($releaseOn, 'Y-m-d\TH:i:s'); return $this; } @@ -242,7 +243,7 @@ public function getProgramToken() { /** * Set the payment program token - * + * * @param string $programToken * @return Payment */ diff --git a/src/Hyperwallet/Model/TransferMethod.php b/src/Hyperwallet/Model/TransferMethod.php index 9c046216..ac5cc5c0 100644 --- a/src/Hyperwallet/Model/TransferMethod.php +++ b/src/Hyperwallet/Model/TransferMethod.php @@ -1,6 +1,8 @@ dateOfExpiry ? new \DateTime($this->dateOfExpiry) : null; } - + /** * Get the bank account id * @@ -866,8 +868,7 @@ public function getDateOfBirth() { */ public function setDateOfBirth($dateOfBirth = null) { - $stringToDate = $dateOfBirth === null ? null : new \DateTime($dateOfBirth); - $this->dateOfBirth = $stringToDate == null ? null : $stringToDate->format('Y-m-d'); + $this->dateOfBirth = StringToDataConverter::convertStringToDate($dateOfBirth, 'Y-m-d'); return $this; } diff --git a/src/Hyperwallet/Model/User.php b/src/Hyperwallet/Model/User.php index e7b1dc1d..d4645727 100644 --- a/src/Hyperwallet/Model/User.php +++ b/src/Hyperwallet/Model/User.php @@ -1,6 +1,8 @@ dateOfBirth = $stringToDate == null ? null : $stringToDate->format('Y-m-d'); + $this->dateOfBirth = StringToDataConverter::convertStringToDate($dateOfBirth, 'Y-m-d'); return $this; } diff --git a/src/Hyperwallet/Util/StringToDataConverter.php b/src/Hyperwallet/Util/StringToDataConverter.php new file mode 100644 index 00000000..d98168b9 --- /dev/null +++ b/src/Hyperwallet/Util/StringToDataConverter.php @@ -0,0 +1,14 @@ +format($format); + } +} \ No newline at end of file From 9feee4b5b5127bf87442982f748db3c2aa8a0165 Mon Sep 17 00:00:00 2001 From: dyurchenko-epam Date: Thu, 28 Nov 2019 21:12:26 +0200 Subject: [PATCH 4/4] added test for StringToDateConverter --- .../Tests/Util/StringToDateConverterTest.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/Hyperwallet/Tests/Util/StringToDateConverterTest.php diff --git a/tests/Hyperwallet/Tests/Util/StringToDateConverterTest.php b/tests/Hyperwallet/Tests/Util/StringToDateConverterTest.php new file mode 100644 index 00000000..def6a707 --- /dev/null +++ b/tests/Hyperwallet/Tests/Util/StringToDateConverterTest.php @@ -0,0 +1,33 @@ +assertEquals($originalDate->format($format), $convertedDate); + } + + public function testShouldReturnNullIfAcceptedParameterIsNull() + { + $format = 'Y-m-d'; + $stringToConvert = null; + + $convertedDate = StringToDataConverter::convertStringToDate($stringToConvert, $format); + $originalDate = null; + + $this->assertEquals(null, $convertedDate); + } +} \ No newline at end of file