Download the PHP package aik27/drom-client without Composer
On this page you can find all versions of the php package aik27/drom-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aik27/drom-client
More information about aik27/drom-client
Files in aik27/drom-client
Package drom-client
Short Description Drom client is a PHP HTTP client library for test assignment
License MIT
Informations about the package drom-client
Задание №2:
Условие:
Необходимо реализовать клиент для абстрактного (вымышленного) сервиса комментариев "example.com".
Проект должен представлять класс или набор классов, который будет делать http запросы к серверу. На выходе должна получиться библиотека, который можно будет подключить через composer к любому другому проекту.
У этого сервиса есть 3 метода:
- GET http://example.com/comments - возвращает список комментариев
- POST http://example.com/comment - добавить комментарий.
- PUT http://example.com/comment/{id} - по идентификатору комментария обновляет поля, которые были в в запросе
Объект comment содержит поля:
- id - тип int. Не нужно указывать при добавлении.
- name - тип string.
- text - тип string.
Написать phpunit тесты, на которых будет проверяться работоспособность клиента. Сервер example.com писать не надо! Только библиотеку для работы с ним.
Решение задания
Клиент написан с нуля, оформлен в библиотеку и опубликован на Packagist: https://packagist.org/packages/aik27/drom-client
При анализе условий задания было решено немного его усложнить. В частности, сделать так, чтобы клиент был более гибким и универсальным, а не ограничивался работой только с комментариями и перечисленными адресами.
Для этого были реализованы следующие возможности:
- Создание разных конфигураций клиента через экземпляры класса
Config
с возможностью смены целевых адресов и контекста применения. - Создание разных сценариев валидации данных перед отправкой на сервер через экземпляры класса
Scenario
- Использование взаимозаменяемых адаптеров для работы с разными HTTP библиотеками (
GuzzleClient
иSymfonyClient
) и возможность создать собственный на основе общего интерфейса. - Использование взаимозаменяемых валидаторов ответа сервера (
JsonValidator
,XmlValidator
) и возможность создать собственный на основе общего интерфейса.
Установка
Применение
PHPUnit тесты
Написано 26 тестов покрывающие различные варианты конфигурации, сценарии валидации и запросы.
All versions of drom-client with dependencies
phpunit/phpunit Version ^9.5
guzzlehttp/guzzle Version ^7.4
symfony/http-client Version ^5.3