GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — codeception.github.com/for/zend-framework.md~ at master · settermjd/codeception.github.com Expand file tree/ Copy pathzend-framework.md~More file actions 180 lines (126 loc) · 6.78 KB / Copy pathzend-framework.md~File metadata and controls180 lines (126 loc) · 6.78 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 --- layout: page title: Codeception for Zend Framework hero: zf_hero.html sidebar: | ## Codeception Tests * Combine **all testing levels** (acceptance, functional, unit) * Allow **multi-request** functional tests * **Fast**: Tests are wrapped into Eloquent transaction * **Scenario-Driven**: described in easy to get PHP DSL * can be written in **BDD** format with Gherkin * Great for **REST** and SOAP API testing ## Reference * [Laravel5 Module](/docs/modules/Laravel5) * [Demo Application](https://github.com/janhenkgerritsen/codeception-laravel5-sample) --- ## Install Install latest stable Codeception via Composer: ```bash composer require codeception/codeception --dev ``` ## Setup It is easy to setup tests by running bootstrap command: ``` composer exec codecept bootstrap ``` This will create `tests` directory and configuration file `codeception.yml`. This also prepares 3 suites for testing: acceptance, functional, and unit. ## Functional Tests Functional tests allow test application by simulating user actions, this is done by sending requests to framework kernel and checking HTML as a result. Unilke internal tests of Laravel, Codeception doesn't limit you to testing only one request per test. You can **test complex interactions involving different actions and controllers**. This way you can easily cover your specifictions with functional tests. To start you need to configure `tests/functional.suite.yml` to use Laravel5 module: ```yaml class_name: FunctionalTester modules: enabled: - Laravel5: environment_file: .env.testing - \AppBundle\Helper\Functional ``` <div class="alert alert-warning"> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> Continue to <a href="http://codeception.com/docs/04-FunctionalTests">Functional Testing Guide »</a> </div> Codeception will also use **Eloquent to cleanup changes to database** by wrapping tests into transaction and rolling it back in the end of a test. This makes tests isolated and fast. Laravel5 module allows to access services from DIC container, user authentication methods, fixture generators, check form validations and more. To create first functional test for `Login` you should run: ``` composer exec codecept g:cest functional Login ``` ## Unit Tests Codeception is powered by PHPUnit so unit and integration test work in a similar manner. To genereate a plain PHPUnit test for `Foo\Bar` class ``` composer exec codecept g:phpunit unit "Foo\Bar" ``` This generates a standard test inherited from `PHPUnit_Framework_TestCase`. For integration tests you may use Codeception-enhanced format which allows accessing services from DI container, use Eloquent, Data Factories. To have it create a unit test extending `Codeception\Test\Unit` class: ``` composer exec codecept g:test unit "Foo\Bar" ``` You will need to enable Laravel5 module in `unit.suite.yml` to have its methods inside `$this->tester` object. <div class="alert alert-warning"> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> Continue to <a href="http://codeception.com/docs/05-UnitTests">Unit Testing Guide »</a>. </div> ### Acceptance Tests To test an application in a real environment by using its UI you should use a real browser. Codeception uses Selenium Webdriver and corresponding WebDriver module to interact with a browser. You should configure `acceptance.suite.yml` to use WebDriver module and a browser of your choice. ```yaml class_name: AcceptanceTester modules: enabled: - WebDriver: url: 'https://localhost/' # put your local url browser: firefox - \Helper\Acceptance ``` Browser can be specified as `firefox`, `chrome`, `phantomjs`, or others. Acceptance tests will be executed in development environment using real web server, so settings from `.env.testing` can't be passed to them. You can also use Eloquent to create data for acceptance tests. This way you can use data factories and models to prepare and cleanup data for tests. You should enable Laravel5 module with ORM part to add ActiveRecord methods: ```yaml class_name: AcceptanceTester modules: enabled: - WebDriver: url: 'https://localhost/' # put your local url browser: firefox - Laravel5 part: ORM cleanup: false # can't wrap into transaction - \Helper\Acceptance ``` Laravel5 module won't be able to wrap test execution in a transaction but methods like `haveRecord` or `haveModel` will delete objects they created when test ends. ### API Tests API Tests are done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. To create api tests you should create a suite for them ``` composer exec codecept g:suite api ``` You will need to enable `REST`, `Laravel5` module in `tests/api.suite.yml`: ```yaml class_name: ApiTester modules: enabled: - REST: url: /api/v1 depends: Laravel5 - \ApiBundle\Helper\Api config: - Laravel5: environment_file: .env.testing ``` Laravel5 module actions like `amOnPage` or `see` should not be available for testing API. This why Laravel5 module is not enabled but declared with `depends` for REST module. Laravel5 should use testing environment which is specified in `config` section <div class="alert alert-warning"> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> Continue to <a href="http://codeception.com/docs/10-WebServices#REST">REST API Testing Guide »</a>. </div> ### BDD If you prefer to describe application with feature files, Codeception can turn them to acceptance or functional tests. It is recommended to store feature files in `features` directory (like it does Behat) but symlinking it to `tests/acceptance/features` or `tests/functional/features` so they can be treated as tests too. For using BDD with acceptance tests you need to run: ``` ln -s $PWD/features tests/acceptance ``` Codeception allows to combine tests written in different formats. If are about to wirite a regression test it probably should not be described as a product's feature. That's why feature-files is subset of all acceptance tests, and they are stored in subfolder of `tests/acceptance`. There is no standard Gherkin steps built in. By writing your feature files you can get code snippets which should be added to `AcceptanceTester` class. ``` composer exec codecept gherkin:snippets ``` In the same manner features can be set up as functional tests. <div class="alert alert-warning"> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> Continue to <a href="http://codeception.com/docs/07-BDD">Behavior Driven Development Guide »</a> </div> |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |