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

73 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2023-01-14 15:37:01 +01:00
<?php
namespace Blackbirdchess\Tests\Service\Import\Readers;
use Blackbirdchess\Service\Import\IOFactory;
2023-01-14 15:37:01 +01:00
use Blackbirdchess\Service\Import\Readers\Swar5;
2023-01-14 16:08:44 +01:00
use Blackbirdchess\Service\Results\Enums\Title;
use Blackbirdchess\Service\Results\Player;
2023-01-14 15:37:01 +01:00
use PHPUnit\Framework\TestCase;
class Swar5Test extends TestCase
{
2023-01-14 16:41:46 +01:00
private string $testfile = '/res/Swar5-testfile.swar';
2023-01-14 15:37:01 +01:00
private Swar5 $testobject;
public function setUp(): void
{
2023-01-14 16:41:46 +01:00
$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 = $directory . $this->testfile;
$this->testobject = IOFactory::createReader('Swar-5');
2023-01-14 16:41:46 +01:00
$this->testobject->read($this->testfile);
2023-01-14 15:37:01 +01:00
}
public function testReadTournamentName(): void
{
$this->assertEquals('Blackbird Chess Unit Test Tournament', $this->testobject->Tournament->Name);
}
public function testReadTournamentOrganiser(): void
{
$this->assertEquals('Blackbird Chess Developers', $this->testobject->Tournament->Organiser);
}
public function testReadTournamentLocation(): void
{
$this->assertEquals('Waregem', $this->testobject->Tournament->OrganiserPlace);
}
public function testHas8Players(): void
{
$this->assertCount(8, $this->testobject->Tournament->Players);
}
public function testHas7Rounds(): void
{
$this->assertCount(7, $this->testobject->Tournament->Rounds);
}
2023-01-14 16:08:44 +01:00
public function testPlayerHas7Pairings(): void
{
$this->assertCount(7, $this->testobject->Tournament->Players[0]->Pairings);
}
public function testPlayerHasTitle(): void
{
2023-01-14 16:41:46 +01:00
$player = Player::PlayersByName('Player 1', $this->testobject->Tournament)[0];
$this->assertInstanceOf(Title::class, $player->Title);
}
public function testPlayerHasNoTitle(): void
{
$player = Player::PlayersByName('Player 3', $this->testobject->Tournament)[0];
$this->assertNull($player->Title);
2023-01-14 16:08:44 +01:00
}
2023-01-14 15:37:01 +01:00
}