Skip to content

Commit f816e5f

Browse files
Merge pull request #6 from frankfoerster/cake-3.4-support
update test setup for cakephp 3.4.x
2 parents dbbc552 + 134f5fa commit f816e5f

File tree

7 files changed

+68
-32
lines changed

7 files changed

+68
-32
lines changed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
language: php
33

44
php:
5-
- 5.5
65
- 5.6
6+
- 7.0
7+
- 7.1
78

89
sudo: false
910

@@ -15,10 +16,10 @@ matrix:
1516
fast_finish: true
1617

1718
include:
18-
- php: 5.5
19+
- php: 7.1
1920
env: PHPCS=1 DEFAULT=0
2021

21-
- php: 5.5
22+
- php: 7.1
2223
env: COVERALLS=1 DEFAULT=0
2324

2425
install:
@@ -36,9 +37,9 @@ before_script:
3637
- set +H
3738

3839
script:
39-
- sh -c "if [ '$DEFAULT' = '1' ]; then phpunit --stderr; fi"
40+
- sh -c "if [ '$DEFAULT' = '1' ]; then ./vendor/bin/phpunit --stderr; fi"
4041
- sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi"
41-
- sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --stderr --coverage-clover build/logs/clover.xml; fi"
42+
- sh -c "if [ '$COVERALLS' = '1' ]; then ./vendor/bin/phpunit --stderr --coverage-clover build/logs/clover.xml; fi"
4243
- sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi"
4344

4445
notifications:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Frank Förster
3+
Copyright (c) 2014-2017 Frank Förster
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,52 @@
1-
CakePHP 3.x Environment Plugin
2-
==============================
1+
# CakePHP 3.x Environment Plugin
32

4-
[![Build Status](https://travis-ci.org/frankfoerster/cakephp-environment.svg?branch=cake3)](https://travis-ci.org/frankfoerster/cakephp-environment)
3+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
4+
[![Build Status](https://img.shields.io/travis/frankfoerster/cakephp-environment/cake3.svg?style=flat-square)](https://travis-ci.org/frankfoerster/cakephp-environment)
5+
[![Coverage Status](https://img.shields.io/coveralls/frankfoerster/cakephp-environment/cake3.svg?style=flat-square)](https://coveralls.io/github/frankfoerster/cakephp-environment)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/frankfoerster/cakephp-environment.svg?style=flat-square)](https://packagist.org/packages/frankfoerster/cakephp-environment)
7+
[![Latest Stable Version](https://img.shields.io/packagist/v/frankfoerster/cakephp-environment.svg?style=flat-square&label=stable)](https://packagist.org/packages/frankfoerster/cakephp-environment)
58

69
Manage multiple environments in your CakePHP application that differ in, e.g.:
710

811
- database setup
912
- configuration settings (Configure)
1013
- custom feature flags
1114

12-
Requirements
13-
------------
15+
## Requirements
1416

15-
- PHP 5.4.16+
17+
- PHP 5.6.0+
1618
- CakePHP 3.x
1719

18-
1. What it does
19-
---------------
20+
## What it does
2021

2122
The Environment plugin hooks into your bootstrap process to initialize the database configuration, configuration parameters and additional custom logic for different environments.
2223

2324
An environment is defined and detected either by a set of domains (e.g. www.domain.com, domain.com, domain.net) or optionally by the absolute app path on a server (cli).
2425

25-
2. Install and use the plugin
26-
-----------------------------
27-
28-
1. `composer require frankfoerster/cakephp-environment`
29-
2. Copy the example configuration files from `example/config/Environment` to your app `/config/Environment`
30-
3. Add the following lines to your `config/bootstrap.php` file
31-
32-
```php
33-
use FrankFoerster\Environment\Environments;
34-
35-
Plugin::load('FrankFoerster/Environment');
36-
Environments::init();
37-
```
26+
## Install and use the plugin
27+
28+
1. `composer require frankfoerster/cakephp-environment`
29+
2. Copy the example configuration files from `example/config/Environment` to your app `/config/Environment`
30+
3. Add the following lines to your `config/bootstrap.php` file
31+
32+
```php
33+
use FrankFoerster\Environment\Environments;
34+
35+
Plugin::load('FrankFoerster/Environment');
36+
Environments::init();
37+
```
38+
39+
before
40+
```php
41+
ConnectionManager::config(Configure::consume('Datasources'));
42+
```
43+
44+
If you want to setup environment specific settings for any "consumed" configuration option, then make sure your environments are initialized **before** the corresponding ``Configure::consume('...')`` call.
3845

3946
Tags ~1.0 are releases for CakePHP 2.x support (master branch).
4047
Tags ~3.0 are releases for CakePHP 3.x support (cake3 branch).
4148

42-
3. Configuration
43-
----------------
49+
## Configuration
4450

4551
The configuration of your environments is managed with multiple files.
4652

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=5.3.0"
21+
"php": ">=5.6.0"
2222
},
2323
"require-dev": {
24-
"cakephp/cakephp": "~3.0",
25-
"phpunit/phpunit": "~4.6",
24+
"cakephp/cakephp": "3.4.*",
25+
"phpunit/phpunit": "~5.7",
2626
"cakephp/cakephp-codesniffer": "dev-master"
2727
},
2828
"autoload": {

phpunit.xml.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@
1818
<directory>./tests/</directory>
1919
</testsuite>
2020
</testsuites>
21+
<filter>
22+
<whitelist processUncoveredFilesFromWhitelist="true">
23+
<directory suffix=".php">./src/</directory>
24+
</whitelist>
25+
<blacklist>
26+
<directory suffix=".php">./vendor</directory>
27+
</blacklist>
28+
</filter>
2129
</phpunit>

src/Environments.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public static function init()
128128
public static function getCurrentEnvironment()
129129
{
130130
$instance = self::getInstance();
131+
131132
return $instance->_current;
132133
}
133134

@@ -152,6 +153,7 @@ protected function _loadEnvironment($envFilePath)
152153
return $availableEnvironments;
153154
}
154155
}
156+
155157
return [];
156158
}
157159

@@ -221,6 +223,7 @@ protected function _getRealAppPath()
221223
if (substr($path, -1, 1) !== DS) {
222224
$path .= DS;
223225
}
226+
224227
return $path;
225228
}
226229

@@ -234,6 +237,7 @@ public static function getInstance()
234237
if (static::$_instance === null) {
235238
static::$_instance = new Environments();
236239
}
240+
237241
return static::$_instance;
238242
}
239243

tests/TestCase/EnvironmentsTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ class EnvironmentsTestWrapper extends Environments
2525
public static function getEnvPath()
2626
{
2727
$instance = self::getInstance();
28+
2829
return $instance->_envPath;
2930
}
3031

3132
public static function getEnvironment()
3233
{
3334
$instance = self::getInstance();
35+
3436
return $instance->_getEnvironment();
3537
}
3638

@@ -120,6 +122,21 @@ public function testHostEnvironmentDetection()
120122
$_SERVER['HTTP_HOST'] = $backup;
121123
}
122124

125+
public function testServerNameEnvironmentDetection()
126+
{
127+
Environments::tearDown();
128+
EnvironmentsTestWrapper::prepareTestEnvironments();
129+
130+
$hostBackup = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
131+
$serverNameBackup = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost';
132+
$_SERVER['HTTP_HOST'] = null;
133+
$_SERVER['SERVER_NAME'] = 'test.com';
134+
$this->assertEquals('testing', EnvironmentsTestWrapper::getEnvironment());
135+
136+
$_SERVER['HTTP_HOST'] = $hostBackup;
137+
$_SERVER['SERVER_NAME'] = $serverNameBackup;
138+
}
139+
123140
public function testPathEnvironmentDetection()
124141
{
125142
Environments::tearDown();

0 commit comments

Comments
 (0)