Skip to content

Commit ea130f8

Browse files
committed
Merge pull request #23 from loadsys/f/travis
F/travis
2 parents 4fef311 + 56d26a5 commit ea130f8

7 files changed

Lines changed: 295 additions & 204 deletions

File tree

.travis.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
language: php
2+
3+
sudo: false
4+
5+
php:
6+
- 5.6
7+
8+
# Environment Variables to set
9+
env:
10+
global:
11+
# Contains a $GITHUB_TOKEN env var for use with composer to avoid API limits.
12+
- secure: "JPIIdecDmF2AsgH3b5QWYzr2TunB4tpIBl0/64EGsWZ+5A85Co3NN+eSshgWI5vOjaaJji/S2rKwMRvV9h/YceTL/UH5D2xd/HobRpHAaJSyjp5cplQawokzR/+PrikjmbwTZdeiIaHpUMCqbQvV2+Jq+Vx5vD28+hya1yTdQsk="
13+
14+
15+
# Cache the composer directories, only allowed if using the container based setup
16+
# which depends on setting sudo to false
17+
cache:
18+
directories:
19+
- $HOME/.composer/cache
20+
21+
# Branches to be built or not
22+
branches:
23+
# Blacklist these branches
24+
except:
25+
- gh-pages
26+
27+
before_install:
28+
- composer self-update
29+
- mkdir -p build/logs
30+
31+
install:
32+
- composer config -g github-oauth.github.com $GITHUB_TOKEN
33+
- composer install --no-interaction
34+
35+
before_script:
36+
- phpenv rehash
37+
- vendor/bin/phpcs --config-set installed_paths vendor/loadsys/loadsys_codesniffer,vendor/cakephp/cakephp-codesniffer
38+
39+
script:
40+
- vendor/bin/phpcs -np --extensions=php --standard=Loadsys ./src ./tests
41+
- vendor/bin/phpunit --coverage-clover=build/logs/clover.xml
42+
43+
after_script:
44+
- php vendor/bin/coveralls -v
45+
46+
notifications:
47+
email: false

README.md

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# CakePHP-ConfigReadShell
22

33
[![Latest Version](https://img.shields.io/github/release/loadsys/CakePHP-ConfigReadShell.svg?style=flat-square)](https://github.com/loadsys/CakePHP-ConfigReadShell/releases)
4+
[![Build Status](https://travis-ci.org/loadsys/CakePHP-ConfigReadShell.svg?branch=master)](https://travis-ci.org/loadsys/CakePHP-ConfigReadShell)
5+
[![Coverage Status](https://coveralls.io/repos/loadsys/CakePHP-ConfigReadShell/badge.svg?branch=master)](https://coveralls.io/r/loadsys/CakePHP-ConfigReadShell?branch=master)
46
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
57
[![Total Downloads](https://img.shields.io/packagist/dt/loadsys/cakephp-config-read.svg?style=flat-square)](https://packagist.org/packages/loadsys/cakephp-config-read)
68

79
A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.
810

9-
10-
* This is the Cake 3.x version of the plugin, which exists on the `master` branch and is tracked by the `3.*` semver.
11-
* For the Cake 2.x version of this plugin, please use the repo's `cake-2.x` branch. (semver `2.*`)
12-
* For the Cake 1.3 version, use the `cake-1.3` branch. (semver `1.*`) **Note:** we don't expect to actively maintain the 1.3 version. It's here because the project started life as a 1.3 Shell.
11+
* This is the Cake 3.x version of the plugin, which exists on the `master` branch and is tracked by the `~3.0` semver.
12+
* For the Cake 2.x version of this plugin, please use the repo's `cake-2.x` branch. (semver `~2.0`)
13+
* For the Cake 1.3 version, use the `cake-1.3` branch. (semver `~1.0`) **Note:** we don't expect to actively maintain the 1.3 version. It's here because the project started life as a 1.3 Shell.
1314

1415

1516
## Requirements
1617

1718
* CakePHP 3.0.0+
18-
* PHP 5.4.19+
19+
* PHP 5.6+
1920

2021

2122
## Installation
@@ -50,6 +51,62 @@ $ ./bin/cake ConfigRead -b Key.Name
5051
KEY_NAME='foo'
5152
```
5253

54+
## Gotchas
55+
56+
### "Consumed" Configure Vars
57+
58+
CakePHP 3 by default "consumes" some of its configs so as not to confused 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:
59+
60+
* Cache/Cache
61+
* Datasources/ConnectionManager
62+
* EmailTransport/Email
63+
* Email/Email
64+
* Log/Log
65+
* Security.salt/Security::salt()
66+
67+
The effect is that you can not use the ConfigReadShell to obtain Configure values for any of these keys since they no longer exist in Configure's store. (This is particularly troublesome if you are using [Environment-Aware Configs](https://github.com/beporter/CakePHP-EnvAwareness/tree/master/slides).)
68+
69+
There are two possible workarounds:
70+
71+
1. Use the `ConsoleShell` instead. For example:
72+
73+
```shell
74+
$ echo 'use Cake\Datasource\ConnectionManager; foreach(ConnectionManager::config("default") as $k => $v) { echo "$k=" . escapeshellarg($v) . PHP_EOL; } exit;' | bin/cake Console -q
75+
className='Cake\Database\Connection'
76+
driver='Cake\Database\Driver\Mysql'
77+
persistent=''
78+
host='localhost'
79+
username='my_app'
80+
password='secret'
81+
database='my_app'
82+
encoding='utf8'
83+
timezone='UTC'
84+
cacheMetadata='1'
85+
quoteIdentifiers=''
86+
name='default'
87+
```
88+
89+
This command is wrapped up in our [loadsys/cakephp-shell-scripts](https://github.com/loadsys/CakePHP-Shell-Scripts) repo as the [`db-credentials`](https://github.com/loadsys/CakePHP-Shell-Scripts/blob/76a24/db-credentials) script.
90+
91+
2. Edit your `config/bootstrap.php` to use `Configure::read()` instead of `Configure::consume()`.
92+
93+
```diff
94+
-Cache::config(Configure::consume('Cache'));
95+
-ConnectionManager::config(Configure::consume('Datasources'));
96+
-Email::configTransport(Configure::consume('EmailTransport'));
97+
-Email::config(Configure::consume('Email'));
98+
-Log::config(Configure::consume('Log'));
99+
-Security::salt(Configure::consume('Security.salt'));
100+
+Cache::config(Configure::read('Cache'));
101+
+ConnectionManager::config(Configure::read('Datasources'));
102+
+Email::configTransport(Configure::read('EmailTransport'));
103+
+Email::config(Configure::read('Email'));
104+
+Log::config(Configure::read('Log'));
105+
+Security::salt(Configure::read('Security.salt'));
106+
```
107+
108+
This will leave the Configure vars in place and allow commands like `bin/cake ConfigRead Datasources.default` to work as expected, but be warned that the values in Configure might not reflect the values actually being used by the various Cake modules.
109+
53110

54111
## Contributing
55112

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"require-dev": {
2828
"phpunit/phpunit": "~4.1",
29-
"squizlabs/php_codesniffer": "~2.0",
29+
"loadsys/loadsys_codesniffer": "~3.0",
3030
"satooshi/php-coveralls": "dev-master"
3131
},
3232
"autoload": {

phpunit.xml.dist

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
processIsolation="false"
7-
stopOnFailure="false"
8-
syntaxCheck="false"
9-
bootstrap="./tests/bootstrap.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
processIsolation="false"
7+
stopOnFailure="false"
8+
syntaxCheck="false"
9+
bootstrap="./tests/bootstrap.php"
1010
>
1111

12-
<testsuites>
13-
<testsuite name="ConfigReadShell Test Suite">
14-
<directory>./tests/TestCase</directory>
15-
</testsuite>
16-
</testsuites>
12+
<testsuites>
13+
<testsuite name="ConfigReadShell Test Suite">
14+
<directory>./tests/TestCase</directory>
15+
</testsuite>
16+
</testsuites>
1717

18-
<!-- Prevent coverage reports from looking in tests and vendors -->
19-
<filter>
20-
<blacklist>
21-
<directory suffix=".php">./vendor/</directory>
22-
<directory suffix=".ctp">./vendor/</directory>
18+
<!-- Prevent coverage reports from looking in tests and vendors -->
19+
<filter>
20+
<blacklist>
21+
<directory suffix=".php">./vendor/</directory>
22+
<directory suffix=".ctp">./vendor/</directory>
2323

24-
<directory suffix=".php">./tests/</directory>
25-
<directory suffix=".ctp">./tests/</directory>
26-
</blacklist>
27-
</filter>
24+
<directory suffix=".php">./tests/</directory>
25+
<directory suffix=".ctp">./tests/</directory>
26+
</blacklist>
27+
</filter>
2828

2929
</phpunit>

src/Shell/ConfigReadShell.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Cake\Console\Shell;
1010
use Cake\Core\Configure;
1111

12-
1312
/**
1413
* ConfigReadShell class.
1514
*
@@ -156,8 +155,8 @@ protected function printVal($key, $val) {
156155
*
157156
* Processing command line options.
158157
*
159-
* @access public
160-
* @return void
158+
* @access public
159+
* @return CosnsoleOptionParser
161160
* @codeCoverageIgnore
162161
*/
163162
public function getOptionParser() {

0 commit comments

Comments
 (0)