diff --git a/tests/Result/Item/ParticipantTest.php b/tests/Result/Item/ParticipantTest.php index 952894a..6ba08b1 100644 --- a/tests/Result/Item/ParticipantTest.php +++ b/tests/Result/Item/ParticipantTest.php @@ -14,6 +14,7 @@ use Meritoo\Common\Type\OopVisibilityType; use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant; use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor; use Meritoo\LimeSurvey\ApiClient\Type\MethodType; +use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility; /** * Test case of the one item of the result/data: full data of participant @@ -196,7 +197,7 @@ class ParticipantTest extends BaseTestCase 'completed' => 'N', 'usesleft' => 10, 'validfrom' => null, - 'validuntil' => (new DateTime())->format('Y-m-d H:i:s'), + 'validuntil' => DateUtility::getDateTime(), ], [ 'tid' => '456', @@ -212,9 +213,9 @@ class ParticipantTest extends BaseTestCase 'sent' => 'Y', 'remindersent' => 'N', 'remindercount' => 1, - 'completed' => (new DateTime())->format('Y-m-d H:i'), + 'completed' => DateUtility::getDateTime(false), 'usesleft' => 5, - 'validfrom' => (new DateTime())->format('Y-m-d H:i:s'), + 'validfrom' => DateUtility::getDateTime(), 'validuntil' => null, ], ]; diff --git a/tests/Result/Item/SurveyTest.php b/tests/Result/Item/SurveyTest.php index 638cac9..6fd7243 100644 --- a/tests/Result/Item/SurveyTest.php +++ b/tests/Result/Item/SurveyTest.php @@ -14,6 +14,7 @@ use Meritoo\Common\Type\OopVisibilityType; use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey; use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor; use Meritoo\LimeSurvey\ApiClient\Type\MethodType; +use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility; /** * Test case of the one item of the result/data: survey @@ -99,13 +100,13 @@ class SurveyTest extends BaseTestCase 'sid' => '123', 'surveyls_title' => 'Test', 'startdate' => null, - 'expires' => (new DateTime())->format('Y-m-d H:i:s'), + 'expires' => DateUtility::getDateTime(), 'active' => 'N', ], [ 'sid' => '456', 'surveyls_title' => 'Another Test', - 'startdate' => (new DateTime())->format('Y-m-d H:i:s'), + 'startdate' => DateUtility::getDateTime(), 'expires' => null, 'active' => 'Y', ], diff --git a/tests/Result/ResultTest.php b/tests/Result/ResultTest.php index 5ccc906..4520826 100644 --- a/tests/Result/ResultTest.php +++ b/tests/Result/ResultTest.php @@ -8,13 +8,13 @@ namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Result; -use DateTime; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Type\OopVisibilityType; use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem; use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException; use Meritoo\LimeSurvey\ApiClient\Result\Result; use Meritoo\LimeSurvey\ApiClient\Type\MethodType; +use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility; use PHPUnit_Framework_MockObject_MockObject; /** @@ -179,7 +179,7 @@ class ResultTest extends BaseTestCase [ 'sid' => '456', 'surveyls_title' => 'Another Test', - 'startdate' => (new DateTime())->format('Y-m-d H:i:s'), + 'startdate' => DateUtility::getDateTime(), 'expires' => null, 'active' => 'Y', ], diff --git a/tests/Service/ParticipantServiceTest.php b/tests/Service/ParticipantServiceTest.php index d57e010..19e7a8d 100644 --- a/tests/Service/ParticipantServiceTest.php +++ b/tests/Service/ParticipantServiceTest.php @@ -8,7 +8,6 @@ namespace Meritoo\LimeSurvey\Test\ApiClient\Service; -use DateTime; use Exception; use Meritoo\Common\Collection\Collection; use Meritoo\Common\Test\Base\BaseTestCase; @@ -23,6 +22,7 @@ use Meritoo\LimeSurvey\ApiClient\Result\Collection\ParticipantsDetails; use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant; use Meritoo\LimeSurvey\ApiClient\Service\ParticipantService; use Meritoo\LimeSurvey\ApiClient\Type\ReasonType; +use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility; use PHPUnit_Framework_MockObject_MockObject; /** @@ -209,10 +209,10 @@ class ParticipantServiceTest extends BaseTestCase 'sent' => 'Y', 'remindersent' => 'N', 'remindercount' => 0, - 'completed' => (new DateTime())->format('Y-m-d H:i:s'), + 'completed' => DateUtility::getDateTime(), 'usesleft' => 10, 'validfrom' => null, - 'validuntil' => (new DateTime())->format('Y-m-d H:i:s'), + 'validuntil' => DateUtility::getDateTime(), ], [ 'tid' => 2, @@ -231,7 +231,7 @@ class ParticipantServiceTest extends BaseTestCase 'completed' => 'N', 'usesleft' => 10, 'validfrom' => null, - 'validuntil' => (new DateTime())->format('Y-m-d H:i:s'), + 'validuntil' => DateUtility::getDateTime(), ], ]; } diff --git a/tests/Utilities/DateUtility.php b/tests/Utilities/DateUtility.php new file mode 100644 index 0000000..7941ed7 --- /dev/null +++ b/tests/Utilities/DateUtility.php @@ -0,0 +1,38 @@ + + * @copyright Meritoo.pl + */ +class DateUtility +{ + /** + * Returns date formatted with long or medium format + * + * @param bool $useLongFormat (optional) If is set to true, long format will be used (default behaviour). + * Otherwise - medium format. + * @return string + */ + public static function getDateTime($useLongFormat = true) + { + $format = 'Y-m-d H:i'; + + if ($useLongFormat) { + $format = 'Y-m-d H:i:s'; + } + + return (new DateTime())->format($format); + } +}