Files
Chamilo/vendor/ddeboer/data-import/tests/ValueConverter/DateTimeValueConverterTest.php
T
Xes 73154ae174
Behat tests 1.11.x 🐞 / PHP 7.4 Test on ubuntu-latest (push) Canceled after 0s
PHP-CS-Fixer / composer_install (7.4) (push) Canceled after 0s
Chamilo 1.11.40 (ZIP oficial v1.11.40)
Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip
sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439
Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2026-08-06 17:59:45 +02:00

58 lines
2.0 KiB
PHP

<?php
namespace Ddeboer\DataImport\Tests\ValueConverter;
use Ddeboer\DataImport\ValueConverter\DateTimeValueConverter;
class DateTimeValueConverterTest extends \PHPUnit_Framework_TestCase
{
public function testConvertWithoutInputOrOutputFormatReturnsDateTimeInstance()
{
$value = '2011-10-20 13:05';
$converter = new DateTimeValueConverter;
$output = call_user_func($converter, $value);
$this->assertInstanceOf('\DateTime', $output);
$this->assertEquals('13', $output->format('H'));
}
public function testConvertWithFormatReturnsDateTimeInstance()
{
$value = '14/10/2008 09:40:20';
$converter = new DateTimeValueConverter('d/m/Y H:i:s');
$output = call_user_func($converter, $value);
$this->assertInstanceOf('\DateTime', $output);
$this->assertEquals('20', $output->format('s'));
}
public function testConvertWithInputAndOutputFormatReturnsString()
{
$value = '14/10/2008 09:40:20';
$converter = new DateTimeValueConverter('d/m/Y H:i:s', 'd-M-Y');
$output = call_user_func($converter, $value);
$this->assertEquals('14-Oct-2008', $output);
}
public function testConvertWithNoInputStringWithOutputFormatReturnsString()
{
$value = '2011-10-20 13:05';
$converter = new DateTimeValueConverter(null, 'd-M-Y');
$output = call_user_func($converter, $value);
$this->assertEquals('20-Oct-2011', $output);
}
public function testInvalidInputFormatThrowsException()
{
$value = '14/10/2008 09:40:20';
$converter = new DateTimeValueConverter('d-m-y', 'd-M-Y');
$this->setExpectedException("UnexpectedValueException", "14/10/2008 09:40:20 is not a valid date/time according to format d-m-y");
call_user_func($converter, $value);
}
public function testNullIsReturnedIfNullPassed()
{
$converter = new DateTimeValueConverter('d-m-y', 'd-M-Y');
$this->assertNull(call_user_func($converter, null));
}
}