Explorar o código

Merge PR #1393 branch 'yii2-basic-codeception' of https://github.com/Ragazzo/yii2 into Ragazzo-yii2-basic-codeception

* 'yii2-basic-codeception' of https://github.com/Ragazzo/yii2:
  small typo fix
  added readme, changelog, license and composer files.
  added new extension yii2-codeception, modified composer settings
  modified tests according yii2-codeception extension
  added testcase for unit tests, bootstrap files improved, tests inherited from base testcase
  configs fixed and improved
  tests modified, bootstrap added
  colors added
  new entry points for application
  codeception configs, web config modifed for db-settings

Conflicts:
	composer.json
Carsten Brandt %!s(int64=12) %!d(string=hai) anos
pai
achega
60bdb6b7cf

+ 1 - 0
codeception.yml

@@ -8,6 +8,7 @@ settings:
     suite_class: \PHPUnit_Framework_TestSuite
     suite_class: \PHPUnit_Framework_TestSuite
     memory_limit: 1024M
     memory_limit: 1024M
     log: true
     log: true
+    colors: true
 modules:
 modules:
     config:
     config:
         Db:
         Db:

+ 1 - 0
composer.json

@@ -18,6 +18,7 @@
 		"yiisoft/yii2": "*",
 		"yiisoft/yii2": "*",
 		"yiisoft/yii2-swiftmailer": "*",
 		"yiisoft/yii2-swiftmailer": "*",
 		"yiisoft/yii2-bootstrap": "*",
 		"yiisoft/yii2-bootstrap": "*",
+		"yiisoft/yii2-codeception": "*",
 		"yiisoft/yii2-debug": "*",
 		"yiisoft/yii2-debug": "*",
 		"yiisoft/yii2-gii": "*"
 		"yiisoft/yii2-gii": "*"
 	},
 	},

+ 9 - 0
config/codeception/acceptance.php

@@ -0,0 +1,9 @@
+<?php
+
+return [
+	'components' => [
+		'db' => [
+			'dsn' => 'mysql:host=localhost;dbname=yii2basic_acceptance',
+		],
+	],
+];

+ 9 - 0
config/codeception/functional.php

@@ -0,0 +1,9 @@
+<?php
+
+return [
+	'components' => [
+		'db' => [
+			'dsn' => 'mysql:host=localhost;dbname=yii2basic_functional',
+		],
+	],
+];

+ 13 - 0
config/codeception/unit.php

@@ -0,0 +1,13 @@
+<?php
+
+return [
+	'components' => [
+		'fixture'	=>	[
+			'class'		=>	'yii\test\DbFixtureManager',
+			'basePath'	=>	'@app/tests/unit/fixtures',
+		],
+		'db' => [
+			'dsn' => 'mysql:host=localhost;dbname=yii2basic_unit',
+		],
+	],
+];

+ 2 - 0
config/web-test.php

@@ -1,5 +1,7 @@
 <?php
 <?php
 
 
+Yii::setAlias('tests', realpath(__DIR__ . '/../tests'));
+
 $config = require(__DIR__ . '/web.php');
 $config = require(__DIR__ . '/web.php');
 
 
 // ... customize $config for the "test" environment here...
 // ... customize $config for the "test" environment here...

+ 11 - 0
config/web.php

@@ -1,5 +1,9 @@
 <?php
 <?php
+
+Yii::setAlias('tests', realpath(__DIR__ . '/../tests'));
+
 $params = require(__DIR__ . '/params.php');
 $params = require(__DIR__ . '/params.php');
+
 $config = [
 $config = [
 	'id' => 'basic',
 	'id' => 'basic',
 	'basePath' => dirname(__DIR__),
 	'basePath' => dirname(__DIR__),
@@ -26,6 +30,13 @@ $config = [
 				],
 				],
 			],
 			],
 		],
 		],
+		'db' => [
+			'class' => 'yii\db\Connection',
+			'dsn' => 'mysql:host=localhost;dbname=yii2basic',
+			'username' => 'root',
+			'password' => '',
+			'charset' => 'utf8',
+		],
 	],
 	],
 	'params' => $params,
 	'params' => $params,
 ];
 ];

+ 3 - 0
tests/_bootstrap.php

@@ -0,0 +1,3 @@
+<?php
+
+require_once(__DIR__.'/yii_bootstrap.php');

+ 10 - 0
tests/_pages/AboutPage.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace tests\_pages;
+
+class AboutPage extends \yii\codeception\BasePage
+{
+
+	public static $URL = '?r=site/about';
+
+}

+ 63 - 0
tests/_pages/ContactPage.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace tests\_pages;
+
+class ContactPage extends \yii\codeception\BasePage
+{
+
+	public static $URL = '?r=site/contact';
+
+	/**
+	 * contact form name text field locator
+	 * @var string 
+	 */
+	public $name = 'input[name="ContactForm[name]"]';
+
+	/**
+	 * contact form email text field locator
+	 * @var string
+	 */
+	public $email = 'input[name="ContactForm[email]"]';
+
+	/**
+	 * contact form subject text field locator
+	 * @var string
+	 */
+	public $subject = 'input[name="ContactForm[subject]"]';
+
+	/**
+	 * contact form body textarea locator
+	 * @var string
+	 */
+	public $body = 'textarea[name="ContactForm[body]"]';
+
+	/**
+	 * contact form verification code text field locator
+	 * @var string
+	 */
+	public $verifyCode = 'input[name="ContactForm[verifyCode]"]';
+
+	/**
+	 * contact form submit button
+	 * @var string
+	 */
+	public $button = 'button[type=submit]';
+
+	/**
+	 * 
+	 * @param array $contactData
+	 */
+	public function submit(array $contactData)
+	{
+		if (!empty($contactData))
+		{
+			$this->guy->fillField($this->name,$contactData['name']);
+			$this->guy->fillField($this->email,$contactData['email']);
+			$this->guy->fillField($this->subject,$contactData['subject']);
+			$this->guy->fillField($this->body,$contactData['body']);
+			$this->guy->fillField($this->verifyCode,$contactData['verifyCode']);
+		}
+		$this->guy->click($this->button);
+	}
+
+}

+ 40 - 0
tests/_pages/LoginPage.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace tests\_pages;
+
+class LoginPage extends \yii\codeception\BasePage
+{
+
+	public static $URL = '?r=site/login';
+
+	/**
+	 * login form username text field locator
+	 * @var string
+	 */
+	public $username = 'input[name="LoginForm[username]"]';
+
+	/**
+	 * login form password text field locator
+	 * @var string
+	 */
+	public $password = 'input[name="LoginForm[password]"]';
+
+	/**
+	 * login form submit button locator
+	 * @var string
+	 */
+	public $button = 'button[type=submit]';
+
+	/**
+	 * 
+	 * @param string $username
+	 * @param string $password
+	 */
+	public function login($username, $password)
+	{
+		$this->guy->fillField($this->username,$username);
+		$this->guy->fillField($this->password,$password);
+		$this->guy->click($this->button);
+	}
+
+}

+ 4 - 3
tests/acceptance.suite.dist.yml

@@ -11,8 +11,9 @@
 class_name: WebGuy
 class_name: WebGuy
 modules:
 modules:
     enabled:
     enabled:
-        - PhpBrowser
         - WebHelper
         - WebHelper
+        - WebDriver
     config:
     config:
-        PhpBrowser:
-            url: 'http://localhost/index-test.php'
+        WebDriver:
+            url: 'http://localhost/basic/web/index-test-accept.php'
+            browser: firefox

+ 3 - 1
tests/acceptance/AboutCept.php

@@ -1,5 +1,7 @@
 <?php
 <?php
+use tests\_pages\AboutPage;
+
 $I = new WebGuy($scenario);
 $I = new WebGuy($scenario);
 $I->wantTo('ensure that about works');
 $I->wantTo('ensure that about works');
-$I->amOnPage('?r=site/about');
+$I->amOnPage(AboutPage::$URL);
 $I->see('About', 'h1');
 $I->see('About', 'h1');

+ 24 - 14
tests/acceptance/ContactCept.php

@@ -1,10 +1,16 @@
 <?php
 <?php
+use tests\_pages\ContactPage;
+
 $I = new WebGuy($scenario);
 $I = new WebGuy($scenario);
 $I->wantTo('ensure that contact works');
 $I->wantTo('ensure that contact works');
-$I->amOnPage('?r=site/contact');
+$contactPage = ContactPage::of($I);
+
+$I->amOnPage(ContactPage::$URL);
 $I->see('Contact', 'h1');
 $I->see('Contact', 'h1');
 
 
-$I->submitForm('#contact-form', []);
+$I->amGoingTo('submit contact form with no data');
+$contactPage->submit([]);
+$I->expectTo('see validations errors');
 $I->see('Contact', 'h1');
 $I->see('Contact', 'h1');
 $I->see('Name cannot be blank');
 $I->see('Name cannot be blank');
 $I->see('Email cannot be blank');
 $I->see('Email cannot be blank');
@@ -12,25 +18,29 @@ $I->see('Subject cannot be blank');
 $I->see('Body cannot be blank');
 $I->see('Body cannot be blank');
 $I->see('The verification code is incorrect');
 $I->see('The verification code is incorrect');
 
 
-$I->submitForm('#contact-form', [
-	'ContactForm[name]' => 'tester',
-	'ContactForm[email]' => 'tester.email',
-	'ContactForm[subject]' => 'test subject',
-	'ContactForm[body]' => 'test content',
-	'ContactForm[verifyCode]' => 'testme',
+$I->amGoingTo('submit contact form with not correct email');
+$contactPage->submit([
+	'name'			=>	'tester',
+	'email'			=>	'tester.email',
+	'subject'		=>	'test subject',
+	'body'			=>	'test content',
+	'verifyCode'	=>	'testme',
 ]);
 ]);
+$I->expectTo('see that email adress is wrong');
 $I->dontSee('Name cannot be blank', '.help-inline');
 $I->dontSee('Name cannot be blank', '.help-inline');
 $I->see('Email is not a valid email address.');
 $I->see('Email is not a valid email address.');
 $I->dontSee('Subject cannot be blank', '.help-inline');
 $I->dontSee('Subject cannot be blank', '.help-inline');
 $I->dontSee('Body cannot be blank', '.help-inline');
 $I->dontSee('Body cannot be blank', '.help-inline');
 $I->dontSee('The verification code is incorrect', '.help-inline');
 $I->dontSee('The verification code is incorrect', '.help-inline');
 
 
-$I->submitForm('#contact-form', [
-	'ContactForm[name]' => 'tester',
-	'ContactForm[email]' => 'tester@example.com',
-	'ContactForm[subject]' => 'test subject',
-	'ContactForm[body]' => 'test content',
-	'ContactForm[verifyCode]' => 'testme',
+$I->amGoingTo('submit contact form with correct data');
+$contactPage->submit([
+	'name'			=>	'tester',
+	'email'			=>	'tester@example.com',
+	'subject'		=>	'test subject',
+	'body'			=>	'test content',
+	'verifyCode'	=>	'testme',
 ]);
 ]);
+$I->wait(3);
 $I->dontSeeElement('#contact-form');
 $I->dontSeeElement('#contact-form');
 $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
 $I->see('Thank you for contacting us. We will respond to you as soon as possible.');

+ 18 - 15
tests/acceptance/LoginCept.php

@@ -1,23 +1,26 @@
 <?php
 <?php
+use tests\_pages\LoginPage;
+
 $I = new WebGuy($scenario);
 $I = new WebGuy($scenario);
 $I->wantTo('ensure that login works');
 $I->wantTo('ensure that login works');
-$I->amOnPage('?r=site/login');
+$loginPage = LoginPage::of($I);
+
+$I->amOnPage(LoginPage::$URL);
 $I->see('Login', 'h1');
 $I->see('Login', 'h1');
 
 
-$I->submitForm('#login-form', []);
-$I->dontSee('Logout (admin)');
-$I->see('Username cannot be blank');
-$I->see('Password cannot be blank');
+$I->amGoingTo('try to login with empty credentials');
+$loginPage->login('', '');
+$I->expectTo('see validations errors');
+$I->see('Username cannot be blank.');
+$I->see('Password cannot be blank.');
 
 
-$I->submitForm('#login-form', [
-	'LoginForm[username]' => 'admin',
-	'LoginForm[password]' => 'wrong',
-]);
-$I->dontSee('Logout (admin)');
-$I->see('Incorrect username or password');
+$I->amGoingTo('try to login with wrong credentials');
+$loginPage->login('admin', 'wrong');
+$I->expectTo('see validations errors');
+$I->see('Incorrect username or password.');
 
 
-$I->submitForm('#login-form', [
-	'LoginForm[username]' => 'admin',
-	'LoginForm[password]' => 'admin',
-]);
+$I->amGoingTo('try to login with correct credentials');
+$loginPage->login('admin', 'admin');
+$I->wait(3);
+$I->expectTo('see user info');
 $I->see('Logout (admin)');
 $I->see('Logout (admin)');

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1432 - 757
tests/acceptance/WebGuy.php


+ 9 - 0
tests/acceptance/_bootstrap.php

@@ -1,2 +1,11 @@
 <?php
 <?php
 // Here you can initialize variables that will for your tests
 // Here you can initialize variables that will for your tests
+
+$config = require(__DIR__.'/../yii_bootstrap.php');
+
+$config = yii\helpers\ArrayHelper::merge(
+	$config,
+	require(__DIR__ . '/../../config/codeception/acceptance.php')
+);
+
+$application = new yii\web\Application($config);

+ 2 - 2
tests/functional.suite.dist.yml

@@ -5,11 +5,11 @@
 # (tip: better to use with frameworks).
 # (tip: better to use with frameworks).
 
 
 # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
 # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
-
+#basic/web/index-test-func.php
 class_name: TestGuy
 class_name: TestGuy
 modules:
 modules:
     enabled: [Filesystem, TestHelper, Yii2]
     enabled: [Filesystem, TestHelper, Yii2]
     config:
     config:
         Yii2:
         Yii2:
-            entryScript: 'web/index-test.php'
+            entryScript: 'web/index-test-func.php'
             url: 'http://localhost/'
             url: 'http://localhost/'

+ 4 - 1
tests/functional/AboutCept.php

@@ -1,5 +1,8 @@
 <?php
 <?php
+
+use tests\_pages\AboutPage;
+
 $I = new TestGuy($scenario);
 $I = new TestGuy($scenario);
 $I->wantTo('ensure that about works');
 $I->wantTo('ensure that about works');
-$I->amOnPage('?r=site/about');
+$I->amOnPage(AboutPage::$URL);
 $I->see('About', 'h1');
 $I->see('About', 'h1');

+ 23 - 14
tests/functional/ContactCept.php

@@ -1,10 +1,16 @@
 <?php
 <?php
+use tests\functional\_pages\ContactPage;
+
 $I = new TestGuy($scenario);
 $I = new TestGuy($scenario);
 $I->wantTo('ensure that contact works');
 $I->wantTo('ensure that contact works');
-$I->amOnPage('?r=site/contact');
+$contactPage = ContactPage::of($I);
+
+$I->amOnPage(ContactPage::$URL);
 $I->see('Contact', 'h1');
 $I->see('Contact', 'h1');
 
 
-$I->submitForm('#contact-form', []);
+$I->amGoingTo('submit contact form with no data');
+$contactPage->submit([]);
+$I->expectTo('see validations errors');
 $I->see('Contact', 'h1');
 $I->see('Contact', 'h1');
 $I->see('Name cannot be blank');
 $I->see('Name cannot be blank');
 $I->see('Email cannot be blank');
 $I->see('Email cannot be blank');
@@ -12,25 +18,28 @@ $I->see('Subject cannot be blank');
 $I->see('Body cannot be blank');
 $I->see('Body cannot be blank');
 $I->see('The verification code is incorrect');
 $I->see('The verification code is incorrect');
 
 
-$I->submitForm('#contact-form', [
-	'ContactForm[name]' => 'tester',
-	'ContactForm[email]' => 'tester.email',
-	'ContactForm[subject]' => 'test subject',
-	'ContactForm[body]' => 'test content',
-	'ContactForm[verifyCode]' => 'testme',
+$I->amGoingTo('submit contact form with not correct email');
+$contactPage->submit([
+	'name'			=>	'tester',
+	'email'			=>	'tester.email',
+	'subject'		=>	'test subject',
+	'body'			=>	'test content',
+	'verifyCode'	=>	'testme',
 ]);
 ]);
+$I->expectTo('see that email adress is wrong');
 $I->dontSee('Name cannot be blank', '.help-inline');
 $I->dontSee('Name cannot be blank', '.help-inline');
 $I->see('Email is not a valid email address.');
 $I->see('Email is not a valid email address.');
 $I->dontSee('Subject cannot be blank', '.help-inline');
 $I->dontSee('Subject cannot be blank', '.help-inline');
 $I->dontSee('Body cannot be blank', '.help-inline');
 $I->dontSee('Body cannot be blank', '.help-inline');
 $I->dontSee('The verification code is incorrect', '.help-inline');
 $I->dontSee('The verification code is incorrect', '.help-inline');
 
 
-$I->submitForm('#contact-form', [
-	'ContactForm[name]' => 'tester',
-	'ContactForm[email]' => 'tester@example.com',
-	'ContactForm[subject]' => 'test subject',
-	'ContactForm[body]' => 'test content',
-	'ContactForm[verifyCode]' => 'testme',
+$I->amGoingTo('submit contact form with correct data');
+$contactPage->submit([
+	'name'			=>	'tester',
+	'email'			=>	'tester@example.com',
+	'subject'		=>	'test subject',
+	'body'			=>	'test content',
+	'verifyCode'	=>	'testme',
 ]);
 ]);
 $I->dontSeeElement('#contact-form');
 $I->dontSeeElement('#contact-form');
 $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
 $I->see('Thank you for contacting us. We will respond to you as soon as possible.');

+ 17 - 15
tests/functional/LoginCept.php

@@ -1,23 +1,25 @@
 <?php
 <?php
+use tests\functional\_pages\LoginPage;
+
 $I = new TestGuy($scenario);
 $I = new TestGuy($scenario);
 $I->wantTo('ensure that login works');
 $I->wantTo('ensure that login works');
-$I->amOnPage('?r=site/login');
+$loginPage = LoginPage::of($I);
+
+$I->amOnPage(LoginPage::$URL);
 $I->see('Login', 'h1');
 $I->see('Login', 'h1');
 
 
-$I->submitForm('#login-form', []);
-$I->dontSee('Logout (admin)');
-$I->see('Username cannot be blank');
-$I->see('Password cannot be blank');
+$I->amGoingTo('try to login with empty credentials');
+$loginPage->login('', '');
+$I->expectTo('see validations errors');
+$I->see('Username cannot be blank.');
+$I->see('Password cannot be blank.');
 
 
-$I->submitForm('#login-form', [
-	'LoginForm[username]' => 'admin',
-	'LoginForm[password]' => 'wrong',
-]);
-$I->dontSee('Logout (admin)');
-$I->see('Incorrect username or password');
+$I->amGoingTo('try to login with wrong credentials');
+$loginPage->login('admin', 'wrong');
+$I->expectTo('see validations errors');
+$I->see('Incorrect username or password.');
 
 
-$I->submitForm('#login-form', [
-	'LoginForm[username]' => 'admin',
-	'LoginForm[password]' => 'admin',
-]);
+$I->amGoingTo('try to login with correct credentials');
+$loginPage->login('admin', 'admin');
+$I->expectTo('see user info');
 $I->see('Logout (admin)');
 $I->see('Logout (admin)');

+ 70 - 51
tests/functional/TestGuy.php

@@ -27,7 +27,7 @@ use Codeception\Module\Yii2;
 
 
 class TestGuy extends \Codeception\AbstractGuy
 class TestGuy extends \Codeception\AbstractGuy
 {
 {
-
+    
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -49,7 +49,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -79,7 +79,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -106,7 +106,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -133,7 +133,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -161,7 +161,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -220,7 +220,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -281,7 +281,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -336,7 +336,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -355,7 +355,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -412,7 +412,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -439,13 +439,32 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
+ 
+    /**
+     * This method is generated.
+     * Documentation taken from corresponding module.
+     * ----------------------------------------------
+     *
+     *
+     * @see Codeception\Module::getName()
+     * @return \Codeception\Maybe
+     */
+    public function getName() {
+        $this->scenario->addStep(new \Codeception\Step\Action('getName', func_get_args()));
+        if ($this->scenario->running()) {
+            $result = $this->scenario->runStep();
+            return new Maybe($result);
+        }
+        return new Maybe();
+    }
 
 
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
      * ----------------------------------------------
      * ----------------------------------------------
      *
      *
-     * Authenticates user for HTTP_AUTH
+     * Authenticates user for HTTP_AUTH 
      *
      *
      * @param $username
      * @param $username
      * @param $password
      * @param $password
@@ -461,7 +480,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -494,7 +513,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -540,7 +559,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -605,7 +624,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -670,7 +689,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -733,7 +752,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -794,7 +813,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -853,7 +872,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -906,7 +925,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -963,7 +982,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1020,7 +1039,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1075,7 +1094,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1130,7 +1149,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1161,7 +1180,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1224,7 +1243,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1285,7 +1304,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1354,7 +1373,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1421,7 +1440,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1477,16 +1496,16 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
      * ----------------------------------------------
      * ----------------------------------------------
      *
      *
      * Fills a text field or textarea with value.
      * Fills a text field or textarea with value.
-     *
+     * 
      * Example:
      * Example:
-     *
+     * 
      * ``` php
      * ``` php
      * <?php
      * <?php
      * $I->fillField("//input[@type='text']", "Hello World!");
      * $I->fillField("//input[@type='text']", "Hello World!");
@@ -1507,7 +1526,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1547,7 +1566,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1577,7 +1596,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1606,7 +1625,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1637,7 +1656,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1662,7 +1681,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1698,7 +1717,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1731,7 +1750,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1764,7 +1783,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1817,7 +1836,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1826,7 +1845,7 @@ class TestGuy extends \Codeception\AbstractGuy
      * Checks if element does not exist (or is visible) on a page, matching it by CSS or XPath
      * Checks if element does not exist (or is visible) on a page, matching it by CSS or XPath
      *
      *
      * Example:
      * Example:
-     *
+     * 
      * ``` php
      * ``` php
      * <?php
      * <?php
      * $I->dontSeeElement('.error');
      * $I->dontSeeElement('.error');
@@ -1854,7 +1873,7 @@ class TestGuy extends \Codeception\AbstractGuy
      * Checks if element does not exist (or is visible) on a page, matching it by CSS or XPath
      * Checks if element does not exist (or is visible) on a page, matching it by CSS or XPath
      *
      *
      * Example:
      * Example:
-     *
+     * 
      * ``` php
      * ``` php
      * <?php
      * <?php
      * $I->dontSeeElement('.error');
      * $I->dontSeeElement('.error');
@@ -1874,7 +1893,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1931,7 +1950,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -1988,7 +2007,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -2025,7 +2044,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -2068,7 +2087,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.
@@ -2123,7 +2142,7 @@ class TestGuy extends \Codeception\AbstractGuy
         return new Maybe();
         return new Maybe();
     }
     }
 
 
-
+ 
     /**
     /**
      * This method is generated.
      * This method is generated.
      * Documentation taken from corresponding module.
      * Documentation taken from corresponding module.

+ 9 - 1
tests/functional/_bootstrap.php

@@ -1,2 +1,10 @@
 <?php
 <?php
-// Here you can initialize variables that will for your tests
+
+$config = require(__DIR__.'/../yii_bootstrap.php');
+
+$config = yii\helpers\ArrayHelper::merge(
+	$config,
+	require(__DIR__ . '/../../config/codeception/functional.php')
+);
+
+$application = new yii\web\Application($config);

+ 56 - 0
tests/functional/_pages/ContactPage.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace tests\functional\_pages;
+
+class ContactPage extends \tests\_pages\ContactPage
+{
+
+	/**
+	 * contact form name text field locator
+	 * @var string 
+	 */
+	public $name = 'ContactForm[name]';
+
+	/**
+	 * contact form email text field locator
+	 * @var string
+	 */
+	public $email = 'ContactForm[email]';
+
+	/**
+	 * contact form subject text field locator
+	 * @var string
+	 */
+	public $subject = 'ContactForm[subject]';
+
+	/**
+	 * contact form body textarea locator
+	 * @var string
+	 */
+	public $body = 'ContactForm[body]';
+
+	/**
+	 * contact form verification code text field locator
+	 * @var string
+	 */
+	public $verifyCode = 'ContactForm[verifyCode]';
+
+	/**
+	 * 
+	 * @param array $contactData
+	 */
+	public function submit(array $contactData)
+	{
+		if (empty($contactData))
+			$this->guy->submitForm('#contact-form',[]);
+		else
+			$this->guy->submitForm('#contact-form',[
+				$this->name			=>	$contactData['name'],
+				$this->email		=>	$contactData['email'],
+				$this->subject		=>	$contactData['subject'],
+				$this->body			=>	$contactData['body'],
+				$this->verifyCode	=>	$contactData['verifyCode'],
+			]);
+	}
+
+}

+ 33 - 0
tests/functional/_pages/LoginPage.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace tests\functional\_pages;
+
+class LoginPage extends \tests\_pages\LoginPage
+{
+
+	/**
+	 * login form username text field locator
+	 * @var string
+	 */
+	public $username = 'LoginForm[username]';
+
+	/**
+	 * login form password text field locator
+	 * @var string
+	 */
+	public $password = 'LoginForm[password]';
+
+	/**
+	 * 
+	 * @param string $username
+	 * @param string $password
+	 */
+	public function login($username, $password)
+	{
+		$this->guy->submitForm('#login-form',[
+			$this->username	=>	$username,
+			$this->password	=>	$password,
+		]);
+	}
+
+}

+ 18 - 1
tests/unit/CodeGuy.php

@@ -25,6 +25,23 @@ use Codeception\Module\CodeHelper;
 
 
 class CodeGuy extends \Codeception\AbstractGuy
 class CodeGuy extends \Codeception\AbstractGuy
 {
 {
-
+    
+    /**
+     * This method is generated.
+     * Documentation taken from corresponding module.
+     * ----------------------------------------------
+     *
+     *
+     * @see Codeception\Module::getName()
+     * @return \Codeception\Maybe
+     */
+    public function getName() {
+        $this->scenario->addStep(new \Codeception\Step\Action('getName', func_get_args()));
+        if ($this->scenario->running()) {
+            $result = $this->scenario->runStep();
+            return new Maybe($result);
+        }
+        return new Maybe();
+    }
 }
 }
 
 

+ 7 - 1
tests/unit/_bootstrap.php

@@ -1,2 +1,8 @@
 <?php
 <?php
-// Here you can initialize variables that will for your tests
+
+$config = require(__DIR__.'/../yii_bootstrap.php');
+
+return yii\helpers\ArrayHelper::merge(
+	$config,
+	require(__DIR__ . '/../../config/codeception/unit.php')
+);

+ 8 - 0
tests/unit/models/ContactFormTest.php

@@ -0,0 +1,8 @@
+<?php
+
+namespace tests\unit\models;
+
+class ContactFormTest extends \yii\codeception\TestCase
+{
+
+}

+ 8 - 0
tests/unit/models/LoginFormTest.php

@@ -0,0 +1,8 @@
+<?php
+
+namespace tests\unit\models;
+
+class LoginFormTest extends \yii\codeception\TestCase
+{
+
+}

+ 25 - 0
tests/unit/models/UserTest.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace tests\unit\models;
+
+#use yii\test\DbTestTrait;
+
+class UserTest extends \yii\codeception\TestCase
+{
+
+	use DbTestTrait;
+
+	protected function setUp()
+	{
+		/*
+		 *
+		 * you can load fixtures in this way
+		 *
+		parent::setUp();
+		$this->loadFixtures([
+			'tbl_user',
+		]);
+		 */
+	}
+
+}

+ 10 - 0
tests/yii_bootstrap.php

@@ -0,0 +1,10 @@
+<?php
+
+defined('YII_DEBUG') or define('YII_DEBUG', true);
+
+defined('YII_ENV') or define('YII_ENV', 'test');
+
+require_once(__DIR__ . '/../vendor/autoload.php');
+require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
+
+return require(__DIR__ . '/../config/web.php');

+ 13 - 0
web/index-debug.php

@@ -0,0 +1,13 @@
+<?php
+
+// comment out the following two lines when deployed to production
+defined('YII_DEBUG') or define('YII_DEBUG', true);
+defined('YII_ENV') or define('YII_ENV', 'dev');
+
+require(__DIR__ . '/../vendor/autoload.php');
+require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
+
+$config = require(__DIR__ . '/../config/web.php');
+
+$application = new yii\web\Application($config);
+$application->run();

+ 16 - 0
web/index-test-accept.php

@@ -0,0 +1,16 @@
+<?php
+
+defined('YII_DEBUG') or define('YII_DEBUG', true);
+
+defined('YII_ENV') or define('YII_ENV', 'test');
+
+require_once(__DIR__ . '/../vendor/autoload.php');
+require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
+
+$config = yii\helpers\ArrayHelper::merge(
+	require(__DIR__ . '/../config/web-test.php'),
+	require(__DIR__ . '/../config/codeception/acceptance.php')
+);
+
+$application = new yii\web\Application($config);
+$application->run();

+ 16 - 0
web/index-test-func.php

@@ -0,0 +1,16 @@
+<?php
+
+defined('YII_DEBUG') or define('YII_DEBUG', true);
+
+defined('YII_ENV') or define('YII_ENV', 'test');
+
+require_once(__DIR__ . '/../vendor/autoload.php');
+require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
+
+$config = yii\helpers\ArrayHelper::merge(
+	require(__DIR__ . '/../config/web-test.php'),
+	require(__DIR__ . '/../config/codeception/functional.php')
+);
+
+$config['class'] = 'yii\web\Application';
+return $config;

+ 0 - 24
web/index-test.php

@@ -1,24 +0,0 @@
-<?php
-
-if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
-	die('You are not allowed to access this file.');
-}
-
-defined('YII_DEBUG') or define('YII_DEBUG', true);
-
-defined('YII_ENV') or define('YII_ENV', 'test');
-
-require_once(__DIR__ . '/../vendor/autoload.php');
-require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
-
-$config = require(__DIR__ . '/../config/web-test.php');
-
-if (isset($this)) {
-	// run in functional tests
-	$config['class'] = 'yii\web\Application';
-	return $config;
-} else {
-	// run in acceptance tests
-	$application = new yii\web\Application($config);
-	$application->run();
-}

+ 2 - 2
web/index.php

@@ -1,8 +1,8 @@
 <?php
 <?php
 
 
 // comment out the following two lines when deployed to production
 // comment out the following two lines when deployed to production
-defined('YII_DEBUG') or define('YII_DEBUG', true);
-defined('YII_ENV') or define('YII_ENV', 'dev');
+defined('YII_DEBUG') or define('YII_DEBUG', false);
+defined('YII_ENV') or define('YII_ENV', 'prod');
 
 
 require(__DIR__ . '/../vendor/autoload.php');
 require(__DIR__ . '/../vendor/autoload.php');
 require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
 require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');