Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to configure new tasks + Symfony 3 compatibility #73

Merged
merged 2 commits into from
Dec 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ language: php
matrix:
include:
- php: 5.3
- php: 5.3
env: DEPENDENCIES='low'
- php: 5.4
- php: 5.5
- php: 5.6
- php: 5.6
env: DEPENDENCIES='low'
- php: 7.0
- php: hhvm
fast_finish: true

before_install:
- composer selfupdate
- bash -c 'if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then wget https://github.com/digitalkaoz/typehint-to-docblock/releases/download/0.2.2/typehint-to-docblock.phar && php typehint-to-docblock.phar transform spec; fi;'

install:
- composer update --prefer-dist --no-scripts --no-interaction
- if [ "$DEPENDENCIES" != "low" ]; then composer update --prefer-dist --no-scripts --no-interaction; fi;
- if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest --no-scripts --no-interaction; fi;


script:
- ./bin/grumphp run
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ parameters:
succeeded: grumphp-happy.txt
tasks:
behat: ~
blacklist: ~
git_blacklist: ~
git_commit_message: ~
phpcsfixer: ~
phpcs:
Expand Down Expand Up @@ -184,7 +184,7 @@ To activate a task, it is sufficient to add an empty task configuration:
parameters:
tasks:
behat: ~
blacklist: ~
git_blacklist: ~
phpcsfixer: ~
phpcs: ~
phpspec: ~
Expand Down Expand Up @@ -228,10 +228,10 @@ If you want to run a particular suite only, specify it with this option.

When this option is enabled, behat will stop at the first error. This means that it will not run your full test suite when an error occurs.

#### Blacklist
#### Git Blacklist

The Blacklist task will test your changes for blacklisted keywords, such as `die(`, `var_dump(` etc.
It lives under the `blacklist` namespace and has following configurable parameters:
The Git Blacklist task will test your changes for blacklisted keywords, such as `die(`, `var_dump(` etc.
It lives under the `git_blacklist` namespace and has following configurable parameters:

**keywords**

Expand All @@ -244,14 +244,14 @@ For example:
# grumphp.yml
parameters:
tasks:
blacklist:
git_blacklist:
keywords:
- "die("
- "var_dump("
- "exit;"
```

#### Git commit message (git_commit_message)
#### Git commit message

The git comit message can be used in combination with the git hook `git:commit-msg`.
It can be used to enforce patterns in a commit message.
Expand Down Expand Up @@ -480,8 +480,7 @@ services:
task.myCustomTask:
class: My\Custom\Task
arguments:
- @config
- "@=parameter('tasks')['myConfigKey'] ? parameter('tasks')['myConfigKey'] : []"
- '@config'
tags:
- {name: grumphp.task, config: myConfigKey}
```
Expand Down
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
"require": {
"php": ">=5.3.6",
"composer-plugin-api": "~1.0",
"symfony/console": "^2.5",
"symfony/expression-language": "^2.4",
"symfony/event-dispatcher": "^2.5",
"symfony/process": "^2.4",
"symfony/filesystem": "^2.4",
"symfony/finder": "^2.4",
"symfony/yaml": "^2.4",
"symfony/dependency-injection": "^2.4",
"symfony/config": "^2.4",
"doctrine/collections": "~1.2",
"gitonomy/gitlib": "~0.1.7"
"gitonomy/gitlib": "~0.1.7",
"symfony/config": "~2.4|~3.0",
"symfony/console": "~2.6|~3.0",
"symfony/dependency-injection": "~2.4|~3.0",
"symfony/event-dispatcher": "~2.5|~3.0",
"symfony/filesystem": "~2.4|~3.0",
"symfony/finder": "~2.4|~3.0",
"symfony/options-resolver": "~2.3|~3.0",
"symfony/process": "~2.4|~3.0",
"symfony/yaml": "~2.4|~3.0"
},
"require-dev": {
"composer/composer": "~1.0@dev",
"phpspec/phpspec": "~2.1",
"composer/composer": "^1.0-alpha11",
"phpspec/phpspec": "~2.4",
"squizlabs/php_codesniffer": "~2.3",
"roave/security-advisories": "dev-master@dev",
"fabpot/php-cs-fixer": "~1.0"
Expand Down
74 changes: 32 additions & 42 deletions resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,120 +7,110 @@ parameters:
succeeded: grumphp-happy.txt

services:

config:
class: GrumPHP\Configuration\GrumPHP
arguments: [@service_container]
arguments:
- '@service_container'

event_dispatcher:
class: Symfony\Component\EventDispatcher\EventDispatcher

filesystem:
class: Symfony\Component\Filesystem\Filesystem

process_builder:
class: Symfony\Component\Process\ProcessBuilder
prototype: true

executable_finder:
class: Symfony\Component\Process\ExecutableFinder

process_builder:
class: GrumPHP\Process\ProcessBuilder
arguments:
- '@locator.external_command'

git.repository:
class: Gitonomy\Git\Repository
arguments:
- %git_dir%
- '%git_dir%'

task_runner:
class: GrumPHP\Runner\TaskRunner
arguments:
- @event_dispatcher
- '@event_dispatcher'

locator.external_command:
class: GrumPHP\Locator\ExternalCommand
arguments: [%bin_dir%, @executable_finder]
arguments:
- '%bin_dir%'
- '@executable_finder'

locator.changed_files:
class: GrumPHP\Locator\ChangedFiles
arguments: [@git.repository]
arguments:
- '@git.repository'

locator.registered_files:
class: GrumPHP\Locator\RegisteredFiles
arguments: [@git.repository]
arguments:
- '@git.repository'

task.phpcs:
class: GrumPHP\Task\Phpcs
arguments:
- @config
- "@=parameter('tasks')['phpcs'] ? parameter('tasks')['phpcs'] : []"
- @locator.external_command
- @process_builder
- '@config'
- '@process_builder'
tags:
- {name: grumphp.task, config: phpcs}

task.phpcsfixer:
class: GrumPHP\Task\Phpcsfixer
arguments:
- @config
- "@=parameter('tasks')['phpcsfixer'] ? parameter('tasks')['phpcsfixer'] : []"
- @locator.external_command
- @process_builder
- '@config'
- '@process_builder'
tags:
- {name: grumphp.task, config: phpcsfixer}

task.phpspec:
class: GrumPHP\Task\Phpspec
arguments:
- @config
- "@=parameter('tasks')['phpspec'] ? parameter('tasks')['phpspec'] : []"
- @locator.external_command
- @process_builder
- '@config'
- '@process_builder'
tags:
- {name: grumphp.task, config: phpspec}

task.phpunit:
class: GrumPHP\Task\Phpunit
arguments:
- @config
- "@=parameter('tasks')['phpunit'] ? parameter('tasks')['phpunit'] : []"
- @locator.external_command
- @process_builder
- '@config'
- '@process_builder'
tags:
- {name: grumphp.task, config: phpunit}

task.behat:
class: GrumPHP\Task\Behat
arguments:
- @config
- "@=parameter('tasks')['behat'] ? parameter('tasks')['behat'] : []"
- @locator.external_command
- @process_builder
- '@config'
- '@process_builder'
tags:
- {name: grumphp.task, config: behat}

task.git.blacklist:
class: GrumPHP\Task\Git\Blacklist
arguments:
- @config
- "@=parameter('tasks')['blacklist'] ? parameter('tasks')['blacklist'] : []"
- @locator.external_command
- @process_builder
- '@config'
- '@process_builder'
tags:
- {name: grumphp.task, config: blacklist}
- {name: grumphp.task, config: git_blacklist}

task.git.commitmessage:
class: GrumPHP\Task\Git\CommitMessage
arguments:
- @config
- "@=parameter('tasks')['git_commit_message'] ? parameter('tasks')['git_commit_message'] : []"
- '@config'
tags:
- {name: grumphp.task, config: git_commit_message}

task.codeception:
class: GrumPHP\Task\Codeception
arguments:
- @config
- "@=parameter('tasks')['codeception'] ? parameter('tasks')['codeception'] : []"
- @locator.external_command
- @process_builder
- '@config'
- '@process_builder'
tags:
- {name: grumphp.task, config: codeception}
35 changes: 27 additions & 8 deletions spec/GrumPHP/Collection/FilesCollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use SplFileInfo;
use Symfony\Component\Finder\SplFileInfo;

class FilesCollectionSpec extends ObjectBehavior
{
public function let(SplFileInfo $file1, SplFileInfo $file2)
/**
* @var string
*/
protected $tempFile;

function let(SplFileInfo $file1, SplFileInfo $file2)
{
$this->tempFile = tempnam(sys_get_temp_dir(), 'phpspec');
$this->beConstructedWith(array($file1, $file2));
}

function letgo()
{
unlink($this->tempFile);
}

function it_is_initializable()
{
$this->shouldHaveType('GrumPHP\Collection\FilesCollection');
Expand Down Expand Up @@ -49,10 +60,10 @@ function it_should_filter_by_not_name(SplFileInfo $file1, SplFileInfo $file2)

function it_should_filter_by_path(SplFileInfo $file1, SplFileInfo $file2)
{
$file1->getPath()->willReturn('path1/file.php');
$file2->getPath()->willReturn('path2/file.png');
$file1->getRelativePathname()->willReturn('path1/file.php');
$file2->getRelativePathname()->willReturn('path2/file.png');

$result = $this->path('path1/*');
$result = $this->path('path1');
$result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
$result->count()->shouldBe(1);
$files = $result->toArray();
Expand All @@ -61,10 +72,10 @@ function it_should_filter_by_path(SplFileInfo $file1, SplFileInfo $file2)

function it_should_filter_by_not_path(SplFileInfo $file1, SplFileInfo $file2)
{
$file1->getPath()->willReturn('path1/file.php');
$file2->getPath()->willReturn('path2/file.png');
$file1->getRelativePathname()->willReturn('path1/file.php');
$file2->getRelativePathname()->willReturn('path2/file.png');

$result = $this->notPath('path2/*');
$result = $this->notPath('path2');
$result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
$result->count()->shouldBe(1);
$files = $result->toArray();
Expand All @@ -73,6 +84,10 @@ function it_should_filter_by_not_path(SplFileInfo $file1, SplFileInfo $file2)

function it_should_filter_by_size(SplFileInfo $file1, SplFileInfo $file2)
{
$file1->isFile()->willReturn(true);
$file2->isFile()->willReturn(true);
$file1->getRealPath()->willReturn($this->tempFile);
$file2->getRealPath()->willReturn($this->tempFile);
$file1->getSize()->willReturn(8 * 1024);
$file2->getSize()->willReturn(16 * 1024);

Expand All @@ -85,6 +100,10 @@ function it_should_filter_by_size(SplFileInfo $file1, SplFileInfo $file2)

function it_should_filter_by_date(SplFileInfo $file1, SplFileInfo $file2)
{
$file1->isFile()->willReturn(true);
$file2->isFile()->willReturn(true);
$file1->getRealPath()->willReturn($this->tempFile);
$file2->getRealPath()->willReturn($this->tempFile);
$file1->getMTime()->willReturn(strtotime('-4 hours'));
$file2->getMTime()->willReturn(strtotime('-5 days'));

Expand Down
Loading