Skip to content

Commit e59f23c

Browse files
committed
Added Tests
1 parent 2b8adde commit e59f23c

17 files changed

+487
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
vendor/
22
composer.lock
3+
.phpunit.result.cache
4+
.phpunit.cache

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,13 @@
2222
"require": {
2323
"php": "^7.3|^8.0",
2424
"ext-json": "*"
25+
},
26+
"require-dev": {
27+
"pestphp/pest": "^1.21"
28+
},
29+
"config": {
30+
"allow-plugins": {
31+
"pestphp/pest-plugin": true
32+
}
2533
}
2634
}

phpunit.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
>
7+
<testsuites>
8+
<testsuite name="Test Suite">
9+
<directory suffix="Test.php">./tests</directory>
10+
</testsuite>
11+
</testsuites>
12+
<coverage processUncoveredFiles="true">
13+
<include>
14+
<directory suffix=".php">./src</directory>
15+
</include>
16+
</coverage>
17+
</phpunit>

src/FluentEntity.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ abstract class FluentEntity implements \JsonSerializable
1111

1212
protected $defaults = [];
1313

14+
public function __construct(array $data = [])
15+
{
16+
$this->data = $data + $this->data;
17+
}
18+
1419
public static function make()
1520
{
1621
return new static;
@@ -25,6 +30,7 @@ public function __call($name, $arguments)
2530
return $this;
2631
}
2732

33+
#[\ReturnTypeWillChange]
2834
public function jsonSerialize()
2935
{
3036
return $this->data;

src/InlineKeyboard/InlineKeyboardButton.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@ class InlineKeyboardButton extends FluentEntity
2121
'pay' => true,
2222
];
2323

24+
public static function make(string $text = null)
25+
{
26+
$data = [];
27+
28+
if ($text) {
29+
$data['text'] = $text;
30+
}
31+
32+
return new static($data);
33+
}
34+
2435
}

src/InlineKeyboard/InlineKeyboardMarkup.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ class InlineKeyboardMarkup extends FluentEntity
1919
public function row(array $row = [])
2020
{
2121
$this->data['inline_keyboard'][] = $row;
22+
23+
return $this;
24+
}
25+
26+
public function button(InlineKeyboardButton $button)
27+
{
28+
$count = count($this->data['inline_keyboard']);
29+
if (count($this->data['inline_keyboard']) === 0) {
30+
$this->data['inline_keyboard'][] = [];
31+
$count++;
32+
}
33+
34+
$this->data['inline_keyboard'][$count - 1][] = $button;
35+
2236
return $this;
2337
}
2438

src/ReplyKeyboard/KeyboardButton.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,26 @@
66

77
/**
88
* @method self text(string $text)
9-
* @method self requestContact(bool $request_contact)
10-
* @method self requestLocation(bool $request_location)
11-
* @method self requestPoll(KeyboardButtonPollType $request_poll)
9+
* @method self requestContact(bool $request_contact = true)
10+
* @method self requestLocation(bool $request_location = true)
11+
* @method self requestPoll(KeyboardButtonPollType|array $request_poll = [])
1212
*/
1313
class KeyboardButton extends FluentEntity
1414
{
15+
protected $defaults = [
16+
'request_contact' => true,
17+
'request_location' => true,
18+
'request_poll' => [],
19+
];
1520

21+
public static function make(string $text = null)
22+
{
23+
$data = [];
24+
25+
if ($text) {
26+
$data['text'] = $text;
27+
}
28+
29+
return new static($data);
30+
}
1631
}

src/ReplyKeyboard/KeyboardButtonPollType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static function regular()
3131
]);
3232
}
3333

34+
#[\ReturnTypeWillChange]
3435
public function jsonSerialize()
3536
{
3637
return $this->data;

src/ReplyKeyboard/ReplyKeyboardMarkup.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ class ReplyKeyboardMarkup extends FluentEntity
3131
public function row(array $row = [])
3232
{
3333
$this->data['keyboard'][] = $row;
34+
35+
return $this;
36+
}
37+
38+
public function button(KeyboardButton $button)
39+
{
40+
$count = count($this->data['keyboard']);
41+
if ($count === 0) {
42+
$this->data['keyboard'][] = [];
43+
$count++;
44+
}
45+
46+
$this->data['keyboard'][$count - 1][] = $button;
47+
3448
return $this;
3549
}
3650

tests/Pest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Test Case
6+
|--------------------------------------------------------------------------
7+
|
8+
| The closure you provide to your test functions is always bound to a specific PHPUnit test
9+
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
10+
| need to change it using the "uses()" function to bind a different classes or traits.
11+
|
12+
*/
13+
14+
// uses(Tests\TestCase::class)->in('Feature');
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Expectations
19+
|--------------------------------------------------------------------------
20+
|
21+
| When you're writing tests, you often need to check that values meet certain conditions. The
22+
| "expect()" function gives you access to a set of "expectations" methods that you can use
23+
| to assert different things. Of course, you may extend the Expectation API at any time.
24+
|
25+
*/
26+
27+
expect()->extend('toBeJsonSerializable', function () {
28+
return $this->jsonSerialize()->toBeArray();
29+
});
30+
31+
/*
32+
|--------------------------------------------------------------------------
33+
| Functions
34+
|--------------------------------------------------------------------------
35+
|
36+
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
37+
| project that you don't want to repeat in every file. Here you can also expose helpers as
38+
| global functions to help you to reduce the number of lines of code in your test files.
39+
|
40+
*/
41+
42+
function something()
43+
{
44+
// ..
45+
}

0 commit comments

Comments
 (0)