Skip to content

Commit

Permalink
Improve Package Testing tools
Browse files Browse the repository at this point in the history
- The package uses PHP CS Fixer to validate the coding standard
- Improve Travis settings
- Improve Scrutinizer settings
  • Loading branch information
nyamsprod committed Sep 25, 2015
1 parent 640f57a commit e81de22
Show file tree
Hide file tree
Showing 26 changed files with 216 additions and 178 deletions.
37 changes: 37 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

$header = <<<'EOF'
This file is part of League\CSV, a CSV manipulation library
@copyright 2015 Ignace Nyamagana Butera. All rights reserved
@license MIT See LICENSE.md at the root of the project for more info
EOF;

Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers([
'ordered_use',
'unused_use',
'remove_lines_between_uses',
'remove_leading_slash_use',
'phpdoc_no_empty_return',
'phpdoc_params',
'phpdoc_to_comment',
'phpdoc_order',
'short_array_syntax',
'single_array_no_trailing_comma',
'multiline_array_trailing_comma',
'concat_without_spaces',
'single_quote',
'ternary_spaces',
'operators_spaces',
'new_with_braces',
'-psr0',
])
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/test')
);
41 changes: 30 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
sudo: false

matrix:
include:
- php: 5.4
env:
- COLLECT_COVERAGE=true
- php: 5.5
env:
- COLLECT_COVERAGE=true
- php: 5.6
env:
- COLLECT_COVERAGE=true
- EXECUTE_CS_CHECK=true
- php: 7.0
- php: hhvm
allow_failures:
- php: 7.0
fast_finish: true

cache:
directories:
- $HOME/.composer/cache

before_install:
- composer self-update
- composer validate

before_script:
- travis_retry composer self-update
- travis_retry composer update --no-interaction --prefer-source
install:
- travis_retry composer install --prefer-dist

script:
- phpunit --coverage-text --coverage-clover=coverage.clover
- if [ "$COLLECT_COVERAGE" != "true" ]; then vendor/bin/phpunit; fi
- if [ "$COLLECT_COVERAGE" == "true" ]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi
- if [ "$EXECUTE_CS_CHECK" == "true" ]; then vendor/bin/php-cs-fixer fix -v --diff --dry-run; fi

after_script:
- bash -c 'if [[ "$TRAVIS_PHP_VERSION" != "hhvm" && "$TRAVIS_PHP_VERSION" != "7.0" ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi;'
- if [ "$COLLECT_COVERAGE" == "true" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$COLLECT_COVERAGE" == "true" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
23 changes: 20 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/theleague/csv).
## Bug Report

We accept bug reports via issues created on [Github](https://github.com/thephpleague/csv/issues).

## Pull Requests
### Prior to submitting your report

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
- **Always search the issue or pull request list first** - The odds are good that if you've found a problem, someone else has found it, too.

- **Always try the [master branch](https://github.com/thephpleague/csv)** - to see if the reported bug has not already been fixed.

### When submitting your report

- **Open a new bug report for each issue.**

- **Write a clear summary in english** - A good summary should quickly and uniquely identify a bug report. It should explain the problem, not your suggested solution.

- **Be brief, but don't leave any important details out** - Tell us what you did, what you expected to happen, and what happened. Do not forget to mention your PHP version, the OS Platform and the package version you were using.

## Pull Request

We accept contributions via Pull Requests on [Github](https://github.com/thephpleague/csv/pull).

- **[PSR-2 Coding Standard](http://www.php-fig.org/psr/psr-2/)** - Your patch won't be accepted if it doesn't pass the package coding style test suite.

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ if (! ini_get("auto_detect_line_endings")) {
Testing
-------

Csv has a [PHPUnit](https://phpunit.de/) test suite. To run the tests, run the following command from the project folder:
`League\Csv` has a [PHPUnit](https://phpunit.de) test suite and a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/). To run the tests, run the following command from the project folder.

``` bash
$ phpunit
$ composer test
```

Contributing
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"ext-mbstring" : "*"
},
"require-dev": {
"phpunit/phpunit" : "~4.0",
"scrutinizer/ocular": "~1.1"
"phpunit/phpunit" : "^4.0",
"fabpot/php-cs-fixer": "^1.9"
},
"autoload": {
"psr-4": {
Expand All @@ -36,6 +36,9 @@
"lib\\": "examples\\lib"
}
},
"scripts": {
"test": "vendor/bin/phpunit; vendor/bin/php-cs-fixer fix -v --diff --dry-run;"
},
"extra": {
"branch-alias": {
"dev-master": "7.1-dev"
Expand Down
15 changes: 2 additions & 13 deletions scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
filter:
paths: [src/*]
excluded_paths: [examples/*, test/*]
checks:
php:
Expand All @@ -18,17 +19,5 @@ checks:
fix_doc_comments: true
tools:
external_code_coverage:
timeout: 600
timeout: 1200
runs: 3
php_code_coverage: false
php_code_sniffer:
config:
standard: PSR2
filter:
paths: ['src']
php_loc:
enabled: true
excluded_dirs: [vendor, test, examples]
php_cpd:
enabled: true
excluded_dirs: [vendor, test, examples]
40 changes: 15 additions & 25 deletions src/AbstractCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
use InvalidArgumentException;
use IteratorAggregate;
use JsonSerializable;
use League\Csv\Config;
use League\Csv\Modifier;
use League\Csv\Config\Controls;
use League\Csv\Config\Output;
use League\Csv\Modifier\QueryFilter;
use League\Csv\Modifier\StreamFilter;
use SplFileInfo;
use SplFileObject;
use SplTempFileObject;
Expand All @@ -31,6 +33,14 @@
*/
abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
{
use Controls;

use Output;

use QueryFilter;

use StreamFilter;

/**
* UTF-8 BOM sequence
*/
Expand Down Expand Up @@ -72,26 +82,6 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
*/
protected $open_mode;

/**
* Csv Controls Trait
*/
use Config\Controls;

/**
* Csv Outputting Trait
*/
use Config\Output;

/**
* Query Filter Trait
*/
use Modifier\QueryFilter;

/**
* Stream Filter API Trait
*/
use Modifier\StreamFilter;

/**
* Creates a new instance
*
Expand All @@ -104,7 +94,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
*/
protected function __construct($path, $open_mode = 'r+')
{
$this->flags = SplFileObject::READ_CSV|SplFileObject::DROP_NEW_LINE;
$this->flags = SplFileObject::READ_CSV | SplFileObject::DROP_NEW_LINE;
$this->open_mode = strtolower($open_mode);
$this->path = $this->normalizePath($path);
$this->initStreamFilter($this->path);
Expand Down Expand Up @@ -160,7 +150,7 @@ public function getIterator()
protected function getConversionIterator()
{
$iterator = $this->getIterator();
$iterator->setFlags($this->flags|SplFileObject::READ_AHEAD|SplFileObject::SKIP_EMPTY);
$iterator->setFlags($this->flags | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY);
$iterator = $this->applyBomStripping($iterator);
$iterator = new CallbackFilterIterator($iterator, function ($row) {
return is_array($row) && [null] != $row;
Expand Down Expand Up @@ -239,7 +229,7 @@ public static function createFromFileObject(SplFileObject $obj)
* The string must be an object that implements the `__toString` method,
* or a string
*
* @param string|object $str the string
* @param string|object $str the string
* @param string $newline the newline character
*
* @return static
Expand Down
12 changes: 6 additions & 6 deletions src/Config/Controls.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ abstract public function getIterator();
*
* @param string $delimiter
*
* @throws \InvalidArgumentException If $delimeter is not a single character
* @throws InvalidArgumentException If $delimeter is not a single character
*
* @return $this
*/
Expand Down Expand Up @@ -123,7 +123,7 @@ protected function fetchRowsCountByDelimiter($delimiter, $nb_rows = 1)
* @param int $nb_rows
* @param string[] $delimiters additional delimiters
*
* @throws \InvalidArgumentException If $nb_rows value is invalid
* @throws InvalidArgumentException If $nb_rows value is invalid
*
* @return string[]
*/
Expand Down Expand Up @@ -153,7 +153,7 @@ public function detectDelimiterList($nb_rows = 1, array $delimiters = [])
*
* @param string $enclosure
*
* @throws \InvalidArgumentException If $enclosure is not a single character
* @throws InvalidArgumentException If $enclosure is not a single character
*
* @return $this
*/
Expand Down Expand Up @@ -182,7 +182,7 @@ public function getEnclosure()
*
* @param string $escape
*
* @throws \InvalidArgumentException If $escape is not a single character
* @throws InvalidArgumentException If $escape is not a single character
*
* @return $this
*/
Expand Down Expand Up @@ -211,7 +211,7 @@ public function getEscape()
*
* @param int $flags
*
* @throws \InvalidArgumentException If the argument is not a valid integer
* @throws InvalidArgumentException If the argument is not a valid integer
*
* @return $this
*/
Expand All @@ -221,7 +221,7 @@ public function setFlags($flags)
throw new InvalidArgumentException('you should use a `SplFileObject` Constant');
}

$this->flags = $flags|SplFileObject::READ_CSV;
$this->flags = $flags | SplFileObject::READ_CSV;

return $this;
}
Expand Down
Loading

0 comments on commit e81de22

Please sign in to comment.