mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 02:11:45 +01:00
Tests - use common method to create/prepare date
This commit is contained in:
@@ -14,6 +14,7 @@ use Meritoo\Common\Type\OopVisibilityType;
|
|||||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
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
|
* Test case of the one item of the result/data: full data of participant
|
||||||
@@ -196,7 +197,7 @@ class ParticipantTest extends BaseTestCase
|
|||||||
'completed' => 'N',
|
'completed' => 'N',
|
||||||
'usesleft' => 10,
|
'usesleft' => 10,
|
||||||
'validfrom' => null,
|
'validfrom' => null,
|
||||||
'validuntil' => (new DateTime())->format('Y-m-d H:i:s'),
|
'validuntil' => DateUtility::getDateTime(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'tid' => '456',
|
'tid' => '456',
|
||||||
@@ -212,9 +213,9 @@ class ParticipantTest extends BaseTestCase
|
|||||||
'sent' => 'Y',
|
'sent' => 'Y',
|
||||||
'remindersent' => 'N',
|
'remindersent' => 'N',
|
||||||
'remindercount' => 1,
|
'remindercount' => 1,
|
||||||
'completed' => (new DateTime())->format('Y-m-d H:i'),
|
'completed' => DateUtility::getDateTime(false),
|
||||||
'usesleft' => 5,
|
'usesleft' => 5,
|
||||||
'validfrom' => (new DateTime())->format('Y-m-d H:i:s'),
|
'validfrom' => DateUtility::getDateTime(),
|
||||||
'validuntil' => null,
|
'validuntil' => null,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Meritoo\Common\Type\OopVisibilityType;
|
|||||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||||
|
use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case of the one item of the result/data: survey
|
* Test case of the one item of the result/data: survey
|
||||||
@@ -99,13 +100,13 @@ class SurveyTest extends BaseTestCase
|
|||||||
'sid' => '123',
|
'sid' => '123',
|
||||||
'surveyls_title' => 'Test',
|
'surveyls_title' => 'Test',
|
||||||
'startdate' => null,
|
'startdate' => null,
|
||||||
'expires' => (new DateTime())->format('Y-m-d H:i:s'),
|
'expires' => DateUtility::getDateTime(),
|
||||||
'active' => 'N',
|
'active' => 'N',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'sid' => '456',
|
'sid' => '456',
|
||||||
'surveyls_title' => 'Another Test',
|
'surveyls_title' => 'Another Test',
|
||||||
'startdate' => (new DateTime())->format('Y-m-d H:i:s'),
|
'startdate' => DateUtility::getDateTime(),
|
||||||
'expires' => null,
|
'expires' => null,
|
||||||
'active' => 'Y',
|
'active' => 'Y',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Result;
|
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Result;
|
||||||
|
|
||||||
use DateTime;
|
|
||||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Type\OopVisibilityType;
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Result;
|
use Meritoo\LimeSurvey\ApiClient\Result\Result;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||||
|
use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility;
|
||||||
use PHPUnit_Framework_MockObject_MockObject;
|
use PHPUnit_Framework_MockObject_MockObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,7 +179,7 @@ class ResultTest extends BaseTestCase
|
|||||||
[
|
[
|
||||||
'sid' => '456',
|
'sid' => '456',
|
||||||
'surveyls_title' => 'Another Test',
|
'surveyls_title' => 'Another Test',
|
||||||
'startdate' => (new DateTime())->format('Y-m-d H:i:s'),
|
'startdate' => DateUtility::getDateTime(),
|
||||||
'expires' => null,
|
'expires' => null,
|
||||||
'active' => 'Y',
|
'active' => 'Y',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Service;
|
namespace Meritoo\LimeSurvey\Test\ApiClient\Service;
|
||||||
|
|
||||||
use DateTime;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Meritoo\Common\Collection\Collection;
|
use Meritoo\Common\Collection\Collection;
|
||||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
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\Result\Item\Participant;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Service\ParticipantService;
|
use Meritoo\LimeSurvey\ApiClient\Service\ParticipantService;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||||
|
use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility;
|
||||||
use PHPUnit_Framework_MockObject_MockObject;
|
use PHPUnit_Framework_MockObject_MockObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -209,10 +209,10 @@ class ParticipantServiceTest extends BaseTestCase
|
|||||||
'sent' => 'Y',
|
'sent' => 'Y',
|
||||||
'remindersent' => 'N',
|
'remindersent' => 'N',
|
||||||
'remindercount' => 0,
|
'remindercount' => 0,
|
||||||
'completed' => (new DateTime())->format('Y-m-d H:i:s'),
|
'completed' => DateUtility::getDateTime(),
|
||||||
'usesleft' => 10,
|
'usesleft' => 10,
|
||||||
'validfrom' => null,
|
'validfrom' => null,
|
||||||
'validuntil' => (new DateTime())->format('Y-m-d H:i:s'),
|
'validuntil' => DateUtility::getDateTime(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'tid' => 2,
|
'tid' => 2,
|
||||||
@@ -231,7 +231,7 @@ class ParticipantServiceTest extends BaseTestCase
|
|||||||
'completed' => 'N',
|
'completed' => 'N',
|
||||||
'usesleft' => 10,
|
'usesleft' => 10,
|
||||||
'validfrom' => null,
|
'validfrom' => null,
|
||||||
'validuntil' => (new DateTime())->format('Y-m-d H:i:s'),
|
'validuntil' => DateUtility::getDateTime(),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
38
tests/Utilities/DateUtility.php
Normal file
38
tests/Utilities/DateUtility.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\LimeSurvey\Test\ApiClient\Utilities;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date-related utility
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user