Skip to content

Commit

Permalink
#14 Link the Game Repo with Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
janis-rullis committed Oct 18, 2020
1 parent 4f82947 commit 05bbdf5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 27 deletions.
8 changes: 4 additions & 4 deletions symfony5/config/services_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

#12
test.App\Service\GameCreatorService:
alias: App\Service\GameCreatorService
public: true
#14
test.App\Interfaces\IGameRepo:
alias: App\Interfaces\IGameRepo
public: true
17 changes: 15 additions & 2 deletions symfony5/src/Entity/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
use Swagger\Annotations as SWG;
use Symfony\Component\Serializer\Annotation\Groups;

/**
* @ORM\Entity(repositoryClass="App\Repository\GameRepository")
* @ORM\Table(name="`game`")
*/
class Game
{
const DRAFT = 'draft';
Expand Down Expand Up @@ -40,10 +44,19 @@ class Game
const HEIGHT = 'height';
const HEIGHT_WIDTH = 'height_width';
const MOVE_CNT_TO_WIN = 'move_cnt_to_win';

/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @SWG\Property(property="id", type="integer", example=1)
* @Groups({"PUB"})
*/
private int $id;

/**
* @ORM\Column(type="string")
* @SWG\Property(property="status", type="string", example="ongoing", nullable=true)
* @ORM\Column(type="string", nullable=true)
* @SWG\Property(property="status", type="string", example="ongoing")
* @Groups({"CREATE", "PUB", "ID_ERROR"})
*/
private ?string $status = null;
Expand Down
17 changes: 7 additions & 10 deletions symfony5/src/Interfaces/IGameRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ public function setBoardDimensions(Game $item, int $width, int $height): Game;

public function setRules(Game $item, int $moveCntToWin): Game;

// public function insertDraftIfNotExist(int $customerId): Order;
//
// public function getCurrentDraft(int $customerId): ?Order;
//
// public function setOrderCostsFromCartItems(Order $order): bool;
//
// public function fillShipping(Order $order, array $shippingData): Order;
//
// public function save();
//
public function insertDraftIfNotExist(): Game;
public function getCurrentDraft(): ?Game;
public function mustFindCurrentDraft(): ?Game;


public function save();

// public function markAsCompleted(Order $order): Order;
//
// public function mustFindUsersOrder(int $userId, int $orderId): Order;
Expand Down
20 changes: 9 additions & 11 deletions symfony5/src/Repository/GameRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ public function setRules(Game $item, int $moveCntToWin): Game
*/
public function insertDraftIfNotExist(): Game
{
// #14 TODO: Uncomment this when the DB struct is ready.
// $item = $this->getCurrentDraft();
$item = $this->getCurrentDraft();

// #14 Create if it doesn't exist yet.
if (empty($item)) {
$item = new Game();
$item->setStatus(Game::DRAFT);
// #14 TODO: Uncomment this when the DB struct is ready.
// $this->em->persist($item);
// $this->em->flush();
$this->em->persist($item);
$this->em->flush();
}

if (empty($item)) {
Expand Down Expand Up @@ -88,13 +86,13 @@ public function mustFindCurrentDraft(): ?Game
}

/*
* #12 Shorthand to write to the database.
* #14 Shorthand to write to the database.
*/
// public function save()
// {
// $this->em->flush();
// $this->em->clear();
// }
public function save()
{
$this->em->flush();
$this->em->clear();
}

/*
* #12 Mark the game as completed.
Expand Down
27 changes: 27 additions & 0 deletions symfony5/tests/GameUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Tests;

use App\Entity\Game;
use App\Interfaces\IGameRepo;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class GameUnitTest extends KernelTestCase
{
private $c;
private $gameRepo ;

protected function setUp(): void
{
$kernel = self::bootKernel();
$this->c = $kernel->getContainer();
$this->gameRepo = $this->c->get('test.'.IGameRepo::class);
}

public function testValid()
{
$this->assertNull($this->gameRepo->getCurrentDraft());
}
}

0 comments on commit 05bbdf5

Please sign in to comment.