DefaultProfileTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. include_once '../../Config.php';
  21. class DefaultProfileTest extends PHPUnit_Framework_TestCase
  22. {
  23. public function testGetProfile()
  24. {
  25. $profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret");
  26. $this->assertEquals("cn-hangzhou", $profile->getRegionId());
  27. $this->assertEquals("accessId", $profile->getCredential()->getAccessKeyId());
  28. $this->assertEquals("accessSecret", $profile->getCredential()->getAccessSecret());
  29. }
  30. public function testAddEndpoint()
  31. {
  32. $profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret");
  33. $profile::addEndpoint("cn-hangzhou", "cn-hangzhou", "TestProduct", "testproduct.aliyuncs.com");
  34. $endpoints = $profile::getEndpoints();
  35. foreach ($endpoints as $key => $endpoint) {
  36. if ("cn-hangzhou" == $endpoint->getName()) {
  37. $regionIds = $endpoint->getRegionIds();
  38. $this->assertContains("cn-hangzhou", $regionIds);
  39. $productDomains = $endpoint->getProductDomains();
  40. $this->assertNotNull($productDomains);
  41. $productDomain = $this->getProductDomain($productDomains);
  42. $this->assertNotNull($productDomain);
  43. $this->assertEquals("TestProduct", $productDomain->getProductName());
  44. $this->assertEquals("testproduct.aliyuncs.com", $productDomain->getDomainName());
  45. }
  46. }
  47. }
  48. /**
  49. * @param $productDomains
  50. *
  51. * @return ProductDomain|null
  52. */
  53. private function getProductDomain($productDomains)
  54. {
  55. foreach ($productDomains as $productDomain) {
  56. if ($productDomain->getProductName() === 'TestProduct') {
  57. return $productDomain;
  58. }
  59. }
  60. return null;
  61. }
  62. }