1
0
mirror of synced 2024-11-21 19:36:02 +03:00

fix serialization keys

This commit is contained in:
Alex Lushpai 2019-07-18 13:01:28 +03:00
parent 6c7cf52a65
commit 9286596157
4 changed files with 59 additions and 3 deletions

View File

@ -34,7 +34,7 @@
"autoload": {
"psr-4": {
"RetailCrm\\Mg\\": ["src/", "tests/"],
"RetailCrm\\Common\\": "src/"
"RetailCrm\\Common\\": ["src/", "tests/"]
},
"files": ["extra/autoloader.php"]
},

View File

@ -14,6 +14,7 @@
namespace RetailCrm\Common;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
@ -43,6 +44,7 @@ class Register
*
* @Type("string")
* @Accessor(getter="getIntegrationCode",setter="setIntegrationCode")
* @SerializedName("integrationCode")
*
* @Assert\NotBlank
*/
@ -84,6 +86,7 @@ class Register
*
* @Type("string")
* @Accessor(getter="getClientId",setter="setClientId")
* @SerializedName("clientId")
*
* @Assert\NotBlank
*/
@ -94,6 +97,7 @@ class Register
*
* @Type("string")
* @Accessor(getter="getBaseUrl",setter="setBaseUrl")
* @SerializedName("baseUrl")
*
* @Assert\NotBlank
* @Assert\Url(
@ -132,6 +136,7 @@ class Register
*
* @Type("array")
* @Accessor(getter="getAvailableCountries",setter="setAvailableCountries")
* @SerializedName("availableCountries")
* @SkipWhenEmpty
*/
private $availableCountries;

View File

@ -44,7 +44,7 @@ class Serializer
{
$serialized = null;
$serializer = SerializerBuilder::create()->build();
$context = self::getContext();
$context = self::getContext(false);
switch ($serialize) {
case self::S_ARRAY:
@ -93,7 +93,7 @@ class Serializer
*
* @return DeserializationContext|SerializationContext
*/
private static function getContext(bool $deserialization = false)
private static function getContext(bool $deserialization)
{
if ($deserialization) {
$context = new DeserializationContext();

View File

@ -0,0 +1,51 @@
<?php
/**
* PHP version 7.1
*
* Class RegisterTest
*
* @package RetailCrm\Common\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common\Tests;
use RetailCrm\Common\Register;
use PHPUnit\Framework\TestCase;
/**
* Class RegisterTest
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class RegisterTest extends TestCase
{
/**
* testGetArrayConfiguration
*/
public function testGetArrayConfiguration()
{
$register = new Register();
$register->setAccountUrl('https://example.com/settings');
$register->setActions(['ativity' => '/activity']);
$register->setActive(true);
$register->setBaseUrl('http:s//example.com');
$register->setClientId(hash('ripemd160', time()));
$register->setCode('somecode');
$register->setIntegrationCode('somecode');
$register->setLogo('https://example.com/logo.svg');
$register->setName('somename');
$array = $register->getArrayConfiguration();
self::assertArrayHasKey('baseUrl', $array);
self::assertArrayHasKey('integrationCode', $array);
self::assertArrayHasKey('clientId', $array);
}
}