-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Manager with Factory Support, refs #11
- Loading branch information
Showing
4 changed files
with
115 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Art4\JsonApiClient\Utils; | ||
|
||
/** | ||
* Manager Interface | ||
*/ | ||
interface FactoryManagerInterface | ||
{ | ||
/** | ||
* Set a factory into the manager | ||
* | ||
* @param FactoryInterface $factory | ||
* @return object | ||
*/ | ||
public function setFactory(FactoryInterface $factory); | ||
|
||
/** | ||
* Get a factory from the manager | ||
* | ||
* @return FactoryInterface | ||
*/ | ||
public function getFactory(); | ||
} |
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 Art4\JsonApiClient\Utils; | ||
|
||
class Manager implements ManagerInterface, FactoryManagerInterface | ||
{ | ||
/** | ||
* @var FactoryInterface | ||
*/ | ||
protected $factory = null; | ||
|
||
/** | ||
* Set a factory into the manager | ||
* | ||
* @param FactoryInterface $factory | ||
* @return object | ||
*/ | ||
public function setFactory(FactoryInterface $factory) | ||
{ | ||
$this->factory = $factory; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get a factory from the manager | ||
* | ||
* @return FactoryInterface | ||
*/ | ||
public function getFactory() | ||
{ | ||
if ( is_null($this->factory) ) | ||
{ | ||
$this->setFactory(new Factory); | ||
} | ||
|
||
return $this->factory; | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Art4\JsonApiClient\Utils; | ||
|
||
/** | ||
* Manager Interface | ||
*/ | ||
interface ManagerInterface { } |
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,44 @@ | ||
<?php | ||
|
||
namespace Art4\JsonApiClient\Utils\Tests; | ||
|
||
use Art4\JsonApiClient\Utils\Manager; | ||
|
||
class ManagerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function testSetFactoryReturnsSelf() | ||
{ | ||
$factory = $this->getMockBuilder('Art4\JsonApiClient\Utils\Factory') | ||
->getMock(); | ||
|
||
$manager = new Manager; | ||
|
||
$this->assertSame($manager, $manager->setFactory($factory)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function testGetFactoryReturnsFactoryInterface() | ||
{ | ||
$factory = $this->getMockBuilder('Art4\JsonApiClient\Utils\Factory') | ||
->getMock(); | ||
|
||
$manager = (new Manager)->setFactory($factory); | ||
|
||
$this->assertInstanceOf('Art4\JsonApiClient\Utils\FactoryInterface', $manager->getFactory()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function testGetFactoryWitoutSetReturnsFactoryInterface() | ||
{ | ||
$manager = new Manager; | ||
|
||
$this->assertInstanceOf('Art4\JsonApiClient\Utils\FactoryInterface', $manager->getFactory()); | ||
} | ||
} |