1
0
mirror of synced 2024-11-25 13:16:01 +03:00

Finished test case, another method of entity validation

This commit is contained in:
Pavel 2019-06-18 13:56:31 +03:00
parent 7d607063c8
commit 35ca05eb83
6 changed files with 127 additions and 9 deletions

View File

@ -203,11 +203,15 @@ class HttpClient
*/ */
private function validateRequest($class) private function validateRequest($class)
{ {
if (method_exists($class, 'validate')) {
$errors = $class->validate();
} else {
$validator = Validation::createValidatorBuilder() $validator = Validation::createValidatorBuilder()
->enableAnnotationMapping() ->enableAnnotationMapping()
->getValidator(); ->getValidator();
$errors = $validator->validate($class); $errors = $validator->validate($class);
}
if ($errors->count() > 0) { if ($errors->count() > 0) {
$message = (string) $errors; $message = (string) $errors;

View File

@ -14,6 +14,7 @@
namespace RetailCrm\Mg\Bot\Model\Entity\Message; namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use LazyJsonMapper\LazyJsonMapper; use LazyJsonMapper\LazyJsonMapper;
use Symfony\Component\Validator\Validation;
/** /**
* PHP version 7.0 * PHP version 7.0

View File

@ -17,8 +17,10 @@ use RetailCrm\Mg\Bot\Model\Constants;
use RetailCrm\Mg\Bot\Model\Entity\Channel; use RetailCrm\Mg\Bot\Model\Entity\Channel;
use RetailCrm\Mg\Bot\Model\Entity\Chat\Chat; use RetailCrm\Mg\Bot\Model\Entity\Chat\Chat;
use RetailCrm\Mg\Bot\Model\Entity\Chat\ChatMember; use RetailCrm\Mg\Bot\Model\Entity\Chat\ChatMember;
use RetailCrm\Mg\Bot\Model\Entity\Customer;
use RetailCrm\Mg\Bot\Model\Entity\Dialog; use RetailCrm\Mg\Bot\Model\Entity\Dialog;
use RetailCrm\Mg\Bot\Model\Entity\Message\Message; use RetailCrm\Mg\Bot\Model\Entity\Message\Message;
use RetailCrm\Mg\Bot\Model\Entity\User;
use RetailCrm\Mg\Bot\Model\Request; use RetailCrm\Mg\Bot\Model\Request;
use RetailCrm\Mg\Bot\Model\Response; use RetailCrm\Mg\Bot\Model\Response;
use RetailCrm\Mg\Bot\Test\TestCase; use RetailCrm\Mg\Bot\Test\TestCase;
@ -171,7 +173,12 @@ class ClientListTest extends TestCase
*/ */
public function testUsers() public function testUsers()
{ {
$client = self::getApiClient(); $client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('users')
);
$request = new Request\UsersRequest(); $request = new Request\UsersRequest();
$request->setActive(1); $request->setActive(1);
@ -179,7 +186,8 @@ class ClientListTest extends TestCase
$response = $client->users($request); $response = $client->users($request);
print_r($response); self::assertEquals(2, $response->count());
self::assertTrue($response[0] instanceof User);
} }
/** /**
@ -188,13 +196,21 @@ class ClientListTest extends TestCase
*/ */
public function testDialogs() public function testDialogs()
{ {
$client = self::getApiClient(); $client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('dialogs')
);
$request = new Request\DialogsRequest(); $request = new Request\DialogsRequest();
$request->setActive(1); $request->setActive(1);
$request->setAssign(1); $request->setAssign(1);
$response = $client->dialogs($request); $response = $client->dialogs($request);
self::assertEquals(2, $response->count());
self::assertTrue($response[0] instanceof Dialog);
} }
/** /**
@ -203,12 +219,18 @@ class ClientListTest extends TestCase
*/ */
public function testCustomers() public function testCustomers()
{ {
$client = self::getApiClient(); $client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('customers')
);
$request = new Request\CustomersRequest(); $request = new Request\CustomersRequest();
$response = $client->customers($request); $response = $client->customers($request);
print_r($response); self::assertEquals(2, $response->count());
self::assertTrue($response[0] instanceof Customer);
} }
} }

View File

@ -0,0 +1,34 @@
[
{
"id": 39,
"external_id": "333296016",
"channel_id": 3,
"username": "user1",
"first_name": "User1",
"last_name": "Lastname1",
"created_at": "2019-06-11T12:49:26.935824Z",
"updated_at": "2019-06-11T14:36:20.840304Z",
"avatar_url": "",
"profile_url": "",
"country": "",
"language": "en",
"phone": "",
"email": ""
},
{
"id": 38,
"external_id": "2272664739519803",
"channel_id": 3,
"username": "user2",
"first_name": "User2",
"last_name": "Lastname2",
"created_at": "2019-06-11T07:34:16.079453Z",
"updated_at": "2019-06-13T08:07:14.898472Z",
"avatar_url": "",
"profile_url": "",
"country": "",
"language": "ru",
"phone": "",
"email": ""
}
]

View File

@ -0,0 +1,34 @@
[
{
"id": 60,
"chat_id": 30,
"begin_message_id": 3540,
"ending_message_id": 3625,
"created_at": "2019-06-11T12:49:26.955306Z",
"updated_at": "2019-06-14T14:40:28.711974Z",
"closed_at": "2019-06-14T14:40:28.684683Z",
"is_assigned": true,
"responsible": {
"type": "user",
"id": 12,
"assigned_at": "2019-06-11T12:49:34.716716Z"
},
"is_active": true
},
{
"id": 59,
"chat_id": 29,
"begin_message_id": 3483,
"ending_message_id": 3626,
"created_at": "2019-06-11T07:34:16.101228Z",
"updated_at": "2019-06-16T08:10:28.659389Z",
"closed_at": "2019-06-16T08:10:28.645607Z",
"is_assigned": true,
"responsible": {
"type": "user",
"id": 12,
"assigned_at": "2019-06-11T08:40:14.136916Z"
},
"is_active": true
}
]

View File

@ -0,0 +1,23 @@
[
{
"id": 1,
"external_id": "11",
"username": "User 1",
"first_name": "User",
"created_at": "2018-10-02T10:10:10.066295Z",
"updated_at": "2019-06-17T07:40:26.613546Z",
"is_online": false,
"is_active": true,
"avatar_url": "<url>"
},
{
"id": 2,
"external_id": "22",
"username": "User 2",
"first_name": "User",
"created_at": "2018-09-06T13:19:25.01842Z",
"updated_at": "2019-06-07T11:36:52.342065Z",
"is_online": false,
"is_active": true
}
]