-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test enhancement #2
Conversation
tests/InstantTest.php
Outdated
*/ | ||
public function testIsBetweenExclusive(int $s1, int $n1, int $s2, int $n2, int $cmp) | ||
{ | ||
$this->assertSame($cmp <= 0, Instant::of($s1, $n1)->isBetweenExclusive(Instant::of($s2, $n2), Instant::of($s2, $n2))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not testing much in these two methods, you're only testing that the value is within an interval of 0 seconds.
What I would do here is hardcode the interval start and end, and test with a range of possible values in between:
public function testIsBetweenExclusive(int $seconds, int $nanos, bool $isBetween)
{
$this->assertSame($isBetween, Instant::of($seconds, $nanos)->isBetweenExclusive(
Instant::of(-1, -1),
Instant::of(1, 1)
);
}
And for the provider:
[
[-1, -2, false],
[-1, -1, false],
[-1, 0, true],
[-1, 1, true],
[0, -1, true],
[0, 0, true],
[0, 1, true],
[1, -1, true],
[1, 0, true],
[1, 1, false],
[1, 2, false],
]
Same for isBetweenInclusive(), with the data provider altered accordingly.
tests/WeekOfYearTest.php
Outdated
* @expectedException Brick\DateTime\DateTimeException | ||
* @expectedExceptionMessage Year 2000 does not have 53 weeks | ||
*/ | ||
public function testCehckTimeShouldThrowDateYimeException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still 2 typos: 'Cehck' instead of 'Check' and 'Yime' instead of 'Time'!
tests/InstantTest.php
Outdated
[ 1, 0, 0, 1, 1], | ||
]; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These providers are obsolete!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove this data provider.
tests/WeekOfYearTest.php
Outdated
* @expectedException Brick\DateTime\DateTimeException | ||
* @expectedExceptionMessage Invalid week-of-year: -1 is not in the range 1 to 53. | ||
*/ | ||
public function testCheckShouldReturnDateTimeExceptionWithFieldNotInRange() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return => Throw
tests/PatternParserBuilderTest.php
Outdated
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage Cannot call endOptional() without a call to startOptional() first. | ||
*/ | ||
public function testEndOptionalShouldReturnRuntimeException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return => Throw
tests/PatternParserBuilderTest.php
Outdated
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage Cannot call endGroup() without a call to startGroup() first. | ||
*/ | ||
public function testEndGroupShouldReturnRunTimeException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return => Throw
tests/YearMonthTest.php
Outdated
public function testWithYearIsTheSameYear() | ||
{ | ||
$year = (int)date('Y'); | ||
$month = (int)date('m'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use fixed year/month here
tests/YearMonthTest.php
Outdated
$month = (int)date('m'); | ||
|
||
$this->assertInstanceOf(YearMonth::class, YearMonth::of($year, $month)->withYear($year)); | ||
$this->assertYearMonthIs($year, $month, YearMonth::of($year, $month)->withYear($year)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should instantiate YearMonth::of(...)
only once and use it in 2 lines.
tests/YearMonthTest.php
Outdated
public function testWithMonth() | ||
{ | ||
$this->assertYearMonthIs(2000, 12, YearMonth::of(2000, 1)->withMonth(12)); | ||
} | ||
|
||
public function testWithMonthWithSameMonth() | ||
{ | ||
$month = (int)date('m'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a fixed month here
tests/YearMonthTest.php
Outdated
@@ -386,6 +407,12 @@ public function testPlusYears(int $year, int $month, int $plusYears, int $expect | |||
$this->assertYearMonthIs($expectedYear, $expectedMonth, $yearMonth->plusYears($plusYears)); | |||
} | |||
|
|||
public function testPlusYearsWithParameterIsZero() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testPlusZeroYears()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that and it seems that the test method name can be short.
tests/YearWeekTest.php
Outdated
public function testNow() | ||
{ | ||
$timeZone = TimeZone::parse('Asia/Taipei'); | ||
$yearWeek = YearWeek::now($timeZone); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should provide a Clock here, and check that the resulting YearWeek is in line with the clock!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give some examples about this?
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set set timestamp that now()
will use, this way:
$clock = new FixedClock(Instant::of(2000000000));
$yearWeek = YearWeek::now($timeZone, $clock);
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame('Thursday', (string)$zonedDateTime->plusPeriod(Period::ofWeeks(11))->getDayOfWeek()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please assert the full string here: assertSame('2000-...', (string) $zonedDateTime->plusPeriod(Period::ofWeeks(11)));
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(56, $zonedDateTime->plusDuration(Duration::zero())->getSecond()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(2002, $zonedDateTime->plusYears(2)->getYear()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(3, $zonedDateTime->plusMonths(2)->getMonth()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(2, $zonedDateTime->plusWeeks(2)->getMonth()); | ||
$this->assertSame(3, $zonedDateTime->plusWeeks(2)->getDay()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(22, $zonedDateTime->plusDays(2)->getDay()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(14, $zonedDateTime->plusHours(2)->getHour()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(36, $zonedDateTime->plusMinutes(2)->getMinute()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(58, $zonedDateTime->plusSeconds(2)->getSecond()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame('Thursday', (string)$zonedDateTime->minusPeriod(Period::ofWeeks(11))->getDayOfWeek()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(56, $zonedDateTime->minusDuration(Duration::zero())->getSecond()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(1999, $zonedDateTime->minusYears(1)->getYear()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(12, $zonedDateTime->minusMonths(1)->getMonth()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/ZonedDateTimeTest.php
Outdated
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame(1, $zonedDateTime->minusWeeks(2)->getMonth()); | ||
$this->assertSame(6, $zonedDateTime->minusWeeks(2)->getDay()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
tests/Field/DayOfMonthTest.php
Outdated
{ | ||
$dayOfMonth = new DayOfMonth(); | ||
|
||
$this->assertNull($dayOfMonth->check(31)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not comfortable with assertNull() for a void method. To remove the assertion and avoid a "risky" test, maybe you can give a try to @doesNotPerformAssertions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds good because it's the void method and not return the null
currently.
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame('2000-01-10T12:34:56.123456789-08:00', (string) $zonedDateTime->withFixedOffsetTimeZone(56)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withFixedOffsetTimeZone() does not take any parameters!
tests/ZonedDateTimeTest.php
Outdated
|
||
public function testPlusPeriod() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame('2000-01-20T12:34:56.123456789-08:00[America/Los_Angeles]', (string) $zonedDateTime->plusDuration(Duration::zero())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please use another Duration than zero?
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame('2000-01-20T12:34:56.123456789-08:00[America/Los_Angeles]', (string) $zonedDateTime->minusDuration(Duration::zero())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, a non-zero Duration would be more useful!
tests/DateTimeParseResultTest.php
Outdated
|
||
declare(strict_types=1); | ||
|
||
namespace Brick\DateTime\Tests; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in namespace Brick\DateTime\Tests\Parser
, and located in a tests/Parser
directory
tests/PatternParserBuilderTest.php
Outdated
|
||
declare(strict_types=1); | ||
|
||
namespace Brick\DateTime\Tests; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in namespace Brick\DateTime\Tests\Parser
, and located in a tests/Parser
directory
tests/PatternParserBuilderTest.php
Outdated
use Brick\DateTime\Parser\PatternParserBuilder; | ||
|
||
/** | ||
* Unit tests for class IsoParsers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for class PatternParserBuilder.
tests/DateTimeParseResultTest.php
Outdated
class DateTimeParseResultTest extends AbstractTestCase | ||
{ | ||
/** | ||
* @expectedException Brick\DateTime\Parser\DateTimeParseException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add leading \
before exception class
tests/Field/WeekOfYearTest.php
Outdated
class WeekOfYearTest extends AbstractTestCase | ||
{ | ||
/** | ||
* @expectedException Brick\DateTime\DateTimeException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add leading \
before exception class
tests/Field/WeekOfYearTest.php
Outdated
} | ||
|
||
/** | ||
* @expectedException Brick\DateTime\DateTimeException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add leading \
before exception class
tests/IntervalTest.php
Outdated
@@ -12,6 +12,18 @@ | |||
*/ | |||
class IntervalTest extends AbstractTestCase | |||
{ | |||
/** | |||
* @expectedException Brick\DateTime\DateTimeException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add leading \
before exception class
tests/PatternParserBuilderTest.php
Outdated
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage Cannot call endGroup() without a call to startGroup() first. | ||
*/ | ||
public function testEndGroupShouldThrowRunTimeException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RunTime => Runtime
tests/YearMonthTest.php
Outdated
@@ -330,16 +330,38 @@ public function testWithYear() | |||
$this->assertYearMonthIs(2001, 5, YearMonth::of(2000, 5)->withYear(2001)); | |||
} | |||
|
|||
public function testWithYearIsTheSameYear() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename to testWithYearWithSameYear
tests/YearMonthTest.php
Outdated
$month = 2; | ||
$yearMonth = YearMonth::of($year, $month); | ||
|
||
$this->assertInstanceOf(YearMonth::class, $yearMonth->withYear($year)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not needed, assertYearMonthIs() will throw a TypeError if it's not an instance of YearMonth.
tests/YearMonthTest.php
Outdated
public function testGetFirstDay() | ||
{ | ||
$this->assertLocalDateIs(2023, 10, 1, YearMonth::of(2023, 10)->getFirstDay()); | ||
} | ||
|
||
public function testGetLastDay() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there was already a test for getLastDay(), that was not executed because it was wrongly named!
You can remove this method, and rename my test getGetLastDay
to testGetLastDay
!
tests/YearWeekTest.php
Outdated
$yearWeek = YearWeek::now($timeZone, $now); | ||
|
||
$this->assertSame('2033-W20', (string) $yearWeek); | ||
$this->assertInstanceOf(YearWeek::class, $yearWeek); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use assertYearWeekIs()
instead of these 2 lines?
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertDayOfWeekIs(4, $zonedDateTime->getDayOfWeek()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the DayOfWeek::THURSDAY
constant instead of 4
for readability
tests/ZonedDateTimeTest.php
Outdated
$localDateTime = LocalDateTime::parse($localDateTime); | ||
$zonedDateTime = ZonedDateTime::of($localDateTime, $timeZone); | ||
|
||
$this->assertSame('2000-03-25T12:34:56.123456789-08:00[America/Los_Angeles]', (string) $zonedDateTime->withSecond(56)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use another second value in withSecond()
? It's the same as in the original date-time!
tests/Field/DayOfMonthTest.php
Outdated
/** | ||
* Unit tests for class DayOfMonth. | ||
* | ||
* @doesNotPerformAssertions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work with the annotation on the method rather than on the class?
It would be better if we add other methods in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I set the wrong place for the annotation.
tests/Field/DayOfMonthTest.php
Outdated
{ | ||
$dayOfMonth = new DayOfMonth(); | ||
|
||
$dayOfMonth->check(31); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check()
is a static method, it should be DayOfMonth::check(31);
and the first line can be removed.
I think you forgot to reintroduce DateTimeParseResultTest and PatternParserBuilderTest, they're missing! |
Looks good now 👍 Thanks! |
Changed log