Skip to content

fix: Proper-case primitive from DocuSign API causes fatal error #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
"firebase/php-jwt": "^5.0 || ^6.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8",
"satooshi/php-coveralls": "~1.0",
"phpunit/phpunit": "~9.0",
"php-coveralls/php-coveralls": "~2.0",
"squizlabs/php_codesniffer": "~2.6",
"friendsofphp/php-cs-fixer": "*"
},
"autoload": {
"psr-4": { "DocuSign\\eSign\\" : "src/" }
},
"autoload-dev": {
"psr-4": { "DocuSign\\eSign\\" : "test/" }
"psr-4": { "DocuSign\\eSign\\Test\\" : "test/" }
}
}
9 changes: 8 additions & 1 deletion src/ObjectSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ public static function deserialize($data, string $class, ?array $httpHeaders = n
} else {
return null;
}
} elseif (in_array($class, ['?bool', '?int', '?string', 'DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
} elseif ($class === 'DateTime' || in_array(strtolower($class), ['?bool', '?int', '?string', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'object', 'string', 'void'], true)) {
$class = $class !== 'DateTime' ? strtolower($class) : $class;
if ($class === 'void') {
$class = 'null';
}
$class=trim($class,"?");
settype($data, $class);
return $data;
Expand Down Expand Up @@ -305,6 +309,9 @@ public static function deserialize($data, string $class, ?array $httpHeaders = n
return $data;
} else {
// If a discriminator is defined and points to a valid subclass, use it.
if (in_array($class, ['Number', 'Date'])) {
$class = '\DocuSign\eSign\Model\\' . $class;
}
$discriminator = $class::DISCRIMINATOR;
if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) {
$subclass = 'DocuSign\eSign\Model\\' . $data->{$discriminator};
Expand Down
27 changes: 14 additions & 13 deletions test/OAuthTests.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php

namespace DocuSign\eSign\Test;

use DocuSign\eSign\Client\ApiClient;
use PHPUnit\Framework\TestCase;

/**
* User: Naveen Gopala
* Date: 1/25/16
* Time: 4:58 PM
*/

class OAuthTests extends PHPUnit_Framework_TestCase
class OAuthTests extends TestCase
{

/**
Expand All @@ -18,39 +21,39 @@ class OAuthTests extends PHPUnit_Framework_TestCase
*/
private $scope = null;

public function setUp()
protected function setUp(): void
{
$testConfig = new TestConfig();

$testConfig->setApiClient(new DocuSign\eSign\Client\ApiClient());
$testConfig->setApiClient(new ApiClient());

$this->config = $testConfig;

$oAuth = $this->config->getApiClient()->getOAuth();
$oAuth->setBasePath($testConfig->getHost());
$this->scope = [
DocuSign\eSign\Client\ApiClient::$SCOPE_SIGNATURE,
DocuSign\eSign\Client\ApiClient::$SCOPE_IMPERSONATION
ApiClient::$SCOPE_SIGNATURE,
ApiClient::$SCOPE_IMPERSONATION
];
}

public function testOauthUri()
{
$uri = $this->config->getApiClient()->getAuthorizationURI($this->config->getIntegratorKey(), $this->scope, $this->config->getReturnUrl(), 'code');
$this->assertStringEndsWith($this->config->getReturnUrl(), $uri);
self::assertStringEndsWith($this->config->getReturnUrl(), $uri);
echo $uri;
}

public function testJwtUser()
{
$token = $this->config->getApiClient()->requestJWTUserToken($this->config->getIntegratorKey(), $this->config->getUserId(), $this->config->getClientKey(), $this->scope);
$this->assertInstanceOf('DocuSign\eSign\Client\Auth\OAuthToken', $token[0]);
self::assertInstanceOf('DocuSign\eSign\Client\Auth\OAuthToken', $token[0]);
}

public function testJwtApplication()
{
$token = $this->config->getApiClient()->requestJWTApplicationToken($this->config->getIntegratorKey(), $this->config->getClientKey(), $this->scope);
$this->assertInstanceOf('DocuSign\eSign\Client\Auth\OAuthToken', $token[0]);
self::assertInstanceOf('DocuSign\eSign\Client\Auth\OAuthToken', $token[0]);
}

/**
Expand All @@ -68,13 +71,13 @@ public function testAuthorizationCodeLogin()
# $code = '';
# $token = $this->config->getApiClient()->generateAccessToken($this->config->getIntegratorKey(), $this->config->getClientSecret(), $code);

# $this->assertInstanceOf('DocuSign\eSign\Client\Auth\OAuthToken', $token[0]);
# self::assertInstanceOf('DocuSign\eSign\Client\Auth\OAuthToken', $token[0]);

# echo $token[0];

# $user = $this->config->getApiClient()->getUserInfo($token[0]['access_token']);
# $this->assertInstanceOf('DocuSign\eSign\Client\Auth\UserInfo', $user[0]);
# $this->assertSame(200, $user[1]);
# self::assertInstanceOf('DocuSign\eSign\Client\Auth\UserInfo', $user[0]);
# self::assertSame(200, $user[1]);

# $loginAccount = $user[0]['accounts'][0];
# if (isset($loginInformation)) {
Expand All @@ -87,5 +90,3 @@ public function testAuthorizationCodeLogin()


}

?>
13 changes: 7 additions & 6 deletions test/TestConfig.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
namespace DocuSign\eSign\Test;

use DocuSign\eSign\Model\Envelope;
use DocuSign\eSign\Model\EnvelopeTemplate;
Expand All @@ -19,7 +20,7 @@ class TestConfig

/**
* $apiClient
* @var DocuSign\eSign\Client\ApiClient
* @var \DocuSign\eSign\Client\ApiClient
*/
protected $apiClient;

Expand Down Expand Up @@ -186,7 +187,7 @@ public function setHost($host)

/**
* Gets apiClient
* @return DocuSign\eSign\Client\ApiClient
* @return \DocuSign\eSign\Client\ApiClient
*/
public function getApiClient()
{
Expand All @@ -195,7 +196,7 @@ public function getApiClient()

/**
* Sets apiClient
* @param DocuSign\eSign\Client\ApiClient $apiClient
* @param \DocuSign\eSign\Client\ApiClient $apiClient
* @return $this
*/
public function setApiClient($apiClient)
Expand Down Expand Up @@ -482,7 +483,7 @@ public function setBrandId($brandId)
/**
* @return Envelope
*/
public function getEnvelope(): Model\Envelope
public function getEnvelope(): Envelope
{
return $this->envelope;
}
Expand All @@ -497,7 +498,7 @@ public function setEnvelope($envelope)
}

/**
* @param Model\EnvelopeTemplate $template
* @param EnvelopeTemplate $template
*/
public function setTemplate(EnvelopeTemplate $template)
{
Expand All @@ -506,7 +507,7 @@ public function setTemplate(EnvelopeTemplate $template)
}

/**
* @return Model\EnvelopeTemplate
* @return EnvelopeTemplate
*/
public function getTemplate()
{
Expand Down
8 changes: 4 additions & 4 deletions test/UnitTests.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace DocuSign\eSign\Test;

use DocuSign\eSign\Api\AccountsApi;
use DocuSign\eSign\Api\ConnectApi;
use DocuSign\eSign\Api\CustomTabsApi;
Expand Down Expand Up @@ -821,7 +823,7 @@ public function testPutDocuments($testConfig)
$addedDocument = $envelopesApi->getDocument($testConfig->getAccountId(), $document->getDocumentId(), $testConfig->getEnvelopeId());

$this->assertNotEmpty($addedDocument);
$this->assertInstanceOf(SplFileObject::class, $addedDocument);
$this->assertInstanceOf(\SplFileObject::class, $addedDocument);
}

/**
Expand Down Expand Up @@ -1670,7 +1672,7 @@ public function testUpdateBrandResourcesByContentTypeTest($testConfig)
{
$accountsApi = new AccountsApi($testConfig->getApiClient());
$brandFile = "/Docs/brand.xml";
$brandResources = $accountsApi->updateBrandResourcesByContentType($testConfig->getAccountId(),$testConfig->getBrandId(),'email',new SplFileObject(__DIR__ . $brandFile));
$brandResources = $accountsApi->updateBrandResourcesByContentType($testConfig->getAccountId(),$testConfig->getBrandId(),'email',new \SplFileObject(__DIR__ . $brandFile));

$this->assertNotEmpty($brandResources);
$this->assertInstanceOf('DocuSign\eSign\Model\BrandResources', $brandResources);
Expand All @@ -1694,5 +1696,3 @@ public function testRecipientsUpdate($testConfig)
return $testConfig;
}
}

?>
32 changes: 13 additions & 19 deletions test/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="DocuSign eSign Test Suite">
<directory>./</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/Api</directory>
<directory suffix=".php">./src/Client</directory>
<directory suffix=".php">./src/Model</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/Api</directory>
<directory suffix=".php">./src/Client</directory>
<directory suffix=".php">./src/Model</directory>
</include>
</coverage>
<testsuites>
<testsuite name="DocuSign eSign Test Suite">
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>