diff --git a/.gitignore b/.gitignore index b5ebe21..9ad8f32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea -/vendor/ \ No newline at end of file +/vendor/ +composer.lock +.phpunit.result.cache \ No newline at end of file diff --git a/composer.json b/composer.json index 2f64ca3..e21caa6 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,26 @@ { "name": "madmagestelegram/types", "description": "Representation of telegram bot types in php classes", + "keywords": [ + "telegram", + "types", + "rpc", + "php" + ], "type": "library", "license": "MIT", "require": { - "php": "^7.2|^8.0", + "php": ">=7.4", "ext-json": "*", "jms/serializer": "^3.1" }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, "autoload": { "psr-4": { - "MadmagesTelegram\\Types\\": "src/" + "MadmagesTelegram\\Types\\": "src/", + "Tests\\": "tests/" } } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..6770863 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,23 @@ + + + + + ./app + + + + + ./tests + + + diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php new file mode 100644 index 0000000..377b9fd --- /dev/null +++ b/tests/BaseTestCase.php @@ -0,0 +1,21 @@ +sendMessage(1, 'test'); + self::assertSame($sampleData, self::clearNullFields($data)); + } + + public function testTypedClient(): void + { + $message = (new TestTypesClient())->sendMessage(1, 'test'); + self::assertSame(TestTypesClient::SAMPLE_DATA, self::clearNullFields($message->_getData())); + } + + public function clientDataProvider(): array + { + return [ + [ + [ + 'sendMessage', + [ + 'chat_id' => 1, + 'text' => 'test', + ], + ], + ], + ]; + } +} \ No newline at end of file diff --git a/tests/Clients/TestClient.php b/tests/Clients/TestClient.php new file mode 100644 index 0000000..bf766c5 --- /dev/null +++ b/tests/Clients/TestClient.php @@ -0,0 +1,13 @@ + 1, + 'from' => + [ + 'id' => 1, + 'is_bot' => true, + 'first_name' => 'test', + 'username' => 'test', + ], + 'date' => 1, + 'chat' => + [ + 'id' => 1, + 'type' => 'private', + 'username' => 'test', + 'first_name' => 'test', + ], + 'text' => 'test', + ]; + + public function _apiCall(string $method, array $parameters): string + { + return json_encode(self::SAMPLE_DATA, JSON_THROW_ON_ERROR); + } +} \ No newline at end of file diff --git a/tests/Types/MessageTest.php b/tests/Types/MessageTest.php new file mode 100644 index 0000000..b12a018 --- /dev/null +++ b/tests/Types/MessageTest.php @@ -0,0 +1,51 @@ +_getData()); + + self::assertSame($sampleMessage, $messageData); + self::assertSame($message->getFrom()->getUsername(), 'test'); + } + + public function messageDataProvider(): array + { + return [ + [ + [ + 'message_id' => 1, + 'from' => + [ + 'id' => 1, + 'is_bot' => true, + 'first_name' => 'test', + 'username' => 'test', + ], + 'date' => 1, + 'chat' => + [ + 'id' => 1, + 'type' => 'private', + 'username' => 'test', + 'first_name' => 'test', + ], + 'text' => 'test', + ], + ], + ]; + } +} \ No newline at end of file