From a80aecac2686a698970fcb4dc7482ea3455f2d4e Mon Sep 17 00:00:00 2001 From: Tyler King Date: Sun, 21 Oct 2018 16:08:35 -0230 Subject: [PATCH] Renaming to match Shopify docs --- README.md | 63 +++++++++++++++++++ .../BasicShopifyResource/Models/Collect.php | 2 + .../Models/CustomCollection.php | 1 + .../BasicShopifyResource/Models/Product.php | 8 ++- .../Models/{Image.php => ProductImage.php} | 5 +- .../{Variant.php => ProductVariant.php} | 9 ++- .../{ImageTest.php => ProductImageTest.php} | 12 ++-- ...VariantTest.php => ProductVariantTest.php} | 18 +++--- test/Resource/ResourceFindTest.php | 10 +-- test/Resource/ResourceRelationsTest.php | 4 +- test/Resource/ResourceTest.php | 6 +- 11 files changed, 107 insertions(+), 31 deletions(-) rename src/OhMyBrew/BasicShopifyResource/Models/{Image.php => ProductImage.php} (87%) rename src/OhMyBrew/BasicShopifyResource/Models/{Variant.php => ProductVariant.php} (84%) rename test/Models/{ImageTest.php => ProductImageTest.php} (75%) rename test/Models/{VariantTest.php => ProductVariantTest.php} (71%) diff --git a/README.md b/README.md index 6750347..6a027c4 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,69 @@ $collect = Collect::all(['collection_id' => $collection->id]); $products = $collect->map(function ($c) { return $c->product; }); ``` +## Status + +11.4% completed + +- [ ] AccessScope +- [ ] StorefrontAccessToken +- [ ] Policy +- [ ] ShippingZone +- [ ] Province +- [ ] Country +- [ ] Shop +- [ ] AbandonedCheckout +- [ ] DraftOrder +- [ ] Order +- [ ] OrderRisk +- [ ] Refund +- [ ] Transaction +- [ ] Payouts +- [ ] Balance +- [ ] Transactions +- [x] Collect +- [x] Product +- [ ] SmartCollection +- [x] ProductImage +- [x] ProductVariant +- [x] CustomCollection +- [ ] Webhook +- [ ] Event +- [ ] CustomerAddress +- [ ] Customer +- [ ] CustomerSavedSearch +- [ ] User +- [ ] Multipass +- [ ] GiftCard +- [ ] ShopifyQL +- [ ] Report +- [ ] PriceRule +- [ ] DiscountCode +- [ ] Checkout +- [ ] ResourceFeedback +- [ ] ProductListing +- [ ] CollectionListing +- [ ] Payment +- [ ] InventoryItem +- [ ] Location +- [ ] InventoryLevel +- [ ] CarrierService +- [ ] FulfillmentEvent +- [ ] Fulfillment +- [ ] FulfillmentService +- [ ] Theme +- [ ] Page +- [ ] Comment +- [ ] Asset +- [ ] Blog +- [ ] Redirect +- [ ] ScriptTag +- [ ] BlogArticle +- [ ] UsageCharge +- [ ] ApplicationCredit +- [ ] ApplicationCharge +- [ ] RecurringApplicationCharge + ## Testing Run `bin/phpunit --no-coverage` for tests. diff --git a/src/OhMyBrew/BasicShopifyResource/Models/Collect.php b/src/OhMyBrew/BasicShopifyResource/Models/Collect.php index 10a59d6..7b8868a 100644 --- a/src/OhMyBrew/BasicShopifyResource/Models/Collect.php +++ b/src/OhMyBrew/BasicShopifyResource/Models/Collect.php @@ -4,6 +4,8 @@ use OhMyBrew\BasicShopifyResource\Relationships\HasOne; use OhMyBrew\BasicShopifyResource\Resource; +use OhMyBrew\BasicShopifyResource\Models\Product; +use OhMyBrew\BasicShopifyResource\Models\CustomCollection; /** * Custom Collection API. diff --git a/src/OhMyBrew/BasicShopifyResource/Models/CustomCollection.php b/src/OhMyBrew/BasicShopifyResource/Models/CustomCollection.php index a75664f..1dc8ebb 100644 --- a/src/OhMyBrew/BasicShopifyResource/Models/CustomCollection.php +++ b/src/OhMyBrew/BasicShopifyResource/Models/CustomCollection.php @@ -4,6 +4,7 @@ use OhMyBrew\BasicShopifyResource\Relationships\HasMany; use OhMyBrew\BasicShopifyResource\Resource; +use OhMyBrew\BasicShopifyResource\Models\Collect; /** * Custom Collection API. diff --git a/src/OhMyBrew/BasicShopifyResource/Models/Product.php b/src/OhMyBrew/BasicShopifyResource/Models/Product.php index 6f5e2ee..dbe9ad8 100644 --- a/src/OhMyBrew/BasicShopifyResource/Models/Product.php +++ b/src/OhMyBrew/BasicShopifyResource/Models/Product.php @@ -5,6 +5,10 @@ use OhMyBrew\BasicShopifyResource\Relationships\HasMany; use OhMyBrew\BasicShopifyResource\Relationships\IncludesMany; use OhMyBrew\BasicShopifyResource\Resource; +use OhMyBrew\BasicShopifyResource\Models\ProductVariant; +use OhMyBrew\BasicShopifyResource\Models\ProductImage; +use OhMyBrew\BasicShopifyResource\Models\Collect; +use OhMyBrew\BasicShopifyResource\Models\CustomCollection; /** * Product API. @@ -40,8 +44,8 @@ class Product extends Resource public function __construct() { $this->relationships = [ - 'variants' => new IncludesMany(Variant::class), - 'images' => (new IncludesMany(Image::class))->setParams( + 'variants' => new IncludesMany(ProductVariant::class), + 'images' => (new IncludesMany(ProductImage::class))->setParams( /** * @codeCoverageIgnore */ diff --git a/src/OhMyBrew/BasicShopifyResource/Models/Image.php b/src/OhMyBrew/BasicShopifyResource/Models/ProductImage.php similarity index 87% rename from src/OhMyBrew/BasicShopifyResource/Models/Image.php rename to src/OhMyBrew/BasicShopifyResource/Models/ProductImage.php index 5e917b0..0413f75 100644 --- a/src/OhMyBrew/BasicShopifyResource/Models/Image.php +++ b/src/OhMyBrew/BasicShopifyResource/Models/ProductImage.php @@ -4,11 +4,12 @@ use OhMyBrew\BasicShopifyResource\Relationships\HasOne; use OhMyBrew\BasicShopifyResource\Resource; +use OhMyBrew\BasicShopifyResource\Models\Product; /** - * Image API. + * ProductImage API. */ -class Image extends Resource +class ProductImage extends Resource { /** * The resource path part. diff --git a/src/OhMyBrew/BasicShopifyResource/Models/Variant.php b/src/OhMyBrew/BasicShopifyResource/Models/ProductVariant.php similarity index 84% rename from src/OhMyBrew/BasicShopifyResource/Models/Variant.php rename to src/OhMyBrew/BasicShopifyResource/Models/ProductVariant.php index d02b38e..74ad562 100644 --- a/src/OhMyBrew/BasicShopifyResource/Models/Variant.php +++ b/src/OhMyBrew/BasicShopifyResource/Models/ProductVariant.php @@ -5,8 +5,13 @@ use OhMyBrew\BasicShopifyResource\Relationships\HasOne; use OhMyBrew\BasicShopifyResource\Relationships\HasOneThrough; use OhMyBrew\BasicShopifyResource\Resource; +use OhMyBrew\BasicShopifyResource\Models\ProductImage; +use OhMyBrew\BasicShopifyResource\Models\Product; -class Variant extends Resource +/** + * ProductVariant API. + */ +class ProductVariant extends Resource { /** * The resource path part. @@ -45,7 +50,7 @@ function () { return ['product_id' => $this->product_id]; } ), - 'image' => (new HasOneThrough(Image::class)) + 'image' => (new HasOneThrough(ProductImage::class)) ->setThrough(Product::class) ->setThroughId( /** diff --git a/test/Models/ImageTest.php b/test/Models/ProductImageTest.php similarity index 75% rename from test/Models/ImageTest.php rename to test/Models/ProductImageTest.php index ad69fa5..e2bf41f 100644 --- a/test/Models/ImageTest.php +++ b/test/Models/ProductImageTest.php @@ -2,7 +2,7 @@ namespace OhMyBrew\BasicShopifyResource\Test\Models; -use OhMyBrew\BasicShopifyResource\Models\Image; +use OhMyBrew\BasicShopifyResource\Models\ProductImage; use OhMyBrew\BasicShopifyResource\Models\Product; use OhMyBrew\BasicShopifyResource\Test\TestCase; use Tightenco\Collect\Support\Collection; @@ -11,7 +11,7 @@ class ImageTest extends TestCase { public function testSetup() { - $props = $this->getResourceProperties(new Image()); + $props = $this->getResourceProperties(new ProductImage()); $this->assertEquals('images', $props->resourcePath); $this->assertEquals('image', $props->resourceName); @@ -22,15 +22,15 @@ public function testSetup() public function testFinders() { $connection = $this->createConnection(['models/image', 'models/images']); - $image = $this->invokeMethod(Image::class, 'find', [850703190]); + $image = $this->invokeMethod(ProductImage::class, 'find', [850703190]); $this->assertEquals( '/admin/images/850703190.json', $this->getLastPathCalled($connection) ); - $this->assertInstanceOf(Image::class, $image); + $this->assertInstanceOf(ProductImage::class, $image); - $images = $this->invokeMethod(Image::class, 'all'); + $images = $this->invokeMethod(ProductImage::class, 'all'); $this->assertEquals( '/admin/images.json', @@ -42,7 +42,7 @@ public function testFinders() public function testRelationships() { $connection = $this->createConnection(['models/image', 'models/products']); - $image = $this->invokeMethod(Image::class, 'find', [850703190]); + $image = $this->invokeMethod(ProductImage::class, 'find', [850703190]); // Product (API call) $product = $image->product; diff --git a/test/Models/VariantTest.php b/test/Models/ProductVariantTest.php similarity index 71% rename from test/Models/VariantTest.php rename to test/Models/ProductVariantTest.php index 83e7016..9aa6cdb 100644 --- a/test/Models/VariantTest.php +++ b/test/Models/ProductVariantTest.php @@ -2,17 +2,17 @@ namespace OhMyBrew\BasicShopifyResource\Test\Models; -use OhMyBrew\BasicShopifyResource\Models\Image; +use OhMyBrew\BasicShopifyResource\Models\ProductImage; use OhMyBrew\BasicShopifyResource\Models\Product; -use OhMyBrew\BasicShopifyResource\Models\Variant; +use OhMyBrew\BasicShopifyResource\Models\ProductVariant; use OhMyBrew\BasicShopifyResource\Test\TestCase; use Tightenco\Collect\Support\Collection; -class VariantTest extends TestCase +class ProductVariantTest extends TestCase { public function testSetup() { - $props = $this->getResourceProperties(new Variant()); + $props = $this->getResourceProperties(new ProductVariant()); $this->assertEquals('variants', $props->resourcePath); $this->assertEquals('variant', $props->resourceName); @@ -24,15 +24,15 @@ public function testFinders() { $connection = $this->createConnection(['models/product', 'models/variant', 'models/variants']); $product = $this->invokeMethod(Product::class, 'find', [632910392]); - $variant = $this->invokeMethod(Variant::class, 'findThrough', [808950810, $product]); + $variant = $this->invokeMethod(ProductVariant::class, 'findThrough', [808950810, $product]); $this->assertEquals( '/admin/products/632910392/variants/808950810.json', $this->getLastPathCalled($connection) ); - $this->assertInstanceOf(Variant::class, $variant); + $this->assertInstanceOf(ProductVariant::class, $variant); - $variants = $this->invokeMethod(Variant::class, 'allThrough', [$product]); + $variants = $this->invokeMethod(ProductVariant::class, 'allThrough', [$product]); $this->assertEquals( '/admin/products/632910392/variants.json', @@ -51,7 +51,7 @@ public function testRelationships() 'models/image', ]); $product = $this->invokeMethod(Product::class, 'find', [632910392]); - $variant = $this->invokeMethod(Variant::class, 'findThrough', [808950810, $product]); + $variant = $this->invokeMethod(ProductVariant::class, 'findThrough', [808950810, $product]); // Product (API call) $product = $variant->product; @@ -59,6 +59,6 @@ public function testRelationships() // Image (API call) $image = $variant->image; - $this->assertInstanceOf(Image::class, $image); + $this->assertInstanceOf(ProductImage::class, $image); } } diff --git a/test/Resource/ResourceFindTest.php b/test/Resource/ResourceFindTest.php index 8a3330a..14c0477 100644 --- a/test/Resource/ResourceFindTest.php +++ b/test/Resource/ResourceFindTest.php @@ -3,7 +3,7 @@ namespace OhMyBrew\BasicShopifyResource\Test\Resource; use OhMyBrew\BasicShopifyResource\Models\Product; -use OhMyBrew\BasicShopifyResource\Models\Variant; +use OhMyBrew\BasicShopifyResource\Models\ProductVariant; use OhMyBrew\BasicShopifyResource\Resource; use OhMyBrew\BasicShopifyResource\Test\TestCase; use Tightenco\Collect\Support\Collection; @@ -29,16 +29,16 @@ public function testFindThrough() // Find through resource $connection = $this->createConnection(['base/variant_find_through', 'base/variant_find_through']); - $variant = $this->invokeMethod(Variant::class, 'findThrough', [808950810, $product]); + $variant = $this->invokeMethod(ProductVariant::class, 'findThrough', [808950810, $product]); $this->assertEquals( '/admin/products/632910392/variants/808950810.json', $this->getLastPathCalled($connection) ); - $this->assertInstanceOf(Variant::class, $variant); + $this->assertInstanceOf(ProductVariant::class, $variant); // Find through string - $variant = $this->invokeMethod(Variant::class, 'findThrough', [808950810, 'products/632910392']); + $variant = $this->invokeMethod(ProductVariant::class, 'findThrough', [808950810, 'products/632910392']); $this->assertEquals( '/admin/products/632910392/variants/808950810.json', @@ -62,7 +62,7 @@ public function testAllThrough() { $connection = $this->createConnection(['base/product_find', 'base/variant_all']); $product = $this->invokeMethod(Product::class, 'find', [632910392]); - $variants = $this->invokeMethod(Variant::class, 'allThrough', [$product]); + $variants = $this->invokeMethod(ProductVariant::class, 'allThrough', [$product]); $this->assertEquals( '/admin/products/632910392/variants.json', diff --git a/test/Resource/ResourceRelationsTest.php b/test/Resource/ResourceRelationsTest.php index 9955b05..a128eab 100644 --- a/test/Resource/ResourceRelationsTest.php +++ b/test/Resource/ResourceRelationsTest.php @@ -3,7 +3,7 @@ namespace OhMyBrew\BasicShopifyResource\Test\Resource; use OhMyBrew\BasicShopifyResource\Models\Product; -use OhMyBrew\BasicShopifyResource\Models\Variant; +use OhMyBrew\BasicShopifyResource\Models\ProductVariant; use OhMyBrew\BasicShopifyResource\Test\TestCase; use Tightenco\Collect\Support\Collection; @@ -54,7 +54,7 @@ public function testHasOneRelationship() { // Product does not exist for variant in the response, so an API call should be made $connection = $this->createConnection(['base/variant_find', 'base/product_all']); - $variant = $this->invokeMethod(Variant::class, 'find', [908950810]); + $variant = $this->invokeMethod(ProductVariant::class, 'find', [908950810]); $this->assertInstanceOf(Product::class, $variant->product); $this->assertEquals( diff --git a/test/Resource/ResourceTest.php b/test/Resource/ResourceTest.php index c31b844..7b3dcc5 100644 --- a/test/Resource/ResourceTest.php +++ b/test/Resource/ResourceTest.php @@ -4,7 +4,7 @@ use OhMyBrew\BasicShopifyAPI; use OhMyBrew\BasicShopifyResource\Models\Product; -use OhMyBrew\BasicShopifyResource\Models\Variant; +use OhMyBrew\BasicShopifyResource\Models\ProductVariant; use OhMyBrew\BasicShopifyResource\Test\TestCase; use ReflectionClass; @@ -61,7 +61,7 @@ public function testProperties() $this->assertEquals('IPod Nano - 8GB', $product->title); // Test setting a relational property - $variant = new Variant(); + $variant = new ProductVariant(); $this->assertNull($variant->product_id); $variant->product = $product; @@ -73,7 +73,7 @@ public function testProperties() */ public function testThrowsErrorTryingToSetInvalidRelational() { - $variant = new Variant(); + $variant = new ProductVariant(); $variant->product = 1; }