Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
661 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace OhMyBrew\BasicShopifyResource\Models; | ||
|
||
use OhMyBrew\BasicShopifyResource\Resource; | ||
use OhMyBrew\BasicShopifyResource\Relationships\HasOne; | ||
use OhMyBrew\BasicShopifyResource\Models\Theme; | ||
|
||
/** | ||
* Asset API. | ||
*/ | ||
class Asset extends Resource | ||
{ | ||
/** | ||
* The resource path part. | ||
* | ||
* @var string | ||
*/ | ||
protected $resourcePath = 'assets'; | ||
|
||
/** | ||
* The resource name. | ||
* | ||
* @var string | ||
*/ | ||
protected $resourceName = 'asset'; | ||
|
||
/** | ||
* The resource name (plural). | ||
* | ||
* @var string | ||
*/ | ||
protected $resourceNamePlural = 'assets'; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @return $this | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->relationships = [ | ||
'theme' => (new HasOne(Theme::class))->setParams( | ||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
function () { | ||
return ['theme_id' => $this->theme_id]; | ||
} | ||
), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace OhMyBrew\BasicShopifyResource\Models; | ||
|
||
use OhMyBrew\BasicShopifyResource\Resource; | ||
|
||
/** | ||
* Shop API. | ||
*/ | ||
class Shop extends Resource | ||
{ | ||
/** | ||
* The resource path. | ||
* | ||
* @var string | ||
*/ | ||
protected $resourcePath = 'shop'; | ||
|
||
/** | ||
* The resource name. | ||
* | ||
* @var string | ||
*/ | ||
protected $resourceName = 'shop'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace OhMyBrew\BasicShopifyResource\Models; | ||
|
||
use OhMyBrew\BasicShopifyResource\Resource; | ||
use OhMyBrew\BasicShopifyResource\Relationships\HasManyThrough; | ||
|
||
/** | ||
* Theme API. | ||
*/ | ||
class Theme extends Resource | ||
{ | ||
/** | ||
* The resource path part. | ||
* | ||
* @var string | ||
*/ | ||
protected $resourcePath = 'themes'; | ||
|
||
/** | ||
* The resource name. | ||
* | ||
* @var string | ||
*/ | ||
protected $resourceName = 'theme'; | ||
|
||
/** | ||
* The resource name (plural). | ||
* | ||
* @var string | ||
*/ | ||
protected $resourceNamePlural = 'themes'; | ||
|
||
|
||
/** | ||
* The constructor. | ||
* | ||
* @return $this | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->relationships = [ | ||
'assets' => (new HasManyThrough(Asset::class)) | ||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
->setThrough(function () { | ||
return $this; | ||
}) | ||
]; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/OhMyBrew/BasicShopifyResource/Relationships/HasManyThrough.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace OhMyBrew\BasicShopifyResource\Relationships; | ||
|
||
use Closure; | ||
|
||
class HasManyThrough extends Relationship | ||
{ | ||
/** | ||
* The through resource. | ||
* | ||
* @var string | ||
*/ | ||
protected $through; | ||
|
||
/** | ||
* Sets the through resource. | ||
* | ||
* @param Closure $through The through resource. | ||
* | ||
* @return $this | ||
*/ | ||
public function setThrough(Closure $through) | ||
{ | ||
$this->through = $through; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Gets the through resource class. | ||
* | ||
* @return Closure | ||
*/ | ||
public function getThrough() | ||
{ | ||
return $this->through; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace OhMyBrew\BasicShopifyResource\Test\Models; | ||
|
||
use OhMyBrew\BasicShopifyResource\Models\Theme; | ||
use OhMyBrew\BasicShopifyResource\Models\Asset; | ||
use OhMyBrew\BasicShopifyResource\Test\TestCase; | ||
use Tightenco\Collect\Support\Collection; | ||
|
||
class AssetTest extends TestCase | ||
{ | ||
public function testSetup() | ||
{ | ||
$props = $this->getResourceProperties(new Asset()); | ||
|
||
$this->assertEquals('assets', $props->resourcePath); | ||
$this->assertEquals('asset', $props->resourceName); | ||
$this->assertEquals('assets', $props->resourceNamePlural); | ||
$this->assertEquals('id', $props->resourcePk); | ||
} | ||
|
||
public function testRelationships() | ||
{ | ||
$connection = $this->createConnection(['models/theme', 'models/assets', 'models/themes']); | ||
$theme = $this->invokeMethod(Theme::class, 'find', [828155753]); | ||
|
||
// Assets (API call) | ||
$theme2 = $theme->assets->first()->theme; | ||
$this->assertInstanceOf(Theme::class, $theme2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace OhMyBrew\BasicShopifyResource\Test\Models; | ||
|
||
use OhMyBrew\BasicShopifyResource\Test\TestCase; | ||
use OhMyBrew\BasicShopifyResource\Models\Shop; | ||
|
||
class ShopTest extends TestCase | ||
{ | ||
public function testSetup() | ||
{ | ||
$props = $this->getResourceProperties(new Shop()); | ||
|
||
$this->assertEquals('shop', $props->resourceName); | ||
$this->assertEquals('id', $props->resourcePk); | ||
} | ||
|
||
public function testFinders() | ||
{ | ||
$connection = $this->createConnection('models/shop'); | ||
$shop = $this->invokeMethod(Shop::class, 'find', [0]); | ||
|
||
$this->assertEquals( | ||
'/admin/shop.json', | ||
$this->getLastPathCalled($connection) | ||
); | ||
$this->assertInstanceOf(SHop::class, $shop); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace OhMyBrew\BasicShopifyResource\Test\Models; | ||
|
||
use OhMyBrew\BasicShopifyResource\Models\Theme; | ||
use OhMyBrew\BasicShopifyResource\Models\Asset; | ||
use OhMyBrew\BasicShopifyResource\Test\TestCase; | ||
use Tightenco\Collect\Support\Collection; | ||
|
||
class ThemeTest extends TestCase | ||
{ | ||
public function testSetup() | ||
{ | ||
$props = $this->getResourceProperties(new Theme()); | ||
|
||
$this->assertEquals('themes', $props->resourcePath); | ||
$this->assertEquals('theme', $props->resourceName); | ||
$this->assertEquals('themes', $props->resourceNamePlural); | ||
$this->assertEquals('id', $props->resourcePk); | ||
} | ||
|
||
public function testFinders() | ||
{ | ||
$connection = $this->createConnection(['models/theme', 'models/themes']); | ||
$theme = $this->invokeMethod(Theme::class, 'find', [828155753]); | ||
|
||
$this->assertEquals( | ||
'/admin/themes/828155753.json', | ||
$this->getLastPathCalled($connection) | ||
); | ||
$this->assertInstanceOf(Theme::class, $theme); | ||
|
||
$themes = $this->invokeMethod(Theme::class, 'all'); | ||
|
||
$this->assertEquals( | ||
'/admin/themes.json', | ||
$this->getLastPathCalled($connection) | ||
); | ||
$this->assertInstanceOf(Collection::class, $themes); | ||
} | ||
|
||
public function testRelationships() | ||
{ | ||
$connection = $this->createConnection(['models/theme', 'models/assets']); | ||
$theme = $this->invokeMethod(Theme::class, 'find', [828155753]); | ||
|
||
// Assets (API call) | ||
$assets = $theme->assets; | ||
$this->assertInstanceOf(Collection::class, $assets); | ||
$this->assertTrue($assets->count() > 0); | ||
} | ||
} |
Empty file.
Oops, something went wrong.