Преглед изворни кода

Merge pull request #30 from meolu/feature-travis

开始集成travis
huamanshu пре 9 година
родитељ
комит
4c55fd83f6
40 измењених фајлова са 4971 додато и 61 уклоњено
  1. 6 4
      .travis.yml
  2. 3 0
      composer.json
  3. 0 3
      config/local.php
  4. 5 2
      config/web.php
  5. 127 0
      tests/README.md
  6. 0 26
      tests/WalleTest.php
  7. BIN
      tests/codecept.phar
  8. 36 0
      tests/codeception.yml
  9. 4 0
      tests/codeception/.gitignore
  10. 16 0
      tests/codeception/_bootstrap.php
  11. 2 0
      tests/codeception/_output/.gitignore
  12. 25 0
      tests/codeception/_pages/LoginPage.php
  13. 26 0
      tests/codeception/_support/AcceptanceTester.php
  14. 26 0
      tests/codeception/_support/FunctionalTester.php
  15. 26 0
      tests/codeception/_support/UnitTester.php
  16. 2016 0
      tests/codeception/_support/_generated/AcceptanceTesterActions.php
  17. 2343 0
      tests/codeception/_support/_generated/FunctionalTesterActions.php
  18. 18 0
      tests/codeception/_support/_generated/UnitTesterActions.php
  19. 27 0
      tests/codeception/acceptance.suite.yml
  20. 2 0
      tests/codeception/acceptance/_bootstrap.php
  21. 10 0
      tests/codeception/bin/_bootstrap.php
  22. 20 0
      tests/codeception/bin/yii
  23. 20 0
      tests/codeception/bin/yii.bat
  24. 11 0
      tests/codeception/config/acceptance.php
  25. 26 0
      tests/codeception/config/config.php
  26. 25 0
      tests/codeception/config/functional.php
  27. 11 0
      tests/codeception/config/unit.php
  28. 2 0
      tests/codeception/fixtures/.gitignore
  29. 16 0
      tests/codeception/functional.suite.yml
  30. 2 0
      tests/codeception/functional/_bootstrap.php
  31. 2 0
      tests/codeception/templates/.gitignore
  32. 6 0
      tests/codeception/unit.suite.yml
  33. 3 0
      tests/codeception/unit/_bootstrap.php
  34. 0 0
      tests/codeception/unit/fixtures/.gitkeep
  35. 0 0
      tests/codeception/unit/fixtures/data/.gitkeep
  36. 62 0
      tests/codeception/unit/models/LoginFormTest.php
  37. 17 0
      tests/codeception/unit/models/UserTest.php
  38. 0 0
      tests/codeception/unit/templates/fixtures/.gitkeep
  39. 30 0
      tests/nginx.conf
  40. 0 26
      tests/phpunit.xml

+ 6 - 4
.travis.yml

@@ -13,13 +13,15 @@ install:
   - travis_retry composer self-update && composer --version
   - travis_retry composer global require "fxp/composer-asset-plugin:~1.0.3"
   - composer install --prefer-source --no-interaction --dev
-  - export PATH="$HOME/.composer/vendor/bin:$PATH"
+  - wget http://codeception.com/codecept.phar -O vendor/bin/codecept && chmod +x vendor/bin/codecept
 
 before_script:
-  - mysql -e 'CREATE DATABASE IF NOT EXISTS walle DEFAULT CHARSET utf8 COLLATE utf8_general_ci;';
-
-script: phpunit -c tests/phpunit.xml
+  - mysql -e 'CREATE DATABASE IF NOT EXISTS walle DEFAULT CHARSET utf8 COLLATE utf8_general_ci;'
+  - ./yii migrate/up  --interactive=0
+  - cd tests && ../vendor/bin/codecept build
 
+script:
+  - ../vendor/bin/codecept run
 matrix:
   fast_finish: true
 

+ 3 - 0
composer.json

@@ -13,6 +13,9 @@
         "yiisoft/yii2-swiftmailer": "*"
     },
     "require-dev": {
+        "codeception/codeception": "2.1.2",
+        "codeception/specify": "0.4.1",
+        "codeception/verify": "0.2.7",
         "yiisoft/yii2-codeception": "*",
         "yiisoft/yii2-debug": "*",
         "yiisoft/yii2-gii": "*",

+ 0 - 3
config/local.php

@@ -9,8 +9,5 @@ setlocale(LC_CTYPE, 'ru_RU.UTF-8');
 
 return [
     'components' => [
-        'request' => [
-            'cookieValidationKey' => 'PdXWDAfV5-gPJJWRar5sEN71DN0JcDRV',
-        ],
     ],
 ];

+ 5 - 2
config/web.php

@@ -10,8 +10,8 @@ $config = [
         'db' => [
             'class'     => 'yii\db\Connection',
             'dsn'       => 'mysql:host=127.0.0.1;dbname=walle',
-            'username'  => 'username',
-            'password'  => 'password',
+            'username'  => 'root',
+            'password'  => '',
             'charset'   => 'utf8',
         ],
         'session' => [
@@ -66,6 +66,9 @@ $config = [
                 '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
             ],
         ],
+        'request' => [
+            'cookieValidationKey' => 'PdXWDAfV5-gPJJWRar5sEN71DN0JcDRV',
+        ],
     ],
     'language'   => 'zh-CN',
     'bootstrap'  => [

+ 127 - 0
tests/README.md

@@ -0,0 +1,127 @@
+This directory contains various tests for the basic application.
+
+Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/).
+
+After creating the basic application, follow these steps to prepare for the tests:
+
+1. Install Codeception if it's not yet installed:
+
+   ```
+   composer global require "codeception/codeception=2.0.*"
+   composer global require "codeception/specify=*"
+   composer global require "codeception/verify=*"
+   ```
+
+   If you've never used Composer for global packages run `composer global status`. It should output:
+
+   ```
+   Changed current directory to <directory>
+   ```
+
+  Then add `<directory>/vendor/bin` to you `PATH` environment variable. Now we're able to use `codecept` from command
+  line globally.
+
+2. Install faker extension by running the following from template root directory where `composer.json` is:
+
+   ```
+   composer require --dev "yiisoft/yii2-faker:*"
+   ```
+
+3. Create `yii2_basic_tests` database and update it by applying migrations (you may skip this step if you do not have created any migrations yet):
+
+   ```
+   codeception/bin/yii migrate
+   ```
+
+   The command needs to be run in the `tests` directory.
+   The database configuration can be found at `tests/codeception/config/config.php`.
+
+4. Build the test suites:
+
+   ```
+   codecept build
+   ```
+
+5. In order to be able to run acceptance tests you need to start a webserver. The simplest way is to use PHP built in
+webserver. In the `web` directory execute the following:
+
+   ```
+   php -S localhost:8080
+   ```
+
+6. Now you can run the tests with the following commands:
+
+   ```
+   # run all available tests
+   codecept run
+   # run acceptance tests
+   codecept run acceptance
+   # run functional tests
+   codecept run functional
+   # run unit tests
+   codecept run unit
+   ```
+
+Fixtures Default Configuration
+------------------------------
+The `fixture` commands refer to the following `ActiveFixture` configuration by default:
+
+- Fixtures path: `@tests/unit/fixtures`
+- Fixtures data path: `@tests/unit/fixtures/data`
+- Template files path: `@tests/unit/templates/fixtures`
+- Namespace: `tests\unit\fixtures`
+
+Where `@tests` refers to `@app/tests/codeception`.
+
+Code coverage support
+---------------------
+
+By default, code coverage is disabled in `codeception.yml` configuration file, you should uncomment needed rows to be able
+to collect code coverage. You can run your tests and collect coverage with the following command:
+
+```
+#collect coverage for all tests
+codecept run --coverage-html --coverage-xml
+
+#collect coverage only for unit tests
+codecept run unit --coverage-html --coverage-xml
+
+#collect coverage for unit and functional tests
+codecept run functional,unit --coverage-html --coverage-xml
+```
+
+You can see code coverage output under the `tests/_output` directory.
+
+###Remote code coverage
+
+When you run your tests not in the same process where code coverage is collected, then you should uncomment `remote` option and its
+related options, to be able to collect code coverage correctly. To setup remote code coverage you should follow [instructions](http://codeception.com/docs/11-Codecoverage)
+from codeception site.
+
+1. install `Codeception c3` remote support `composer require "codeception/c3:*"`;
+
+2. copy `c3.php` file under your `web` directory;
+
+3. include `c3.php` file in your `index-test.php` file before application run, so it can catch needed requests.
+
+4. edit `c3.php` to update config file path (~ line 55) with `$config_file = realpath(__DIR__ . '/../tests/codeception.yml');`
+
+Configuration options that are used by remote code coverage:
+
+- c3_url: url pointing to entry script that includes `c3.php` file, so `Codeception` will be able to produce code coverage;
+- remote: whether to enable remote code coverage or not;
+- remote_config: path to the `codeception.yml` configuration file, from the directory where `c3.php` file is located. This is needed
+  so that `Codeception` can create itself instance and collect code coverage correctly.
+
+By default `c3_url` and `remote_config` setup correctly, you only need to copy and include `c3.php` file in your `index-test.php`
+
+After that you should be able to collect code coverage from tests that run through `PhpBrowser` or `WebDriver` with same command
+as for other tests:
+
+```
+#collect coverage from remote
+codecept run acceptance --coverage-html --coverage-xml
+```
+
+Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for
+more details about writing and running acceptance, functional and unit tests.

+ 0 - 26
tests/WalleTest.php

@@ -1,26 +0,0 @@
-<?php
-/* *****************************************************************
- * @Author: wushuiyong
- * @Created Time : 日 10/11 22:45:02 2015
- *
- * @File Name: tests/WalleTest.php
- * @Description:
- * *****************************************************************/
-namespace tests;
-
-class WalleTest extends \PHPUnit_Framework_TestCase
-{
-    public function setUp() {
-        echo __METHOD__;
-    }
-
-    public function tearDown() {
-        echo __METHOD__;
-    }
-
-    public function testWalle() {
-        echo __METHOD__;
-        $this->assertEquals('walle-web', 'walle-web');
-    }
-
-}

BIN
tests/codecept.phar


+ 36 - 0
tests/codeception.yml

@@ -0,0 +1,36 @@
+actor: Tester
+#coverage:
+#    #c3_url: http://localhost:8080/index-test.php/
+#    enabled: true
+#    #remote: true
+#    #remote_config: '../tests/codeception.yml'
+#    white_list:
+#        include:
+#            - ../models/*
+#            - ../controllers/*
+#            - ../commands/*
+#            - ../mail/*
+#    blacklist:
+#        include:
+#            - ../assets/*
+#            - ../config/*
+#            - ../runtime/*
+#            - ../vendor/*
+#            - ../views/*
+#            - ../web/*
+#            - ../tests/*
+paths:
+    tests: codeception
+    log: codeception/_output
+    data: codeception/_data
+    helpers: codeception/_support
+settings:
+    bootstrap: _bootstrap.php
+    suite_class: \PHPUnit_Framework_TestSuite
+    memory_limit: 1024M
+    log: true
+    colors: true
+config:
+    # the entry script URL (with host info) for functional and acceptance tests
+    # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
+    test_entry_url: http://localhost/index.php/

+ 4 - 0
tests/codeception/.gitignore

@@ -0,0 +1,4 @@
+# these files are auto generated by codeception build
+/unit/UnitTester.php
+/functional/FunctionalTester.php
+/acceptance/AcceptanceTester.php

+ 16 - 0
tests/codeception/_bootstrap.php

@@ -0,0 +1,16 @@
+<?php
+defined('YII_DEBUG') or define('YII_DEBUG', true);
+defined('YII_ENV') or define('YII_ENV', 'test');
+
+defined('YII_TEST_ENTRY_URL') or define('YII_TEST_ENTRY_URL', parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PATH));
+defined('YII_TEST_ENTRY_FILE') or define('YII_TEST_ENTRY_FILE', dirname(dirname(__DIR__)) . '/web/index.php');
+
+require_once(__DIR__ . '/../../vendor/autoload.php');
+require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
+
+$_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
+$_SERVER['SCRIPT_NAME'] = YII_TEST_ENTRY_URL;
+$_SERVER['SERVER_NAME'] = parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_HOST);
+$_SERVER['SERVER_PORT'] =  parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PORT) ?: '80';
+
+Yii::setAlias('@tests', dirname(__DIR__));

+ 2 - 0
tests/codeception/_output/.gitignore

@@ -0,0 +1,2 @@
+*
+!.gitignore

+ 25 - 0
tests/codeception/_pages/LoginPage.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace tests\codeception\_pages;
+
+use yii\codeception\BasePage;
+
+/**
+ * Represents login page
+ * @property \AcceptanceTester|\FunctionalTester $actor
+ */
+class LoginPage extends BasePage
+{
+    public $route = 'site/login';
+
+    /**
+     * @param string $username
+     * @param string $password
+     */
+    public function login($username, $password)
+    {
+        $this->actor->fillField('input[name="LoginForm[username]"]', $username);
+        $this->actor->fillField('input[name="LoginForm[password]"]', $password);
+        $this->actor->click('input[type=submit]');
+    }
+}

+ 26 - 0
tests/codeception/_support/AcceptanceTester.php

@@ -0,0 +1,26 @@
+<?php
+
+
+/**
+ * Inherited Methods
+ * @method void wantToTest($text)
+ * @method void wantTo($text)
+ * @method void execute($callable)
+ * @method void expectTo($prediction)
+ * @method void expect($prediction)
+ * @method void amGoingTo($argumentation)
+ * @method void am($role)
+ * @method void lookForwardTo($achieveValue)
+ * @method void comment($description)
+ * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
+ *
+ * @SuppressWarnings(PHPMD)
+*/
+class AcceptanceTester extends \Codeception\Actor
+{
+    use _generated\AcceptanceTesterActions;
+
+   /**
+    * Define custom actions here
+    */
+}

+ 26 - 0
tests/codeception/_support/FunctionalTester.php

@@ -0,0 +1,26 @@
+<?php
+
+
+/**
+ * Inherited Methods
+ * @method void wantToTest($text)
+ * @method void wantTo($text)
+ * @method void execute($callable)
+ * @method void expectTo($prediction)
+ * @method void expect($prediction)
+ * @method void amGoingTo($argumentation)
+ * @method void am($role)
+ * @method void lookForwardTo($achieveValue)
+ * @method void comment($description)
+ * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
+ *
+ * @SuppressWarnings(PHPMD)
+*/
+class FunctionalTester extends \Codeception\Actor
+{
+    use _generated\FunctionalTesterActions;
+
+   /**
+    * Define custom actions here
+    */
+}

+ 26 - 0
tests/codeception/_support/UnitTester.php

@@ -0,0 +1,26 @@
+<?php
+
+
+/**
+ * Inherited Methods
+ * @method void wantToTest($text)
+ * @method void wantTo($text)
+ * @method void execute($callable)
+ * @method void expectTo($prediction)
+ * @method void expect($prediction)
+ * @method void amGoingTo($argumentation)
+ * @method void am($role)
+ * @method void lookForwardTo($achieveValue)
+ * @method void comment($description)
+ * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
+ *
+ * @SuppressWarnings(PHPMD)
+*/
+class UnitTester extends \Codeception\Actor
+{
+    use _generated\UnitTesterActions;
+
+   /**
+    * Define custom actions here
+    */
+}

Разлика између датотеке није приказан због своје велике величине
+ 2016 - 0
tests/codeception/_support/_generated/AcceptanceTesterActions.php


Разлика између датотеке није приказан због своје велике величине
+ 2343 - 0
tests/codeception/_support/_generated/FunctionalTesterActions.php


+ 18 - 0
tests/codeception/_support/_generated/UnitTesterActions.php

@@ -0,0 +1,18 @@
+<?php  //[STAMP] a4430c256cd39bdff4f6b568fdd0e70f
+namespace _generated;
+
+// This class was automatically generated by build task
+// You should not change it manually as it will be overwritten on next build
+// @codingStandardsIgnoreFile
+
+
+
+trait UnitTesterActions
+{
+    /**
+     * @return \Codeception\Scenario
+     */
+    abstract protected function getScenario();
+
+    
+}

+ 27 - 0
tests/codeception/acceptance.suite.yml

@@ -0,0 +1,27 @@
+# Codeception Test Suite Configuration
+
+# suite for acceptance tests.
+# perform tests in browser using the Selenium-like tools.
+# powered by Mink (http://mink.behat.org).
+# (tip: that's what your customer will see).
+# (tip: test your ajax and javascript by one of Mink drivers).
+
+# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
+
+class_name: AcceptanceTester
+modules:
+    enabled:
+        - PhpBrowser
+# you can use WebDriver instead of PhpBrowser to test javascript and ajax.
+# This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
+# "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
+# it is useful if you want to login in your app in each test.
+#        - WebDriver
+    config:
+        PhpBrowser:
+# PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO
+            url: http://localhost
+#        WebDriver:
+#            url: http://localhost:8080
+#            browser: firefox
+#            restart: true

+ 2 - 0
tests/codeception/acceptance/_bootstrap.php

@@ -0,0 +1,2 @@
+<?php
+new yii\web\Application(require(dirname(__DIR__) . '/config/acceptance.php'));

+ 10 - 0
tests/codeception/bin/_bootstrap.php

@@ -0,0 +1,10 @@
+<?php
+defined('YII_DEBUG') or define('YII_DEBUG', true);
+defined('YII_ENV') or define('YII_ENV', 'test');
+
+defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', dirname(dirname(dirname(__DIR__))));
+
+require(YII_APP_BASE_PATH . '/vendor/autoload.php');
+require(YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php');
+
+Yii::setAlias('@tests', dirname(dirname(__DIR__)));

+ 20 - 0
tests/codeception/bin/yii

@@ -0,0 +1,20 @@
+#!/usr/bin/env php
+<?php
+/**
+ * Yii console bootstrap file.
+ *
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright (c) 2008 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+require_once __DIR__ . '/_bootstrap.php';
+
+$config = yii\helpers\ArrayHelper::merge(
+    require(YII_APP_BASE_PATH . '/config/console.php'),
+    require(__DIR__ . '/../config/config.php')
+);
+
+$application = new yii\console\Application($config);
+$exitCode = $application->run();
+exit($exitCode);

+ 20 - 0
tests/codeception/bin/yii.bat

@@ -0,0 +1,20 @@
+@echo off
+
+rem -------------------------------------------------------------
+rem  Yii command line bootstrap script for Windows.
+rem
+rem  @author Qiang Xue <qiang.xue@gmail.com>
+rem  @link http://www.yiiframework.com/
+rem  @copyright Copyright (c) 2008 Yii Software LLC
+rem  @license http://www.yiiframework.com/license/
+rem -------------------------------------------------------------
+
+@setlocal
+
+set YII_PATH=%~dp0
+
+if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
+
+"%PHP_COMMAND%" "%YII_PATH%yii" %*
+
+@endlocal

+ 11 - 0
tests/codeception/config/acceptance.php

@@ -0,0 +1,11 @@
+<?php
+/**
+ * Application configuration for acceptance tests
+ */
+return yii\helpers\ArrayHelper::merge(
+    require(__DIR__ . '/../../../config/web.php'),
+    require(__DIR__ . '/config.php'),
+    [
+
+    ]
+);

+ 26 - 0
tests/codeception/config/config.php

@@ -0,0 +1,26 @@
+<?php
+/**
+ * Application configuration shared by all test types
+ */
+return [
+    'language' => 'en-US',
+    'controllerMap' => [
+        'fixture' => [
+            'class' => 'yii\faker\FixtureController',
+            'fixtureDataPath' => '@tests/codeception/fixtures',
+            'templatePath' => '@tests/codeception/templates',
+            'namespace' => 'tests\codeception\fixtures',
+        ],
+    ],
+    'components' => [
+        'db' => [
+            'dsn' => 'mysql:host=localhost;dbname=walle',
+        ],
+        'mailer' => [
+            'useFileTransport' => true,
+        ],
+        'urlManager' => [
+            'showScriptName' => true,
+        ],
+    ],
+];

+ 25 - 0
tests/codeception/config/functional.php

@@ -0,0 +1,25 @@
+<?php
+$_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
+$_SERVER['SCRIPT_NAME'] = YII_TEST_ENTRY_URL;
+
+/**
+ * Application configuration for functional tests
+ */
+return yii\helpers\ArrayHelper::merge(
+    require(__DIR__ . '/../../../config/web.php'),
+    require(__DIR__ . '/config.php'),
+    [
+        'components' => [
+            'request' => [
+                // it's not recommended to run functional tests with CSRF validation enabled
+                'enableCsrfValidation' => false,
+                // but if you absolutely need it set cookie domain to localhost
+                /*
+                'csrfCookie' => [
+                    'domain' => 'localhost',
+                ],
+                */
+            ],
+        ],
+    ]
+);

+ 11 - 0
tests/codeception/config/unit.php

@@ -0,0 +1,11 @@
+<?php
+/**
+ * Application configuration for unit tests
+ */
+return yii\helpers\ArrayHelper::merge(
+    require(__DIR__ . '/../../../config/web.php'),
+    require(__DIR__ . '/config.php'),
+    [
+
+    ]
+);

+ 2 - 0
tests/codeception/fixtures/.gitignore

@@ -0,0 +1,2 @@
+*
+!.gitignore

+ 16 - 0
tests/codeception/functional.suite.yml

@@ -0,0 +1,16 @@
+# Codeception Test Suite Configuration
+
+# suite for functional (integration) tests.
+# emulate web requests and make application process them.
+# (tip: better to use with frameworks).
+
+# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
+#basic/web/index.php
+class_name: FunctionalTester
+modules:
+    enabled:
+      - Filesystem
+      - Yii2
+    config:
+        Yii2:
+            configFile: 'codeception/config/functional.php'

+ 2 - 0
tests/codeception/functional/_bootstrap.php

@@ -0,0 +1,2 @@
+<?php
+new yii\web\Application(require(dirname(__DIR__) . '/config/functional.php'));

+ 2 - 0
tests/codeception/templates/.gitignore

@@ -0,0 +1,2 @@
+*
+!.gitignore

+ 6 - 0
tests/codeception/unit.suite.yml

@@ -0,0 +1,6 @@
+# Codeception Test Suite Configuration
+
+# suite for unit (internal) tests.
+# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
+
+class_name: UnitTester

+ 3 - 0
tests/codeception/unit/_bootstrap.php

@@ -0,0 +1,3 @@
+<?php
+
+// add unit testing specific bootstrap code here

+ 0 - 0
tests/codeception/unit/fixtures/.gitkeep


+ 0 - 0
tests/codeception/unit/fixtures/data/.gitkeep


+ 62 - 0
tests/codeception/unit/models/LoginFormTest.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace tests\codeception\unit\models;
+
+use Yii;
+use yii\codeception\TestCase;
+use app\models\forms\LoginForm;
+use Codeception\Specify;
+
+class LoginFormTest extends TestCase
+{
+    use Specify;
+
+    protected function tearDown()
+    {
+        Yii::$app->user->logout();
+        parent::tearDown();
+    }
+
+    public function testLoginNoUser()
+    {
+        $model = new LoginForm([
+            'username' => 'not_existing_username',
+            'password' => 'not_existing_password',
+        ]);
+
+
+        $this->specify('user should not be able to login, when there is no identity', function () use ($model) {
+            expect('model should not login user', $model->login())->false();
+            expect('user should not be logged in', Yii::$app->user->isGuest)->true();
+        });
+    }
+
+//    public function testLoginWrongPassword()
+//    {
+//        $model = new LoginForm([
+//            'username' => 'demo',
+//            'password' => 'wrong_password',
+//        ]);
+//
+//        $this->specify('user should not be able to login with wrong password', function () use ($model) {
+//            expect('model should not login user', $model->login())->false();
+//            expect('error message should be set', $model->errors)->hasKey('password');
+//            expect('user should not be logged in', Yii::$app->user->isGuest)->true();
+//        });
+//    }
+
+    public function testLoginCorrect()
+    {
+        $model = new LoginForm([
+            'username' => 'demo',
+            'password' => 'demo',
+        ]);
+
+        $this->specify('user should be able to login with correct credentials', function () use ($model) {
+            expect('model should login user', $model->login())->true();
+            expect('error message should not be set', $model->errors)->hasntKey('password');
+            expect('user should be logged in', Yii::$app->user->isGuest)->false();
+        });
+    }
+
+}

+ 17 - 0
tests/codeception/unit/models/UserTest.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace tests\codeception\unit\models;
+
+use yii\codeception\TestCase;
+
+class UserTest extends TestCase
+{
+    protected function setUp()
+    {
+        parent::setUp();
+        // uncomment the following to load fixtures for user table
+        //$this->loadFixtures(['user']);
+    }
+
+    // TODO add test methods here
+}

+ 0 - 0
tests/codeception/unit/templates/fixtures/.gitkeep


+ 30 - 0
tests/nginx.conf

@@ -0,0 +1,30 @@
+worker_processes  1;
+
+events {
+    worker_connections  1024;
+}
+
+http {
+    include       mime.types;
+    default_type  application/octet-stream;
+
+    gzip  on;
+
+    server {
+        listen       80;
+        server_name  localhost;
+        root /home/travis/build/meolu/walle-web/web;
+        index index.php;
+
+        location / {
+            try_files $uri $uri/ /index.php$is_args$args;
+        }
+
+        location ~ \.php$ {
+            try_files $uri =404;
+            fastcgi_pass   127.0.0.1:9000;
+            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
+            include        fastcgi_params;
+        }
+    }
+}

+ 0 - 26
tests/phpunit.xml

@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<phpunit backupGlobals="false"
-         backupStaticAttributes="false"
-         bootstrap="phpunit.php"
-         colors="true"
-         convertErrorsToExceptions="true"
-         convertNoticesToExceptions="true"
-         convertWarningsToExceptions="true"
-         processIsolation="false"
-         stopOnFailure="false"
-         syntaxCheck="false">
-
-    <php>
-        <var name="db_dsn" value="mysql:dbname=walle;host=localhost"/>
-        <var name="db_username" value="root"/>
-        <var name="db_password" value=""/>
-    </php>
-
-    <testsuites>
-        <testsuite name="WalleTest">
-            <file>../tests/WalleTest.php</file>
-        </testsuite>
-    </testsuites>
-
-</phpunit>