-
Notifications
You must be signed in to change notification settings - Fork 1
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
2 changed files
with
71 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,38 @@ | ||
<?php | ||
namespace Packaged\Config; | ||
|
||
use Packaged\Config\Provider\ConfigSection; | ||
|
||
trait ConfigurableTrait | ||
{ | ||
/** | ||
* @var ConfigSectionInterface | ||
*/ | ||
protected $_configuration; | ||
|
||
/** | ||
* Configure the data connection | ||
* | ||
* @param ConfigSectionInterface $configuration | ||
* | ||
* @return static | ||
*/ | ||
public function configure(ConfigSectionInterface $configuration) | ||
{ | ||
$this->_configuration = $configuration; | ||
} | ||
|
||
/** | ||
* Retrieve the configuration | ||
* | ||
* @return ConfigSectionInterface | ||
*/ | ||
protected function _config() | ||
{ | ||
if($this->_configuration === null) | ||
{ | ||
$this->_configuration = new ConfigSection(); | ||
} | ||
return $this->_configuration; | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
use Packaged\Config\Provider\ConfigSection; | ||
use Packaged\Config\ConfigurableTrait; | ||
|
||
class ConfigurableTraitTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testTrait() | ||
{ | ||
$config = new ConfigSection('abstract', ['name' => 'test']); | ||
$mock = new MockConfigurableTrait(); | ||
$mock->configure($config); | ||
$this->assertSame($config, $mock->config()); | ||
} | ||
|
||
public function testDefaultConfig() | ||
{ | ||
$mock = new MockConfigurableTrait(); | ||
$this->assertEmpty($mock->config()->getItems()); | ||
} | ||
} | ||
|
||
class MockConfigurableTrait | ||
{ | ||
use ConfigurableTrait; | ||
|
||
/** | ||
* @return \Packaged\Config\ConfigSectionInterface | ||
*/ | ||
public function config() | ||
{ | ||
return $this->_config(); | ||
} | ||
} |