diff --git a/src/Hyperwallet/Model/BankAccount.php b/src/Hyperwallet/Model/BankAccount.php index 5ace32fa..5cf081bb 100644 --- a/src/Hyperwallet/Model/BankAccount.php +++ b/src/Hyperwallet/Model/BankAccount.php @@ -1,6 +1,8 @@ dateOfBirth = $dateOfBirth == null ? null : $dateOfBirth->format('Y-m-d'); + public function setDateOfBirth($dateOfBirth = null) + { + $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 143023be..d58952bf 100644 --- a/src/Hyperwallet/Model/BankCard.php +++ b/src/Hyperwallet/Model/BankCard.php @@ -1,6 +1,8 @@ dateOfExpiry = $dateOfExpiry == null ? null : $dateOfExpiry->format('Y-m-d'); + public function setDateOfExpiry($dateOfExpiry = null) + { + $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 7662de4a..e9e699bb 100644 --- a/src/Hyperwallet/Model/Payment.php +++ b/src/Hyperwallet/Model/Payment.php @@ -1,6 +1,8 @@ releaseOn = $releaseOn == null ? null : $releaseOn->format('Y-m-d\TH:i:s'); + public function setReleaseOn($releaseOn = null) + { + $this->releaseOn = StringToDataConverter::convertStringToDate($releaseOn, 'Y-m-d\TH:i:s'); return $this; } @@ -240,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 b7ce38d2..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 * @@ -861,11 +863,12 @@ 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) + { + $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 1e5a2094..d4645727 100644 --- a/src/Hyperwallet/Model/User.php +++ b/src/Hyperwallet/Model/User.php @@ -1,6 +1,8 @@ dateOfBirth = $dateOfBirth == null ? null : $dateOfBirth->format('Y-m-d'); + public function setDateOfBirth($dateOfBirth = null) + { + $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 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(); 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