Skip to content

Commit

Permalink
Merge pull request #2495 from lucasmichot/feat/test-more-properties
Browse files Browse the repository at this point in the history
Test more properties
  • Loading branch information
kylekatarnls authored Nov 8, 2021
2 parents c37370b + c7e8cfa commit 19102bb
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 38 deletions.
50 changes: 45 additions & 5 deletions tests/Carbon/IssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,92 @@

namespace Tests\Carbon;

use Carbon\Carbon;
use Generator;
use Tests\AbstractTestCase;

class IssetTest extends AbstractTestCase
{
public function testIssetReturnFalseForUnknownProperty()
public function testIssetReturnFalseForUnknownProperty(): void
{
$this->assertFalse(isset(Carbon::create(1234, 5, 6, 7, 8, 9)->sdfsdfss));
$this->assertFalse(isset($this->now->sdfsdfss));
}

public function providerTestIssetReturnTrueForProperties(): Generator
{
yield ['age'];
yield ['century'];
yield ['day'];
yield ['dayName'];
yield ['dayOfWeek'];
yield ['dayOfWeekIso'];
yield ['dayOfYear'];
yield ['daysInMonth'];
yield ['daysInYear'];
yield ['decade'];
yield ['dst'];
yield ['englishDayOfWeek'];
yield ['englishMonth'];
yield ['firstWeekDay'];
yield ['hour'];
yield ['isoWeek'];
yield ['isoWeekYear'];
yield ['isoWeeksInYear'];
yield ['lastWeekDay'];
yield ['latinMeridiem'];
yield ['latinUpperMeridiem'];
yield ['local'];
yield ['locale'];
yield ['localeDayOfWeek'];
yield ['localeMonth'];
yield ['meridiem'];
yield ['micro'];
yield ['microsecond'];
yield ['millennium'];
yield ['milli'];
yield ['millisecond'];
yield ['milliseconds'];
yield ['minDayName'];
yield ['minute'];
yield ['month'];
yield ['monthName'];
yield ['noZeroHour'];
yield ['offset'];
yield ['offsetHours'];
yield ['offsetMinutes'];
yield ['quarter'];
yield ['second'];
yield ['shortDayName'];
yield ['shortEnglishDayOfWeek'];
yield ['shortEnglishMonth'];
yield ['shortLocaleDayOfWeek'];
yield ['shortLocaleMonth'];
yield ['shortMonthName'];
yield ['timestamp'];
yield ['timezone'];
yield ['timezoneAbbreviatedName'];
yield ['timezoneName'];
yield ['tz'];
yield ['tzAbbrName'];
yield ['tzName'];
yield ['upperMeridiem'];
yield ['utc'];
yield ['week'];
yield ['weekNumberInMonth'];
yield ['weekOfMonth'];
yield ['weekOfYear'];
yield ['weekYear'];
yield ['weeksInYear'];
yield ['year'];
yield ['yearIso'];
}

/**
* @dataProvider \Tests\Carbon\IssetTest::providerTestIssetReturnTrueForProperties
*
* @param string $property
*/
public function testIssetReturnTrueForProperties($property)
public function testIssetReturnTrueForProperties(string $property): void
{
$this->assertTrue(isset(Carbon::now()->$property));
$this->assertTrue(isset($this->now->{$property}));
}
}
105 changes: 72 additions & 33 deletions tests/CarbonImmutable/IssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,92 @@

namespace Tests\CarbonImmutable;

use Carbon\CarbonImmutable as Carbon;
use Generator;
use Tests\AbstractTestCase;

class IssetTest extends AbstractTestCase
{
public function testIssetReturnFalseForUnknownProperty()
public function testIssetReturnFalseForUnknownProperty(): void
{
$this->assertFalse(isset(Carbon::create(1234, 5, 6, 7, 8, 9)->sdfsdfss));
$this->assertFalse(isset($this->immutableNow->sdfsdfss));
}

public function providerTestIssetReturnTrueForProperties()
public function providerTestIssetReturnTrueForProperties(): Generator
{
return [
['age'],
['day'],
['dayOfWeek'],
['dayOfYear'],
['daysInMonth'],
['dst'],
['hour'],
['local'],
['micro'],
['minute'],
['month'],
['offset'],
['offsetHours'],
['quarter'],
['second'],
['timestamp'],
['timezone'],
['timezoneName'],
['tz'],
['tzName'],
['utc'],
['weekOfMonth'],
['weekOfYear'],
['year'],
];
yield ['age'];
yield ['century'];
yield ['day'];
yield ['dayName'];
yield ['dayOfWeek'];
yield ['dayOfWeekIso'];
yield ['dayOfYear'];
yield ['daysInMonth'];
yield ['daysInYear'];
yield ['decade'];
yield ['dst'];
yield ['englishDayOfWeek'];
yield ['englishMonth'];
yield ['firstWeekDay'];
yield ['hour'];
yield ['isoWeek'];
yield ['isoWeekYear'];
yield ['isoWeeksInYear'];
yield ['lastWeekDay'];
yield ['latinMeridiem'];
yield ['latinUpperMeridiem'];
yield ['local'];
yield ['locale'];
yield ['localeDayOfWeek'];
yield ['localeMonth'];
yield ['meridiem'];
yield ['micro'];
yield ['microsecond'];
yield ['millennium'];
yield ['milli'];
yield ['millisecond'];
yield ['milliseconds'];
yield ['minDayName'];
yield ['minute'];
yield ['month'];
yield ['monthName'];
yield ['noZeroHour'];
yield ['offset'];
yield ['offsetHours'];
yield ['offsetMinutes'];
yield ['quarter'];
yield ['second'];
yield ['shortDayName'];
yield ['shortEnglishDayOfWeek'];
yield ['shortEnglishMonth'];
yield ['shortLocaleDayOfWeek'];
yield ['shortLocaleMonth'];
yield ['shortMonthName'];
yield ['timestamp'];
yield ['timezone'];
yield ['timezoneAbbreviatedName'];
yield ['timezoneName'];
yield ['tz'];
yield ['tzAbbrName'];
yield ['tzName'];
yield ['upperMeridiem'];
yield ['utc'];
yield ['week'];
yield ['weekNumberInMonth'];
yield ['weekOfMonth'];
yield ['weekOfYear'];
yield ['weekYear'];
yield ['weeksInYear'];
yield ['year'];
yield ['yearIso'];
}

/**
* @dataProvider \Tests\Carbon\IssetTest::providerTestIssetReturnTrueForProperties
* @dataProvider \Tests\CarbonImmutable\IssetTest::providerTestIssetReturnTrueForProperties
*
* @param string $property
*/
public function testIssetReturnTrueForProperties($property)
public function testIssetReturnTrueForProperties(string $property): void
{
$this->assertTrue(isset(Carbon::now()->$property));
$this->assertTrue(isset($this->immutableNow->{$property}));
}
}

0 comments on commit 19102bb

Please sign in to comment.