Skip to content

Commit 1753706

Browse files
committed
Resolve deprecation warnings and backwards compat issues.
1 parent 1164d07 commit 1753706

4 files changed

Lines changed: 51 additions & 49 deletions

File tree

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ Array
105105

106106
CakePHP 3 by default "consumes" some of its configs so as not to confuse developers. [`Configure::consume()`](http://book.cakephp.org/3.0/en/development/configuration.html#Cake\Core\Configure::consume) removes the configuration key from Configure, making it unavailable to the rest of the app. At the [time of this writing](https://github.com/cakephp/app/blob/a0f2c4/config/bootstrap.php#L136,L141), it does this for the following keys/classes:
107107

108-
| _`[Configure.Key]`_ | _`Class::configEnumerationMethod()`_ | _`Class::configFetchMethod()`_ |
109-
|----------------------|---------------------------------------|---------------------------------|
110-
| `[Cache]` | `Cache::configured()` | `Cache::config()` |
111-
| `[Datasources]` | `ConnectionManager::configured()` | `ConnectionManager::config()` |
112-
| `[EmailTransport]` | `Email::configuredTransport()` | `Email::configTransport()` |
113-
| `[Email]` | `Email::configured()` | `Email::config()` |
114-
| `[Log]` | `Log::configured()` | `Log::config()` |
115-
| `[Security.salt]` | _(none)_ | `Security::salt()` |
108+
| _`[Configure.Key]`_ | _`Class::configEnumerationMethod()`_ | _`Class::configFetchMethod()`_ |
109+
|----------------------|---------------------------------------|-----------------------------------|
110+
| `[Cache]` | `Cache::configured()` | `Cache::getConfig()` |
111+
| `[Datasources]` | `ConnectionManager::configured()` | `ConnectionManager::getConfig()` |
112+
| `[EmailTransport]` | `Email::configuredTransport()` | `Email::getConfigTransport()` |
113+
| `[Email]` | `Email::configured()` | `Email::getConfig()` |
114+
| `[Log]` | `Log::configured()` | `Log::getConfig()` |
115+
| `[Security.salt]` | _(none)_ | `Security::getSalt()` |
116116

117117

118-
The ConfigReadShell devotes about half of its codebase dealing with this for you, allowing you to continue to fetch values using the Configure path (`Datasources.default.host` -> `localhost`) while in the background it is actually querying `ConnectionManager::config('default')['host']`. (This is particularly helpful if you are using [Environment-Aware Configs](https://github.com/beporter/CakePHP-EnvAwareness/tree/master/slides).)
118+
The ConfigReadShell devotes about half of its codebase dealing with this for you, allowing you to continue to fetch values using the Configure path (`Datasources.default.host` -> `localhost`) while in the background it is actually querying `ConnectionManager::getConfig('default')['host']`. (This is particularly helpful if you are using [Environment-Aware Configs](https://github.com/beporter/CakePHP-EnvAwareness/tree/master/slides).)
119119

120-
The "gotcha" here is that ConfigReadShell has to maintain a hard-coded list of Configure keys that are normally consumed, and how to access them in their new container. This is further complicated by the fact that not all consumed configs are loaded into or retrieved from their containers the same way, although the base assumption is that the container implements the [`StaticConfigTrait`](http://api.cakephp.org/3.0/class-Cake.Core.StaticConfigTrait.html) and so will have `::config()` and `::configured()` available.
120+
The "gotcha" here is that ConfigReadShell has to maintain a hard-coded list of Configure keys that are normally consumed, and how to access them in their new container. This is further complicated by the fact that not all consumed configs are loaded into or retrieved from their containers the same way, although the base assumption is that the container implements the [`StaticConfigTrait`](http://api.cakephp.org/3.0/class-Cake.Core.StaticConfigTrait.html) and so will have `::getConfig()` and `::configured()` available.
121121

122122
:warning: **If your app uses `Configure::consume()` on any non-standard Configure key during bootstrapping, you will not be able to obtain any child values of those keys from the ConfigReadShell.**
123123

src/Shell/ConfigReadShell.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,29 @@ class ConfigReadShell extends Shell {
4747
* Cake 3 uses Configure::consume() on a number of Configure keys to
4848
* prime different Cake modules in `config/boostrap.php`.
4949
*
50-
* Cache::config(Configure::consume('Cache'));
51-
* ConnectionManager::config(Configure::consume('Datasources'));
52-
* Email::configTransport(Configure::consume('EmailTransport'));
53-
* Email::config(Configure::consume('Email'));
54-
* Log::config(Configure::consume('Log'));
55-
* Security::salt(Configure::consume('Security.salt'));
50+
* Cache::setConfig(Configure::consume('Cache'));
51+
* ConnectionManager::setConfig(Configure::consume('Datasources'));
52+
* Email::setConfigTransport(Configure::consume('EmailTransport'));
53+
* Email::setConfig(Configure::consume('Email'));
54+
* Log::setConfig(Configure::consume('Log'));
55+
* Security::setSalt(Configure::consume('Security.salt'));
5656
*
5757
* This removes the configs from Configure, making them inaccessible
5858
* through standard means in this Shell.
5959
*
6060
* This property tracks specific key names and the class::method they
6161
* map to so we can perform the correct logic to fetch the values. For
6262
* example, a request for `Cache._cake_core_.className` would result
63-
* in a call like `\Cake\Cache\Cache::config('_cake_core_')['className']`.
63+
* in a call like `\Cake\Cache\Cache::getConfig('_cake_core_')['className']`.
6464
*
6565
* @var array
6666
*/
6767
public $specialKeys = [
68-
'Cache' => '\Cake\Cache\Cache::config',
69-
'Datasources' => '\Cake\Datasource\ConnectionManager::config',
70-
'EmailTransport' => '\Cake\Mailer\Email::configTransport',
71-
'Email' => '\Cake\Mailer\Email::config',
72-
'Log' => '\Cake\Log\Log::config',
68+
'Cache' => '\Cake\Cache\Cache::getConfig',
69+
'Datasources' => '\Cake\Datasource\ConnectionManager::getConfig',
70+
'EmailTransport' => '\Cake\Mailer\Email::getConfigTransport',
71+
'Email' => '\Cake\Mailer\Email::getConfig',
72+
'Log' => '\Cake\Log\Log::getConfig',
7373
'Security.salt' => 'self::securitySaltHelper',
7474
];
7575

@@ -100,7 +100,7 @@ public function startup() {
100100
}
101101

102102
// All other output should not be processed by the Shell.
103-
$this->_io->outputAs(ConsoleOutput::RAW);
103+
$this->_io->setOutputAs(ConsoleOutput::RAW);
104104
}
105105

106106
/**
@@ -262,16 +262,16 @@ protected function specialKey($search) {
262262
* There are three cases to handle:
263263
*
264264
* 1. A "deep" subkey like `Cache.default.className`. In this case,
265-
* we need to fetch `Cache::config('default')` and then return
265+
* we need to fetch `Cache::getConfig('default')` and then return
266266
* the ['className'] from the result.
267267
*
268268
* 2. A single config array like `Cache.default. We need to fetch
269-
* `Cache::config('default')` and return the whole thing.
269+
* `Cache::getConfig('default')` and return the whole thing.
270270
*
271271
* 3. All configs in a module like `Cache`. In this case we need to
272272
* try calling `Cache::configured()` (if it exists), then looping
273273
* over the results using each as a key name for a separate call
274-
* to `Cache::config($name)` and accumulating all of the results
274+
* to `Cache::getConfig($name)` and accumulating all of the results
275275
* together to return.
276276
*
277277
* @param array $special An array containing at least a [callable] key and possibly [arg] and [subkey]s.
@@ -282,7 +282,7 @@ protected function fetchSpecial($special) {
282282
$set = call_user_func($special['callable'], $special['arg']);
283283
} else {
284284
$allConfigCallable = str_replace(
285-
'::config',
285+
'::getConfig',
286286
'::configured',
287287
$special['callable'],
288288
$replaceCount
@@ -362,20 +362,20 @@ protected function printVal($key, $val) {
362362
/**
363363
* Provides a custom helper for fetching the App's Security.salt value.
364364
*
365-
* The call to Security::salt() method requires no arguments to get the
365+
* The call to Security::getSalt() method requires no arguments to get the
366366
* current value but we will have split the command line request for
367367
* `Security.salt` into
368-
* `call_user_func('\Cake\Utility\Security::salt', 'salt'). That will
368+
* `call_user_func('\Cake\Utility\Security::getSalt', 'salt'). That will
369369
* **set** the salt to `salt` and return "salt" as the new value, which
370370
* isn't what we want. This method exists to be the callable function,
371-
* which itself passes the proper `null` value as the argument, which
372-
* in turn will return the _actual_ salt value.
371+
* which itself passes no arguments to getSalt, which in turn will return
372+
* the _actual_ salt value.
373373
*
374374
* @param string $salt Because of how this is implemented, this will always be the literal string "salt" and will be ignored.
375-
@return string The result of calling `Security::salt(null);`
375+
* @return string The result of calling `Security::getSalt();`
376376
*/
377377
private function securitySaltHelper($salt) {
378-
return call_user_func('\Cake\Utility\Security::salt', null);
378+
return call_user_func('\Cake\Utility\Security::getSalt');
379379
}
380380

381381
/**
@@ -402,10 +402,10 @@ public function getOptionParser() {
402402
'default' => false,
403403
'help' => __('Encode all output using PHP\'s `serialize()` method. Makes the Shell\'s output suitable for consumption by other PHP console scripts. Always overrides the --bash option. A single requested key will be serialized directly. Multiple requested keys will be combined into an associative array with the provided arguments as key names and then serialized.'),
404404
])
405-
->description(
405+
->setDescription(
406406
__('Provides CLI access to variables defined in the Configure class of the host CakePHP application. Will output the value of any keys passed as arguments. Equivelant to `Configure::read(\'Key.Name\')`. Unrecognized keys will produce empty string or `null` output.')
407407
)
408-
->epilog(
408+
->setEpilog(
409409
__('Provide the Key.name(s) to fetch from Configure::read() as arguments. Multiple keys may be specified, separated by spaces.')
410410
);
411411

tests/TestCase/Shell/ConfigReadShellTest.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ class ConfigReadShellTest extends TestCase {
8888
*/
8989
public static function setUpBeforeClass() {
9090
// Prime the ConnectionManager with some configs.
91-
ConnectionManager::config(self::$datasources);
91+
ConnectionManager::setConfig(self::$datasources);
9292

9393
// Prime the security salt.
94-
Security::salt(self::$salt);
94+
Security::setSalt(self::$salt);
9595
}
9696

9797
/**
@@ -104,7 +104,7 @@ public static function tearDownAfterClass() {
104104
ConnectionManager::drop($ds);
105105
}
106106

107-
Security::salt('');
107+
Security::setSalt('');
108108
}
109109

110110
/**
@@ -206,26 +206,29 @@ protected function initSUT($additionalMocks = []) {
206206
'_displayHelp', 'error',
207207
];
208208

209-
$this->io = $this->getMock('\Cake\Console\ConsoleIo', [], [], '', false);
209+
$this->io = $this->getMockBuilder('\Cake\Console\ConsoleIo')
210+
->disableOriginalConstructor()
211+
->getMock();
210212
$this->io->expects($this->any())
211213
->method('out')
212214
->with($this->anything())
213215
->will($this->returnCallback([$this, 'outputCollector']));
214216

215-
216217
$class = $this->getSUTClassName();
217218
$mockedMethods = array_merge($defaultMocks, $additionalMocks);
218-
$shell = $this->getMock(
219-
$class,
220-
$mockedMethods,
221-
[$this->io]
222-
);
219+
$shell = $this->getMockBuilder($class)
220+
->setMethods($mockedMethods)
221+
->setConstructorArgs([$this->io])
222+
->getMock();
223223

224224
$shell->expects($this->any())
225225
->method('error')
226226
->with($this->anything())
227227
->will($this->returnCallback([$this, 'outputCollector']));
228-
$shell->OptionParser = $this->getMock('\Cake\Console\ConsoleOptionParser', [], [null, false]);
228+
$shell->OptionParser = $this->getMockBuilder('\Cake\Console\ConsoleOptionParser')
229+
->setMethods([])
230+
->setConstructorArgs([null, false])
231+
->getMock();
229232
$shell->params = [
230233
'help' => false,
231234
'verbose' => false,
@@ -253,7 +256,7 @@ public function testStartupHelp() {
253256
$this->Shell->expects($this->once())
254257
->method('_displayHelp');
255258

256-
Cache::config('_cake_core_', [
259+
Cache::setConfig('_cake_core_', [
257260
'className' => 'File',
258261
]);
259262
$this->Shell->startup();
@@ -482,7 +485,6 @@ public function provideSerializedArgs() {
482485
];
483486
}
484487

485-
486488
/**
487489
* test main(), requesting "special" config keys.
488490
*

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
if (!getenv('db_dsn')) {
5353
putenv('db_dsn=sqlite:///:memory:');
5454
}
55-
ConnectionManager::config('test', ['url' => getenv('db_dsn')]);
55+
ConnectionManager::setConfig('test', ['url' => getenv('db_dsn')]);
5656

5757
Plugin::load('ConfigReadShell', [
5858
'path' => dirname(dirname(__FILE__)) . DS,

0 commit comments

Comments
 (0)