Skip to content

Commit

Permalink
Testing and a bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
koencaerels committed Feb 6, 2024
1 parent 1dffff9 commit 99ce5f1
Show file tree
Hide file tree
Showing 14 changed files with 471 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function hydrateFromJson(\stdClass $json): self
trim($json->remarks),
boolval($json->isJudogiBelt),
floatval($json->newMemberFee),
boolval($json->isSendMail),
boolval($json->sendMail),
);
}

Expand Down
37 changes: 37 additions & 0 deletions tests/Unit/YoshiKan/Domain/Model/Common/ChecksumEntityTest.php
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
<?php

/*
* This file is part of the Yoshi-Kan software.
*
* (c) Koen Caerels
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use App\YoshiKan\Domain\Model\Common\ChecksumEntity;

it('creates a content code', function () {

$checksumEntity = new class () {
use ChecksumEntity;

private string $firstname = 'firstname';
private string $lastname = 'lastname';
private \DateTime $createdAt;
private \DateTime $updatedAt;

public function __construct()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
};
$contentString = hash('sha256', $_ENV['APP_SECRET']);
$contentString .= 'firstname';
$contentString .= 'lastname';
$checksum = md5($contentString);
$checksumEntity->setChecksum();

expect($checksumEntity->getChecksum())->toBe($checksum);

})->group('unit');
25 changes: 25 additions & 0 deletions tests/Unit/YoshiKan/Domain/Model/Common/IdEntityTest.php
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
<?php

/*
* This file is part of the Yoshi-Kan software.
*
* (c) Koen Caerels
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use App\YoshiKan\Domain\Model\Common\IdEntity;
use Symfony\Component\Uid\Uuid;

it('creates identifiers for an object', function () {

$entityId = new class () {
use IdEntity;
};
$uuid = Uuid::v4();
$entityId->identify(1, $uuid);

expect($entityId->getId())->toBe(1)
->and($entityId->getUuid())->toBe($uuid);

})->group('unit');
21 changes: 21 additions & 0 deletions tests/Unit/YoshiKan/Domain/Model/Common/SequenceEntityTest.php
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
<?php

/*
* This file is part of the Yoshi-Kan software.
*
* (c) Koen Caerels
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use App\YoshiKan\Domain\Model\Common\SequenceEntity;

it('creates sequences for an object', function () {

$sequenceEntity = new class () {
use SequenceEntity;
};
$sequenceEntity->setSequence(1);
expect($sequenceEntity->getSequence())->toBe(1);

})->group('unit');
41 changes: 41 additions & 0 deletions tests/Unit/YoshiKan/Domain/Model/Member/FederationTest.php
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
<?php

use App\YoshiKan\Domain\Model\Member\Federation;
use Symfony\Component\Uid\Uuid;

it('can create a federation', function () {
$uuid = Uuid::v4();
$federation = Federation::make(
uuid: $uuid,
sequence: 1,
code: 'JV',
name: 'Judo Vlaanderen',
yearlySubscriptionFee: 49,
publicLabel: 'Competitie'
);
expect($federation->getCode())->toBe('JV')
->and($federation->getName())->toBe('Judo Vlaanderen')
->and($federation->getYearlySubscriptionFee())->toBe(49)
->and($federation->getPublicLabel())->toBe('Competitie');
});

it('can change federation attributes', function () {
$uuid = Uuid::v4();
$federation = Federation::make(
uuid: $uuid,
sequence: 1,
code: 'JV',
name: 'Judo Vlaanderen',
yearlySubscriptionFee: 49,
publicLabel: 'Competitie'
);
$federation->change(
code: 'JJ',
name: 'Judo Japan',
yearlySubscriptionFee: 59,
publicLabel: 'Competition'
);
expect($federation->getCode())->toBe('JJ')
->and($federation->getName())->toBe('Judo Japan')
->and($federation->getYearlySubscriptionFee())->toBe(59)
->and($federation->getPublicLabel())->toBe('Competition');
});
1 change: 0 additions & 1 deletion tests/Unit/YoshiKan/Domain/Model/Member/GenderTest.php

This file was deleted.

26 changes: 26 additions & 0 deletions tests/Unit/YoshiKan/Domain/Model/Member/GradeLogTest.php
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
<?php

use App\Tests\Unit\YoshiKan\Domain\Model\ModelFactory;
use App\YoshiKan\Domain\Model\Member\GradeLog;
use Symfony\Component\Uid\Uuid;

it('can create a grade log', function () {
$uuid = Uuid::v4();
$member = ModelFactory::makeMember(Uuid::v4());
$fromGrade = ModelFactory::makeGrade(Uuid::v4());
$toGrade = ModelFactory::makeGrade(Uuid::v4());
$date = new \DateTimeImmutable();
$remark = 'Promoted to next grade';
$gradeLog = GradeLog::make(
uuid: $uuid,
date: $date,
remark: $remark,
member: $member,
fromGrade: $fromGrade,
toGrade: $toGrade
);
expect($gradeLog->getDate())->toBe($date)
->and($gradeLog->getRemark())->toBe($remark)
->and($gradeLog->getMember())->toBe($member)
->and($gradeLog->getFromGrade())->toBe($fromGrade)
->and($gradeLog->getToGrade())->toBe($toGrade);
});
34 changes: 34 additions & 0 deletions tests/Unit/YoshiKan/Domain/Model/Member/GradeTest.php
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
<?php

use App\YoshiKan\Domain\Model\Member\Grade;
use Symfony\Component\Uid\Uuid;

it('can create a grade', function () {
$uuid = Uuid::v4();
$grade = Grade::make(
uuid: $uuid,
code: '1K',
name: '1e Kyu',
color: 'brown'
);
expect($grade->getCode())->toBe('1K')
->and($grade->getName())->toBe('1e Kyu')
->and($grade->getColor())->toBe('brown');
});

it('can change grade attributes', function () {
$uuid = Uuid::v4();
$grade = Grade::make(
uuid: $uuid,
code: '1K',
name: '1e Kyu',
color: 'brown'
);
$grade->change(
code: '2K',
name: '2e Kyu',
color: 'green'
);
expect($grade->getCode())->toBe('2K')
->and($grade->getName())->toBe('2e Kyu')
->and($grade->getColor())->toBe('green');
});
39 changes: 39 additions & 0 deletions tests/Unit/YoshiKan/Domain/Model/Member/GroupTest.php
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
<?php

use App\YoshiKan\Domain\Model\Member\Group;
use Symfony\Component\Uid\Uuid;

it('can create a group', function () {
$uuid = Uuid::v4();
$group = Group::make(
uuid: $uuid,
code: 'adults',
name: 'Adults Group',
minAge: 18,
maxAge: 99
);
expect($group->getCode())->toBe('adults')
->and($group->getName())->toBe('Adults Group')
->and($group->getMinAge())->toBe(18)
->and($group->getMaxAge())->toBe(99);
});

it('can change group attributes', function () {
$uuid = Uuid::v4();
$group = Group::make(
uuid: $uuid,
code: 'adults',
name: 'Adults Group',
minAge: 18,
maxAge: 99
);
$group->change(
code: 'seniors',
name: 'Seniors Group',
minAge: 60,
maxAge: 99
);
expect($group->getCode())->toBe('seniors')
->and($group->getName())->toBe('Seniors Group')
->and($group->getMinAge())->toBe(60)
->and($group->getMaxAge())->toBe(99);
});
29 changes: 29 additions & 0 deletions tests/Unit/YoshiKan/Domain/Model/Member/LocationTest.php
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
<?php

use App\YoshiKan\Domain\Model\Member\Location;
use Symfony\Component\Uid\Uuid;

it('can create a location', function () {
$uuid = Uuid::v4();
$location = Location::make(
uuid: $uuid,
code: 'dojo',
name: 'Dojo Location'
);
expect($location->getCode())->toBe('dojo')
->and($location->getName())->toBe('Dojo Location');
});

it('can change location attributes', function () {
$uuid = Uuid::v4();
$location = Location::make(
uuid: $uuid,
code: 'dojo',
name: 'Dojo Location'
);
$location->change(
code: 'gym',
name: 'Gym Location'
);
expect($location->getCode())->toBe('gym')
->and($location->getName())->toBe('Gym Location');
});
108 changes: 108 additions & 0 deletions tests/Unit/YoshiKan/Domain/Model/Member/MemberTest.php
Original file line number Diff line number Diff line change
@@ -1 +1,109 @@
<?php

use App\Tests\Unit\YoshiKan\Domain\Model\ModelFactory;
use App\YoshiKan\Domain\Model\Member\Gender;
use App\YoshiKan\Domain\Model\Member\Member;
use App\YoshiKan\Domain\Model\Member\MemberStatus;
use Symfony\Component\Uid\Uuid;

it('can create a member', function () {
$uuid = Uuid::v4();
$grade = ModelFactory::makeGrade(Uuid::v4());
$location = ModelFactory::makeLocation(Uuid::v4());
$federation = ModelFactory::makeFederation(Uuid::v4());
$gender = Gender::M;

$member = Member::make(
uuid: $uuid,
firstname: 'John',
lastname: 'Doe',
dateOfBirth: new \DateTimeImmutable('1990-01-01'),
gender: $gender,
grade: $grade,
location: $location,
federation: $federation,
email: '[email protected]',
nationalRegisterNumber: '12345678901',
addressStreet: 'Main Street',
addressNumber: '123',
addressBox: '',
addressZip: '12345',
addressCity: 'Anytown',
numberOfTraining: 10,
);
expect($member->getFirstname())->toBe('John')
->and($member->getLastname())->toBe('Doe')
->and($member->getDateOfBirth())->toBeInstanceOf(\DateTimeImmutable::class)
->and($member->getGender())->toBe(Gender::M)
->and($member->getGrade())->toBe($grade)
->and($member->getLocation())->toBe($location)
->and($member->getFederation())->toBe($federation)
->and($member->getEmail())->toBe('[email protected]')
->and($member->getNationalRegisterNumber())->toBe('12345678901')
->and($member->getAddressStreet())->toBe('Main Street')
->and($member->getAddressNumber())->toBe('123')
->and($member->getAddressZip())->toBe('12345')
->and($member->getAddressCity())->toBe('Anytown')
->and($member->getNumberOfTraining())->toBe(10);
});

it('can change member details', function () {
$uuid = Uuid::v4();
$grade = ModelFactory::makeGrade(Uuid::v4());
$location = ModelFactory::makeLocation(Uuid::v4());
$federation = ModelFactory::makeFederation(Uuid::v4());
$gender = Gender::M;
$member = Member::make(
uuid: $uuid,
firstname: 'John',
lastname: 'Doe',
dateOfBirth: new \DateTimeImmutable('1990-01-01'),
gender: $gender,
grade: $grade,
location: $location,
federation: $federation,
email: '[email protected]',
nationalRegisterNumber: '12345678901',
addressStreet: 'Main Street',
addressNumber: '123',
addressBox: '',
addressZip: '12345',
addressCity: 'Anytown',
numberOfTraining: 10,
);
$member->changeDetails(
firstname: 'Jane',
lastname: 'Smith',
gender: Gender::V,
dateOfBirth: new \DateTimeImmutable('1995-05-05'),
status: MemberStatus::ACTIVE,
location: ModelFactory::makeLocation(Uuid::v4()),
nationalRegisterNumber: '98765432109',
email: '[email protected]',
addressStreet: 'New Avenue',
addressNumber: '456',
addressBox: 'A',
addressZip: '54321',
addressCity: 'Newtown',
contactFirstname: 'John',
contactLastname: 'Doe',
contactEmail: '[email protected]',
contactPhone: '123456789',
);
expect($member->getFirstname())->toBe('Jane')
->and($member->getLastname())->toBe('Smith')
->and($member->getDateOfBirth())->toBeInstanceOf(\DateTimeImmutable::class)
->and($member->getGender())->toBe(Gender::V)
->and($member->getStatus())->toBe(MemberStatus::ACTIVE)
->and($member->getLocation())->not()->toBe($location)
->and($member->getNationalRegisterNumber())->toBe('98765432109')
->and($member->getEmail())->toBe('[email protected]')
->and($member->getAddressStreet())->toBe('New Avenue')
->and($member->getAddressNumber())->toBe('456')
->and($member->getAddressZip())->toBe('54321')
->and($member->getAddressCity())->toBe('Newtown')
->and($member->getContactFirstname())->toBe('John')
->and($member->getContactLastname())->toBe('Doe')
->and($member->getContactEmail())->toBe('[email protected]')
->and($member->getContactPhone())->toBe('123456789');
});
Loading

0 comments on commit 99ce5f1

Please sign in to comment.