Skip to content

Commit

Permalink
Constant refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
peteraba committed Jan 27, 2020
1 parent 7fa77d7 commit a486919
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 95 deletions.
13 changes: 6 additions & 7 deletions src/Constant/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class Env

public const DIR_PRIVATE = 'DIR_PRIVATE';
public const DIR_PUBLIC = 'DIR_PUBLIC';
public const DIR_MEDIA = 'DIR_MEDIA';
public const DIR_AUTH_CONFIG = 'DIR_AUTH_CONFIG';
public const DIR_MIGRATIONS = 'DIR_MIGRATIONS';
public const DIR_LOGS = 'DIR_LOGS';
public const DIR_ROOT_JS = 'DIR_ROOT_JS';
public const DIR_ROOT_CSS = 'DIR_ROOT_CSS';
public const DIR_CACHE_JS = 'DIR_CACHE_JS';
public const DIR_CACHE_CSS = 'DIR_CACHE_CSS';

public const DIR_ROOT_JS = 'DIR_ROOT_JS';
public const DIR_ROOT_CSS = 'DIR_ROOT_CSS';
public const DIR_CACHE_JS = 'DIR_CACHE_JS';
public const DIR_CACHE_CSS = 'DIR_CACHE_CSS';

public const PATH_CACHE_JS = 'PATH_CACHE_JS';
public const PATH_CACHE_CSS = 'PATH_CACHE_CSS';
Expand All @@ -55,9 +57,6 @@ class Env
public const EMAIL_SMTP_PASSWORD = 'EMAIL_SMTP_PASSWORD';
public const EMAIL_SENDMAIL_COMMAND = 'EMAIL_SENDMAIL_COMMAND';

public const ADMIN_DATE_FORMAT = 'ADMIN_DATE_FORMAT';
public const ADMIN_DATETIME_FORMAT = 'ADMIN_DATETIME_FORMAT';

public const MODULE_CACHE_KEY = 'MODULE_CACHE_KEY';

public const GENERAL_CACHE_BRIDGE = 'GENERAL_CACHE_BRIDGE';
Expand Down
31 changes: 0 additions & 31 deletions src/Helper/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,11 @@

namespace AbterPhp\Framework\Helper;

use AbterPhp\Framework\Constant\Env;
use Opulence\Environments\Environment;

class DateHelper
{
const MYSQL_DATE_FORMAT = "Y-m-d";
const MYSQL_DATETIME_FORMAT = "Y-m-d H:i:s";

/**
* @param \DateTime|null $dateTime
*
* @return string
*/
public static function format(?\DateTime $dateTime): string
{
if (!$dateTime) {
return '';
}

return $dateTime->format(Environment::getVar(Env::ADMIN_DATE_FORMAT));
}

/**
* @param \DateTime|null $dateTime
*
* @return string
*/
public static function formatDateTime(?\DateTime $dateTime): string
{
if (!$dateTime) {
return '';
}

return $dateTime->format(Environment::getVar(Env::ADMIN_DATETIME_FORMAT));
}

/**
* @param \DateTime|null $date
*
Expand Down
58 changes: 1 addition & 57 deletions tests/Helper/DateHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,6 @@

class DateHelperTest extends TestCase
{
/**
* @return array
*/
public function formatProvider(): array
{
return [
[new \DateTime('2010-11-27 09:08:59'), 'Y-m-d', '2010-11-27'],
[new \DateTime('2010-11-27 09:08:59'), 'd.m.Y', '27.11.2010'],
[null, 'Y-m-d', ''],
];
}

/**
* @dataProvider formatProvider
*
* @param \DateTime|null $dateTime
* @param string $dateFormat
* @param string $expectedResult
*/
public function testFormat(?\DateTime $dateTime, string $dateFormat, string $expectedResult)
{
putenv(sprintf('ADMIN_DATE_FORMAT=%s', $dateFormat));

$actualResult = DateHelper::format($dateTime);

$this->assertSame($expectedResult, $actualResult);
}

/**
* @return array
*/
public function formatDateTimeProvider(): array
{
return [
[new \DateTime('2010-11-27 09:08:59'), 'Y-m-d H:i:s', '2010-11-27 09:08:59'],
[new \DateTime('2010-11-27 09:08:59'), 'd.m.Y H:i:s', '27.11.2010 09:08:59'],
[null, 'Y-m-d H:i:s', ''],
];
}

/**
* @dataProvider formatDateTimeProvider
*
* @param \DateTime|null $dateTime
* @param string $dateFormat
* @param string $expectedResult
*/
public function testFormatDateTime(?\DateTime $dateTime, string $dateFormat, string $expectedResult)
{
putenv(sprintf('ADMIN_DATETIME_FORMAT=%s', $dateFormat));

$actualResult = DateHelper::formatDateTime($dateTime);

$this->assertSame($expectedResult, $actualResult);
}

/**
* @return array
*/
Expand All @@ -78,7 +22,7 @@ public function mysqlDateProvider(): array
* @dataProvider mysqlDateProvider
*
* @param \DateTime|null $date
* @param string $expectedResult
* @param string $expectedResult
*/
public function testMysqlDate(?\DateTime $date, string $expectedResult)
{
Expand Down

0 comments on commit a486919

Please sign in to comment.