Finished test case, another method of entity validation
This commit is contained in:
parent
7d607063c8
commit
35ca05eb83
@ -203,11 +203,15 @@ class HttpClient
|
||||
*/
|
||||
private function validateRequest($class)
|
||||
{
|
||||
if (method_exists($class, 'validate')) {
|
||||
$errors = $class->validate();
|
||||
} else {
|
||||
$validator = Validation::createValidatorBuilder()
|
||||
->enableAnnotationMapping()
|
||||
->getValidator();
|
||||
|
||||
$errors = $validator->validate($class);
|
||||
}
|
||||
|
||||
if ($errors->count() > 0) {
|
||||
$message = (string) $errors;
|
||||
|
@ -14,6 +14,7 @@
|
||||
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
|
||||
|
||||
use LazyJsonMapper\LazyJsonMapper;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* PHP version 7.0
|
||||
|
@ -17,8 +17,10 @@ use RetailCrm\Mg\Bot\Model\Constants;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Channel;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Chat\Chat;
|
||||
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\Message\Message;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\User;
|
||||
use RetailCrm\Mg\Bot\Model\Request;
|
||||
use RetailCrm\Mg\Bot\Model\Response;
|
||||
use RetailCrm\Mg\Bot\Test\TestCase;
|
||||
@ -171,7 +173,12 @@ class ClientListTest extends TestCase
|
||||
*/
|
||||
public function testUsers()
|
||||
{
|
||||
$client = self::getApiClient();
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getJsonResponse('users')
|
||||
);
|
||||
|
||||
$request = new Request\UsersRequest();
|
||||
$request->setActive(1);
|
||||
@ -179,7 +186,8 @@ class ClientListTest extends TestCase
|
||||
|
||||
$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()
|
||||
{
|
||||
$client = self::getApiClient();
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getJsonResponse('dialogs')
|
||||
);
|
||||
|
||||
$request = new Request\DialogsRequest();
|
||||
$request->setActive(1);
|
||||
$request->setAssign(1);
|
||||
|
||||
$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()
|
||||
{
|
||||
$client = self::getApiClient();
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getJsonResponse('customers')
|
||||
);
|
||||
|
||||
$request = new Request\CustomersRequest();
|
||||
|
||||
$response = $client->customers($request);
|
||||
|
||||
print_r($response);
|
||||
self::assertEquals(2, $response->count());
|
||||
self::assertTrue($response[0] instanceof Customer);
|
||||
}
|
||||
}
|
||||
|
34
tests/Resources/customers.json
Normal file
34
tests/Resources/customers.json
Normal 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": ""
|
||||
}
|
||||
]
|
34
tests/Resources/dialogs.json
Normal file
34
tests/Resources/dialogs.json
Normal 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
|
||||
}
|
||||
]
|
23
tests/Resources/users.json
Normal file
23
tests/Resources/users.json
Normal 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
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user