Skip to content

Commit

Permalink
Removendo alguns testes desnecessários e refatorando outros.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardokovalski committed Aug 14, 2020
1 parent cf3968e commit 612eb6b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 108 deletions.
38 changes: 1 addition & 37 deletions tests/AllHolidaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function setUp()
$this->actualYear = (int) date('Y');
}

public function testAssertEqualLengthCollection()
public function testAssertEqualsLengthCollection()
{
$this->assertEquals(19, $this->collection->length());
}
Expand Down Expand Up @@ -193,42 +193,6 @@ public function testAssertInstanceOfLastElementCollectionOrderByTimestampDescend
);
}

public function testAssertEqualsFormatterDate()
{
$this->assertEquals(
(new \Holidays\Types\NewYearsDay())->formatter(),
$this->collection
->orderByTimestamp()
->descending()
->last()
->formatter()
);
}

public function testAssertEqualsNextHolidayFormatter()
{
$this->assertEquals(
(new \Holidays\Types\NewYearsDay())->next(),
$this->collection
->orderByTimestamp()
->descending()
->last()
->next()
);
}

public function testAssertEqualsPreviousHolidayFormatter()
{
$this->assertEquals(
(new \Holidays\Types\NewYearsDay())->previous(),
$this->collection
->orderByTimestamp()
->descending()
->last()
->previous()
);
}

public function testExpectedExceptionDates()
{
$endDate = \DateTime::createFromFormat('d/m/Y', '01/01/2020')->setTime(0,0,0);
Expand Down
48 changes: 25 additions & 23 deletions tests/NationalHolidaysTest.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<?php

use Holidays\Collections\NationalHolidays;

class NationalHolidaysTest extends \PHPUnit_Framework_TestCase
{
private $collection;
private $actualYear;

public function setUp() {
$this->collection = new NationalHolidays();
$this->collection = new Holidays\Collections\NationalHolidays();
$this->actualYear = (int) date('Y');
}

public function testCountCollection()
public function testAssertEqualsLengthCollection()
{
$this->assertCount(
11,
$this->collection->getCollection()
);
$this->assertEquals(11, $this->collection->length());
}

public function testAssertEqualPluckByName()
Expand Down Expand Up @@ -164,26 +161,26 @@ public function testAssertInstanceOfLastElementCollectionOrderByTimestampDescend
);
}

private function expectedCollectionDefault()
private function expectedCollectionDefault($year)
{
return [
new \Holidays\Types\AllSoulsDay(),
new \Holidays\Types\ChildrenDay(),
new \Holidays\Types\ChristmasDay(),
new \Holidays\Types\EasterSunday(),
new \Holidays\Types\GoodFriday(),
new \Holidays\Types\IndependenceBrazil(),
new \Holidays\Types\LaborDay(),
new \Holidays\Types\NewYearsDay(),
new \Holidays\Types\OurLadyOfAparecida(),
new \Holidays\Types\RepublicProclamationDay(),
new \Holidays\Types\TiradentesDay(),
new \Holidays\Types\AllSoulsDay($year),
new \Holidays\Types\ChildrenDay($year),
new \Holidays\Types\ChristmasDay($year),
new \Holidays\Types\EasterSunday($year),
new \Holidays\Types\GoodFriday($year),
new \Holidays\Types\IndependenceBrazil($year),
new \Holidays\Types\LaborDay($year),
new \Holidays\Types\NewYearsDay($year),
new \Holidays\Types\OurLadyOfAparecida($year),
new \Holidays\Types\RepublicProclamationDay($year),
new \Holidays\Types\TiradentesDay($year),
];
}

private function expectedCollectionOrderByNameAscending()
{
$collection = $this->expectedCollectionDefault();
$collection = $this->expectedCollectionDefault($this->getActualYear());

usort($collection, function(\Holidays\Contract\Holiday $a, \Holidays\Contract\Holiday $b) {
return $a->getName() > $b->getName();
Expand All @@ -199,7 +196,7 @@ private function expectedCollectionOrderByNameDescending()

private function expectedCollectionOrderByTimestampAscending()
{
$collection = $this->expectedCollectionDefault();
$collection = $this->expectedCollectionDefault($this->getActualYear());

usort($collection, function(\Holidays\Contract\Holiday $a, \Holidays\Contract\Holiday $b) {
return $a->getTimestamp() > $b->getTimestamp();
Expand All @@ -210,12 +207,17 @@ private function expectedCollectionOrderByTimestampAscending()

private function expectedCollectionOrderByTimestampDescending()
{
$collection = $this->expectedCollectionDefault();
$collection = $this->expectedCollectionDefault($this->getActualYear());

usort($collection, function(\Holidays\Contract\Holiday $a, \Holidays\Contract\Holiday $b) {
return $a->getTimestamp() < $b->getTimestamp();
});

return $collection;
}

public function getActualYear()
{
return $this->actualYear;
}
}
42 changes: 18 additions & 24 deletions tests/OptionalHolidaysTest.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
<?php

use Holidays\Collections\OptionalHolidays;

class OptionalHolidaysTest extends \PHPUnit_Framework_TestCase
{
private $collection;
private $actualYear;

public function setUp() {
$this->collection = new OptionalHolidays();
}

public function testAssertEqualsOptionalHolidaysCollection()
{
$this->assertEquals(
$this->expectedCollectionDefault(),
$this->collection->getCollection()
);
$this->collection = new Holidays\Collections\OptionalHolidays();
$this->actualYear = (int) date('Y');
}

public function testCountCollection()
public function testAssertEqualsLengthCollection()
{
$this->assertCount(
4,
$this->collection->getCollection()
);
$this->assertEquals(4, $this->collection->length());
}

public function testAssertEqualPluckByName()
Expand Down Expand Up @@ -188,19 +177,19 @@ public function testAssertInstanceOfLastElementCollectionOrderByTimestampDescend
);
}

private function expectedCollectionDefault()
private function expectedCollectionDefault($year)
{
return [
new \Holidays\Types\Carnival(),
new \Holidays\Types\CorpusChrist(),
new \Holidays\Types\FatherDay(),
new \Holidays\Types\MotherDay(),
new \Holidays\Types\Carnival($year),
new \Holidays\Types\CorpusChrist($year),
new \Holidays\Types\FatherDay($year),
new \Holidays\Types\MotherDay($year),
];
}

private function expectedCollectionOrderByNameAscending()
{
$collection = $this->expectedCollectionDefault();
$collection = $this->expectedCollectionDefault($this->getActualYear());

usort($collection, function(\Holidays\Contract\Holiday $a, \Holidays\Contract\Holiday $b) {
return $a->getName() > $b->getName();
Expand All @@ -216,7 +205,7 @@ private function expectedCollectionOrderByNameDescending()

private function expectedCollectionOrderByTimestampAscending()
{
$collection = $this->expectedCollectionDefault();
$collection = $this->expectedCollectionDefault($this->getActualYear());

usort($collection, function(\Holidays\Contract\Holiday $a, \Holidays\Contract\Holiday $b) {
return $a->getTimestamp() > $b->getTimestamp();
Expand All @@ -227,12 +216,17 @@ private function expectedCollectionOrderByTimestampAscending()

private function expectedCollectionOrderByTimestampDescending()
{
$collection = $this->expectedCollectionDefault();
$collection = $this->expectedCollectionDefault($this->getActualYear());

usort($collection, function(\Holidays\Contract\Holiday $a, \Holidays\Contract\Holiday $b) {
return $a->getTimestamp() < $b->getTimestamp();
});

return $collection;
}

public function getActualYear()
{
return $this->actualYear;
}
}
42 changes: 18 additions & 24 deletions tests/SeasonsTest.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
<?php

use Holidays\Collections\Seasons;

class SeasonsTest extends \PHPUnit_Framework_TestCase
{
private $collection;
private $actualYear;

public function setUp() {
$this->collection = new Seasons();
}

public function testAssertEqualsSeasonsCollection()
{
$this->assertEquals(
$this->expectedCollectionDefault(),
$this->collection->getCollection()
);
$this->collection = new Holidays\Collections\Seasons();
$this->actualYear = (int) date('Y');
}

public function testCountCollection()
public function testAssertEqualsLengthCollection()
{
$this->assertCount(
4,
$this->collection->getCollection()
);
$this->assertEquals(4,$this->collection->length());
}

public function testAssertEqualPluckByName()
Expand Down Expand Up @@ -188,19 +177,19 @@ public function testAssertInstanceOfLastElementCollectionOrderByTimestampDescend
);
}

private function expectedCollectionDefault()
private function expectedCollectionDefault($year)
{
return [
new Holidays\Types\DecemberSolstice(),
new Holidays\Types\JuneSolstice(),
new Holidays\Types\MarchEquinox(),
new Holidays\Types\SeptemberEquinox(),
new Holidays\Types\DecemberSolstice($year),
new Holidays\Types\JuneSolstice($year),
new Holidays\Types\MarchEquinox($year),
new Holidays\Types\SeptemberEquinox($year),
];
}

private function expectedCollectionOrderByNameAscending()
{
$collection = $this->expectedCollectionDefault();
$collection = $this->expectedCollectionDefault($this->getActualYear());

usort($collection, function(\Holidays\Contract\Holiday $a, \Holidays\Contract\Holiday $b) {
return $a->getName() > $b->getName();
Expand All @@ -216,7 +205,7 @@ private function expectedCollectionOrderByNameDescending()

private function expectedCollectionOrderByTimestampAscending()
{
$collection = $this->expectedCollectionDefault();
$collection = $this->expectedCollectionDefault($this->getActualYear());

usort($collection, function(\Holidays\Contract\Holiday $a, \Holidays\Contract\Holiday $b) {
return $a->getTimestamp() > $b->getTimestamp();
Expand All @@ -227,12 +216,17 @@ private function expectedCollectionOrderByTimestampAscending()

private function expectedCollectionOrderByTimestampDescending()
{
$collection = $this->expectedCollectionDefault();
$collection = $this->expectedCollectionDefault($this->getActualYear());

usort($collection, function(\Holidays\Contract\Holiday $a, \Holidays\Contract\Holiday $b) {
return $a->getTimestamp() < $b->getTimestamp();
});

return $collection;
}

public function getActualYear()
{
return $this->actualYear;
}
}

0 comments on commit 612eb6b

Please sign in to comment.