Übersetzungen dieser Seite:
  • de

Back to Yii2 Overview

Yii2 Testing

This page contains my notes about learning testing with Yii2. My environment is Windows 7.

Yii2 uses PHPUnit and Codeception to run tests.

Test Types

  • Unit - verifies that a single unit of code is working as expected;
  • Functional - verifies scenarios from a user's perspective via browser emulation;
  • Acceptance - verifies scenarios from a user's perspective in a browser.

Unit Tests

Unit tests are usually developed by people who write the classes being tested.

Functional Tests

Functional tests are generally faster than acceptance tests.

Requirements

Config Files

  • Change modules > enabled > WebDriver > url and browser
tests/Acceptance.suite.yaml
class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: http://localhost:8080/
            browser: chrome
        - Yii2:
            part: orm
            entryScript: index-test.php
            cleanup: false

Console

Chrome Driver

Running Tests

  • If your are working in an environment using a proxy server, unset the environment variable HTTP_PROXY:
$ HTTP_PROXY= && vendor/bin/codecept run