X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fconsolidation%2Fconfig%2Ftests%2FConfigForSettersTest.php;fp=vendor%2Fconsolidation%2Fconfig%2Ftests%2FConfigForSettersTest.php;h=422b0a00b8c81286aa44479bfbb4565b5cf0958d;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/consolidation/config/tests/ConfigForSettersTest.php b/vendor/consolidation/config/tests/ConfigForSettersTest.php new file mode 100644 index 000000000..422b0a00b --- /dev/null +++ b/vendor/consolidation/config/tests/ConfigForSettersTest.php @@ -0,0 +1,87 @@ + [ + 'Operations' => [ + // task.Operations.settings apply to all tasks in + // any *.Tass.Operations namespace. + 'settings' => [ + 'dir' => '/base/dir', + ], + 'Frobulate' => [ + // task.Operations.Frobulate.settings applies only + // the Frobulate task. + 'settings' => [ + 'dir' => '/override/dir', + ], + ], + ], + ], + ]; + $config = new Config($data); + + $applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.'); + + $testTarget = new ApplyConfigTestTarget(); + + $applicator->apply($testTarget, 'settings'); + + $this->assertEquals('/override/dir', $testTarget->getDir()); + $this->assertEquals(null, $testTarget->getBad()); + } + + public function testApplyBadConfig() + { + $data = [ + // Define some configuration settings for the configuration + // of some task \My\Tasks\Operations\Frobulate. + 'task' => [ + 'Operations' => [ + // task.Operations.settings apply to all tasks in + // any *.Tass.Operations namespace. + 'settings' => [ + 'dir' => '/base/dir', + ], + 'Frobulate' => [ + // task.Operations.Frobulate.settings applies only + // the Frobulate task. + 'settings' => [ + 'bad' => 'fire truck', + ], + ], + ], + ], + ]; + $config = new Config($data); + + $applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.'); + + $testTarget = new ApplyConfigTestTarget(); + + $exceptionMessage = ''; + try + { + $applicator->apply($testTarget, 'settings'); + } + catch (\Exception $e) + { + $exceptionMessage = $e->getMessage(); + } + // We would prefer it if bad methods were never called; unfortunately, + // declaring the return type of a method cannot be done in a reliable + // way (via reflection) until php 7, so we allow these methods to be + // called for now. + $this->assertEquals('fire truck', $testTarget->getBad()); + $this->assertEquals('Consolidation\\TestUtils\\ApplyConfigTestTarget::bad did not return \'$this\' when processing task.Operations.Frobulate.settings.', $exceptionMessage); + } +}