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

Added kahlan support #236

Merged
merged 3 commits into from
Dec 5, 2016
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ To make GrumPHP even more awesome, it will suggest installing some extra package
- sensiolabs/security-checker : ~3.0
- phpmd/phpmd : ~2.4
- nikic/php-parser: ~2.1
- kahlan/kahlan: ~3

GrumPHP will never push you into using a specific task. You can choose the tasks that fit your needs, and activate or
deactivate any task in no time!
Expand Down Expand Up @@ -103,6 +104,7 @@ parameters:
grunt: ~
gulp: ~
jsonlint: ~
kahlan: ~
npm_script: ~
phing: ~
php7cc: ~
Expand Down
2 changes: 2 additions & 0 deletions doc/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ parameters:
grunt: ~
gulp: ~
jsonlint: ~
kahlan: ~
make: ~
npm_script: ~
phing: ~
Expand Down Expand Up @@ -62,6 +63,7 @@ Every task has it's own default configuration. It is possible to overwrite the p
- [Grunt](tasks/grunt.md)
- [Gulp](tasks/gulp.md)
- [JsonLint](tasks/jsonlint.md)
- [Kahlan](tasks/kahlan.md)
- [Make](tasks/make.md)
- [NPM script](tasks/npm_script.md)
- [Phing](tasks/phing.md)
Expand Down
153 changes: 153 additions & 0 deletions doc/tasks/kahlan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Phpspec

Kahlan is a full-featured Unit & BDD test framework a la RSpec/JSpec which uses a describe-it syntax and moves testing in PHP one step forward.
It lives under the `kahlan` namespace and has following configurable parameters:

```yaml
# grumphp.yml
parameters:
tasks:
kahlan:
config: ~
src: ~
spec: ~
pattern: ~
reporter: ~
coverage: ~
clover: ~
istanbul: ~
lcov: ~
ff: ~
no_colors: ~
no_header: ~
include: ~
exclude: ~
persistent: ~
cc: ~
autoclear: ~
```

**config**

*Default: `kahlan-config.php`*

The PHP configuration file to use


**src**

*Default: `['src']`*

Paths of source directories


**spec**

*Default: `['spec']`*

Paths of specification directories


**pattern**

*Default: `*Spec.php`*

A shell wildcard pattern


**reporter**

*Default: null*

The name of the text reporter to use, the built-in text reporters
are `'dot'`, `'bar'`, `'json'`, `'tap'` & `'verbose'`.
You can optionally redirect the reporter output to a file by using the
colon syntax (multiple --reporter options are also supported).


**coverage**

*Default: null*

Generate code coverage report. The value specify the level of
detail for the code coverage report (0-4). If a namespace, class, or
method definition is provided, it will generate a detailed code
coverage of this specific scope.


**clover**

*Default: null*

Export code coverage report into a Clover XML format.


**istanbul**

*Default: null*

Export code coverage report into an istanbul compatible JSON format.


**lcov**

*Default: null*

Export code coverage report into a lcov compatible text format.


**ff**

*Default: 0*

Fast fail option. `0` mean unlimited


**no_colors**

*Default: `false`*

To turn off colors.


**no_header**

*Default: `false`*

To turn off header.


**include**

*Default: `['*']`*

Paths to include for patching.


**exlude**

*Default: `[]`*

Paths to exclude for patching.


**persistent**

*Default: true*

Cache patched files.


**cc**

*Default: false*

Clear cache before spec run.


**autoclear**

*Default: `['Kahlan\Plugin\Monkey','Kahlan\Plugin\Call','Kahlan\Plugin\Stub','Kahlan\Plugin\Quit']`*

Classes to autoclear after each spec

9 changes: 9 additions & 0 deletions resources/config/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ services:
tags:
- {name: grumphp.task, config: jsonlint}

task.kahlan:
class: GrumPHP\Task\Kahlan
arguments:
- '@config'
- '@process_builder'
- '@formatter.raw_process'
tags:
- {name: grumphp.task, config: kahlan}

task.make:
class: GrumPHP\Task\Make
arguments:
Expand Down
122 changes: 122 additions & 0 deletions spec/GrumPHP/Task/KahlanSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

namespace spec\GrumPHP\Task;

use GrumPHP\Collection\FilesCollection;
use GrumPHP\Collection\ProcessArgumentsCollection;
use GrumPHP\Configuration\GrumPHP;
use GrumPHP\Formatter\ProcessFormatterInterface;
use GrumPHP\Process\ProcessBuilder;
use GrumPHP\Runner\TaskResult;
use GrumPHP\Runner\TaskResultInterface;
use GrumPHP\Task\Context\ContextInterface;
use GrumPHP\Task\Context\GitPreCommitContext;
use GrumPHP\Task\Context\RunContext;
use GrumPHP\Task\Kahlan;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Process\Process;

/**
* Class PhpspecSpec
*/
class KahlanSpec extends ObjectBehavior
{

function let(GrumPHP $grumPHP, ProcessBuilder $processBuilder, ProcessFormatterInterface $formatter)
{
$grumPHP->getTaskConfiguration('kahlan')->willReturn([]);
$this->beConstructedWith($grumPHP, $processBuilder, $formatter);
}

function it_is_initializable()
{
$this->shouldHaveType(Kahlan::class);
}

function it_should_have_a_name()
{
$this->getName()->shouldBe('kahlan');
}

function it_should_have_configurable_options()
{
$options = $this->getConfigurableOptions();
$options->shouldBeAnInstanceOf(OptionsResolver::class);
$options->getDefinedOptions()->shouldContain('config');
$options->getDefinedOptions()->shouldContain('src');
$options->getDefinedOptions()->shouldContain('spec');
$options->getDefinedOptions()->shouldContain('pattern');
$options->getDefinedOptions()->shouldContain('reporter');
$options->getDefinedOptions()->shouldContain('coverage');
$options->getDefinedOptions()->shouldContain('clover');
$options->getDefinedOptions()->shouldContain('istanbul');
$options->getDefinedOptions()->shouldContain('lcov');
$options->getDefinedOptions()->shouldContain('ff');
$options->getDefinedOptions()->shouldContain('no_colors');
$options->getDefinedOptions()->shouldContain('no_header');
$options->getDefinedOptions()->shouldContain('include');
$options->getDefinedOptions()->shouldContain('exclude');
$options->getDefinedOptions()->shouldContain('persistent');
$options->getDefinedOptions()->shouldContain('cc');
$options->getDefinedOptions()->shouldContain('autoclear');
}

function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context)
{
$this->canRunInContext($context)->shouldReturn(true);
}

function it_should_run_in_run_context(RunContext $context)
{
$this->canRunInContext($context)->shouldReturn(true);
}

function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context)
{
$processBuilder->buildProcess('kahlan')->shouldNotBeCalled();
$processBuilder->buildProcess()->shouldNotBeCalled();
$context->getFiles()->willReturn(new FilesCollection());

$result = $this->run($context);
$result->shouldBeAnInstanceOf(TaskResultInterface::class);
$result->getResultCode()->shouldBe(TaskResult::SKIPPED);
}

function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context)
{
$arguments = new ProcessArgumentsCollection();
$processBuilder->createArgumentsForCommand('kahlan')->willReturn($arguments);
$processBuilder->buildProcess($arguments)->willReturn($process);

$process->run()->shouldBeCalled();
$process->isSuccessful()->willReturn(true);

$context->getFiles()->willReturn(new FilesCollection([
new SplFileInfo('test.php', '.', 'test.php')
]));

$result = $this->run($context);
$result->shouldBeAnInstanceOf(TaskResultInterface::class);
$result->isPassed()->shouldBe(true);
}

function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process, ContextInterface $context)
{
$arguments = new ProcessArgumentsCollection();
$processBuilder->createArgumentsForCommand('kahlan')->willReturn($arguments);
$processBuilder->buildProcess($arguments)->willReturn($process);

$process->run()->shouldBeCalled();
$process->isSuccessful()->willReturn(false);

$context->getFiles()->willReturn(new FilesCollection([
new SplFileInfo('test.php', '.', 'test.php')
]));

$result = $this->run($context);
$result->shouldBeAnInstanceOf(TaskResultInterface::class);
$result->isPassed()->shouldBe(false);
}
}
Loading