Skip to content

Commit

Permalink
Use frozen time in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Jun 2, 2019
1 parent 86e21c5 commit 4b6a41d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
28 changes: 28 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
engines:
phpmd:
enabled: true
config:
rulesets: "phpmd.xml"
rubocop:
enabled: true
shellcheck:
enabled: true
stylelint:
enabled: true
duplication:
enabled: true
metrics:
enabled: true
coverage:
enabled: true
structure:
enabled: true
sonar-php:
enabled: true
fixme:
enabled: true
phpcodesniffer:
enabled: true
exclude_paths:
- 'tests/**'
27 changes: 27 additions & 0 deletions phpmd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<ruleset name="Mess detection rules for Jenssegers\Date"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Mess detection rules for Jenssegers\Date
</description>
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/cleancode.xml" />
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml/BooleanGetMethodName" />
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass" />
<rule ref="rulesets/naming.xml/ConstantNamingConventions" />
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum" value="25" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortVariable" />
<rule ref="rulesets/naming.xml/ShortMethodName" />
<rule ref="rulesets/unusedcode.xml" />
</ruleset>
8 changes: 4 additions & 4 deletions src/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ class Date extends Carbon
*/
protected static $parseFunction = 'parseWithCurrentLocale';

public static function parseWithCurrentLocale($time = null, $tz = null)
public static function parseWithCurrentLocale($time = null, $timezone = null)
{
if (is_string($time)) {
$time = static::translateTimeString($time, static::getLocale(), 'en');
}

return parent::rawParse($time, $tz);
return parent::rawParse($time, $timezone);
}

public static function createFromFormatWithCurrentLocale($format, $time = null, $tz = null)
public static function createFromFormatWithCurrentLocale($format, $time = null, $timezone = null)
{
if (is_string($time)) {
$time = static::translateTimeString($time, static::getLocale(), 'en');
}

return parent::rawCreateFromFormat($format, $time, $tz);
return parent::rawCreateFromFormat($format, $time, $timezone);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ public function testConstructFromString()
$this->assertSame(1359590400, $date->getTimestamp());

$date = new Date('1 day ago');
$this->assertSame(time() - 86400, $date->getTimestamp());
$this->assertSame($this->time - 86400, $date->getTimestamp());
}

public function testConstructWithTimezone()
{
$date = new Date('now', 'Europe/Paris');
date_default_timezone_set('Europe/Paris');
$this->assertSame(time(), $date->getTimestamp());
$this->assertSame($this->time, $date->getTimestamp());

date_default_timezone_set('Europe/Brussels');

$date = new Date(null, 'Europe/Paris');
date_default_timezone_set('Europe/Paris');
$this->assertSame(time(), $date->getTimestamp());
$this->assertSame($this->time, $date->getTimestamp());
}

public function testConstructTimestamp()
Expand Down

0 comments on commit 4b6a41d

Please sign in to comment.