├── LICENSE ├── README.md ├── composer.json ├── test └── CTestCase.php ├── web └── CodeceptionHttpRequest.php └── yiit.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Codeception PHP Testing Framework 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Codeception <=> Yii Bridge 2 | ========= 3 | 4 | Wrapper classes required to run Yii functional tests with Codeception. 5 | Does not provide a smooth integration (yet). For now use for your own pain and risk. 6 | 7 | ### Concept 8 | 9 | Yii1 framework was not designed for functional testing. This bridge classes include components that override standart Yii components to be testable. The most common issues with Yii functional tests are usage `headers`, `cookies` functions in PHP code, which produce errors on testing. Also usage of `exit` directive might even stop test execution completely. 10 | 11 | ### Install 12 | 13 | * Install [Codeception](http://codeception.com/install) via composer 14 | ``` 15 | php composer.phar require "codeception/codeception:*" 16 | php composer.phar update 17 | ``` 18 | 19 | * Bootstrap Codeception to ```protected/tests``` 20 | 21 | ``` 22 | ./vendor/bin/codecept bootstrap protected/tests 23 | ``` 24 | 25 | * And set up [Yii1](http://codeception.com/docs/modules/Yii1) module. 26 | 27 | __test.php__: 28 | ```php 29 | 'CWebApplication', 46 | 'config' => $config, 47 | ); 48 | 49 | ``` 50 | 51 | __codeception.yml__: 52 | ``` 53 | actor: Dev 54 | paths: 55 | tests: protected/tests 56 | log: protected/tests/_log 57 | data: protected/tests/_data 58 | helpers: protected/tests/_helpers 59 | settings: 60 | bootstrap: _bootstrap.php 61 | colors: true 62 | memory_limit: 1024M 63 | log: true 64 | debug: true 65 | modules: 66 | enabled: [PhpBrowser, WebHelper, TestHelper, Yii1] 67 | config: 68 | PhpBrowser: 69 | url: http://localhost:8234 70 | Yii1: 71 | appPath: test.php 72 | url: http://localhost:8234/test.php 73 | 74 | ``` 75 | 76 | * Install YiiBridge via Composer 77 | ``` 78 | php composer.phar require "codeception/YiiBridge:*" 79 | php composer.phar update 80 | ``` 81 | 82 | * Modify your ```protected/config/test.php``` configuration file to use the ```CodeceptionHttpRequest``` class instead of ```CHttpRequest``` 83 | 84 | ```php 85 | array( 89 | 90 | [...] 91 | 92 | 'request' => array( 93 | 'class' => 'CodeceptionHttpRequest' 94 | ), 95 | 96 | [...] 97 | ), 98 | ); 99 | ``` 100 | 101 | * Done! Use codeception normally to generate at run tests 102 | 103 | ### Important Notes 104 | 105 | This bridge is far from complete. It might not suit your project as well. So any contributions are welcome. If you feel like you need to customize any of provided classes - please do that. 106 | 107 | ### Known Issues and Roadmap 108 | 109 | * Sessions -> triggers php error 110 | * Forwards -> triggers php error 111 | * CLocale -> triggers error 112 | * Http Codes 113 | * WebApplication->end -> triggers `exit` directive 114 | 115 | ### Credits 116 | 117 | Initial version created by [**Ragazzo**](https://github.com/Ragazzo). 118 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codeception/YiiBridge", 3 | "description": "YiiBridge extension", 4 | "license": "MIT", 5 | "type": "package", 6 | "minimum-stability": "dev" 7 | } -------------------------------------------------------------------------------- /test/CTestCase.php: -------------------------------------------------------------------------------- 1 | _headers[$name] = $value; 14 | } 15 | 16 | public function getHeader($name,$default=null) 17 | { 18 | return isset($this->_headers[$name])? $this->_headers[$name] : $default; 19 | } 20 | 21 | public function getAllHeaders() 22 | { 23 | return $this->_headers; 24 | } 25 | 26 | public function getCookies() 27 | { 28 | if($this->_cookies!==null) 29 | return $this->_cookies; 30 | else 31 | return $this->_cookies=new CodeceptionCookieCollection($this); 32 | } 33 | 34 | public function redirect($url, $terminate = true, $statusCode = 302) 35 | { 36 | $this->setHeader('Location', $url); 37 | if($terminate) 38 | Yii::app()->end(0,false); 39 | } 40 | 41 | } 42 | 43 | class CodeceptionCookieCollection extends CCookieCollection 44 | { 45 | 46 | protected function addCookie($cookie) 47 | { 48 | $_COOKIE[$cookie->name] = $cookie->value; 49 | } 50 | 51 | protected function removeCookie($cookie) 52 | { 53 | unset($_COOKIE[$cookie->name]); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /yiit.php: -------------------------------------------------------------------------------- 1 |