Skip to content

Commit 14a9a41

Browse files
authored
tests: add functional test (#75)
* feat: Removed AbstractEvent and event Uid * fix: Fixed CS * chore: Fixed factory name * chore: Added 100% test coverage
1 parent 7ad741a commit 14a9a41

File tree

25 files changed

+151
-57
lines changed

25 files changed

+151
-57
lines changed

.dagger/src/CalendR.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,39 @@ public function test(
6666
#[DefaultPath('.')] Directory $source,
6767
string $phpVersion = '8.4',
6868
string $dependencyVersion = 'highest',
69-
): string {
70-
return $this
69+
?string $coverallsRepoToken = null,
70+
?string $ciName = null,
71+
?string $ciJobId = null,
72+
?string $ciBranch = null,
73+
): string
74+
{
75+
$container = $this
7176
->build($source, $phpVersion, $dependencyVersion)
72-
->withExec(['php', './vendor/bin/phpunit', '--coverage-text'])
77+
->withFile('/tmp/coveralls-linux.tar.gz', dag()->http('https://coveralls.io/coveralls-linux.tar.gz'))
78+
->withExec(['tar', '-xvzf', '/tmp/coveralls-linux.tar.gz', '-C', '/usr/local/bin']);
79+
80+
81+
$exec = ['php', './vendor/bin/phpunit', '--coverage-text'];
82+
if ($coverallsRepoToken) {
83+
$exec[] = '--coverage-clover=build/logs/clover.xml';
84+
85+
$container = $container->withEnvVariable('COVERALLS_REPO_TOKEN', $coverallsRepoToken);
86+
}
87+
88+
if ($ciName && $ciJobId && $ciBranch) {
89+
$container = $container
90+
->withEnvVariable('CI_NAME', $ciName)
91+
->withEnvVariable('CI_JOB_ID', $ciJobId)
92+
->withEnvVariable('CI_BRANCH', $ciBranch);
93+
}
94+
95+
$container = $container->withExec($exec);
96+
97+
if ($coverallsRepoToken) {
98+
$container = $container->withExec(['coveralls', 'report']);
99+
}
100+
101+
return $container
73102
->stdout();
74103
}
75104

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
with:
5757
version: "latest"
5858
verb: call
59-
args: test --source=. --php-version=${{ matrix.php-versions }} --dependency-version=${{ matrix.dependencies-versions }}
59+
args: test --source=. --php-version=${{ matrix.php-versions }} --dependency-version=${{ matrix.dependencies-versions }} --coveralls-repo-token=${{ secrets.COVERALLS_REPO_TOKEN }} --ci-name=gha --ci-job-id=${{ github.run_id }} --ci-branch=${{ github.ref }}
6060
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
6161

6262
mutation:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
CalendR provides a clean, immutable, and iterable API to manipulate time periods (Years, Months, Weeks, Days...) and manage associated events.
66

77
[![CI Status](https://github.com/yohang/CalendR/actions/workflows/ci.yml/badge.svg)](https://github.com/yohang/CalendR/actions/workflows/ci.yml)
8+
[![Coverage Status](https://coveralls.io/repos/github/yohang/CalendR/badge.svg?branch=master)](https://coveralls.io/github/yohang/CalendR?branch=main)
89
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyohang%2FCalendR%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/yohang/CalendR/main)
910

1011
## ✨ Features

src/Bridge/Symfony/Bundle/DependencyInjection/CalendRExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function load(array $configs, ContainerBuilder $container): void
2727

2828
$defaultFirstWeekday = $config['periods']['default_first_weekday'];
2929
if (!($defaultFirstWeekday instanceof DayOfWeek)) {
30-
$defaultFirstWeekday = DayOfWeek::from($defaultFirstWeekday);
30+
$defaultFirstWeekday = DayOfWeek::from($defaultFirstWeekday); // @codeCoverageIgnore
3131
}
3232

3333
$container

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ public function getConfigTreeBuilder(): TreeBuilder
2828
->enumFqcn(DayOfWeek::class)
2929
->defaultValue(DayOfWeek::MONDAY);
3030
} else {
31+
// @codeCoverageIgnoreStart
3132
$enumNode
3233
->values(array_map(fn (DayOfWeek $dayOfWeek) => $dayOfWeek->value, DayOfWeek::cases()))
3334
->defaultValue(DayOfWeek::MONDAY->value)
3435
->validate()
3536
->ifNotInArray(array_map(static fn (DayOfWeek $d) => $d->value, DayOfWeek::cases()))
3637
->thenInvalid('Day must be be between 0 (Sunday) and 6 (Saturday)')
3738
->end();
39+
// @codeCoverageIgnoreEnd
3840
}
3941

4042
return $treeBuilder;

src/Bridge/Symfony/Bundle/Resources/config/services.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use CalendR\Bridge\Twig\CalendRExtension;
66
use CalendR\Calendar;
77
use CalendR\Event\EventManager;
8-
use CalendR\Period\PeriodPeriodFactory;
8+
use CalendR\Period\PeriodFactory;
99
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1010

1111
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
@@ -16,12 +16,12 @@
1616
->public();
1717

1818
$container->services()
19-
->set(PeriodPeriodFactory::class)
19+
->set(PeriodFactory::class)
2020
->public();
2121

2222
$container->services()
2323
->set(Calendar::class)
24-
->arg('$factory', service(PeriodPeriodFactory::class))
24+
->arg('$factory', service(PeriodFactory::class))
2525
->arg('$eventManager', service(EventManager::class))
2626
->public();
2727

@@ -35,7 +35,7 @@
3535
->public();
3636

3737
$container->services()
38-
->alias('calendr.factory', PeriodPeriodFactory::class)
38+
->alias('calendr.factory', PeriodFactory::class)
3939
->public();
4040

4141
$container->services()

src/Calendar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use CalendR\Period\Hour;
1212
use CalendR\Period\Minute;
1313
use CalendR\Period\Month;
14+
use CalendR\Period\PeriodFactory;
1415
use CalendR\Period\PeriodFactoryInterface;
1516
use CalendR\Period\PeriodInterface;
16-
use CalendR\Period\PeriodPeriodFactory;
1717
use CalendR\Period\Second;
1818
use CalendR\Period\Week;
1919
use CalendR\Period\Year;
@@ -26,7 +26,7 @@
2626
readonly class Calendar
2727
{
2828
public function __construct(
29-
protected PeriodFactoryInterface $factory = new PeriodPeriodFactory(),
29+
protected PeriodFactoryInterface $factory = new PeriodFactory(),
3030
private EventManager $eventManager = new EventManager(),
3131
) {
3232
}

src/Event/Collection/IndexedCollection.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ final class IndexedCollection implements CollectionInterface, \IteratorAggregate
4747
*/
4848
public function __construct(array $events = [], ?callable $callable = null)
4949
{
50-
$this->indexFunction = (static fn (\DateTimeInterface $dateTime): string => $dateTime->format('Y-m-d'));
51-
if (\is_callable($callable)) {
52-
$this->indexFunction = $callable;
53-
}
50+
$this->indexFunction = $callable ?? static fn (\DateTimeInterface $dateTime): string => $dateTime->format('Y-m-d');
5451

5552
foreach ($events as $event) {
5653
$this->add($event);

src/Period/Month.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getDays(): array
3333

3434
/**
3535
* Returns the first day of the first week of month.
36-
* First day of week is configurable via {@link PeriodPeriodFactory}.
36+
* First day of week is configurable via {@link PeriodFactory}.
3737
*/
3838
public function getFirstDayOfFirstWeek(): \DateTimeImmutable
3939
{
@@ -51,7 +51,7 @@ public function getExtendedMonth(): PeriodInterface
5151

5252
/**
5353
* Returns the last day of last week of month
54-
* First day of week is configurable via {@link PeriodPeriodFactory}.
54+
* First day of week is configurable via {@link PeriodFactory}.
5555
*/
5656
public function getLastDayOfLastWeek(): \DateTimeImmutable
5757
{

src/Period/PeriodAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function getEnd(): \DateTimeImmutable
110110
protected function getFactory(): PeriodFactoryInterface
111111
{
112112
if (null === $this->factory) {
113-
$this->factory = new PeriodPeriodFactory();
113+
$this->factory = new PeriodFactory();
114114
}
115115

116116
return $this->factory;

0 commit comments

Comments
 (0)