Davert 9 lat temu
rodzic
commit
b1015559e0
48 zmienionych plików z 6853 dodań i 73 usunięć
  1. 2 0
      .gitignore
  2. 6 11
      tests/codeception.yml
  3. 2 0
      composer.json
  4. 1025 0
      composer.lock
  5. 35 0
      config/test.php
  6. 1 1
      config/web.php
  7. 10 0
      tests/_bootstrap.php
  8. 0 0
      tests/_output/.gitignore
  9. 0 0
      tests/_pages/AboutPage.php
  10. 26 0
      tests/_pages/ContactPage.php
  11. 0 0
      tests/_pages/LoginPage.php
  12. 26 0
      tests/_support/AcceptanceTester.php
  13. 26 0
      tests/_support/FunctionalTester.php
  14. 26 0
      tests/_support/UnitTester.php
  15. 2247 0
      tests/_support/_generated/AcceptanceTesterActions.php
  16. 2691 0
      tests/_support/_generated/FunctionalTesterActions.php
  17. 576 0
      tests/_support/_generated/UnitTesterActions.php
  18. 27 0
      tests/acceptance.suite.yml.example
  19. 10 0
      tests/acceptance/AboutCept.php
  20. 57 0
      tests/acceptance/ContactCept.php
  21. 11 0
      tests/acceptance/HomeCept.php
  22. 37 0
      tests/acceptance/LoginCept.php
  23. 0 0
      tests/acceptance/_bootstrap.php
  24. 0 0
      tests/bin/_bootstrap.php
  25. 0 0
      tests/bin/yii
  26. 0 0
      tests/bin/yii.bat
  27. 0 23
      tests/codeception/_bootstrap.php
  28. 0 26
      tests/codeception/config/config.php
  29. 0 2
      tests/codeception/functional/_bootstrap.php
  30. 1 1
      tests/codeception/config/acceptance.php
  31. 1 4
      tests/codeception/config/functional.php
  32. 1 1
      tests/codeception/config/unit.php
  33. 0 0
      tests/fixtures/.gitignore
  34. 2 4
      tests/codeception/functional.suite.yml
  35. 0 0
      tests/functional/AboutCept.php
  36. 0 0
      tests/functional/ContactCept.php
  37. 0 0
      tests/functional/HomeCept.php
  38. 0 0
      tests/functional/LoginCept.php
  39. 1 0
      tests/functional/_bootstrap.php
  40. 0 0
      tests/templates/.gitignore
  41. 6 0
      tests/codeception/unit.suite.yml
  42. 0 0
      tests/unit/_bootstrap.php
  43. 0 0
      tests/unit/fixtures/.gitkeep
  44. 0 0
      tests/unit/fixtures/data/.gitkeep
  45. 0 0
      tests/unit/models/ContactFormTest.php
  46. 0 0
      tests/unit/models/LoginFormTest.php
  47. 0 0
      tests/unit/models/UserTest.php
  48. 0 0
      tests/unit/templates/fixtures/.gitkeep

+ 2 - 0
.gitignore

@@ -25,3 +25,5 @@ composer.phar
 phpunit.phar
 # local phpunit config
 /phpunit.xml
+
+tests/_output/*

+ 6 - 11
tests/codeception.yml

@@ -1,4 +1,5 @@
 actor: Tester
+# To enable code coverage:
 #coverage:
 #    #c3_url: http://localhost:8080/index-test.php/
 #    enabled: true
@@ -20,17 +21,11 @@ actor: Tester
 #            - ../web/*
 #            - ../tests/*
 paths:
-    tests: codeception
-    log: codeception/_output
-    data: codeception/_data
-    helpers: codeception/_support
+    tests: tests
+    log: tests/_output
+    data: tests/_data
+    helpers: tests/_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:8080/index-test.php
+    colors: true

+ 2 - 0
composer.json

@@ -21,6 +21,8 @@
     },
     "require-dev": {
         "yiisoft/yii2-codeception": "*",
+        "codeception/specify": "*",
+        "codeception/verify": "*",
         "yiisoft/yii2-debug": "*",
         "yiisoft/yii2-gii": "*",
         "yiisoft/yii2-faker": "*"

Plik diff jest za duży
+ 1025 - 0
composer.lock


+ 35 - 0
config/test.php

@@ -0,0 +1,35 @@
+<?php
+$params = require(__DIR__ . '/params.php');
+$dbParams = require(__DIR__ . '/db.php');
+
+// test database! Important not to run tests on production or development databases
+$dbParams['dsn'] = 'mysql:host=localhost;dbname=yii2_basic_tests';
+
+/**
+ * Application configuration shared by all test types
+ */
+return [
+    'id' => 'basic-tests',
+    'basePath' => dirname(__DIR__),    
+    'language' => 'en-US',
+    'components' => [
+        'db' => $dbParams,
+        'mailer' => [
+            'useFileTransport' => true,
+        ],
+        'urlManager' => [
+            'showScriptName' => true,
+        ],
+        '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',
+            ],
+            */
+        ],        
+    ],
+    'params' => $params,
+];

+ 1 - 1
config/web.php

@@ -9,7 +9,7 @@ $config = [
     'components' => [
         'request' => [
             // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
-            'cookieValidationKey' => '',
+            'cookieValidationKey' => '12334543543',
         ],
         'cache' => [
             'class' => 'yii\caching\FileCache',

+ 10 - 0
tests/_bootstrap.php

@@ -0,0 +1,10 @@
+<?php
+require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
+
+defined('YII_DEBUG') or define('YII_DEBUG', true);
+defined('YII_ENV') or define('YII_ENV', 'test');
+
+$_SERVER['SCRIPT_FILENAME'] = codecept_root_dir() . '/web/index.php';
+$_SERVER['SCRIPT_NAME'] = 'http://localhost:8080/index-test.php';
+
+\Codeception\Specify\Config::setDeepClone(false);

tests/codeception/_output/.gitignore → tests/_output/.gitignore


tests/codeception/_pages/AboutPage.php → tests/_pages/AboutPage.php


+ 26 - 0
tests/_pages/ContactPage.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace tests\codeception\_pages;
+
+use yii\codeception\BasePage;
+
+/**
+ * Represents contact page
+ * @property \AcceptanceTester|\FunctionalTester $actor
+ */
+class ContactPage extends BasePage
+{
+    public $route = 'site/contact';
+
+    /**
+     * @param array $contactData
+     */
+    public function submit(array $contactData)
+    {
+        foreach ($contactData as $field => $value) {
+            $inputType = $field === 'body' ? 'textarea' : 'input';
+            $this->actor->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value);
+        }
+        $this->actor->click('contact-button');
+    }
+}

tests/codeception/_pages/LoginPage.php → tests/_pages/LoginPage.php


+ 26 - 0
tests/_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/_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/_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
+    */
+}

Plik diff jest za duży
+ 2247 - 0
tests/_support/_generated/AcceptanceTesterActions.php


Plik diff jest za duży
+ 2691 - 0
tests/_support/_generated/FunctionalTesterActions.php


+ 576 - 0
tests/_support/_generated/UnitTesterActions.php

@@ -0,0 +1,576 @@
+<?php  //[STAMP] 5277d920e2dff79e69b22748b3b5c29b
+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
+
+use Codeception\Module\Asserts;
+use Codeception\Module\Yii2;
+
+trait UnitTesterActions
+{
+    /**
+     * @return \Codeception\Scenario
+     */
+    abstract protected function getScenario();
+
+    
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that two variables are equal.
+     *
+     * @param        $expected
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertEquals()
+     */
+    public function assertEquals($expected, $actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that two variables are not equal
+     *
+     * @param        $expected
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertNotEquals()
+     */
+    public function assertNotEquals($expected, $actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that two variables are same
+     *
+     * @param        $expected
+     * @param        $actual
+     * @param string $message
+     * @return mixed|void
+     * @see \Codeception\Module\Asserts::assertSame()
+     */
+    public function assertSame($expected, $actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertSame', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that two variables are not same
+     *
+     * @param        $expected
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertNotSame()
+     */
+    public function assertNotSame($expected, $actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that actual is greater than expected
+     *
+     * @param        $expected
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertGreaterThan()
+     */
+    public function assertGreaterThan($expected, $actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThan', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that actual is greater or equal than expected
+     *
+     * @param        $expected
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertGreaterThanOrEqual()
+     */
+    public function assertGreaterThanOrEqual($expected, $actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThanOrEqual', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that actual is less than expected
+     *
+     * @param        $expected
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertLessThan()
+     */
+    public function assertLessThan($expected, $actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThan', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that actual is less or equal than expected
+     *
+     * @param        $expected
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertLessThanOrEqual()
+     */
+    public function assertLessThanOrEqual($expected, $actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThanOrEqual', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that haystack contains needle
+     *
+     * @param        $needle
+     * @param        $haystack
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertContains()
+     */
+    public function assertContains($needle, $haystack, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertContains', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that haystack doesn't contain needle.
+     *
+     * @param        $needle
+     * @param        $haystack
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertNotContains()
+     */
+    public function assertNotContains($needle, $haystack, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotContains', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that string match with pattern
+     *
+     * @param string $pattern
+     * @param string $string
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertRegExp()
+     */
+    public function assertRegExp($pattern, $string, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertRegExp', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that string not match with pattern
+     *
+     * @param string $pattern
+     * @param string $string
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertNotRegExp()
+     */
+    public function assertNotRegExp($pattern, $string, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotRegExp', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that variable is empty.
+     *
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertEmpty()
+     */
+    public function assertEmpty($actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that variable is not empty.
+     *
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertNotEmpty()
+     */
+    public function assertNotEmpty($actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEmpty', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that variable is NULL
+     *
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertNull()
+     */
+    public function assertNull($actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNull', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that variable is not NULL
+     *
+     * @param        $actual
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertNotNull()
+     */
+    public function assertNotNull($actual, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotNull', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that condition is positive.
+     *
+     * @param        $condition
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertTrue()
+     */
+    public function assertTrue($condition, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertTrue', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that condition is negative.
+     *
+     * @param        $condition
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertFalse()
+     */
+    public function assertFalse($condition, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFalse', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks if file exists
+     *
+     * @param string $filename
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertFileExists()
+     */
+    public function assertFileExists($filename, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileExists', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks if file doesn't exist
+     *
+     * @param string $filename
+     * @param string $message
+     * @see \Codeception\Module\Asserts::assertFileNotExists()
+     */
+    public function assertFileNotExists($filename, $message = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileNotExists', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * @param $expected
+     * @param $actual
+     * @param $description
+     * @see \Codeception\Module\Asserts::assertGreaterOrEquals()
+     */
+    public function assertGreaterOrEquals($expected, $actual, $description = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterOrEquals', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * @param $expected
+     * @param $actual
+     * @param $description
+     * @see \Codeception\Module\Asserts::assertLessOrEquals()
+     */
+    public function assertLessOrEquals($expected, $actual, $description = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessOrEquals', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * @param $actual
+     * @param $description
+     * @see \Codeception\Module\Asserts::assertIsEmpty()
+     */
+    public function assertIsEmpty($actual, $description = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsEmpty', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * @param $key
+     * @param $actual
+     * @param $description
+     * @see \Codeception\Module\Asserts::assertArrayHasKey()
+     */
+    public function assertArrayHasKey($key, $actual, $description = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayHasKey', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * @param $key
+     * @param $actual
+     * @param $description
+     * @see \Codeception\Module\Asserts::assertArrayNotHasKey()
+     */
+    public function assertArrayNotHasKey($key, $actual, $description = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayNotHasKey', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * @param $class
+     * @param $actual
+     * @param $description
+     * @see \Codeception\Module\Asserts::assertInstanceOf()
+     */
+    public function assertInstanceOf($class, $actual, $description = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInstanceOf', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * @param $class
+     * @param $actual
+     * @param $description
+     * @see \Codeception\Module\Asserts::assertNotInstanceOf()
+     */
+    public function assertNotInstanceOf($class, $actual, $description = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotInstanceOf', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * @param $type
+     * @param $actual
+     * @param $description
+     * @see \Codeception\Module\Asserts::assertInternalType()
+     */
+    public function assertInternalType($type, $actual, $description = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInternalType', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Fails the test with message.
+     *
+     * @param $message
+     * @see \Codeception\Module\Asserts::fail()
+     */
+    public function fail($message) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Handles and checks exception called inside callback function.
+     * Either exception class name or exception instance should be provided.
+     *
+     * ```php
+     * <?php
+     * $I->expectException(MyException::class, function() {
+     *     $this->doSomethingBad();
+     * });
+     *
+     * $I->expectException(new MyException(), function() {
+     *     $this->doSomethingBad();
+     * });
+     * ```
+     * If you want to check message or exception code, you can pass them with exception instance:
+     * ```php
+     * <?php
+     * // will check that exception MyException is thrown with "Don't do bad things" message
+     * $I->expectException(new MyException("Don't do bad things"), function() {
+     *     $this->doSomethingBad();
+     * });
+     * ```
+     *
+     * @param $exception string or \Exception
+     * @param $callback
+     * @see \Codeception\Module\Asserts::expectException()
+     */
+    public function expectException($exception, $callback) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('expectException', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Inserts record into the database.
+     *
+     * ``` php
+     * <?php
+     * $user_id = $I->haveRecord('app\models\User', array('name' => 'Davert'));
+     * ?>
+     * ```
+     *
+     * @param $model
+     * @param array $attributes
+     * @return mixed
+     * @part orm
+     * @see \Codeception\Module\Yii2::haveRecord()
+     */
+    public function haveRecord($model, $attributes = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('haveRecord', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that record exists in database.
+     *
+     * ``` php
+     * $I->seeRecord('app\models\User', array('name' => 'davert'));
+     * ```
+     *
+     * @param $model
+     * @param array $attributes
+     * @part orm
+     * Conditional Assertion: Test won't be stopped on fail
+     * @see \Codeception\Module\Yii2::seeRecord()
+     */
+    public function canSeeRecord($model, $attributes = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeRecord', func_get_args()));
+    }
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that record exists in database.
+     *
+     * ``` php
+     * $I->seeRecord('app\models\User', array('name' => 'davert'));
+     * ```
+     *
+     * @param $model
+     * @param array $attributes
+     * @part orm
+     * @see \Codeception\Module\Yii2::seeRecord()
+     */
+    public function seeRecord($model, $attributes = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeRecord', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that record does not exist in database.
+     *
+     * ``` php
+     * $I->dontSeeRecord('app\models\User', array('name' => 'davert'));
+     * ```
+     *
+     * @param $model
+     * @param array $attributes
+     * @part orm
+     * Conditional Assertion: Test won't be stopped on fail
+     * @see \Codeception\Module\Yii2::dontSeeRecord()
+     */
+    public function cantSeeRecord($model, $attributes = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeRecord', func_get_args()));
+    }
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Checks that record does not exist in database.
+     *
+     * ``` php
+     * $I->dontSeeRecord('app\models\User', array('name' => 'davert'));
+     * ```
+     *
+     * @param $model
+     * @param array $attributes
+     * @part orm
+     * @see \Codeception\Module\Yii2::dontSeeRecord()
+     */
+    public function dontSeeRecord($model, $attributes = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeRecord', func_get_args()));
+    }
+
+ 
+    /**
+     * [!] Method is generated. Documentation taken from corresponding module.
+     *
+     * Retrieves record from database
+     *
+     * ``` php
+     * $category = $I->grabRecord('app\models\User', array('name' => 'davert'));
+     * ```
+     *
+     * @param $model
+     * @param array $attributes
+     * @return mixed
+     * @part orm
+     * @see \Codeception\Module\Yii2::grabRecord()
+     */
+    public function grabRecord($model, $attributes = null) {
+        return $this->getScenario()->runStep(new \Codeception\Step\Action('grabRecord', func_get_args()));
+    }
+}

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

@@ -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/03-AcceptanceTests#selenium-webdriver
+# "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:8080
+#        WebDriver:
+#            url: http://localhost:8080
+#            browser: firefox
+#            restart: true

+ 10 - 0
tests/acceptance/AboutCept.php

@@ -0,0 +1,10 @@
+<?php
+
+use tests\codeception\_pages\AboutPage;
+
+/* @var $scenario Codeception\Scenario */
+
+$I = new AcceptanceTester($scenario);
+$I->wantTo('ensure that about works');
+AboutPage::openBy($I);
+$I->see('About', 'h1');

+ 57 - 0
tests/acceptance/ContactCept.php

@@ -0,0 +1,57 @@
+<?php
+
+use tests\codeception\_pages\ContactPage;
+
+/* @var $scenario Codeception\Scenario */
+
+$I = new AcceptanceTester($scenario);
+$I->wantTo('ensure that contact works');
+
+$contactPage = ContactPage::openBy($I);
+
+$I->see('Contact', 'h1');
+
+$I->amGoingTo('submit contact form with no data');
+$contactPage->submit([]);
+if (method_exists($I, 'wait')) {
+    $I->wait(3); // only for selenium
+}
+$I->expectTo('see validations errors');
+$I->see('Contact', 'h1');
+$I->see('Name cannot be blank');
+$I->see('Email cannot be blank');
+$I->see('Subject cannot be blank');
+$I->see('Body cannot be blank');
+$I->see('The verification code is incorrect');
+
+$I->amGoingTo('submit contact form with not correct email');
+$contactPage->submit([
+    'name' => 'tester',
+    'email' => 'tester.email',
+    'subject' => 'test subject',
+    'body' => 'test content',
+    'verifyCode' => 'testme',
+]);
+if (method_exists($I, 'wait')) {
+    $I->wait(3); // only for selenium
+}
+$I->expectTo('see that email address is wrong');
+$I->dontSee('Name cannot be blank', '.help-inline');
+$I->see('Email is not a valid email address.');
+$I->dontSee('Subject cannot be blank', '.help-inline');
+$I->dontSee('Body cannot be blank', '.help-inline');
+$I->dontSee('The verification code is incorrect', '.help-inline');
+
+$I->amGoingTo('submit contact form with correct data');
+$contactPage->submit([
+    'name' => 'tester',
+    'email' => 'tester@example.com',
+    'subject' => 'test subject',
+    'body' => 'test content',
+    'verifyCode' => 'testme',
+]);
+if (method_exists($I, 'wait')) {
+    $I->wait(3); // only for selenium
+}
+$I->dontSeeElement('#contact-form');
+$I->see('Thank you for contacting us. We will respond to you as soon as possible.');

+ 11 - 0
tests/acceptance/HomeCept.php

@@ -0,0 +1,11 @@
+<?php
+
+/* @var $scenario Codeception\Scenario */
+
+$I = new AcceptanceTester($scenario);
+$I->wantTo('ensure that home page works');
+$I->amOnPage(Yii::$app->homeUrl);
+$I->see('My Company');
+$I->seeLink('About');
+$I->click('About');
+$I->see('This is the About page.');

+ 37 - 0
tests/acceptance/LoginCept.php

@@ -0,0 +1,37 @@
+<?php
+
+use tests\codeception\_pages\LoginPage;
+
+/* @var $scenario Codeception\Scenario */
+
+$I = new AcceptanceTester($scenario);
+$I->wantTo('ensure that login works');
+
+$loginPage = LoginPage::openBy($I);
+
+$I->see('Login', 'h1');
+
+$I->amGoingTo('try to login with empty credentials');
+$loginPage->login('', '');
+if (method_exists($I, 'wait')) {
+    $I->wait(3); // only for selenium
+}
+$I->expectTo('see validations errors');
+$I->see('Username cannot be blank.');
+$I->see('Password cannot be blank.');
+
+$I->amGoingTo('try to login with wrong credentials');
+$loginPage->login('admin', 'wrong');
+if (method_exists($I, 'wait')) {
+    $I->wait(3); // only for selenium
+}
+$I->expectTo('see validations errors');
+$I->see('Incorrect username or password.');
+
+$I->amGoingTo('try to login with correct credentials');
+$loginPage->login('admin', 'admin');
+if (method_exists($I, 'wait')) {
+    $I->wait(3); // only for selenium
+}
+$I->expectTo('see user info');
+$I->see('Logout (admin)');

tests/codeception/acceptance/_bootstrap.php → tests/acceptance/_bootstrap.php


tests/codeception/bin/_bootstrap.php → tests/bin/_bootstrap.php


tests/codeception/bin/yii → tests/bin/yii


tests/codeception/bin/yii.bat → tests/bin/yii.bat


+ 0 - 23
tests/codeception/_bootstrap.php

@@ -1,23 +0,0 @@
-<?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-test.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__));
-
-/**
- * this configure codeception specify to not deep clone objects properties
- * it can be configure localy in your tests
- * @see https://github.com/Codeception/Specify/tree/master/docs
- */
-\Codeception\Specify\Config::setDeepClone(false);

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

@@ -1,26 +0,0 @@
-<?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=yii2_basic_tests',
-        ],
-        'mailer' => [
-            'useFileTransport' => true,
-        ],
-        'urlManager' => [
-            'showScriptName' => true,
-        ],
-    ],
-];

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

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

+ 1 - 1
tests/codeception/config/acceptance.php

@@ -3,7 +3,7 @@
  * Application configuration for acceptance tests
  */
 return yii\helpers\ArrayHelper::merge(
-    require(__DIR__ . '/../../../config/web.php'),
+    require(__DIR__ . '/../../config/web.php'),
     require(__DIR__ . '/config.php'),
     [
 

+ 1 - 4
tests/codeception/config/functional.php

@@ -1,12 +1,9 @@
 <?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/web.php'),
     require(__DIR__ . '/config.php'),
     [
         'components' => [

+ 1 - 1
tests/codeception/config/unit.php

@@ -3,7 +3,7 @@
  * Application configuration for unit tests
  */
 return yii\helpers\ArrayHelper::merge(
-    require(__DIR__ . '/../../../config/web.php'),
+    require(__DIR__ . '/../../config/web.php'),
     require(__DIR__ . '/config.php'),
     [
 

tests/codeception/fixtures/.gitignore → tests/fixtures/.gitignore


+ 2 - 4
tests/codeception/functional.suite.yml

@@ -10,7 +10,5 @@ class_name: FunctionalTester
 modules:
     enabled:
       - Filesystem
-      - Yii2
-    config:
-        Yii2:
-            configFile: 'codeception/config/functional.php'
+      - Yii2:
+            configFile: 'config/test.php'

tests/codeception/functional/AboutCept.php → tests/functional/AboutCept.php


tests/codeception/functional/ContactCept.php → tests/functional/ContactCept.php


tests/codeception/functional/HomeCept.php → tests/functional/HomeCept.php


tests/codeception/functional/LoginCept.php → tests/functional/LoginCept.php


+ 1 - 0
tests/functional/_bootstrap.php

@@ -0,0 +1 @@
+<?php

tests/codeception/templates/.gitignore → tests/templates/.gitignore


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

@@ -4,3 +4,9 @@
 # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
 
 class_name: UnitTester
+modules:
+    enabled:
+      - Asserts
+      - Yii2:
+            configFile: 'config/test.php'
+            part: orm

tests/codeception/unit/_bootstrap.php → tests/unit/_bootstrap.php


tests/codeception/unit/fixtures/.gitkeep → tests/unit/fixtures/.gitkeep


tests/codeception/unit/fixtures/data/.gitkeep → tests/unit/fixtures/data/.gitkeep


tests/codeception/unit/models/ContactFormTest.php → tests/unit/models/ContactFormTest.php


tests/codeception/unit/models/LoginFormTest.php → tests/unit/models/LoginFormTest.php


tests/codeception/unit/models/UserTest.php → tests/unit/models/UserTest.php


tests/codeception/unit/templates/fixtures/.gitkeep → tests/unit/templates/fixtures/.gitkeep