blackbirdchess-service-import/tests/Readers/Trf16Test.php

110 lines
3.8 KiB
PHP
Raw Normal View History

2023-01-21 16:46:41 +01:00
<?php
namespace Blackbirdchess\Tests\Service\Import\Readers;
use Blackbirdchess\Service\Import\Readers\Trf16;
use Blackbirdchess\Service\Results\Enums\Gender;
use Blackbirdchess\Service\Results\Enums\Title;
use DateTime;
use PHPUnit\Framework\TestCase;
class Trf16Test extends TestCase
{
private string $testfile = '/res/trf16-testfile.trf';
private Trf16 $testobject;
public function setUp(): void
{
$root = NULL;
$directory = dirname(__FILE__);
do {
$directory = dirname($directory);
$composer = $directory . '/composer.json';
if(file_exists($composer)) $root = $directory;
} while(is_null($root) && $directory != '/');
$this->testfile = $root . $this->testfile;
$this->testobject = new Trf16();
$this->testobject->read($this->testfile);
}
public function testReadTournamentName(): void
{
$this->assertEquals('Blackbird Chess Unit Test Tournament', $this->testobject->Tournament->Name);
}
public function testReadTournamentLocation(): void
{
$this->assertEquals('Waregem', $this->testobject->Tournament->OrganiserPlace);
}
public function testReadTournamentFederation(): void
{
$this->assertEquals('BEL', $this->testobject->Tournament->OrganiserCountry);
}
public function testReadTournamentStartDate(): void
{
$expected = DateTime::createFromFormat("Y/m/d", "2023/01/14");
$this->assertEquals($expected, $this->testobject->Tournament->StartDate);
}
public function testReadTournamentEndDate(): void
{
$expected = DateTime::createFromFormat("Y/m/d", "2023/01/14");
$this->assertEquals($expected, $this->testobject->Tournament->EndDate);
}
public function testReadTournamentArbiter(): void
{
$this->assertEquals("Jeroen De Meerleer", $this->testobject->Tournament->Arbiters[0]);
}
public function testReadTournamentDeputyArbiter(): void
{
$this->assertEquals("Jerry The Blackbird", $this->testobject->Tournament->Arbiters[1]);
}
public function testReadPlayerInitialRank(): void
{
$this->assertEquals(1, $this->testobject->Tournament->Players[0]->InitialRank);
}
public function testReadPlayerSex(): void
{
$this->assertEquals(Gender::MALE, $this->testobject->Tournament->Players[0]->Gender);
}
public function testReadPlayerTitle(): void
{
$this->assertEquals(Title::WIM, $this->testobject->Tournament->Players[1]->Title);
}
public function testReadPlayerName(): void
{
$this->assertEquals('Player 3', $this->testobject->Tournament->Players[0]->Name);
}
public function testReadPlayerRating(): void
{
$this->assertEquals(1850, $this->testobject->Tournament->Players[0]->getElo('Fide'));
}
public function testReadPlayerFederation(): void
{
$this->assertEquals('BEL', $this->testobject->Tournament->Players[0]->Nation);
}
public function testReadPlayerID(): void
{
$this->assertEquals('0', $this->testobject->Tournament->Players[0]->GetId('Fide'));
}
public function testReadPlayerBirthday(): void
{
$expected = DateTime::createFromFormat("Y/m/d", "1900/01/01");
$this->assertEquals($expected, $this->testobject->Tournament->Players[0]->DateOfBirth);
}
public function testReadPlayerPoints(): void
{
$this->assertEquals(7, $this->testobject->Tournament->Players[0]->Points);
}
public function testReadPlayerRank(): void
{
$this->assertEquals(3, $this->testobject->Tournament->Players[0]->Rank);
}
public function testReadPlayerPairing1Opponent(): void
{
$this->assertEquals($this->testobject->Tournament->Players[7], $this->testobject->Tournament->Players[0]->Pairings[0]->Opponent);
}
}