Compare commits

..

2 Commits

Author SHA1 Message Date
b6c9be66cb
BUGFIX: checking for the composer root 2023-01-14 16:41:46 +01:00
c1db2253ce
Added tests with titles 2023-01-14 16:40:15 +01:00
4 changed files with 42 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,8 @@
namespace Blackbirdchess\Tests\Service\Import\Readers; namespace Blackbirdchess\Tests\Service\Import\Readers;
use Blackbirdchess\Service\Import\Readers\Pairtwo6; use Blackbirdchess\Service\Import\Readers\Pairtwo6;
use Blackbirdchess\Service\Results\Enums\Title;
use Blackbirdchess\Service\Results\Player;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Pairtwo6Test extends TestCase class Pairtwo6Test extends TestCase
@ -12,7 +14,15 @@ class Pairtwo6Test extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->testfile = getcwd() . $this->testfile; $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 Pairtwo6(); $this->testobject = new Pairtwo6();
$this->testobject->read($this->testfile); $this->testobject->read($this->testfile);
} }
@ -46,4 +56,16 @@ class Pairtwo6Test extends TestCase
{ {
$this->assertCount(7, $this->testobject->Tournament->Players[0]->Pairings); $this->assertCount(7, $this->testobject->Tournament->Players[0]->Pairings);
} }
public function testPlayerHasTitle(): void
{
$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);
}
} }

View File

@ -9,14 +9,22 @@ use PHPUnit\Framework\TestCase;
class Swar5Test extends TestCase class Swar5Test extends TestCase
{ {
private string $swarfile = '/res/Swar5-testfile.swar'; private string $testfile = '/res/Swar5-testfile.swar';
private Swar5 $testobject; private Swar5 $testobject;
public function setUp(): void public function setUp(): void
{ {
$this->swarfile = getcwd() . $this->swarfile; $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 = new Swar5(); $this->testobject = new Swar5();
$this->testobject->read($this->swarfile); $this->testobject->read($this->testfile);
} }
public function testReadTournamentName(): void public function testReadTournamentName(): void
@ -51,7 +59,13 @@ class Swar5Test extends TestCase
public function testPlayerHasTitle(): void public function testPlayerHasTitle(): void
{ {
$player1 = Player::PlayersByName('Player 1', $this->testobject->Tournament)[0]; $player = Player::PlayersByName('Player 1', $this->testobject->Tournament)[0];
$this->assertInstanceOf(Title::class, $player1->Title); $this->assertInstanceOf(Title::class, $player->Title);
}
public function testPlayerHasNoTitle(): void
{
$player = Player::PlayersByName('Player 3', $this->testobject->Tournament)[0];
$this->assertNull($player->Title);
} }
} }