Added documentation

This commit is contained in:
Dmitry Khomutov 2016-07-17 20:20:35 +06:00
parent 96bc300f77
commit fa42071d01
49 changed files with 1255 additions and 0 deletions

54
docs/en/README.md Normal file
View file

@ -0,0 +1,54 @@
#### Getting Started
* [Installing PHPCI](installing.md)
* [Adding a Virtual Host](virtual_host.md)
* [Run Builds Using a Worker](workers/worker.md)
* [Run Builds Using a Daemon](workers/daemon.md)
* [Run Builds Using Cron](workers/cron.md)
* [Adding PHPCI Support to Your Projects](config.md)
* [Setting up Logging](logging.md)
* [Updating PHPCI](updating.md)
* [Configuring PHPCI](configuring.md)
#### Using PHPCI
* Automatically building commits pushed to
* [Github](sources/github.md)
* [Bitbucket](sources/bitbucket.md)
* [GitLab](sources/gitlab.md)
* [Git](sources/git.md)
* [Injecting variables into messages](interpolation.md)
* [Project Status Images and Status Page](status.md)
#### Plugins
* [Atoum](plugins/atoum.md) - `atoum`
* [Behat](plugins/behat.md) - `behat`
* [Campfire](plugins/campfire.md) - `campfire`
* [Clean Build](plugins/clean_build.md) - `clean_build`
* [Codeception](plugins/codeception.md) - `codeception`
* [Composer](plugins/composer.md) - `composer`
* [Copy Build](plugins/copy_build.md) - `copy_build`
* [Deployer](plugins/deployer.md) - `deployer`
* [Email](plugins/email.md) - `email`
* [Env](plugins/env.md) - `env`
* [Grunt](plugins/grunt.md) - `grunt`
* [Hipchat](plugins/hipchat_notify.md) - `hipchat_notify`
* [IRC](plugins/irc.md) - `irc`
* [Lint](plugins/lint.md) - `lint`
* [MySQL](plugins/mysql.md) - `mysql`
* [Package Build](plugins/package_build.md) - `package_build`
* [PDepend](plugins/pdepend.md) - `pdepend`
* [PostgreSQL](plugins/pgsql.md) - `pgsql`
* [Phar](plugins/phar.md) - `phar`
* [Phing](plugins/phing.md) - `phing`
* [PHP Code Sniffer](plugins/php_code_sniffer.md) - `php_code_sniffer`
* [PHP Copy/Paste Detector](plugins/php_cpd.md) - `php_cpd`
* [PHP Coding Standards Fixer](plugins/php_cs_fixes.md) - `php_cs_fixer`
* [PHP Docblock Checker](plugins/php_docblock_checker.md) - `php_docblock_checker`
* [PHP Loc](plugins/php_loc.md) - `php_loc`
* [PHP Mess Detector](plugins/php_mess_detector.md) - `php_mess_detector`
* [PHP Parallel Lint](plugins/php_parallel_lint.md) - `php_parallel_lint`
* [PHP Spec](plugins/php_spec.md) - `php_spec`
* [PHP Unit](plugins/php_unit.md) - `php_unit`
* [Shell](plugins/shell.md) - `shell`
* [Slack](plugins/slack_notify.md) - `slack_notify`
* [Technical Debt](plugins/technical_dept.md) - `technical_debt`
* [XMPP](plugins/xmpp.md) - `xmpp`

58
docs/en/config.md Normal file
View file

@ -0,0 +1,58 @@
Similar to Travis CI, to support PHPCI in your project, you simply need to add a `phpci.yml` file to the root of your repository. The file should look something like this:
```yml
build_settings:
clone_depth: 1 # depth of 1 is a shallow clone, remove this line to clone entire repo
ignore:
- "vendor"
- "tests"
mysql:
host: "localhost"
user: "root"
pass: ""
setup:
mysql:
- "DROP DATABASE IF EXISTS test;"
- "CREATE DATABASE test;"
- "GRANT ALL PRIVILEGES ON test.* TO test@'localhost' IDENTIFIED BY 'test';"
composer:
action: "install"
test:
php_unit:
config:
- "PHPUnit-all.xml"
- "PHPUnit-ubuntu-fix.xml"
directory:
- "tests/"
run_from: "phpunit/"
coverage: "tests/logs/coverage"
php_mess_detector:
allow_failures: true
php_code_sniffer:
standard: "PSR2"
php_cpd:
allow_failures: true
grunt:
task: "build"
complete:
mysql:
host: "localhost"
user: "root"
pass: ""
- "DROP DATABASE IF EXISTS test;"
```
As mentioned earlier, PHPCI is powered by plugins, there are several phases in which plugins can be run:
* `setup` - This phase is designed to initialise the build procedure.
* `test` - The tests that should be run during the build. Plugins run during this phase will contribute to the success or failure of the build.
* `complete` - Always called when the `test` phase completes, regardless of success or failure. **Note** that is you do any mysql stuff here, you will need to add the mysql credentials to this section as well, as it runs in a separate instance.
* `success` - Called upon success of the `test` phase.
* `failure` - Called upon failure of the `test` phase.
* `fixed` - Called upon success of the `test` phase if the previous build of the branch was a success.
* `broken` - Called upon failure of the `test` phase if the previous build of the branch was a failure.
The `ignore` section is merely an array of paths that should be ignored in all tests (where possible.)

10
docs/en/configuring.md Normal file
View file

@ -0,0 +1,10 @@
The PHPCI configuration on the server is automatically generated into the `phpci/PHPCI/config.yml` file during installation. One might need to also edit the file manually.
For example, to [disable authentication](https://www.phptesting.org/news/phpci-1-5-released), one could log into phpci and go into the settings to disable it. But if you have already set up a username/password pair and have forgotten the password, and if the server is on a local network, and it's not sending the `forgot password` email, then editing the config file manually would be handy. To do so, just edit the `phpci` section in the config file (which is in [yaml format](https://en.wikipedia.org/wiki/YAML)), and add
phpci:
authentication_settings:
state: 1
user_id: 1
where you can get the user_id by logging into the mysql database and selecting your user ID from the `users` table in the `phpci` database.

33
docs/en/installing.md Normal file
View file

@ -0,0 +1,33 @@
## What you'll need:
* PHP 5.3.6 or above
* A web server (we recommend [nginx](http://nginx.org))
* [Composer](https://getcomposer.org/download/)
* [Git](http://git-scm.com/downloads)
* A MySQL server to connect to. This doesn't have to be on the same server as PHPCI.
* The following functions need to be enabled: `exec()`, `shell_exec()` and `proc_open()`
* PHP must have OpenSSL support enabled.
## Installing PHPCI from Composer:
* Go to the directory in which you want to install PHPCI, for example: `/var/www`
* Download Composer if you haven't already: `curl -sS https://getcomposer.org/installer | php`
* Download PHPCI: `./composer.phar create-project block8/phpci phpci --keep-vcs --no-dev`
* Go to the newly created PHPCI directory, and install Composer dependencies: `cd phpci && ../composer.phar install`
* Run the PHPCI installer: `./console phpci:install`
* [Add a virtual host to your web server](/Block8/PHPCI/wiki/Add-a-Virtual-Host), pointing to the `public` directory within your new PHPCI directory. You'll need to set up rewrite rules to point all non-existent requests to PHPCI.
* [Set up the PHPCI Worker](https://github.com/Block8/PHPCI/wiki/Run-Builds-Using-a-Worker), or you can run builds using the [PHPCI daemon](/Block8/PHPCI/wiki/Run-Builds-Using-a-Daemon) or [a cron-job](/Block8/PHPCI/wiki/Run-Builds-Using-Cron) to run PHPCI builds.
## Installing PHPCI Manually:
* Go to the directory in which you want to install PHPCI, for example: `/var/www`
* [Download PHPCI](https://github.com/Block8/PHPCI/releases/latest) and unzip it.
* Go to the PHPCI directory: `cd /var/www/phpci`
* Install dependencies using Composer: `composer install`
* Install PHPCI itself: `php ./console phpci:install`
* [Add a virtual host to your web server](/Block8/PHPCI/wiki/Add-a-Virtual-Host), pointing to the `public` directory within your new PHPCI directory. You'll need to set up rewrite rules to point all non-existent requests to PHPCI.
* [Set up the PHPCI Worker](https://github.com/Block8/PHPCI/wiki/Run-Builds-Using-a-Worker), or you can run builds using the [PHPCI daemon](/Block8/PHPCI/wiki/Run-Builds-Using-a-Daemon) or [a cron-job](/Block8/PHPCI/wiki/Run-Builds-Using-Cron) to run PHPCI builds.
### Extended Guides
- [Installing PHPCI on Mac OSX Mavericks](https://github.com/Block8/PHPCI/wiki/Vanilla-Mac-Mavericks-Server-Installation-Guide)
- [Installing PHPCI on Mac OSX Yosemite](https://github.com/Block8/PHPCI/wiki/Vanilla-Installation-on-OS-X-10.10-Yosemite-with-OS-X-Server-4)

19
docs/en/interpolation.md Normal file
View file

@ -0,0 +1,19 @@
Most strings used in the build configuration can have variables related to the build inserted into them with the following syntax:
"My important message is about %SOMETHING%"
Where something can be one of the following:
* **COMMIT** - The commit hash
* **SHORT_COMMIT** - The shortened version of the commit hash
* **COMMIT_EMAIL** - The email address of the committer
* **COMMIT_MESSAGE** - The message written by the committer
* **COMMIT_URI** - The URL to the commit
* **BRANCH** - The name of the branch
* **BRANCH_URI** - The URL to the branch
* **PROJECT** - The ID of the project
* **BUILD** - The build number
* **PROJECT_TITLE** - The name of the project
* **BUILD_PATH** - The path to the build
* **BUILD_URI** - The URL to the build in PHPCI

50
docs/en/logging.md Normal file
View file

@ -0,0 +1,50 @@
# Basics
The phpci codebase makes use of the [psr3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) logging standard. By default we use [Monolog](https://github.com/Seldaek/monolog) to handle the actual work implementing this standard.
# How to Setup Logging (For people running a PHPCI instance)
The only step required to activate logging is to create a file in the root directory called loggerconfig.php with content like the following:
```php
<?php
return array(
/** Loggers attached to every command */
"_" => function () {
return array(
new \Monolog\Handler\StreamHandler('path/to/log', \Monolog\Logger::ERROR),
);
}
);
```
This file should return an array of key value pairs. Each key tells phpci which command to attach the logger to (the underscore is a special value which matches all commands). For each command an array of [Monolog](https://github.com/Seldaek/monolog) handlers should be returned. In the example above we've used one that simply writes to the file system but in practise this could be any handler written for monolog.
Once this file is created all plugins and core phpci functionality should start writing to the configured handlers.
# How to write to the Log (For people creating a new plugin)
## Using the plugin constructor to get a logger directly
For plugin creators the simplest way to get hold of an error logger is to add a parameter to the constructor and typehint on 'Psr\Log\LoggerInterface'. The code that loads your plugin will automatically inject the logger when it sees this. For example:
```php
class ExampleLoggingPlugin implements \PHPCI\Plugin
{
protected $log;
public function __construct(Psr\Log\LoggerInterface $log)
{
$this->log = $log;
}
public function execute()
{
$this->log->notice("You'll notice this in the log");
}
}
```
## Using convenience methods provided by the Builder
Your plugin can also call a couple of messages on the Builder object:
logSuccess()
logFailure()
log()
All calls will get piped through to the appropriate logger.

19
docs/en/plugins/atoum.md Normal file
View file

@ -0,0 +1,19 @@
Allows you to run [Atoum](https://github.com/atoum/atoum) unit tests.
## Configuration
### Options
- **args** [string, optional] - Allows you to pass command line arguments to Atoum.
- **config** [string, optional] - Path to an Atoum configuration file.
- **directory** [string, optional] - Path in which to run Atom (defaults to the build root).
- **executable** [string, optional] - Allows you to provide a path to the Atom binary (defaults to PHPCI root, vendor/bin, or a system-provided Atom binary).
### Example
```yml
test:
atoum:
args: "command line arguments go here"
config: "path to config file"
directory: "directory to run tests"
executable: "path to atoum executable"
```

14
docs/en/plugins/behat.md Normal file
View file

@ -0,0 +1,14 @@
A very simple plugin for running [Behat](http://behat.org/) BDD tests.
## Configuration
### Options
- **executable** [string, optional] - Allows you to provide a path to the Behat binary (defaults to PHPCI root, vendor/bin, or a system-provided Behat binary).
- **features** [string, optional] - Provide a list of Behat features to run.
### Example
```yml
test:
behat:
executable: "path to behat binary"
features: "command line arguments"
```

View file

@ -0,0 +1,20 @@
This plugin joins a [Campfire](https://campfirenow.com/) room and sends a user-defined message, for example a "Build Succeeded" message.
## Configuration
### Options
- **authToken** [string, required] - Your Campfire user authentication token.
- **message** [string, required] - The message to send to the room.
- **roomId** [string, required] - Your Campfire room ID number.
- **url** [string, required] - Your Campfire chat room URL.
### Example
```yml
build_settings:
campfire:
authToken: "campfire auth token"
roomId: "campfire room ID"
url: "campfire URL"
success:
campfire:
message: "Build succeeded!"
```

View file

@ -0,0 +1,16 @@
Works through a list of files to remove from your build. Useful when used in combination with Copy Build or Package Build.
### Configuration Options:
* **remove** - Required - An array of files and / or directories to remove.
### Example Configuration:
```yml
complete:
clean_build:
remove:
- composer.json
- composer.phar
- config.dev.php
```

View file

@ -0,0 +1,42 @@
A simple plugin that allows you to run [Codeception](http://codeception.com/) tests.
### Configuration Options:
* **config** - Required - Can be either a single string pointing to a Codeception configuration file, or an array of configuration file paths. By default this is called `codeception.yml` and will be in the root of your project.
* **args** - Optional - The string of arguments to be passed to the run command. **Important**, due to the assumption made on line [132](https://github.com/Block8/PHPCI/blob/master/PHPCI/Plugin/Codeception.php#L132) regarding the value of `--xml` being the next argument which will not be correct if the user provides arguments using this config param, you must specify `report.xml` before any user input arguments to satisfy the report processing on line [146](https://github.com/Block8/PHPCI/blob/master/PHPCI/Plugin/Codeception.php#L146)
* **path** - Optional - The path from the root of your project to the root of the codeception _output directory
##### Default values
- config
- `codeception.yml` if it exists in the root of the project
- `codeception.dist.yml` if it exists in the root of the project
- null if no option provided and the above two fail, this will cause an Exception to be thrown on execution
- args
- Empty string
- path
- `tests/_output/`
##### Example on running codeception with default settings (when tests are in tests/ directory):
```
codeception:
config: "codeception.yml"
path: "tests/"
```
##### Example usage against the Yii2 framework
```
codeception:
allow_failures: false
config: "tests/codeception.yml"
path: "tests/codeception/_output/"
args: "report.xml --no-ansi --coverage-html"
```
The path value will need to be changed if you have your tests directory somewhere other than in the root of the project.

View file

@ -0,0 +1,24 @@
Allows you to run Composer within your build, to install dependencies prior to testing. Best run as a "setup" stage plugin.
## Configuration
### Options
* **directory** [optional, string] - Directory within which you want Composer to run (default: build root)
* **action** [optional, string, update|install] - Action you wish Composer to run (default: 'install')
* **prefer_dist** [optional, bool, true|false] - whether Composer should run with the `--prefer-dist` flag (default: false)
### Example
```yml
setup:
composer:
directory: "my/composer/dir"
action: "update"
prefer_dist: true
```
## Warning
If you are using a Composer private repository like Satis, with HTTP authentication, you must check your username and password inside the ```auth.json``` file. PHPCI uses the ```--no-interaction``` flag, so it will not warn if you must provide that info.
For more info, please check the Composer documentation.
https://getcomposer.org/doc/04-schema.md#config

View file

@ -0,0 +1,7 @@
Copies all files from your build, with the exception of those in the "ignore" build settings property, to a directory of your choosing.
### Configuration Options:
* **directory** - Required - The directory to which you want to copy the build.
* **respect_ignore** - Optional - Whether to respect the global "ignore" setting when copying files. Default is false.
* **wipe** - Optional - Set true if you want destination directory to be cleared before copying. Default is false.

View file

@ -0,0 +1,16 @@
Triggers a deployment of the project to run via [Deployer](http://phpdeployment.org)
**Configuration Options:**
### Options
* **webhook_url** [required, string] - The URL to your Deployer WebHook
* **reason** [optional, string] - Your deployment message. Default - PHPCI Build #%BUILD% - %COMMIT_MESSAGE%
* **update_only** [optional, bool, true|false] - Whether the deployment should only be run if the currently deployed branches matches the one being built. Default - true
### Example
```yaml
success:
deployer:
webhook_url: "https://deployer.example.com/deploy/QZaF1bMIUqbMFTmKDmgytUuykRN0cjCgW9SooTnwkIGETAYhDTTYoR8C431t"
reason: "PHPCI Build #%BUILD% - %COMMIT_MESSAGE%"
update_only: true
```

30
docs/en/plugins/email.md Normal file
View file

@ -0,0 +1,30 @@
Sends a build status email.
### Configuration Options:
* **committer** - Whether or not to send the email to the committer that prompted this build.
* **addresses** - A list of addresses to send to.
* **default_mailto_address** - A default address to send to.
* **cc** - A list of addresses that will receive a copy of every emails sent.
* **template** - The template to use, options are short and long. Default is short on success and long otherwise.
**Note:** _This plugin will only work if you configured email settings during installation or configured them later in Admin Options > Settings > Email Settings_
### Configuration Example
See [Adding PHPCI Support to Your Projects](https://www.phptesting.org/wiki/Adding-PHPCI-Support-to-Your-Projects) for more information about how to configure plugins.
Send an email to the committer as well as one@exameple.com if a build fails:
```yml
failure:
email:
committer: true
default_mailto_address: one@example.com
```
Send an email to one@example.com every time a build is run:
```yml
complete:
email:
default_mailto_address: one@example.com
```

9
docs/en/plugins/env.md Normal file
View file

@ -0,0 +1,9 @@
Sets environment variables on the PHPCI server for the build.
### Sample Configuration:
```yml
setup:
env:
APPLICATION_ENV: "development"
```

18
docs/en/plugins/grunt.md Normal file
View file

@ -0,0 +1,18 @@
This plugin runs [Grunt](http://gruntjs.com/) tasks.
## Configuration
### Options
- **directory** [string, optional] - The directory in which to run Grunt (defaults to build root.)
- **grunt** [string, optional] - Allows you to provide a path to Grunt (defaults to PHPCI root, vendor/bin, or a system-provided Grunt).
- **gruntfile** [string, optional] - Gruntfile to run (defaults to `Gruntfile.js`).
- **task** [string, optional] - The Grunt task to run.
### Example
```yml
test:
grunt:
directory: "path to run grunt in"
grunt: "path to grunt executable"
gruntfile: "gruntfile.js"
task: "css"
```

View file

@ -0,0 +1,26 @@
This plugin joins a [HipChat](https://www.hipchat.com/) room and sends a user-defined message, for example a "Build Succeeded" message.
**Configuration Options:**
| Field | Required? | Description |
|-------|-----------|-------------|
| `authToken` | Yes | Your HipChat API authentication token (v1) |
| `room` | Yes | Your Hipchat room name or ID number. This can also be an array of room names or numbers, and the message will be sent to all rooms. |
| `message` | No | The message to send to the room. Default - `%PROJECT_TITLE% built at %BUILD_URI%` |
| `color` | No | Message color. Valid values: yellow, green, red, purple, gray, random. Default - `yellow`|
| `notify` | No | Whether or not this message should trigger a notification for people in the room (change the tab color, play a sound, etc). Default - `false`. |
Message can be formatted via HTML. Example:
```html
<b>%PROJECT_TITLE%</b> - build <a href="%BUILD_URI%">%BUILD%</a> failed!
```
Configuration example:
```yaml
hipchat_notify:
authToken: 123
room: 456
message: <b>%PROJECT_TITLE%</b> - build <a href="%BUILD_URI%">%BUILD%</a> failed!
color: red
notify: true
```

13
docs/en/plugins/irc.md Normal file
View file

@ -0,0 +1,13 @@
Connects to an IRC server and sends a defined message.
### Configuration Options:
* **message** - Required - The message to send.
### Build Settings
* **irc** - All child properties are required
* **server** - IRC server to connect to.
* **port** - IRC server port, defaults to 6667.
* **room** - The room you wish to send your message to (must start with a #)
* **nick** - The nickname you want the bot to use.

19
docs/en/plugins/lint.md Normal file
View file

@ -0,0 +1,19 @@
This plugin runs PHP's built in Lint (syntax / error check) functionality.
## Configuration
### Options
- **directory** [string, optional] - A single path in which you wish to lint files.
- **directories** [array, optional] - An array of paths in which you wish to lint files. This overrides `directory`.
- **recursive** [bool, optional] - Whether or not you want to recursively check sub-directories of the above (defaults to true).
### Example
```yml
test:
lint:
directory: "single path to lint files"
directories:
- "directory to lint files"
- "directory to lint files"
- "directory to lint files"
recursive: false
```

29
docs/en/plugins/mysql.md Normal file
View file

@ -0,0 +1,29 @@
Connects to a given MySQL server and runs a selection of queries.
### Example Configuration:
```yaml
build_settings:
mysql:
host: 'localhost'
user: 'testuser'
pass: '12345678'
setup:
mysql:
- "CREATE DATABASE my_app_test;"
complete:
mysql:
- "DROP DATABASE my_app_test;"
```
Import SQL from file:
```yaml
setup:
mysql:
import-from-file: # This key name doesn´t matter
import:
database: "foo" # Database name
file: "/path/dump.sql" # Relative path in build folder
```

View file

@ -0,0 +1,16 @@
Builds a tar or zip archive of your build and places it in a directory of your choosing.
### Configuration Options:
* **directory** - Required - Directory in which to put the package file.
* **filename** - Required - File name for the package.
* **format** - Required - `tar` or `zip`
You can use following variables in filename:
* %build.commit%
* %build.id%
* %build.branch%
* %project.title%
* %date%
* %time%

View file

@ -0,0 +1,5 @@
Runs [PDepend](http://pdepend.org/) software metrics.
### Configuration Options:
* **directory** - Required - Directory in which to run PDepend.

19
docs/en/plugins/pgsql.md Normal file
View file

@ -0,0 +1,19 @@
Connects to a given PostgreSQL server and runs a list of queries.
### Example Configuration:
```yaml
build_settings:
pgsql:
host: 'localhost'
user: 'testuser'
pass: '12345678'
setup:
pgsql:
- "CREATE DATABASE my_app_test;"
complete:
pgsql:
- "DROP DATABASE my_app_test;"
```

18
docs/en/plugins/phar.md Normal file
View file

@ -0,0 +1,18 @@
Allows you to create a [Phar](http://php.net/manual/en/book.phar.php) archive from your project.
### Example
```
phar:
directory: /path/to/directory
filename: foobar.phar
regexp: /\.(php|phtml)$/
stub: filestub.php
```
### Configuration Options
* **directory**: `phar` output directory. Default: `%buildpath%`;
* **filename**: `phar` filename inside output directory. Default: `build.phar`;
* **regexp**: regular expression for Phar iterator. Default: `/\.php$/`; and
* **stub**: stub content filename. No default value.

18
docs/en/plugins/phing.md Normal file
View file

@ -0,0 +1,18 @@
This plugin allows you to use the Phing build system to build your project.
### Configuration options:
* **directory** - Relative path to the directory in which you want to run phing.
* **build_file** - Your phing build.xml file.
* **targets** - Which build targets you want to run.
* **properties** - Any custom properties you wish to pass to phing.
* **property_file** - A file containing properties you wish to pass to phing.
### Sample config:
```yml
phing:
build_file: 'build.xml'
targets:
- "build:test"
properties:
config_file: "PHPCI"
```

View file

@ -0,0 +1,33 @@
Runs PHP Code Sniffer against your build.
## Configuration
### Options
* **allowed_warnings** [int, optional] - The warning limit for a successful build.
* **allowed_errors** [int, optional] - The error limit for a successful build.
* **suffixes** [array, optional] - An array of file extensions to check.
* **standard** [string, optional] - The standard against which your files should be checked (defaults to PSR2.)
* **tab_width** [int, optional] - Your chosen tab width.
* **encoding** [string, optional] - The file encoding you wish to check for.
* **path** [string, optional] - Path in which to run PHP Code Sniffer.
* **ignore** [array, optional] - A list of files / paths to ignore, defaults to the build_settings ignore list.
### Example
Simple example where PHPCS will run on app directory, but ignore the views folder, and use PSR-1 and PSR-2 rules for validation:
```yml
test:
php_code_sniffer:
path: "app"
ignore:
- "app/views"
standard: "PSR1,PSR2"
```
For use with an existing project:
```yml
test:
php_code_sniffer:
standard: "/phpcs.xml" # The leading slash is needed to trigger an external ruleset.
# Without it, PHPCI looks for a rule named "phpcs.xml"
allowed_errors: -1 # Even a single error will cause the build to fail. -1 = unlimited
allowed_warnings: -1
```

View file

@ -0,0 +1,18 @@
Runs PHP Copy / Paste Detector against your build.
## Configuration
### Options
* **path** - Optional - Path in which to run PHP Copy/Paste Detector (default: build root).
* **ignore** - Optional - A list of files / paths to ignore (default: build_settings > ignore).
* **standard** [string, optional] - which PSR standard to follow (default: 'PSR1').
### Example
```yml
test:
php_cpd:
standard: "PSR2"
path: "app"
ignore:
- "app/my/path"
```

View file

@ -0,0 +1,21 @@
Runs PHP Coding Standards Fixer against your build.
## Configuration
### Options
* **verbose** [bool, optional] - Whether to run in verbose mode (default: false)
* **diff** [bool, optional] - Whether to run with the `--diff` flag enabled (default: false)
* **level** [string, optional] - `psr0`, `psr1`, `psr2`, or `symphony` (default: all)
* **workingdir** [string, optional] - The directory in which PHP CS Fixer should work (default: build root)
### Example
```yml
test:
php_cs_fixer:
verbose: true
diff: true
level: "psr2"
workingdir: "my/dir/path"
```
## Warning
There is currently a bug with this plugin that will cause an error if you leave the level to default to `all`. That level does not exist and will cause the build to fail. Instead specify the level explicitly until this is fixed.

View file

@ -0,0 +1,16 @@
Runs the PHP Docblock Checker against your build. This tool verifies that all classes and methods have docblocks.
### Configuration Options:
* **allowed_warnings** - Optional - The warning limit for a successful build.
* **path** - Optional - Directory in which PHP Docblock Checker should run.
* **skip_methods** - Optional - Tells the checker to ignore methods that don't have a docblock.
* **skip_classes** - Optional - Tells the checker to ignore classes that don't have a docblock.
### Example config:
```yml
php_docblock_checker:
allowed_warnings: 10
skip_classes: true
```

View file

@ -0,0 +1,14 @@
Runs [PHPLoc](https://github.com/sebastianbergmann/phploc) against your project and records some key metrics.
## Configuration
### Options
* **directory** - Optional - The directory in which phploc should run.
### Example
Run PHPLOC against the app directory only. This will prevent inclusion of code from 3rd party libraries that are included outside of the app directory.
```yml
test:
php_loc:
directory: "app"
```

View file

@ -0,0 +1,30 @@
Runs PHP Mess Detector against your build. Records some key metrics, and also reports errors and warnings.
## Configuration
### Options
- **allowed_warnings** [int, optional] - The warning limit for a successful build (default: 0). -1 disables warnings. Setting allowed_warnings in conjunction with zero_config will override zero_config.
- **suffixes** [array, optional] - An array of file extensions to check (default: 'php')
- **ignore** [array, optional] - An array of files/paths to ignore (default: build_settings > ignore)
- **path** [string, optional] - Directory in which PHPMD should run (default: build root)
- **rules** [array, optional] - Array of rulesets that PHPMD should use when checking your build or a string containing at least one slash, will be treated as path to PHPMD ruleset. See http://phpmd.org/rules/index.html for complete details on the rules. (default: ['codesize', 'unusedcode', 'naming']).
- **zero_config** [bool, optional] - Suppresses build failure on errors and warnings if set to true. (default: false).
### Example
```yml
test:
php_mess_detector:
path: 'app'
ignore:
- 'vendor'
allowed_warnings: -1
rules:
- "cleancode"
- "controversial"
- "codesize"
- "design"
- "naming"
- "unusedcode"
- "somedir/customruleset.xml"
zero_config: true
```

View file

@ -0,0 +1,16 @@
Similar to the [standard PHP Lint plugin](https://github.com/Block8/PHPCI/wiki/Lint-plugin), except that it uses the [PHP Parallel Lint](https://github.com/JakubOnderka/PHP-Parallel-Lint) project to run.
## Configuration
### Options
* **directory** [string, optional] - directory to inspect (default: build root)
* **ignore** [array, optional] - directory to ignore (default: inherits ignores specified in setup)
### Example
```yml
test:
php_parallel_lint:
directory: "app"
ignore:
- "vendor"
- "test"
```

View file

@ -0,0 +1,24 @@
Runs [PHP Spec](http://www.phpspec.net/) tests against your build.
### Configuration Options:
* **bootstrap** - Optional - Path to a PHPSpec bootstrap file.
### Example
```
build_settings:
[...]
setup:
[...]
test:
php_spec:
complete:
[...]
success:
[...]
```

View file

@ -0,0 +1,34 @@
Runs PHPUnit tests against your build.
## Configuration
### Options
Has two modes:
#### phpunit.xml Configuration File
Its activated if you have phpunit.xml file in your build path, `tests/` subfolder, or you specify it as a parameter:
* **config** - Optional - Path to a PHP Unit XML configuration file.
* **run_from** - Optional - When running PHPUnit with an XML config, the command is run from this directory
* **coverage** - Optional - Value for the `--coverage-html` command line flag.
* **path** - Optional - In cases where tests files are in a sub path of the /tests path, allows this path to be set in the config.
#### Running Tests By Specifying Directory
* **directory** - Optional - The directory (or array of dirs) to run PHPUnit on
Both modes accept:
* **args** - Optional - Command line args (in string format) to pass to PHP Unit
### Examples
Specify config file and test directory:
```yml
test:
php_unit:
config:
- "path/to/phpunit.xml"
path: "app/tests/"
```
## Troubleshooting
If standard logging of PHPCI is not enough, to get standard output from any command, including PHPUnit, edit `BaseCommandExecutor::executeCommand()` to see what exactly is wrong
* Run `composer update` in phpunit plugin directory of PHPCI to get all of its dependencies
* If phpunit is inside of the project's composer.json, it might interfere with PHPCI's phpunit installation
* Make sure you have XDebug installed.`The Xdebug extension is not loaded. No code coverage will be generated.`
Otherwise test report parsing in `TapParser` will fail, wanting coverage report as well `Invalid TAP string, number of tests does not match specified test count.`

48
docs/en/plugins/shell.md Normal file
View file

@ -0,0 +1,48 @@
Runs a given Shell command.
**Note: ** Because this plugin could potentially be abused, it requires extra steps to enable it:
1. In the root of your PHPCI system, in the same directory where you'll find composer.json and vars.php, look for a file local_vars.php. If it does not exist, create it.
2. In local_vars.php add this code:
```php
<?php
define('ENABLE_SHELL_PLUGIN', true);
```
If `ENABLE_SHELL_PLUGIN` is either false or undefined, the shell plugin won't work.
### Configuration Options:
* **command** - Required - The shell command to run.
```yml
setup:
shell:
command: "bin/console build"
```
You should understand, that in old configuration type, you can run only one command!
### New format of Configuration Options
```yml
setup:
shell:
- "cd /www"
- "chmod u+x %BUILD_PATH%/bin/console"
- "%BUILD_PATH%/bin/console build"
```
#### Each new command forgets about what was before
So if you want cd to directory and then run script there, combine those two commands into one like:
```yml
setup:
shell:
- "cd %BUILD_PATH% && php artisan migrate" # Laravel Migrations
```
[See variables which you can use in shell commands](../interpolation.md)

View file

@ -0,0 +1,50 @@
This plugin joins a [Slack](https://www.slack.com/) room and sends a user-defined message, for example a "Build Succeeded" message.
**Configuration Options:**
| Field | Required? | Description |
|-------|-----------|-------------|
| `webhook_url` | Yes | The URL to your Slack WebHook |
| `room` | No | Your Slack room name. Default - #phpci |
| `username` | No | The name to send the message as. Default - PHPCI |
| `icon` | No | The URL to the user icon or an emoji such as :ghost:. Default - The value configured on Slack's WebHook setup |
| `message` | No | The message to send to the room. Default - `<%PROJECT_URI%|%PROJECT_TITLE%> - <%BUILD_URI%|Build #%BUILD%> has finished for commit <%COMMIT_URI%|%SHORT_COMMIT% (%COMMIT_EMAIL%)> on branch <%BRANCH_URI%|%BRANCH%>` |
| `show_status` | No | Whether or not to append the build status as an attachment in slack. Default - true
Send a message if the build fails:
```yaml
failure:
slack_notify:
webhook_url: "https://hooks.slack.com/services/R212T827A/G983UY31U/aIp0yuW9u0iTqwAMOEwTg"
room: "#phpci"
username: "PHPCI"
icon: ":ghost:"
message: "%PROJECT_TITLE% - build %BUILD% failed! :angry:"
show_status: false
```
Send a message if the build is successful:
```yaml
success:
slack_notify:
webhook_url: "https://hooks.slack.com/services/R212T827A/G983UY31U/aIp0yuW9u0iTqwAMOEwTg"
room: "#phpci"
username: "PHPCI"
icon: ":ghost:"
message: "%PROJECT_TITLE% - build %BUILD% succeeded! :smiley:"
show_status: false
```
Send a message every time the build runs:
```yaml
complete:
slack_notify:
webhook_url: "https://hooks.slack.com/services/R212T827A/G983UY31U/aIp0yuW9u0iTqwAMOEwTg"
room: "#phpci"
username: "PHPCI"
icon: ":ghost:"
message: "%PROJECT_TITLE% - build %BUILD% completed"
show_status: true
```

View file

@ -0,0 +1,5 @@
Checks all files in your project for TODOs and other technical debt.
## Configuration Options:
* **searches** - Optional - Case-insensitive array of terms to search for. Defaults to TODO, TO DO, FIXME and FIX ME.

31
docs/en/plugins/xmpp.md Normal file
View file

@ -0,0 +1,31 @@
## Requirements
- sendxmpp package
## Installation
1. On debian system (for example) use aptitude command to install sendxmpp
2. Add XMPP plugin in "complete" section of your phpci.yml
## Configuration options
- username : Username of your XMPP sender account. (example : login@server.com)
- password : Password of your XMPP sender account.
- recipients : List of your XMPP recipents account.
- server : If your server is not the same that your login server (optional, example : gtalk.google.com)
- tls : Set 1 to enable TLS connection or 0 to disable it. (optional, default is 0)
- alias : Alias of your sender account. (optional)
- date_format : strftime mask date format display in notification message. (optional, default is %c of strftime function)
## Configuration example
```
complete:
xmpp:
username: "login@gmail.com"
password: "AZERTY123"
recipients:
- "recipient1@jabber.org"
- "recipient2@jabber.org"
server: "gtalk.google.com"
tls: 1
alias: "PHPCi Notification"
date_format: "%d/%m/%Y"
```

View file

@ -0,0 +1,10 @@
If you would like your builds to run automatically whenever there is a commit or other similar activity in your Bitbucket repository, perform the following steps:
1. Log into PHPCI.
2. Click on your Bitbucket project.
3. Copy the web hook link specified on the left.
4. Log into Bitbucket and go to your repo.
5. Click the settings cog icon at the top right of the page.
6. Click on "Hooks" in the left hand menu
7. Select "POST" from the drop-down and click "Add hook"
8. Paste the web hook link you copied above, and press save.

53
docs/en/sources/git.md Normal file
View file

@ -0,0 +1,53 @@
## Requirements
- A git repository on a server (bare or plain does not matter)
- [curl](http://curl.haxx.se) to send the web hook
## Installation
1. Create a new file `post-receive` inside the [git `hooks` directory](http://www.git-scm.com/book/en/Customizing-Git-Git-Hooks) with the following content:
```shell
#!/bin/sh
PROJECT_ID=1
PHPCI_URL="http://my.server.com/PHPCI/"
trigger_hook() {
NEWREV="$2"
REFNAME="$3"
if [ "$NEWREV" = "0000000000000000000000000000000000000000" ]; then
# Ignore deletion
return
fi
case "$REFNAME" in
# Triggers only on branches and tags
refs/heads/*|refs/tags/*) ;;
# Bail out on other references
*) return ;;
esac
BRANCH=$(git rev-parse --symbolic --abbrev-ref "$REFNAME")
COMMITTER=$(git log -1 "$NEWREV" --pretty=format:%ce)
MESSAGE=$(git log -1 "$NEWREV" --pretty=format:%s)
echo "Sending webhook"
curl \
--data-urlencode branch="$BRANCH" \
--data-urlencode commit="$NEWREV" \
--data-urlencode committer="$COMMITTER" \
--data-urlencode message="$MESSAGE" \
"$PHPCI_URL/webhook/git/$PROJECT_ID"
}
if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
PAGER= trigger_hook $1 $2 $3
else
while read oldrev newrev refname; do
trigger_hook $oldrev $newrev $refname
done
fi
```
2. Change the file to be executable: `chmod a+x post-receive`
3. Push changes to the repository

11
docs/en/sources/github.md Normal file
View file

@ -0,0 +1,11 @@
If you would like your builds to run automatically whenever there is a commit or other similar activity in your GitHub repository, perform the following steps:
1. Log into PHPCI.
2. Click on your GitHub project.
3. Copy the web hook link specified on the right of the page.
4. Log into GitHub and go to your repository.
5. Click the settings icon on the lower right sidebar.
6. Click on "Webhooks & Services".
7. Add your web hook link you copied above, and specify when you would like it to run.
8. Add the public key for the project in PHPCI to the deploy keys for the repository on GitHub.
9. Verify that the initial test delivery was successful. If not, make sure that your PHPCI machine is reachable from the internet.

11
docs/en/sources/gitlab.md Normal file
View file

@ -0,0 +1,11 @@
If you would like your builds to run automatically whenever there is a commit or other similar activity in your Gitlab repository, perform the following steps:
1. Log into PHPCI.
2. Click on your Gitlab project.
3. Copy the web hook link specified on the left.
4. Log into Gitlab and go to your repo.
5. Click the "settings" tab in the top right corner of the page.
6. Click on "Web Hooks".
7. Paste the link you copied from PHPCI into the "URL" textbox.
8. Select the events which you want to trigger a PHPCI build. The default and recommended setup is to only enable "push events."
9. Click "Add Web Hook," and verify that the test was successful.

27
docs/en/status.md Normal file
View file

@ -0,0 +1,27 @@
### Status Image
Most Continuous Integration systems provide a simple image URL that you can use to display your project status on other web sites (like Github) - PHPCI is no different.
You can find the status image at the following location: `http://{PHPCI URL}/build-status/image/{PROJECT ID}`
So for example, our instance of PHPCI is at `phpci.block8.net`, and our PHPCI project ID is `2`, so the image URL is: `http://phpci.block8.net/build-status/image/2`.
Example:
![](http://phpci.block8.net/build-status/image/2)
### Status Page
PHPCI also provides a public project status page, that is accessible for everyone.
You can find the status page at the following location: `http://{PHPCI URL}/build-status/view/{PROJECT ID}`
Example:
http://phpci.block8.net/build-status/view/2
#### Where do I find my project ID?
Go to your instance of PHPCI, and open the project you are interested in. The project ID is the number in the last part of the URL in your browser.
Example:
http://phpci.block8.net/project/view/2 ~> PROJECT ID: `2`
#### Enable/disable status image and page
You can enable or disable access to the public status image and page in your project's settings.

8
docs/en/updating.md Normal file
View file

@ -0,0 +1,8 @@
Updating PHPCI to the latest release, or even dev-master updates is something that will need to be done from time to time. Most of this may be self-explanatory, but for clarity and completeness, it should be added to the documentation.
1. Go to your PHPCI root folder in a Terminal.
2. Pull the latest code. On Linux and Mac this would look like this: `git pull`
3. Update the PHPCI database: `./console phpci:update`
4. Update the composer and its packages: `composer self-update && composer update`
5. Return to the PHPCI admin screens and check your desired plugins are still installed correctly.
7. Run a build to make sure everything is working as expected.

106
docs/en/virtual_host.md Normal file
View file

@ -0,0 +1,106 @@
In order to access the PHPCI web interface, you need to set up a virtual host in your web server.
Below are a few examples of how to do this for various different web servers.
## Nginx Example:
```
server {
... standard virtual host ...
location / {
try_files $uri @phpci;
}
location @phpci {
# Pass to FastCGI:
fastcgi_pass unix:/path/to/phpfpm.sock;
fastcgi_index index.php;
fastcgi_buffers 256 4k;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME index.php;
}
}
```
## Apache Example:
For Apache, you can use a standard virtual host, as long as your server supports PHP. All you need to do is add the following to a `.htaccess` file in your PHPCI `/public` directory.
```
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
```
### Installing in Vagrant
- Edit virtual host in apache2.
```
<VirtualHost *:80>
ServerAdmin user@domain.com
DocumentRoot /var/www/phpci/public
ServerName phpci.vagrant
ServerAlias phpci.vagrant
<Directory /var/www/phpci/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/phpci-error_log
CustomLog ${APACHE_LOG_DIR}/phpci-access_log combined
</VirtualHost>
```
- In Mac OS X add in /etc/hosts
```
127.0.0.1 phpci.vagrant
```
## Other Servers
### Lighttpd Example (lighttpd >= `1.4.24`):
This example uses the `$HTTP["host"]` conditional block because `$HTTP["url"]` blocks aren't supported with url rewriting in lighttpd <= `1.4.33` (source: [lighttpd docs for mod_rewrite](http://redmine.lighttpd.net/projects/1/wiki/Docs_ModRewrite)). In lighttpd >= `1.4.34` however, [this has been fixed](http://redmine.lighttpd.net/issues/2526).
### lighttpd <= `1.4.33`
```
$HTTP["host"] =~ "^phpci\.example\.com$" {
# Rewrite all requests to non-physical files
url.rewrite-if-not-file =
(
"^(.*)$" => "index.php/$1"
)
}
```
### lighttpd >= `1.4.34`
```
$HTTP["url"] =~ "^\/PHPCI/$" {
# Rewrite all requests to non-physical files
url.rewrite-if-not-file =
(
"^(.*)$" => "index.php/$1"
)
}
```
If you ~~would like~~ are forced to use lighttpd <= `1.4.24`, [you can use mod_magnet and Lua instead] (http://redmine.lighttpd.net/projects/1/wiki/AbsoLUAtion).
### Built-in PHP Server Example:
You can use the built-in PHP server `php -S localhost:8080` by adding `public/routing.php`.
```php
<?php
if (file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) {
return false; // serve the requested resource as-is.
} else {
include_once 'index.php';
}
```

13
docs/en/workers/cron.md Normal file
View file

@ -0,0 +1,13 @@
Running builds using cron is a quick and simple method of getting up and running with PHPCI. It also removes the need for PHPCI to be running all the time.
If you want a little more control over how PHPCI runs, you may want to [set up the PHPCI daemon](/Block8/PHPCI/wiki/Run-Builds-Using-a-Daemon) instead.
## Setting up the Cron Job:
You'll want to set up PHPCI to run as a regular cronjob, so run `crontab -e` and enter the following:
```sh
* * * * * /usr/bin/php /path/to/phpci/console phpci:run-builds
```
**Note:** Make sure you change the `/path/to/phpci` to the directory in which you installed PHPCI, and update the PHP path if necessary.

19
docs/en/workers/daemon.md Normal file
View file

@ -0,0 +1,19 @@
The PHPCI daemon runs in the background on your server and continuously checks for new builds. Unless already running a build, the daemon should pick up and start running new builds within seconds of being created.
The daemon is also useful if you want to run multiple PHPCI workers in a virtualised environment (i.e. Docker)
If you want to run PHPCI builds on a regular schedule instead, you should [set up a cron-job](/Block8/PHPCI/wiki/Run-Builds-Using-Cron).
## Starting the Daemon:
On a Linux/Unix server, the following command will start the daemon and keep it running even when you log out of the server:
```sh
nohup php ./daemonise phpci:daemonise >/dev/null 2>&1 &
```
If you need to debug what's going on with your builds, you can also run the daemon directly using the following command, which will output the daemon's log directly to your terminal:
```sh
php daemonise phpci:daemonise
```

55
docs/en/workers/worker.md Normal file
View file

@ -0,0 +1,55 @@
The PHPCI Worker (added in v1.7) runs in the background on your server and waits for new builds to be added to a Beanstalkd queue. Unless already running a build, the worker will pick up and start running new builds almost immediately after their creation.
The worker is the recommended way to run PHPCI builds. You can run several workers all watching one queue, allowing jobs to be run simultaneously without the overhead of polling your MySQL database.
If you can't run Beanstalkd on your server, or would prefer to run builds on a regular schedule, you should consider using the [build daemon](https://github.com/Block8/PHPCI/wiki/Run-Builds-Using-a-Daemon) or [running builds via Cron](https://github.com/Block8/PHPCI/wiki/Run-Builds-Using-Cron).
## Pre-Requisites
* You need to install [Beanstalkd](http://kr.github.io/beanstalkd/) - On Ubuntu, this is as simple as running `apt-get install beanstalkd`.
* [Supervisord](http://supervisord.org/) needs to be installed and running on your server.
## Setting up the PHPCI Worker
### On a new installation:
Setting up the worker on a new installation of PHPCI is as simple as entering the appropriate values for your Beanstalkd server hostname and queue name when running the PHPCI installer. By default, the installer assumes that you'll be using beanstalkd on `localhost` and will use the queue name `phpci`.
![PHPCI Worker Installer](https://www.phptesting.org/media/render/f48f63699a04444630352643af18b643)
### On an existing installation:
On an existing installation, to set up the worker, you simply need to add the beanstalkd host and queue names directly into your `/PHPCI/config.yml` file. You should add a `worker` key beneath the `phpci` section, with the properties `host` and `queue` as outlined in the screenshot below:
![PHPCI Worker Config](https://www.phptesting.org/media/render/9a88e9298670f2913f5798e68b94c9ed)
## Running the PHPCI Worker:
Once you've set up PHPCI to add your jobs to a beanstalkd queue, you need to start the worker so that it can pick up and run your builds. On most servers, it is best to manage this using supervisord. The following instructions work on Ubuntu, but will need slight amendments for other distributions.
Using your preferred text editor, create a file named `phpci.conf` under `/etc/supervisor/conf.d`. In it, enter the following config:
```
[program:phpci]
command=/path/to/phpci/latest/console phpci:worker
process_name=%(program_name)s_%(process_num)02d
stdout_logfile=/var/log/phpci.log
stderr_logfile=/var/log/phpci-err.log
user=phpci
autostart=true
autorestart=true
environment=HOME="/home/phpci",USER="phpci"
numprocs=2
```
You'll need to edit the '/path/to/phpci', the `user` value and the `environment` value to suit your server. The user needs to be an actual system user with suitable permissions to execute PHP and PHPCI.
Once you've created this file, simply restart supervisord using the command `service supervisor restart` and 2 instances of PHPCI's worker should start immediately. You can verify this by running the command `ps aux | grep phpci`, which should give you output as follows:
```
➜ ~ ps aux | grep phpci
phpci 19057 0.0 0.9 200244 18720 ? S 03:00 0:01 php /phpci/console phpci:worker
phpci 19058 0.0 0.9 200244 18860 ? S 03:00 0:01 php /phpci/console phpci:worker
```
That's it! Now, whenever you create a new build in PHPCI, it should start building immediately.