|
| 1 | +# Codeception |
| 2 | + |
| 3 | +Codeception is new PHP full-stack testing framework. |
| 4 | +Inspired by BDD, it provides you absolutely new way for writing acceptance, functional and even unit tests. |
| 5 | +Powered by PHPUnit 3.6. |
| 6 | + |
| 7 | +[](http://travis-ci.org/Codeception/codeception) |
| 8 | + |
| 9 | +### In a Glance |
| 10 | + |
| 11 | +Describe what you test and how you test it. Use PHP to write descriptions faster. |
| 12 | + |
| 13 | +Run tests and see what actions were taken and what results were seen. |
| 14 | + |
| 15 | +#### Sample acceptance test |
| 16 | + |
| 17 | +``` php |
| 18 | +<?php |
| 19 | + |
| 20 | +$I = new TestGuy($scenario); |
| 21 | +$I->wantTo('create wiki page'); |
| 22 | +$I->amOnPage('/'); |
| 23 | +$I->click('Pages'); |
| 24 | +$I->click('New'); |
| 25 | +$I->see('New Page'); |
| 26 | +$I->submitForm('#pageForm', array('page' => array( |
| 27 | + 'title' => 'Tree of Life Movie Review', |
| 28 | + 'body' => 'Next time don\'t let Hollywood create arthouse =) ' |
| 29 | +))); |
| 30 | +$I->see('page created'); // notice generated |
| 31 | +$I->see('Tree of Life Movie Review','h1'); // head of page of is our title |
| 32 | +$I->seeInCurrentUrl('pages/tree-of-life-mobie-review'); // slug is generated |
| 33 | +$I->seeInDatabase('pages', array('title' => 'Tree of Life Movie Review')); // data is stored in database |
| 34 | +?> |
| 35 | +``` |
| 36 | +Ok, as for unit test similar approach may seem weired, but... |
| 37 | +Take a look at this: |
| 38 | + |
| 39 | +#### Sample unit test |
| 40 | + |
| 41 | +``` php |
| 42 | +<?php |
| 43 | +class UserControllerCest { |
| 44 | + public $class = 'UserController'; |
| 45 | + |
| 46 | + public function createAction(CodeGuy $I) |
| 47 | + { |
| 48 | + $I->haveFakeClass($userController = Stub::make('UserController')); |
| 49 | + $I->executeTestedMethodOn($userController, array('username' => 'MilesDavis', 'email' => ' [email protected]')) |
| 50 | + ->seeResultEquals(true) |
| 51 | + ->seeMethodInvoked($userController, 'renderHtml') |
| 52 | + ->seeInDabatase('users', array('username' => 'MilesDavis')); |
| 53 | + } |
| 54 | +} |
| 55 | +?> |
| 56 | + |
| 57 | +``` |
| 58 | + |
| 59 | +Anyway, If you don't really like writing unit tests in DSL, Codeceptance can run PHPUnit tests natively. |
| 60 | + |
| 61 | +## Documentation |
| 62 | + |
| 63 | +[Documentation on Github](https://github.com/Codeception/Codeception/tree/master/docs) |
| 64 | + |
| 65 | +Documentation is currently bounded with project. Look for it in 'docs' directory. |
| 66 | + |
| 67 | +## Installation |
| 68 | + |
| 69 | +### PEAR |
| 70 | +Install latest PEAR package from GitHub: |
| 71 | + |
| 72 | +``` |
| 73 | +pear channel-discover codeception.github.com/pear |
| 74 | +pear install codeception/Codeception |
| 75 | +``` |
| 76 | + |
| 77 | +### Phar |
| 78 | + |
| 79 | +Download [codecept.phar](https://github.com/Codeception/Codeception/raw/master/package/codecept.phar) |
| 80 | + |
| 81 | +Copy it into your project. |
| 82 | +Run CLI utility: |
| 83 | + |
| 84 | +``` |
| 85 | +php codecept.phar |
| 86 | +``` |
| 87 | + |
| 88 | +## Getting Started |
| 89 | + |
| 90 | +If you sucessfully installed Codeception, run this commands: |
| 91 | + |
| 92 | +``` |
| 93 | +codecept install |
| 94 | +``` |
| 95 | + |
| 96 | +this will install all dependency tools like PHPUnit and Mink |
| 97 | + |
| 98 | +``` |
| 99 | +codecept bootstrap |
| 100 | +``` |
| 101 | + |
| 102 | +this will create default directory structure and default test suites |
| 103 | + |
| 104 | +``` |
| 105 | +codecept build |
| 106 | +``` |
| 107 | + |
| 108 | +This will generate Guy-classes, in order to make autocomplete works. |
| 109 | + |
| 110 | +See Documentation for more information. |
| 111 | + |
| 112 | +### License |
| 113 | +MIT |
| 114 | + |
| 115 | +(c) Michael Bodnarchuk "Davert" |
| 116 | +2011 |
0 commit comments