Skip to content

Commit

Permalink
test: turn EventDate tests into Scheduling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-becker committed Oct 17, 2024
1 parent d76fdb0 commit 2dec229
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

declare(strict_types=1);

namespace Atoolo\EventsCalendar\Test\Service\GraphQL\Factory;
namespace Atoolo\EventsCalendar\Test;

use Atoolo\EventsCalendar\Service\GraphQL\Factory\EventDateFactory;
use Atoolo\EventsCalendar\SchedulingFactory;
use Atoolo\EventsCalendar\Test\Constraint\EqualsRRule;
use Atoolo\EventsCalendar\Test\Constraint\IsRRule;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(EventDateFactory::class)]
#[CoversClass(SchedulingFactory::class)]
class EventDateFactoryTest extends TestCase
{
private EventDateFactory $factory;
private SchedulingFactory $factory;

// 01.01.2025 00:00 GMT
private const UNTIL = 1735689600;

public function setUp(): void
{
$this->factory = new EventDateFactory();
$this->factory = new SchedulingFactory();
}

public function testCreateFromRawSchedulungInvalid()
Expand All @@ -30,10 +30,10 @@ public function testCreateFromRawSchedulungInvalid()
"isFullDay" => true,
"endDate" => 1726178400,
];
$eventDate = $this->factory->createFromRawSchedulung(
$scheduling = $this->factory->createFromRawSchedulung(
$rawScheduling,
);
$this->assertNull($eventDate);
$this->assertNull($scheduling);
}

public function testCreateFromRawSchedulungMulti()
Expand All @@ -44,15 +44,14 @@ public function testCreateFromRawSchedulungMulti()
"beginDate" => 1726005600,
"endDate" => 1726178400,
];
$eventDate = $this->factory->createFromRawSchedulung(
$scheduling = $this->factory->createFromRawSchedulung(
$rawScheduling,
);
$this->assertEquals(1726005600, $eventDate->start->getTimestamp());
$this->assertEquals(1726178400, $eventDate->end->getTimestamp());
$this->assertTrue($eventDate->isFullDay);
$this->assertFalse($eventDate->hasStartTime);
$this->assertFalse($eventDate->hasEndTime);
$this->assertNUll($eventDate->status);
$this->assertEquals(1726005600, $scheduling->getStart()->getTimestamp());
$this->assertEquals(1726178400, $scheduling->getEnd()->getTimestamp());
$this->assertTrue($scheduling->isFullDay());
$this->assertFalse($scheduling->hasStartTime());
$this->assertFalse($scheduling->hasEndTime());
}

public function testGetStartDateTimeFromRawScheduling()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace Atoolo\EventsCalendar\Test\Service\GraphQL\Resolver\Resource;

use Atoolo\EventsCalendar\Scheduling;
use Atoolo\EventsCalendar\SchedulingFactory;
use Atoolo\EventsCalendar\Service\GraphQL\Factory\EventDateFactory;
use Atoolo\EventsCalendar\Service\GraphQL\Resolver\Resource\ResourceEventDateResolver;
use Atoolo\EventsCalendar\Service\GraphQL\Resolver\Resource\ResourceSchedulingResolver;
use Atoolo\EventsCalendar\Service\GraphQL\Types\EventDate;
use Atoolo\Resource\DataBag;
use Atoolo\Resource\Resource;
use Atoolo\Resource\ResourceLanguage;
use DateTime;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

#[CoversClass(ResourceSchedulingResolver::class)]
class ResourceEventDateResolverTest extends TestCase
{
private ResourceSchedulingResolver $resolver;

private SchedulingFactory&MockObject $schedulingFactory;

public function setUp(): void
{
$this->schedulingFactory = $this->createMock(
SchedulingFactory::class,
);
$this->resolver = new ResourceSchedulingResolver(
$this->schedulingFactory,
);
}

public function testGetEventDates(): void
{
$resource = $this->createResource([]);
$schedulingsExpected = [new Scheduling(new DateTime())];
$this->schedulingFactory
->method('create')
->willReturn($schedulingsExpected);
$schedulings = $this->resolver->getSchedulings($resource);
$this->assertNotEmpty($schedulings);
$this->assertEquals(
$schedulingsExpected,
$schedulings,
);
}

/**
* @param array<string,mixed> $data
*/
private function createResource(array $data): Resource
{
return new Resource(
$data['url'] ?? '',
$data['id'] ?? '',
$data['name'] ?? '',
$data['objectType'] ?? '',
ResourceLanguage::default(),
new DataBag($data),
);
}
}
19 changes: 8 additions & 11 deletions test/Service/GraphQL/Resolver/Teaser/EventTeaserResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Atoolo\EventsCalendar\Test\Service\GraphQL\Resolver\Teaser;

use Atoolo\EventsCalendar\Service\GraphQL\Resolver\Resource\ResourceEventDateResolver;
use Atoolo\EventsCalendar\Service\GraphQL\Resolver\Resource\ResourceSchedulingResolver;
use Atoolo\EventsCalendar\Service\GraphQL\Resolver\Teaser\EventTeaserResolver;
use Atoolo\EventsCalendar\Service\GraphQL\Types\EventTeaser;
use Atoolo\GraphQL\Search\Resolver\Resource\ResourceAssetResolver;
Expand All @@ -29,7 +30,7 @@ class EventTeaserResolverTest extends TestCase

private ResourceKickerResolver&MockObject $kickerResolver;

private ResourceEventDateResolver&MockObject $eventDateResolver;
private ResourceSchedulingResolver&MockObject $schedulingResolver;

/**
* @throws Exception
Expand All @@ -45,14 +46,14 @@ public function setUp(): void
$this->kickerResolver = $this->createMock(
ResourceKickerResolver::class,
);
$this->eventDateResolver = $this->createMock(
ResourceEventDateResolver::class,
$this->schedulingResolver = $this->createMock(
ResourceSchedulingResolver::class,
);
$this->resolver = new EventTeaserResolver(
$this->assetResolver,
$this->symbolicImageResolver,
$this->kickerResolver,
$this->eventDateResolver,
$this->schedulingResolver,
);
}

Expand Down Expand Up @@ -84,7 +85,6 @@ public function testGetAsset(): void
$this->createStub(Resource::class),
);
$args = $this->createStub(ArgumentInterface::class);

$this->resolver->getAsset($teaser, $args);
}

Expand All @@ -99,7 +99,6 @@ public function testGetSymbolicImage(): void
$this->createStub(Resource::class),
);
$args = $this->createStub(ArgumentInterface::class);

$this->resolver->getSymbolicImage($teaser, $args);
}

Expand All @@ -114,22 +113,20 @@ public function testGetKicker(): void
$this->createStub(Resource::class),
);
$args = $this->createStub(ArgumentInterface::class);

$this->resolver->getKicker($teaser, $args);
}

public function testGetEventDates(): void
{
$this->eventDateResolver->expects($this->once())
->method('getEventDates');
$this->schedulingResolver->expects($this->once())
->method('getSchedulings');
$teaser = new EventTeaser(
null,
'',
'',
$this->createStub(Resource::class),
);
$args = $this->createStub(ArgumentInterface::class);

$this->resolver->getEventDates($teaser, $args);
$this->resolver->getSchedulings($teaser, $args);
}
}

0 comments on commit 2dec229

Please sign in to comment.