OptionsTraitTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\Unit\Credentials\Ini;
  3. use ReflectionClass;
  4. use ReflectionException;
  5. use PHPUnit\Framework\TestCase;
  6. use AlibabaCloud\Client\Clients\EcsRamRoleClient;
  7. use AlibabaCloud\Client\Exception\ClientException;
  8. use AlibabaCloud\Client\Credentials\Ini\IniCredential;
  9. /**
  10. * Class OptionsTraitTest
  11. *
  12. * @package AlibabaCloud\Client\Tests\Unit\Credentials\Ini
  13. */
  14. class OptionsTraitTest extends TestCase
  15. {
  16. /**
  17. * @param array $configures
  18. *
  19. * @param mixed $expectedCert
  20. *
  21. * @throws ReflectionException
  22. * @throws ClientException
  23. * @dataProvider setCert
  24. */
  25. public function testSetCert(array $configures, $expectedCert)
  26. {
  27. // Setup
  28. $client = new EcsRamRoleClient('test');
  29. $object = new IniCredential();
  30. $ref = new ReflectionClass(IniCredential::class);
  31. $method = $ref->getMethod('setCert');
  32. $method->setAccessible(true);
  33. $method->invokeArgs($object, [$configures, $client]);
  34. self::assertEquals($expectedCert, $client->options['cert']);
  35. }
  36. /**
  37. * @return array
  38. */
  39. public function setCert()
  40. {
  41. return [
  42. [
  43. [
  44. 'cert_file' => '/file/file.pem',
  45. ],
  46. '/file/file.pem',
  47. ],
  48. [
  49. [
  50. 'cert_file' => '/file/file.pem',
  51. 'cert_password' => 'password',
  52. ],
  53. [
  54. '/file/file.pem',
  55. 'password',
  56. ],
  57. ],
  58. ];
  59. }
  60. }