Skip to content

Commit

Permalink
Add Codeception support
Browse files Browse the repository at this point in the history
  • Loading branch information
pbogut authored and janko committed Dec 6, 2016
1 parent 360d3b4 commit 2c530af
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Currently the following testing frameworks are supported:
| **Shell** | Bats | `bats` |
| **VimScript** | VSpec, Vader.vim | `vspec`, `vader` |
| **Lua** | Busted | `busted` |
| **PHP** | PHPUnit, Behat, PHPSpec | `phpunit`, `behat`, `phpspec` |
| **PHP** | PHPUnit, Behat, PHPSpec, Codeception | `phpunit`, `behat`, `phpspec`, `codeception` |
| **Perl** | Prove | `prove` |
| **Java** | Maven | `maventest` |

Expand All @@ -38,7 +38,7 @@ in, so they all work in the same unified way.

## Setup

Using [vim-plug](https://github.com/junegunn/vim-plug), add
Using [vim-plug](https://github.com/junegunn/vim-plug), add
```vim
Plug 'janko-m/vim-test'
```
Expand Down
48 changes: 48 additions & 0 deletions autoload/test/php/codeception.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
if !exists('g:test#php#codeception#file_pattern')
let g:test#php#codeception#file_pattern =
\ '\v((c|C)e(p|s)t\.php$|\.feature$|(t|T)est\.php$)'
endif

function! test#php#codeception#test_file(file) abort
if a:file =~# g:test#php#codeception#file_pattern
return filereadable('./codeception.yml')
endif
endfunction

function! test#php#codeception#build_position(type, position) abort
if a:type == 'nearest'
let testname = s:nearest_test(a:position)
let filename = a:position['file']
if !empty(testname) | let filename .= ':' . testname | endif
return [filename]
elseif a:type == 'file'
return [a:position['file']]
else
return []
endif
endfunction

function! test#php#codeception#build_args(args) abort
let args = a:args

if test#base#no_colors()
let args = ['--no-ansi'] + args
endif

return ['run'] + args
endfunction

function! test#php#codeception#executable() abort
if filereadable('./vendor/bin/codecept')
return './vendor/bin/codecept'
elseif filereadable('./bin/codecept')
return './bin/codecept'
else
return 'codecept'
endif
endfunction

function! s:nearest_test(position)
let name = test#base#nearest_test(a:position, g:test#php#patterns)
return join(name['test'])
endfunction
3 changes: 3 additions & 0 deletions doc/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ In all commands [args] are forwarded to the underlying test runner.
*test-:PHPSpec*
:PHPSpec [args] Uses the `phpspec` command.

*test-:Codeception*
:Codeception [args] Uses the `codecept` command.

*test-:Prove*
:Prove [args] Uses the `prove` command.

Expand Down
2 changes: 1 addition & 1 deletion plugin/test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ call s:extend(g:test#runners, {
\ 'Shell': ['Bats'],
\ 'VimL': ['VSpec', 'Vader'],
\ 'Lua': ['Busted'],
\ 'PHP': ['PHPUnit', 'Behat', 'PHPSpec'],
\ 'PHP': ['Codeception', 'PHPUnit', 'Behat', 'PHPSpec'],
\ 'Perl': ['Prove'],
\ 'Java': ['MavenTest'],
\})
Expand Down
86 changes: 86 additions & 0 deletions spec/codeception_spec.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
source spec/support/helpers.vim

describe "Codeception"

before
cd spec/fixtures/codeception
end

after
call Teardown()
cd -
end

it "runs cest file tests"
view tests/functional/NormalCest.php
TestFile

Expect g:test#last_command == 'codecept run tests/functional/NormalCest.php'
end

it "runs cept file tests"
view tests/functional/NormalCept.php
TestFile

Expect g:test#last_command == 'codecept run tests/functional/NormalCept.php'
end

it "runs feature file tests"
view tests/functional/Normal.feature
TestFile

Expect g:test#last_command == 'codecept run tests/functional/Normal.feature'
end

it "runs unit test file"
view tests/functional/NormalTest.php
TestFile

Expect g:test#last_command == 'codecept run tests/functional/NormalTest.php'
end

it "runs cest nearest tests"
view +21 tests/functional/NormalCest.php
TestNearest

Expect g:test#last_command ==
\ 'codecept run tests/functional/NormalCest.php:tryToTestSomethingElse'
end

it "runs cept nearest tests"
view +3 tests/functional/NormalCept.php
TestNearest

Expect g:test#last_command == 'codecept run tests/functional/NormalCept.php'
end

it "runs feature nearest tests"
view +1 tests/functional/Normal.feature
TestNearest

Expect g:test#last_command == 'codecept run tests/functional/Normal.feature'
end

it "runs nearest unit tests"
view +23 tests/functional/NormalTest.php
TestNearest

Expect g:test#last_command ==
\ 'codecept run tests/functional/NormalTest.php:testMe'
end

it "runs test suites"
view tests/functional/NormalCest.php
TestSuite

Expect g:test#last_command == 'codecept run'
end

it "doesn't recognize files that don't end with 'Cest', 'Cept' or 'Test'"
view tests/functional/normal.php
TestFile

Expect exists('g:test#last_command') == 0
end

end
21 changes: 21 additions & 0 deletions spec/fixtures/codeception/codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
6 changes: 6 additions & 0 deletions spec/fixtures/codeception/tests/functional/Normal.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Normal
In order to ...
As a ...
I need to ...

Scenario: try Normal
3 changes: 3 additions & 0 deletions spec/fixtures/codeception/tests/functional/NormalCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
$I = new FunctionalTester($scenario);
$I->wantTo('perform actions and see result');
24 changes: 24 additions & 0 deletions spec/fixtures/codeception/tests/functional/NormalCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php


class NormalCest
{
public function _before(FunctionalTester $I)
{
}

public function _after(FunctionalTester $I)
{
}

// tests
public function tryToTest(FunctionalTester $I)
{
$I->wantTo('perform actions and see result');
}

public function tryToTestSomethingElse(FunctionalTester $I)
{
$I->wantTo('perform another actions and see result');
}
}
29 changes: 29 additions & 0 deletions spec/fixtures/codeception/tests/functional/NormalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php


class NormalTest extends \Codeception\Test\Unit
{
/**
* @var \FunctionalTester
*/
protected $tester;

protected function _before()
{
}

protected function _after()
{
}

// tests
public function testMe()
{

}

public function testSomethingElse()
{

}
}
2 changes: 2 additions & 0 deletions spec/fixtures/codeception/tests/functional/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests

0 comments on commit 2c530af

Please sign in to comment.