Skip to content

Commit

Permalink
#14 GameUnitTest: Add testValid()
Browse files Browse the repository at this point in the history
  • Loading branch information
janis-rullis committed Oct 18, 2020
1 parent 05bbdf5 commit 95c2686
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
11 changes: 8 additions & 3 deletions symfony5/src/Entity/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,26 @@ class Game
* @SWG\Property(property="width", type="integer", example=3)
* @Groups({"CREATE", "PUB", "ID_ERROR"})
*/
private int $width;
private int $width = 3;

/**
* @ORM\Column(type="integer")
* @SWG\Property(property="height", type="integer", example=3)
* @Groups({"CREATE", "PUB", "ID_ERROR"})
*/
private int $height;
private int $height = 3;

/**
* @ORM\Column(type="integer", nullable=true)
* @SWG\Property(property="move_cnt_to_win", type="integer", example=3)
* @Groups({"CREATE", "PUB", "ID_ERROR"})
*/
private ?int $moveCntToWin = null;
private ?int $moveCntToWin;

public function getId(): ?int
{
return $this->id;
}

/**
* #14 Set games status like 'ongoing'.
Expand Down
28 changes: 28 additions & 0 deletions symfony5/src/Migrations/Version2020101819169.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version2020101819169 extends AbstractMigration
{
public function getDescription(): string
{
return '#14 game: allow the move_cnt_to_win to be null..';
}

public function up(Schema $schema): void
{
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql("ALTER TABLE `game` CHANGE `move_cnt_to_win` `move_cnt_to_win` TINYINT UNSIGNED NULL DEFAULT NULL COMMENT 'Must be no smaller than the min board dimensions or go outside the board. #14 #15'");
}

public function down(Schema $schema): void
{
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql("ALTER TABLE `game` CHANGE `move_cnt_to_win` TINYINT UNSIGNED NOT NULL DEFAULT 3 COMMENT 'Must be no smaller than the min board dimensions or go outside the board. #14 #15'");
}
}
9 changes: 9 additions & 0 deletions symfony5/tests/GameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ protected function setUp(): void
public function testValid()
{
$this->assertNull($this->gameRepo->getCurrentDraft());

$item = $this->gameRepo->insertDraftIfNotExist();
$this->assertGreaterThan(1, $item->getId());
$this->assertEquals(Game::DRAFT, $item->getStatus());
$this->assertEquals(3, $item->getWidth());
$this->assertEquals(3, $item->getHeight());

$item2 = $this->gameRepo->getCurrentDraft();
$this->assertEquals($item2->getId(), $item->getId());
}
}

0 comments on commit 95c2686

Please sign in to comment.