Skip to content

Commit 4d325d4

Browse files
Clean for Symfony < 4.0 (#51)
1 parent 7296eb1 commit 4d325d4

File tree

11 files changed

+138
-43
lines changed

11 files changed

+138
-43
lines changed

.github/workflows/ci.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ jobs:
6868
run: composer update --no-progress --no-suggest --ansi
6969
- name: Remove flysystem-bundle
7070
run: |
71-
composer remove --dev --no-progress --no-update --ansi \
72-
league/flysystem-bundle
71+
composer remove --dev --no-progress --no-update --ansi league/flysystem-bundle
72+
composer update --no-progress --no-suggest --ansi --prefer-lowest
7373
- name: Run PHPUnit tests
7474
run: vendor/bin/phpunit --colors=always
75+
- name: Run phpstan tests
76+
run: vendor/bin/phpstan analyze -c phpstan.neon.lowest.dist
77+
- name: Run php-cs-fixer tests
78+
run: vendor/bin/php-cs-fixer fix --dry-run --diff

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"php": "^7.2",
77
"ext-simplexml": "*",
88
"docusign/esign-client": "^3.0",
9-
"lcobucci/jwt": "^3.3",
9+
"lcobucci/jwt": "^3.3.1",
1010
"league/flysystem": "^1",
1111
"psr/log": "^1.1",
1212
"symfony/config": "^3.4 || ^4.2",

phpstan.neon.lowest.dist

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src
5+
inferPrivatePropertyTypeFromConstructor: true
6+
ignoreErrors:
7+
- "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component.+' and 'getRootNode' will always evaluate to false\\.#"
8+
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::arrayNode\(\)\.#'
9+
- '#Class League\\FlysystemBundle\\FlysystemBundle not found\.#'
10+
- '#Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder does not have a constructor and must be instantiated without any parameters\.#'
11+
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::getRootNode\(\)\.#'
12+
- '#Access to undefined constant League\\Flysystem\\Adapter\\Local::DISALLOW_LINKS\.#'
13+
- '#Access to undefined constant League\\Flysystem\\Adapter\\Local::SKIP_LINKS\.#'

src/DependencyInjection/Configuration.php

+53-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ public function getConfigTreeBuilder(): TreeBuilder
3030
->scalarNode('account_id')
3131
->info('Obtain your accountId from DocuSign: the account id is shown in the drop down on the upper right corner of the screen by your picture or the default picture')
3232
->cannotBeEmpty()
33+
->validate()
34+
->ifTrue(static function ($v) {
35+
try {
36+
Assert::integer($v);
37+
Assert::true(7 === \strlen((string) $v));
38+
39+
return false;
40+
} catch (\Exception $e) {
41+
return true;
42+
}
43+
})
44+
->thenInvalid('Invalid account id %s')
45+
->end()
3346
->end()
3447
->scalarNode('default_signer_name')
3548
->info('Recipient Information as the signer full name')
@@ -95,10 +108,46 @@ public function getConfigTreeBuilder(): TreeBuilder
95108
->isRequired()
96109
->info('Configure JSON Web Token (JWT) authentication: https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-jsonwebtoken')
97110
->children()
98-
->scalarNode('private_key')->isRequired()->info('Path to the private RSA key generated by DocuSign')->end()
99-
->scalarNode('integration_key')->isRequired()->info('To generate your integration key, follow this documentation: https://developers.docusign.com/esign-soap-api/reference/Introduction-Changes/Integration-Keys')->end()
100-
->scalarNode('user_guid')->isRequired()->info('Obtain your user UID (also called API username) from DocuSign Admin > Users > User > Actions > Edit')->end()
101-
->integerNode('ttl')->defaultValue(3600)->info('Token TTL in seconds (default: 3600)')->end()
111+
->scalarNode('private_key')
112+
->isRequired()
113+
->info('Path to the private RSA key generated by DocuSign')
114+
->end()
115+
->scalarNode('integration_key')
116+
->isRequired()
117+
->info('To generate your integration key, follow this documentation: https://developers.docusign.com/esign-soap-api/reference/Introduction-Changes/Integration-Keys')
118+
->validate()
119+
->ifTrue(static function ($v) {
120+
try {
121+
Assert::uuid($v);
122+
123+
return false;
124+
} catch (\Exception $e) {
125+
return true;
126+
}
127+
})
128+
->thenInvalid('Invalid integration key %s')
129+
->end()
130+
->end()
131+
->scalarNode('user_guid')
132+
->isRequired()
133+
->info('Obtain your user UID (also called API username) from DocuSign Admin > Users > User > Actions > Edit')
134+
->validate()
135+
->ifTrue(static function ($v) {
136+
try {
137+
Assert::uuid($v);
138+
139+
return false;
140+
} catch (\Exception $e) {
141+
return true;
142+
}
143+
})
144+
->thenInvalid('Invalid user guid %s')
145+
->end()
146+
->end()
147+
->integerNode('ttl')
148+
->defaultValue(3600)
149+
->info('Token TTL in seconds (default: 3600)')
150+
->end()
102151
->end()
103152
->end()
104153
->end();

src/DependencyInjection/DocusignExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ private function flySystemCompatibility(ContainerBuilder $container, array $conf
5858
$adapterFactory = new AdapterDefinitionFactory();
5959
$container
6060
->registerForAutoconfiguration(PluginInterface::class)
61-
->addTag('flysystem.plugin')
62-
;
61+
->addTag('flysystem.plugin');
62+
6363
foreach ($config['storages'] as $storageName => $storageConfig) {
6464
// Create adapter service definition
6565
if ($adapter = $adapterFactory->createDefinition($storageConfig['adapter'], $storageConfig['options'])) {

src/Grant/JwtGrant.php

-3
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ final class JwtGrant implements GrantInterface
2424
private $privateKey;
2525
private $integrationKey;
2626
private $userGuid;
27-
private $apiUri;
2827
private $accountApiUri;
2928
private $ttl;
3029

3130
public function __construct(
3231
string $privateKey,
3332
string $integrationKey,
3433
string $userGuid,
35-
string $apiURI,
3634
string $accountApiUri,
3735
int $ttl,
3836
HttpClientInterface $client = null
@@ -41,7 +39,6 @@ public function __construct(
4139
$this->privateKey = $privateKey;
4240
$this->integrationKey = $integrationKey;
4341
$this->userGuid = $userGuid;
44-
$this->apiUri = $apiURI;
4542
$this->accountApiUri = $accountApiUri;
4643
$this->ttl = $ttl;
4744
}

src/Resources/config/services.xml

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<argument>%docusign.auth_jwt.private_key%</argument>
3030
<argument>%docusign.auth_jwt.integration_key%</argument>
3131
<argument>%docusign.auth_jwt.user_guid%</argument>
32-
<argument>%docusign.api_uri%</argument>
3332
<argument>%docusign.account_api_uri%</argument>
3433
<argument>%docusign.auth_jwt.ttl%</argument>
3534
</service>

tests/DependencyInjection/Compiler/EnvelopeBuilderPassTest.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
namespace DocusignBundle\Tests\DependencyInjection\Compiler;
66

77
use DocusignBundle\DependencyInjection\Compiler\EnvelopeBuilderPass;
8+
use DocusignBundle\DependencyInjection\DocusignExtension;
89
use DocusignBundle\EnvelopeBuilder;
9-
use DocusignBundle\Exception\MissingStorageException;
10+
use League\FlysystemBundle\FlysystemBundle;
1011
use PHPUnit\Framework\TestCase;
1112
use Prophecy\Argument;
13+
use Prophecy\Prophecy\ObjectProphecy;
1214
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1315
use Symfony\Component\DependencyInjection\ContainerBuilder;
1416
use Symfony\Component\DependencyInjection\Definition;
15-
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
1617
use Symfony\Component\DependencyInjection\Reference;
1718

1819
class EnvelopeBuilderPassTest extends TestCase
@@ -22,6 +23,8 @@ public function testProcess(): void
2223
$envelopeBuilderPass = new EnvelopeBuilderPass();
2324

2425
$this->assertInstanceOf(CompilerPassInterface::class, $envelopeBuilderPass);
26+
27+
/** @var Definition|ObjectProphecy $clientDefinitionProphecy */
2528
$clientDefinitionProphecy = $this->prophesize(Definition::class);
2629
$clientDefinitionProphecy->setAutowired(true)->shouldBeCalled();
2730
$clientDefinitionProphecy->setArgument('$accountId', 'docusign_account_id')->shouldBeCalled();
@@ -31,7 +34,7 @@ public function testProcess(): void
3134
$clientDefinitionProphecy->setArgument('$callBackRouteName', 'docusign_callback_route_name')->shouldBeCalled();
3235
$clientDefinitionProphecy->setArgument('$webhookRouteName', 'docusign_webhook_route_name')->shouldBeCalled();
3336

34-
37+
/** @var ContainerBuilder|ObjectProphecy $containerBuilderProphecy */
3538
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
3639
$containerBuilderProphecy->findDefinition(EnvelopeBuilder::class)->shouldBeCalled()->willReturn($clientDefinitionProphecy->reveal());
3740

@@ -42,6 +45,17 @@ public function testProcess(): void
4245
$containerBuilderProphecy->getParameter('docusign.callback_route_name')->shouldBeCalled()->willReturn('docusign_callback_route_name');
4346
$containerBuilderProphecy->getParameter('docusign.webhook_route_name')->shouldBeCalled()->willReturn('docusign_webhook_route_name');
4447

48+
if (!class_exists(FlysystemBundle::class)) {
49+
$containerBuilderProphecy->findTaggedServiceIds('flysystem.storage')->willReturn([
50+
DocusignExtension::STORAGE_NAME => [['name' => 'flysystem.storage']],
51+
]);
52+
$clientDefinitionProphecy->setArgument('$docusignStorage', Argument::type(Reference::class))->shouldBeCalled();
53+
$clientDefinitionProphecy->getArgument('$docusignStorage')->shouldBeCalled();
54+
$clientDefinitionProphecy->setArgument('$logger', Argument::type(Reference::class))->shouldBeCalled();
55+
$clientDefinitionProphecy->setArgument('$stopwatch', Argument::type(Reference::class))->shouldBeCalled();
56+
$clientDefinitionProphecy->setArgument('$router', Argument::type(Reference::class))->shouldBeCalled();
57+
}
58+
4559
$envelopeBuilderPass->process($containerBuilderProphecy->reveal());
4660
}
4761

tests/DependencyInjection/ConfigurationTest.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public function testDefaultConfig(): void
3636
'demo' => false,
3737
'auth_jwt' => [
3838
'private_key' => '%kernel.project_dir%/var/jwt/docusign.pem',
39-
'integration_key' => 'yourIntegrationKey',
40-
'user_guid' => 'yourUserGuid',
39+
'integration_key' => 'c9763e9d-74e1-4370-9889-d749efd2b2ac',
40+
'user_guid' => '1d57a6cb-4fb0-4fb2-9fd9-09051f5b07ba',
4141
'ttl' => 1600,
4242
],
43-
'account_id' => 'ID',
43+
'account_id' => 1234567,
4444
'default_signer_name' => 'Grégoire Hébert',
4545
'default_signer_email' => '[email protected]',
4646
],
@@ -52,11 +52,11 @@ public function testDefaultConfig(): void
5252
'demo' => false,
5353
'auth_jwt' => [
5454
'private_key' => '%kernel.project_dir%/var/jwt/docusign.pem',
55-
'integration_key' => 'yourIntegrationKey',
56-
'user_guid' => 'yourUserGuid',
55+
'integration_key' => 'c9763e9d-74e1-4370-9889-d749efd2b2ac',
56+
'user_guid' => '1d57a6cb-4fb0-4fb2-9fd9-09051f5b07ba',
5757
'ttl' => 1600,
5858
],
59-
'account_id' => 'ID',
59+
'account_id' => 1234567,
6060
'default_signer_name' => 'Grégoire Hébert',
6161
'default_signer_email' => '[email protected]',
6262
'api_uri' => 'https://www.docusign.net/restapi',
@@ -76,11 +76,11 @@ public function testConfig(): void
7676
'demo' => false,
7777
'auth_jwt' => [
7878
'private_key' => '%kernel.project_dir%/var/jwt/docusign.pem',
79-
'integration_key' => 'yourIntegrationKey',
80-
'user_guid' => 'yourUserGuid',
79+
'integration_key' => 'c9763e9d-74e1-4370-9889-d749efd2b2ac',
80+
'user_guid' => '1d57a6cb-4fb0-4fb2-9fd9-09051f5b07ba',
8181
'ttl' => 2400,
8282
],
83-
'account_id' => 'ID',
83+
'account_id' => 1234567,
8484
'default_signer_name' => 'Grégoire Hébert',
8585
'default_signer_email' => '[email protected]',
8686
'signatures_overridable' => true,
@@ -114,11 +114,11 @@ public function testConfig(): void
114114
'demo' => false,
115115
'auth_jwt' => [
116116
'private_key' => '%kernel.project_dir%/var/jwt/docusign.pem',
117-
'integration_key' => 'yourIntegrationKey',
118-
'user_guid' => 'yourUserGuid',
117+
'integration_key' => 'c9763e9d-74e1-4370-9889-d749efd2b2ac',
118+
'user_guid' => '1d57a6cb-4fb0-4fb2-9fd9-09051f5b07ba',
119119
'ttl' => 2400,
120120
],
121-
'account_id' => 'ID',
121+
'account_id' => 1234567,
122122
'default_signer_name' => 'Grégoire Hébert',
123123
'default_signer_email' => '[email protected]',
124124
'api_uri' => 'https://www.docusign.net/restapi',

tests/DependencyInjection/DocusignExtensionTest.php

+26-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use DocusignBundle\Grant\GrantInterface;
1313
use DocusignBundle\Grant\JwtGrant;
1414
use DocusignBundle\Utils\SignatureExtractor;
15+
use League\Flysystem\PluginInterface;
16+
use League\FlysystemBundle\FlysystemBundle;
1517
use PHPUnit\Framework\TestCase;
1618
use Prophecy\Argument;
1719
use Symfony\Component\DependencyInjection\Alias;
@@ -26,21 +28,21 @@ class DocusignExtensionTest extends TestCase
2628
'demo' => false,
2729
'auth_jwt' => [
2830
'private_key' => '%kernel.project_dir%/var/jwt/docusign.pem',
29-
'integration_key' => 'yourIntegrationKey',
30-
'user_guid' => 'yourUserGuid',
31+
'integration_key' => 'c9763e9d-74e1-4370-9889-d749efd2b2ac',
32+
'user_guid' => '1d57a6cb-4fb0-4fb2-9fd9-09051f5b07ba',
3133
],
32-
'account_id' => 'ID',
34+
'account_id' => 1234567,
3335
'default_signer_name' => 'Grégoire Hébert',
3436
'default_signer_email' => '[email protected]',
3537
]];
3638
public const DEMO_CONFIG = ['docusign' => [
3739
'demo' => true,
3840
'auth_jwt' => [
3941
'private_key' => '%kernel.project_dir%/var/jwt/docusign.pem',
40-
'integration_key' => 'yourIntegrationKey',
41-
'user_guid' => 'yourUserGuid',
42+
'integration_key' => 'c9763e9d-74e1-4370-9889-d749efd2b2ac',
43+
'user_guid' => '1d57a6cb-4fb0-4fb2-9fd9-09051f5b07ba',
4244
],
43-
'account_id' => 'ID',
45+
'account_id' => 1234567,
4446
'default_signer_name' => 'Grégoire Hébert',
4547
'default_signer_email' => '[email protected]',
4648
]];
@@ -65,6 +67,12 @@ public function testLoadDefaultConfig(): void
6567

6668
$containerBuilderProphecy->hasExtension('http://symfony.com/schema/dic/services')->willReturn(false);
6769

70+
if (!class_exists(FlysystemBundle::class)) {
71+
$childDefinitionProphecy = $this->prophesize(ChildDefinition::class);
72+
$containerBuilderProphecy->registerForAutoconfiguration(PluginInterface::class)->willReturn($childDefinitionProphecy)->shouldBeCalled();
73+
$childDefinitionProphecy->addTag('flysystem.plugin')->shouldBeCalled();
74+
}
75+
6876
$parameterBag = new EnvPlaceholderParameterBag();
6977
$containerBuilderProphecy->getParameterBag()->willReturn($parameterBag);
7078

@@ -91,10 +99,10 @@ public function testLoadDefaultConfig(): void
9199
$containerBuilderProphecy->setAlias(GrantInterface::class, Argument::type(Alias::class))->shouldBeCalled();
92100

93101
$containerBuilderProphecy->setParameter('docusign.auth_jwt.private_key', '%kernel.project_dir%/var/jwt/docusign.pem')->shouldBeCalled();
94-
$containerBuilderProphecy->setParameter('docusign.auth_jwt.integration_key', 'yourIntegrationKey')->shouldBeCalled();
95-
$containerBuilderProphecy->setParameter('docusign.auth_jwt.user_guid', 'yourUserGuid')->shouldBeCalled();
102+
$containerBuilderProphecy->setParameter('docusign.auth_jwt.integration_key', 'c9763e9d-74e1-4370-9889-d749efd2b2ac')->shouldBeCalled();
103+
$containerBuilderProphecy->setParameter('docusign.auth_jwt.user_guid', '1d57a6cb-4fb0-4fb2-9fd9-09051f5b07ba')->shouldBeCalled();
104+
$containerBuilderProphecy->setParameter('docusign.account_id', 1234567)->shouldBeCalled();
96105
$containerBuilderProphecy->setParameter('docusign.auth_jwt.ttl', 3600)->shouldBeCalled();
97-
$containerBuilderProphecy->setParameter('docusign.account_id', 'ID')->shouldBeCalled();
98106
$containerBuilderProphecy->setParameter('docusign.default_signer_name', 'Grégoire Hébert')->shouldBeCalled();
99107
$containerBuilderProphecy->setParameter('docusign.default_signer_email', '[email protected]')->shouldBeCalled();
100108
$containerBuilderProphecy->setParameter('docusign.api_uri', 'https://www.docusign.net/restapi')->shouldBeCalled();
@@ -114,6 +122,12 @@ public function testLoadDemoConfig(): void
114122

115123
$containerBuilderProphecy->hasExtension('http://symfony.com/schema/dic/services')->willReturn(false);
116124

125+
if (!class_exists(FlysystemBundle::class)) {
126+
$childDefinitionProphecy = $this->prophesize(ChildDefinition::class);
127+
$containerBuilderProphecy->registerForAutoconfiguration(PluginInterface::class)->willReturn($childDefinitionProphecy)->shouldBeCalled();
128+
$childDefinitionProphecy->addTag('flysystem.plugin')->shouldBeCalled();
129+
}
130+
117131
$parameterBag = new EnvPlaceholderParameterBag();
118132
$containerBuilderProphecy->getParameterBag()->willReturn($parameterBag);
119133

@@ -140,10 +154,10 @@ public function testLoadDemoConfig(): void
140154
$containerBuilderProphecy->setAlias(GrantInterface::class, Argument::type(Alias::class))->shouldBeCalled();
141155

142156
$containerBuilderProphecy->setParameter('docusign.auth_jwt.private_key', '%kernel.project_dir%/var/jwt/docusign.pem')->shouldBeCalled();
143-
$containerBuilderProphecy->setParameter('docusign.auth_jwt.integration_key', 'yourIntegrationKey')->shouldBeCalled();
144-
$containerBuilderProphecy->setParameter('docusign.auth_jwt.user_guid', 'yourUserGuid')->shouldBeCalled();
157+
$containerBuilderProphecy->setParameter('docusign.auth_jwt.integration_key', 'c9763e9d-74e1-4370-9889-d749efd2b2ac')->shouldBeCalled();
158+
$containerBuilderProphecy->setParameter('docusign.auth_jwt.user_guid', '1d57a6cb-4fb0-4fb2-9fd9-09051f5b07ba')->shouldBeCalled();
159+
$containerBuilderProphecy->setParameter('docusign.account_id', 1234567)->shouldBeCalled();
145160
$containerBuilderProphecy->setParameter('docusign.auth_jwt.ttl', 3600)->shouldBeCalled();
146-
$containerBuilderProphecy->setParameter('docusign.account_id', 'ID')->shouldBeCalled();
147161
$containerBuilderProphecy->setParameter('docusign.default_signer_name', 'Grégoire Hébert')->shouldBeCalled();
148162
$containerBuilderProphecy->setParameter('docusign.default_signer_email', '[email protected]')->shouldBeCalled();
149163
$containerBuilderProphecy->setParameter('docusign.api_uri', 'https://demo.docusign.net/restapi')->shouldBeCalled();

0 commit comments

Comments
 (0)