public function testSetterGetter()
 {
     $item = new ProductItem();
     $item->setProductName("test-product_name");
     $item->setServiceName("test-service-name");
     $item->setUnitPrice(500);
     $item->setRegionName("test-region-name");
     $this->assertEquals("test-product_name", $item->getProductname());
     $this->assertEquals("test-service-name", $item->getServiceName());
     $this->assertEquals(500, $item->getUnitPrice());
     $this->assertEquals("test-region-name", $item->getRegionName());
 }
Example #2
0
 /**
  * VPSやSwift、追加IPなどのサービス毎に商品を一覧で返す
  *
  * @api
  * @link https://www.conoha.jp/docs/account-products.html
  *
  * @param string $service_name (Optional) The service name for filtering.
  *                             It should be one of following.
  *                             VPS, VPSAddDisk, VPSBackup, AddIP, LoadBalancer,
  *                             ImageSave, Mail, MailBackup, StaticIP, MailAddDisk,
  *                             DB, DBBackup, DBAddDisk, ObjectStorage or DNS.
  * @return \ConoHa\Common\ResourceCollection
  */
 public function productItems($service_name = null)
 {
     $query = [];
     switch ($service_name) {
         case 'VPS':
         case 'VPSAddDisk':
         case 'VPSBackup':
         case 'AddIP':
         case 'LoadBalancer':
         case 'ImageSave':
         case 'Mail':
         case 'MailBackup':
         case 'StaticIP':
         case 'MailAddDisk':
         case 'DB':
         case 'DBBackup':
         case 'DBAddDisk':
         case 'ObjectStorage':
         case 'DNS':
             $query = ['service_name' => $service_name];
             break;
         case null:
             break;
         default:
             throw \InvalidArgumentException('Invalid service name.');
     }
     $res = $this->getClient()->get($this->getUri('product-items', $query));
     $item = new ProductItem();
     $col = new ResourceCollection();
     foreach ($res->getJson()->product_items as $item) {
         foreach ($item->regions as $region) {
             foreach ($region->products as $product) {
                 $product_item = new ProductItem();
                 $product_item->setServiceName($item->service_name);
                 $product_item->setRegionName($region->region_name);
                 $product_item->setProductName($product->product_name);
                 $product_item->setUnitPrice($product->unit_price);
                 $col[] = $product_item;
                 $tmp[$item->service_name] = '';
             }
         }
     }
     return $col;
 }