2 namespace Consolidation\Config\Inject;
4 use Consolidation\Config\Config;
5 use Consolidation\TestUtils\ApplyConfigTestTarget;
7 class ConfigForSettersTest extends \PHPUnit_Framework_TestCase
9 public function testApplyConfig()
12 // Define some configuration settings for the configuration
13 // of some task \My\Tasks\Operations\Frobulate.
16 // task.Operations.settings apply to all tasks in
17 // any *.Tass.Operations namespace.
22 // task.Operations.Frobulate.settings applies only
23 // the Frobulate task.
25 'dir' => '/override/dir',
31 $config = new Config($data);
33 $applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.');
35 $testTarget = new ApplyConfigTestTarget();
37 $applicator->apply($testTarget, 'settings');
39 $this->assertEquals('/override/dir', $testTarget->getDir());
40 $this->assertEquals(null, $testTarget->getBad());
43 public function testApplyBadConfig()
46 // Define some configuration settings for the configuration
47 // of some task \My\Tasks\Operations\Frobulate.
50 // task.Operations.settings apply to all tasks in
51 // any *.Tass.Operations namespace.
56 // task.Operations.Frobulate.settings applies only
57 // the Frobulate task.
59 'bad' => 'fire truck',
65 $config = new Config($data);
67 $applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.');
69 $testTarget = new ApplyConfigTestTarget();
71 $exceptionMessage = '';
74 $applicator->apply($testTarget, 'settings');
78 $exceptionMessage = $e->getMessage();
80 // We would prefer it if bad methods were never called; unfortunately,
81 // declaring the return type of a method cannot be done in a reliable
82 // way (via reflection) until php 7, so we allow these methods to be
84 $this->assertEquals('fire truck', $testTarget->getBad());
85 $this->assertEquals('Consolidation\\TestUtils\\ApplyConfigTestTarget::bad did not return \'$this\' when processing task.Operations.Frobulate.settings.', $exceptionMessage);