Skip to content

Commit

Permalink
#17 - Tests fix and cleanup (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
BarTracz authored Jun 26, 2024
1 parent 2de939b commit e6ff782
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 15 deletions.
13 changes: 11 additions & 2 deletions tests/ArrayAccessItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
use Blumilk\HeatmapBuilder\HeatmapBuilder;
use Blumilk\HeatmapBuilder\Tile;
use Carbon\Carbon;
use Carbon\CarbonTimeZone;
use PHPUnit\Framework\TestCase;

class ArrayAccessItemsTest extends TestCase
{
public function testBasicArrayAccessItems(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-11-18"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-18"),
timezone: new CarbonTimeZone("1"),
);
$result = $builder->build($this->getData());

$this->assertSame(
Expand All @@ -25,7 +29,9 @@ public function testArrayAccessItemsWithIndexChanged(): void
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-18"),
arrayAccessIndex: "updated_at",
timezone: new CarbonTimeZone("1"),
);

$result = $builder->build($this->getData());

$this->assertSame(
Expand All @@ -36,7 +42,10 @@ public function testArrayAccessItemsWithIndexChanged(): void

public function testArrayAccessItemsWithIndexChangedByMethod(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-11-18"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-18"),
timezone: new CarbonTimeZone("1"),
);
$builder->changeArrayAccessIndex("updated_at");

$result = $builder->build($this->getData());
Expand Down
6 changes: 5 additions & 1 deletion tests/ContractedItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
use Blumilk\HeatmapBuilder\HeatmapBuilder;
use Blumilk\HeatmapBuilder\Tile;
use Carbon\Carbon;
use Carbon\CarbonTimeZone;
use PHPUnit\Framework\TestCase;

class ContractedItemsTest extends TestCase
{
public function testBasicContractedItems(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-11-18"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-18"),
timezone: new CarbonTimeZone("1"),
);
$result = $builder->build($this->getData());

$this->assertSame(
Expand Down
2 changes: 2 additions & 0 deletions tests/DecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Blumilk\HeatmapBuilder\HeatmapBuilder;
use Blumilk\HeatmapBuilder\Tile;
use Carbon\Carbon;
use Carbon\CarbonTimeZone;
use PHPUnit\Framework\TestCase;

class DecoratorTest extends TestCase
Expand Down Expand Up @@ -33,6 +34,7 @@ public function testBasicArrayAccessItems(): void
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-18"),
decorator: new TailwindDecorator("green"),
timezone: new CarbonTimeZone("1"),
);

$result = $builder->build($data);
Expand Down
11 changes: 9 additions & 2 deletions tests/NowChangedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
use Blumilk\HeatmapBuilder\HeatmapBuilder;
use Blumilk\HeatmapBuilder\Tile;
use Carbon\Carbon;
use Carbon\CarbonTimeZone;
use PHPUnit\Framework\TestCase;

class NowChangedTest extends TestCase
{
public function testChangingNow(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-11-19"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-19"),
timezone: new CarbonTimeZone("1"),
);
$result = $builder->build($this->getData());

$this->assertSame(
Expand All @@ -23,7 +27,10 @@ public function testChangingNow(): void
public function testChangingNowByMethod(): void
{
$builder = new HeatmapBuilder();
$builder->changeNow(Carbon::parse("2022-11-20"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-20"),
timezone: new CarbonTimeZone("1"),
);

$result = $builder->build($this->getData());

Expand Down
26 changes: 21 additions & 5 deletions tests/PeriodActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

use Blumilk\HeatmapBuilder\HeatmapBuilder;
use Carbon\Carbon;
use Carbon\CarbonTimeZone;
use PHPUnit\Framework\TestCase;

class PeriodActionsTest extends TestCase
{
public function testChangingPeriodForMonth(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-11-19 00:00:00"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-19"),
timezone: new CarbonTimeZone("1"),
);
$builder->forLastMonth();

$result = $builder->build($this->getData());
Expand All @@ -23,7 +27,10 @@ public function testChangingPeriodForMonth(): void

public function testChangingPeriodForShorterMonth(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-03-01 00:00:00"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-03-01 00:00:00"),
timezone: new CarbonTimeZone("1"),
);
$builder->forLastMonth();

$result = $builder->build($this->getData());
Expand All @@ -36,7 +43,10 @@ public function testChangingPeriodForShorterMonth(): void

public function testChangingPeriodForYear(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-11-19 00:00:00"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-19 00:00:00"),
timezone: new CarbonTimeZone("1"),
);
$builder->forLastYear();

$result = $builder->build($this->getData());
Expand All @@ -49,7 +59,10 @@ public function testChangingPeriodForYear(): void

public function testChangingPeriodForLeapYear(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2020-05-01 00:00:00"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2020-05-01 00:00:00"),
timezone: new CarbonTimeZone("1"),
);
$builder->forLastYear();

$result = $builder->build($this->getData());
Expand All @@ -62,7 +75,10 @@ public function testChangingPeriodForLeapYear(): void

public function testChangingPeriodForNumberOfTiles(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-03-01 00:00:00"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2020-03-01 00:00:00"),
timezone: new CarbonTimeZone("1"),
);
$builder->forNumberOfTiles(100);

$result = $builder->build($this->getData());
Expand Down
16 changes: 13 additions & 3 deletions tests/PeriodAligningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

use Blumilk\HeatmapBuilder\HeatmapBuilder;
use Carbon\Carbon;
use Carbon\CarbonTimeZone;
use PHPUnit\Framework\TestCase;

class PeriodAligningTest extends TestCase
{
public function testAligningPeriodForDailyHeatmap(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-11-19 00:00:00"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-19 00:00:00"),
timezone: new CarbonTimeZone("1"),
);
$builder->forLastMonth()->alignedToStartOfPeriod();

$result = $builder->build($this->getData());
Expand All @@ -23,7 +27,10 @@ public function testAligningPeriodForDailyHeatmap(): void

public function testAligningPeriodForDailyHeatmapFromBothSides(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-11-19 00:00:00"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-19 00:00:00"),
timezone: new CarbonTimeZone("1"),
);
$builder->forLastMonth()->alignedToStartOfPeriod()->alignedToEndOfPeriod();

$result = $builder->build($this->getData());
Expand All @@ -36,7 +43,10 @@ public function testAligningPeriodForDailyHeatmapFromBothSides(): void

public function testAligningPeriodForNumberOfTiles(): void
{
$builder = new HeatmapBuilder(now: Carbon::parse("2022-11-19 00:00:00"));
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-19 00:00:00"),
timezone: new CarbonTimeZone("1"),
);
$builder->forNumberOfTiles(4)->alignedToStartOfPeriod();

$result = $builder->build($this->getData());
Expand Down
8 changes: 6 additions & 2 deletions tests/PeriodChangedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Blumilk\HeatmapBuilder\Tile;
use Carbon\Carbon;
use Carbon\CarbonPeriod;
use Carbon\CarbonTimeZone;
use PHPUnit\Framework\TestCase;

class PeriodChangedTest extends TestCase
Expand All @@ -14,7 +15,10 @@ public function testChangingPeriod(): void
{
$start = Carbon::parse("2022-11-01");
$end = Carbon::parse("2022-11-11");
$builder = new HeatmapBuilder(period: new CarbonPeriod($start, "1 day", $end));
$builder = new HeatmapBuilder(
period: new CarbonPeriod($start, "1 day", $end),
timezone: new CarbonTimeZone("1"),
);

$result = $builder->build($this->getData());

Expand All @@ -29,7 +33,7 @@ public function testChangingPeriodByMethod(): void
$start = Carbon::parse("2022-11-01");
$end = Carbon::parse("2022-11-11");

$builder = new HeatmapBuilder();
$builder = new HeatmapBuilder(timezone: new CarbonTimeZone("1"));
$builder->changePeriod(new CarbonPeriod($start, "1 day", $end));

$result = $builder->build($this->getData());
Expand Down
2 changes: 2 additions & 0 deletions tests/PeriodIntervalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Blumilk\HeatmapBuilder\PeriodInterval;
use Blumilk\HeatmapBuilder\Tile;
use Carbon\Carbon;
use Carbon\CarbonTimeZone;
use PHPUnit\Framework\TestCase;

class PeriodIntervalTest extends TestCase
Expand All @@ -15,6 +16,7 @@ public function testChangingPeriodForMonth(): void
$builder = new HeatmapBuilder(
now: Carbon::parse("2022-11-19"),
periodInterval: PeriodInterval::Monthly,
timezone: new CarbonTimeZone("1"),
);
$builder->forLastYear();

Expand Down

0 comments on commit e6ff782

Please sign in to comment.