Last active
December 20, 2022 14:05
-
-
Save terabytesoftw/7ae1dc2b3bd6b852c4f89e056b323607 to your computer and use it in GitHub Desktop.
Codeception For Tests Yii3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Add in your composer codeception tests. | |
$composer require codeception/codeception:^3.0 | |
#Create your directory /tests in your proyect | |
$mkdir /tests | |
#Create codepction systems tests with namespaces | |
$vendor/bin/codecept bootstrap --namespace AppTests | |
#Custom options codeception.yml: | |
namespace: AppTests | |
paths: | |
tests: tests | |
output: tests/_output | |
data: tests/_data | |
support: tests/_support | |
envs: tests/_envs | |
actor_suffix: Tester | |
extensions: | |
enabled: | |
- Codeception\Extension\RunFailed | |
- Codeception\Extension\Logger //add extesion recoder codeption. | |
settings: //add settings codeception | |
suite_class: \PHPUnit_Framework_TestSuite | |
memory_limit: 1024M | |
colors: true | |
coverage: | |
enabled: true | |
whitelist: | |
include: | |
- src/* | |
exclude: | |
- src/assets //exclude list coverage tests | |
#Download c3.php for https://github.com/Codeception/c3, add directory / root. | |
#Config codeception tests | |
#acceptance.suite.yml | |
# Codeception Test Suite Configuration | |
# | |
# Suite for acceptance tests. | |
# Perform tests in browser using the WebDriver or PhpBrowser. | |
# If you need both WebDriver and PHPBrowser tests - create a separate suite. | |
actor: AcceptanceTester | |
modules: | |
enabled: | |
- WebDriver | |
- \ModuleUser\Helper\Acceptance | |
config: | |
WebDriver: | |
url: 'http://127.0.0.1:8080' | |
browser: chrome | |
capabilities: | |
"goog:chromeOptions": | |
args: ["--headless", "--disable-gpu", "--window-size=1024,768"] | |
step_decorators: ~ | |
#functional.suite.yml: | |
# Codeception Test Suite Configuration | |
# | |
# Suite for functional tests | |
# Emulate web requests and make application process them | |
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it | |
# Remove this suite if you don't use frameworks | |
actor: FunctionalTester | |
modules: | |
enabled: | |
- PhpBrowser: | |
url: http://127.0.0.1:8080 | |
# add a framework module here | |
- \ModuleUser\Helper\Functional | |
step_decorators: ~ | |
#unit.suite.yml | |
# Codeception Test Suite Configuration | |
# | |
# Suite for unit or integration tests. | |
actor: UnitTester | |
modules: | |
enabled: | |
- Asserts | |
- \ModuleUser\Helper\Unit | |
step_decorators: ~ | |
#custom /public/index.php | |
<?php | |
use hiqdev\composer\config\Builder; | |
use yii\di\Container; | |
use yii\helpers\Yii; | |
include '../c3.php'; | |
define('MY_APP_STARTED', true); | |
// ensure we get report on all possible php errors | |
error_reporting(-1); | |
define('YII_ENABLE_ERROR_HANDLER', true); | |
define('YII_DEBUG', true); | |
define('YII_ENV', 'test'); | |
(function () { | |
require_once __DIR__ . '/../vendor/autoload.php'; | |
$container = new Container(require Builder::path('web')); | |
Yii::setContainer($container); | |
$container->get('app')->run(); | |
})(); | |
#Download selenium-server and move /usr/bin | |
$wget -c -nc --retry-connrefused --tries=0 https://bit.ly/2TlkRyu -O selenium-server-standalone.jar | |
$mv selenium-server-standalone.jar /usr/bin | |
#Download chromedriver and move /usr/bin | |
$wget https://chromedriver.storage.googleapis.com/74.0.3729.6/chromedriver_linux64.zip | |
$unzip -o -q chromedriver_linux64.zip -d /usr/bin | |
#Run selenium-server | |
$/usr/bin/java.exe -jar /usr/bin/selenium-server-standalone.jar > /dev/null 2>&1& | |
#Run php socket web | |
$php -S 127.0.0.1:8080 -t public > /dev/null 2>&1& | |
#Create acceptance tests | |
$vendor/bin/codecept generate:cest acceptance Example | |
#Run Tests coverage | |
$vendor/bin/codecept run --coverage --coverage-xml --coverage-html | |
#travis.yml | |
language: php | |
php: | |
- 7.2 | |
- 7.3 | |
dist: trusty | |
addons: | |
chrome: stable | |
# faster builds on new travis setup not using sudo | |
sudo: false | |
# cache vendor dirs | |
cache: | |
directories: | |
- $HOME/.composer/cache | |
install: | |
- travis_retry composer self-update && composer --version | |
- travis_retry composer update --prefer-dist --no-interaction | |
before_script: | |
- echo "Config required" | |
- "export DISPLAY=:99.0" | |
- "sh -e /etc/init.d/xvfb start" | |
- sleep 3 # give xvfb some time to start | |
- echo "Download selenium-server-standalone jar file" | |
- wget -c -nc --retry-connrefused --tries=0 https://bit.ly/2TlkRyu -O selenium-server-standalone.jar | |
- echo "Download chromedriver" | |
- wget https://chromedriver.storage.googleapis.com/74.0.3729.6/chromedriver_linux64.zip | |
- unzip -o -q chromedriver_linux64.zip | |
- echo "Run selenium-server" | |
- nohup bash -c "java -jar selenium-server-standalone.jar &" && sleep 1; cat nohup.out | |
script: | |
- | | |
cd tests | |
php -S 127.0.0.1:8080 -t public > /dev/null 2>&1& | |
cd .. | |
vendor/bin/codecept build | |
vendor/bin/codecept run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment