Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / config / tests / ConfigForSettersTest.php
1 <?php
2 namespace Consolidation\Config\Inject;
3
4 use Consolidation\Config\Config;
5 use Consolidation\TestUtils\ApplyConfigTestTarget;
6
7 class ConfigForSettersTest extends \PHPUnit_Framework_TestCase
8 {
9     public function testApplyConfig()
10     {
11         $data = [
12             // Define some configuration settings for the configuration
13             // of some task \My\Tasks\Operations\Frobulate.
14             'task' => [
15                 'Operations' => [
16                     // task.Operations.settings apply to all tasks in
17                     // any *.Tass.Operations namespace.
18                     'settings' => [
19                         'dir' => '/base/dir',
20                     ],
21                     'Frobulate' => [
22                         // task.Operations.Frobulate.settings applies only
23                         // the Frobulate task.
24                         'settings' => [
25                             'dir' => '/override/dir',
26                         ],
27                     ],
28                 ],
29             ],
30         ];
31         $config = new Config($data);
32
33         $applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.');
34
35         $testTarget = new ApplyConfigTestTarget();
36
37         $applicator->apply($testTarget, 'settings');
38
39         $this->assertEquals('/override/dir', $testTarget->getDir());
40         $this->assertEquals(null, $testTarget->getBad());
41     }
42
43     public function testApplyBadConfig()
44     {
45         $data = [
46             // Define some configuration settings for the configuration
47             // of some task \My\Tasks\Operations\Frobulate.
48             'task' => [
49                 'Operations' => [
50                     // task.Operations.settings apply to all tasks in
51                     // any *.Tass.Operations namespace.
52                     'settings' => [
53                         'dir' => '/base/dir',
54                     ],
55                     'Frobulate' => [
56                         // task.Operations.Frobulate.settings applies only
57                         // the Frobulate task.
58                         'settings' => [
59                             'bad' => 'fire truck',
60                         ],
61                     ],
62                 ],
63             ],
64         ];
65         $config = new Config($data);
66
67         $applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.');
68
69         $testTarget = new ApplyConfigTestTarget();
70
71         $exceptionMessage = '';
72         try
73         {
74             $applicator->apply($testTarget, 'settings');
75         }
76         catch (\Exception $e)
77         {
78             $exceptionMessage = $e->getMessage();
79         }
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
83         // called for now.
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);
86     }
87 }