Skip to content

Commit

Permalink
Feature / Telegram Dice domains
Browse files Browse the repository at this point in the history
  • Loading branch information
glavvra4 committed Dec 16, 2023
1 parent 374208b commit 38774a7
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 0 deletions.
20 changes: 20 additions & 0 deletions core/Telegram/Message/Entity/Dice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Core\Telegram\Message\Entity;

/** This object represents an animated emoji that displays a random value. */
readonly class Dice implements DiceInterface
{
/**
* @param Dice\Emoji $emoji
* @param Dice\Value $value
*/
public function __construct(
public Dice\Emoji $emoji,
public Dice\Value $value,
)
{
}
}
12 changes: 12 additions & 0 deletions core/Telegram/Message/Entity/Dice/Emoji.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Core\Telegram\Message\Entity\Dice;

use Core\Common\Entity\StringValueObject;

/** Emoji on which the dice throw animation is based */
class Emoji extends StringValueObject
{
}
12 changes: 12 additions & 0 deletions core/Telegram/Message/Entity/Dice/Value.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Core\Telegram\Message\Entity\Dice;

use Core\Common\Entity\IntValueObject;

/** Value of the dice, 1-6 for “🎲”, “🎯” and “🎳” base emoji, 1-5 for “🏀” and “⚽” base emoji, 1-64 for “🎰” base emoji */
class Value extends IntValueObject
{
}
9 changes: 9 additions & 0 deletions core/Telegram/Message/Entity/DiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Core\Telegram\Message\Entity;

interface DiceInterface
{
}
24 changes: 24 additions & 0 deletions core/Telegram/Message/Proxy/Dice/AssociativeArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Core\Telegram\Message\Proxy\Dice;

use Core\Telegram\Message\Entity\Dice;
use JetBrains\PhpStorm\ArrayShape;

readonly class AssociativeArray extends Dice
{
public function __construct(
#[ArrayShape([
'emoji' => 'string',
'value' => 'int',
])] array $data
)
{
parent::__construct(
new Dice\Emoji($data['emoji']),
new Dice\Value($data['value'])
);
}
}
31 changes: 31 additions & 0 deletions tests-core/Telegram/Message/Entity/DiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Core\Tests\Telegram\Message\Entity;

use Core\Telegram\Message\Entity\Contact;
use Core\Telegram\Message\Entity\Dice;
use Core\Telegram\User\Entity\User;
use PHPUnit\Framework\TestCase;

class DiceTest extends TestCase
{
public function testGetValues()
{
$object = new Dice(
new Dice\Emoji('emoji'),
new Dice\Value(10),
);

$this->assertEquals(
'emoji',
$object->emoji->getValue()
);

$this->assertEquals(
10,
$object->value->getValue()
);
}
}
29 changes: 29 additions & 0 deletions tests-core/Telegram/Message/Proxy/Dice/AssociativeArrayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Core\Tests\Telegram\Message\Proxy\Dice;

use Core\Telegram\Message\Proxy\Dice\AssociativeArray;
use PHPUnit\Framework\TestCase;

class AssociativeArrayTest extends TestCase
{
public function testGetValues()
{
$object = new AssociativeArray([
'emoji' => 'emoji',
'value' => 10,
]);

$this->assertEquals(
'emoji',
$object->emoji->getValue()
);

$this->assertEquals(
10,
$object->value->getValue()
);
}
}

0 comments on commit 38774a7

Please sign in to comment.