Skip to content
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

Use generators for test data providers #2412

Merged
merged 1 commit into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 25 additions & 32 deletions tests/Carbon/AddMonthsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Tests\Carbon;

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

class AddMonthsTest extends AbstractTestCase
Expand All @@ -31,15 +32,13 @@ protected function setUp(): void
$this->carbon = $date;
}

public function providerTestAddMonthNoOverflow()
public function providerTestAddMonthNoOverflow(): Generator
{
return [
[-2, 2015, 11, 30],
[-1, 2015, 12, 31],
[0, 2016, 1, 31],
[1, 2016, 2, 29],
[2, 2016, 3, 31],
];
yield [-2, 2015, 11, 30];
yield [-1, 2015, 12, 31];
yield [0, 2016, 1, 31];
yield [1, 2016, 2, 29];
yield [2, 2016, 3, 31];
}

/**
Expand Down Expand Up @@ -68,15 +67,13 @@ public function testAddMonthsNoOverflow($months, $y, $m, $d)
$this->assertCarbon($this->carbon->addMonthsNoOverflow($months), $y, $m, $d);
}

public function providerTestSubMonthNoOverflow()
public function providerTestSubMonthNoOverflow(): Generator
{
return [
[-2, 2016, 3, 31],
[-1, 2016, 2, 29],
[0, 2016, 1, 31],
[1, 2015, 12, 31],
[2, 2015, 11, 30],
];
yield [-2, 2016, 3, 31];
yield [-1, 2016, 2, 29];
yield [0, 2016, 1, 31];
yield [1, 2015, 12, 31];
yield [2, 2015, 11, 30];
}

/**
Expand Down Expand Up @@ -105,15 +102,13 @@ public function testSubMonthsNoOverflow($months, $y, $m, $d)
$this->assertCarbon($this->carbon->subMonthsNoOverflow($months), $y, $m, $d);
}

public function providerTestAddMonthWithOverflow()
public function providerTestAddMonthWithOverflow(): Generator
{
return [
[-2, 2015, 12, 1],
[-1, 2015, 12, 31],
[0, 2016, 1, 31],
[1, 2016, 3, 2],
[2, 2016, 3, 31],
];
yield [-2, 2015, 12, 1];
yield [-1, 2015, 12, 31];
yield [0, 2016, 1, 31];
yield [1, 2016, 3, 2];
yield [2, 2016, 3, 31];
}

/**
Expand Down Expand Up @@ -142,15 +137,13 @@ public function testAddMonthsWithOverflow($months, $y, $m, $d)
$this->assertCarbon($this->carbon->addMonthsWithOverflow($months), $y, $m, $d);
}

public function providerTestSubMonthWithOverflow()
public function providerTestSubMonthWithOverflow(): Generator
{
return [
[-2, 2016, 3, 31],
[-1, 2016, 3, 2],
[0, 2016, 1, 31],
[1, 2015, 12, 31],
[2, 2015, 12, 1],
];
yield [-2, 2016, 3, 31];
yield [-1, 2016, 3, 2];
yield [0, 2016, 1, 31];
yield [1, 2015, 12, 31];
yield [2, 2015, 12, 1];
}

/**
Expand Down
Loading