Skip to content

Commit

Permalink
Merge branch "2.2" of github.com:Codeception/Codeception into 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Jan 17, 2017
2 parents 4e38a8c + da34f97 commit 22b43de
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 63 deletions.
58 changes: 13 additions & 45 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ matrix:
env: dependencies=lowest SYMFONY_DEPRECATIONS_HELPER=weak
- php: 5.6
env: SYMFONY=2.8.12 SYMFONY_DEPRECATIONS_HELPER=weak # latest version of 2.8.*
- php: hhvm
dist: trusty
group: edge

addons:
postgresql: "9.2"
Expand All @@ -36,19 +33,8 @@ services:
- redis

install:
- '[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || pecl install mongodb'
# reset mysql password on trusty
- 'if [ -f ~/.my.cnf ]; then mysql -e "update mysql.user set password='''' where User=''root''"; fi'
- 'if [ -f ~/.my.cnf ]; then mysql -e "flush privileges"; fi'
- 'if [ -f ~/.my.cnf ]; then sed -i "s/password = travis/password =/" ~/.my.cnf; fi'
# use different mysql socket on trusty
- 'if [ -f ~/.my.cnf ]; then echo "pdo_mysql.default_socket = /run/mysql-5.6/mysqld.sock" >> /etc/hhvm/php.ini; fi'
- 'pecl install mongodb'
#- echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
# use hhvm-serve instead of builtin server
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || mkdir -p /home/travis/go/{src,bin,pkg}'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || export GOPATH="/home/travis/go"'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || export PATH="$GOPATH/bin:$PATH"'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || go get github.com/Naktibalda/hhvm-serve'
- composer self-update && composer --version
- if [ -n "$CI_USER_TOKEN" ]; then composer config github-oauth.github.com ${CI_USER_TOKEN}; echo "Configured Github token"; fi;
- composer global require "fxp/composer-asset-plugin:~1.1.1"
Expand All @@ -59,19 +45,18 @@ install:
- '[[ -z "$SYMFONY" ]] || composer require symfony/css-selector=~$SYMFONY --no-update --ignore-platform-reqs'
- '[[ -z "$SYMFONY" ]] || composer require symfony/dom-crawler=~$SYMFONY --no-update --ignore-platform-reqs'
- '[[ -z "$SYMFONY" ]] || composer require symfony/browser-kit=~$SYMFONY --no-update --ignore-platform-reqs'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || composer remove mongodb/mongodb --no-update --dev'
- composer_parameters="-n --prefer-dist" # this variable will be used in all composer install commands
- '[[ "$dependencies" != "lowest" ]] || composer_parameters="$composer_parameters --prefer-lowest"'
- composer update $composer_parameters
- composer_parameters="$composer_parameters --no-dev" # Codeception needs dev dependencies, but frameworks don't
# Yii2
- composer create-project "yiisoft/yii2-app-basic:@dev" frameworks-yii-basic --no-dev
# Phalcon
- "[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || [[ -z "$PHALCON" ]] || git clone -q --depth=1 https://github.com/phalcon/cphalcon.git -b $PHALCON"
- "[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || [[ ! -z "$PHALCON" ]] || git clone -q --depth=1 https://github.com/phalcon/cphalcon.git"
- "[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || (cd cphalcon/build; bash install &>/dev/null && phpenv config-add ../tests/_ci/phalcon.ini &> /dev/null && cd ../..;)"
- "[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || git clone -q --depth=1 https://github.com/Codeception/phalcon-demo.git frameworks-phalcon"
- "[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || composer update -d frameworks-phalcon $composer_parameters"
- "[[ -z "$PHALCON" ]] || git clone -q --depth=1 https://github.com/phalcon/cphalcon.git -b $PHALCON"
- "[[ ! -z "$PHALCON" ]] || git clone -q --depth=1 https://github.com/phalcon/cphalcon.git"
- "(cd cphalcon/build; bash install &>/dev/null && phpenv config-add ../tests/_ci/phalcon.ini &> /dev/null && cd ../..;)"
- "git clone -q --depth=1 https://github.com/Codeception/phalcon-demo.git frameworks-phalcon"
- "composer update -d frameworks-phalcon $composer_parameters"
# Laravel 5
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || [[ "$TRAVIS_PHP_VERSION" == "5.5" ]] || git clone -q -b codeception-2.2 https://github.com/janhenkgerritsen/codeception-laravel5-sample.git frameworks-l5'
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || [[ "$TRAVIS_PHP_VERSION" == "5.5" ]] || composer update -d frameworks-l5 $composer_parameters'
Expand All @@ -93,29 +78,16 @@ install:
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || composer update -d frameworks-zend-expressive $composer_parameters'

before_script:
- '[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || [[ "$TRAVIS_PHP_VERSION" == "7.0" ]] || echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini'
# create config file for hhvm daemon
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || echo "pid = /tmp/hhvm.pid" >>/tmp/hhvm.ini'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || echo "hhvm.server.port = 9000" >>/tmp/hhvm.ini'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || echo "hhvm.server.type = fastcgi" >>/tmp/hhvm.ini'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || echo "hhvm.server.default_document = index.php" >>/tmp/hhvm.ini'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || echo "hhvm.log.use_log_file = true" >>/tmp/hhvm.ini'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || echo "hhvm.log.file = /tmp/hhvm-error.log" >>/tmp/hhvm.ini'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || echo "hhvm.repo.central.path = /tmp/hhvm.hhbc" >>/tmp/hhvm.ini'
# start hhvm daemon
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || hhvm --config "/tmp/hhvm.ini" --mode daemon'
- '[[ "$TRAVIS_PHP_VERSION" == "7.0" ]] || echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini'
# preparing databases
- "mysql -e 'create database codeception_test;'"
- psql -c 'create database codeception_test;' -U postgres
# starting demo servers
- '[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || php -S 127.0.0.1:8000 -t tests/data/app >/dev/null 2>&1 &'
- '[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || php -S 127.0.0.1:8010 -t tests/data >/dev/null 2>&1 &'
# use hhvm-serve instead of builtin server
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || hhvm-serve --document-root=tests/data/app --listen=127.0.0.1:8000 >/dev/null 2>&1 &'
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || hhvm-serve --document-root=tests/data --listen=127.0.0.1:8010 >/dev/null 2>&1 &'
- 'php -S 127.0.0.1:8000 -t tests/data/app >/dev/null 2>&1 &'
- 'php -S 127.0.0.1:8010 -t tests/data >/dev/null 2>&1 &'
# Phalcon
- mysql -e 'CREATE DATABASE phalcon_demo CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;'
- "[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || cat frameworks-phalcon/schemas/phalcon_demo.sql | mysql phalcon_demo"
- "cat frameworks-phalcon/schemas/phalcon_demo.sql | mysql phalcon_demo"
# Laravel 5
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || [[ "$TRAVIS_PHP_VERSION" == "5.5" ]] || touch frameworks-l5/storage/testing.sqlite'
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || [[ "$TRAVIS_PHP_VERSION" == "5.5" ]] || php frameworks-l5/artisan migrate --database=sqlite_testing --force'
Expand All @@ -131,7 +103,7 @@ before_script:
- php frameworks-zf2/vendor/bin/doctrine-module orm:schema-tool:create
# Build
- php codecept build -c frameworks-yii-basic
- "[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || php codecept build -c frameworks-phalcon"
- "php codecept build -c frameworks-phalcon"
- '[[ -z "$SYMFONY" ]] || php codecept build -c frameworks-symfony/src/AppBundle'
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || [[ "$TRAVIS_PHP_VERSION" == "5.5" ]] || php codecept build -c frameworks-l5'
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || [[ "$TRAVIS_PHP_VERSION" == "5.5" ]] || php codecept build -c frameworks-lumen'
Expand All @@ -140,16 +112,12 @@ before_script:
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || php codecept build -c frameworks-zend-expressive'

script:
# enable xdebug before running codeception tests on hhvm
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || echo "xdebug.enable = On" >> /etc/hhvm/php.ini'
- php codecept run cli,unit # self tests
- '[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || php codecept run coverage' # run coverage tests on php only
# disable xdebug before running framework tests
- '[[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] || echo "xdebug.enable = Off" >> /etc/hhvm/php.ini'
- 'php codecept run coverage' # run coverage tests on php only
- php codecept run functional -c frameworks-yii-basic # Yii2 tests
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || [[ "$TRAVIS_PHP_VERSION" == "5.5" ]] || php codecept run -c frameworks-l5' # Laravel5 Tests
- '[[ "$TRAVIS_PHP_VERSION" == "5.4" ]] || [[ "$TRAVIS_PHP_VERSION" == "5.5" ]] || php codecept run -c frameworks-lumen' # Lumen Tests
- "[[ "$TRAVIS_PHP_VERSION" == "hhvm" ]] || php codecept run functional -c frameworks-phalcon" # Phalcon Tests
- "php codecept run functional -c frameworks-phalcon" # Phalcon Tests
- '[[ -z "$SYMFONY" ]] || php codecept run functional -c frameworks-symfony/src/AppBundle '# Symfony Tests
- php codecept run functional -c frameworks-zf1 # ZF1 Tests
- php codecept run -c frameworks-zf2 functional,doctrine # ZF2 Tests
Expand Down
2 changes: 1 addition & 1 deletion codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ settings:
colors: true
memory_limit: 1024M
log: true
lint: true
lint: false
modules:
config:
AMQP:
Expand Down
43 changes: 40 additions & 3 deletions src/Codeception/Coverage/Subscriber/LocalServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Codeception\Event\SuiteEvent;
use Codeception\Event\TestEvent;
use Codeception\Events;
use Codeception\Exception\ModuleException;
use Codeception\Exception\RemoteException;

/**
Expand Down Expand Up @@ -148,18 +149,54 @@ function ($h) {

protected function startCoverageCollection($testName)
{
$cookie = [
$value = [
'CodeCoverage' => $testName,
'CodeCoverage_Suite' => $this->suiteName,
'CodeCoverage_Config' => $this->settings['remote_config']
];
$value = json_encode($value);

$this->module->amOnPage('/');
$this->module->setCookie(self::COVERAGE_COOKIE, json_encode($cookie));
$this->module->setCookie(self::COVERAGE_COOKIE, $value);

// putting in configuration ensures the cookie is used for all sessions of a MultiSession test

$cookies = $this->module->_getConfig('cookies');
if (!$cookies || !is_array($cookies)) {
$cookies = [];
}

$found = false;
foreach ($cookies as &$cookie) {
if (!is_array($cookie) || !array_key_exists('Name', $cookie) || !array_key_exists('Value', $cookie)) {
// \Codeception\Lib\InnerBrowser will complain about this
continue;
}
if ($cookie['Name'] === self::COVERAGE_COOKIE) {
$found = true;
$cookie['Value'] = $value;
break;
}
}
if (!$found) {
$cookies[] = [
'Name' => self::COVERAGE_COOKIE,
'Value' => $value
];
}

$this->module->_setConfig(['cookies' => $cookies]);
}

protected function fetchErrors()
{
$error = $this->module->grabCookie(self::COVERAGE_COOKIE_ERROR);
try {
$error = $this->module->grabCookie(self::COVERAGE_COOKIE_ERROR);
} catch (ModuleException $e) {
// when a new session is started we can't get cookies because there is no
// current page, but there can be no code coverage error either
$error = null;
}
if (!empty($error)) {
$this->module->resetCookie(self::COVERAGE_COOKIE_ERROR);
throw new RemoteException($error);
Expand Down
12 changes: 9 additions & 3 deletions src/Codeception/Module/PhpBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public function _requires()

public function _initialize()
{
$this->client = $this->guessGuzzleConnector();
$this->_initializeSession();
}

Expand All @@ -150,7 +149,7 @@ public function _before(TestInterface $test)
if (!$this->client) {
$this->client = $this->guessGuzzleConnector();
}
$this->_initializeSession();
$this->_prepareSession();
}

public function _getUrl()
Expand Down Expand Up @@ -193,7 +192,7 @@ public function amOnSubdomain($subdomain)

protected function onReconfigure()
{
$this->_initializeSession();
$this->_prepareSession();
}

/**
Expand Down Expand Up @@ -227,6 +226,13 @@ public function _getResponseCode()
}

public function _initializeSession()
{
// independent sessions need independent cookies
$this->client = $this->guessGuzzleConnector();
$this->_prepareSession();
}

public function _prepareSession()
{
$defaults = array_intersect_key($this->config, array_flip($this->guzzleConfigFields));
$curlOptions = [];
Expand Down
8 changes: 8 additions & 0 deletions tests/data/app/hhvm-server.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hhvm.server.port = 8000
hhvm.server.type = proxygen
hhvm.server.default_document = index.php
hhvm.server.error_document404 = index.php
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
hhvm.log.use_log_file = false
hhvm.hack.lang.auto_typecheck=0
hhvm.hack.lang.look_for_typechecker=0
1 change: 1 addition & 0 deletions tests/data/claypit/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ settings:
suite_class: \PHPUnit_Framework_TestSuite
colors: false
memory_limit: 1024M
lint: false
log: true
groups:
failed: tests/_log/failed
Expand Down
6 changes: 5 additions & 1 deletion tests/data/claypit/tests/remote/DemoCept.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
$I = new OtherGuy($scenario);
$I->amOnPage('/');
$I->see('Welcome to test app');
$I->see('Welcome to test app');
$I->haveFriend("friend")->does(function(OtherGuy $I) {
$I->amOnPage('/info');
$I->see('Lots of valuable data');
});
8 changes: 8 additions & 0 deletions tests/data/rest/hhvm-server.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hhvm.server.port = 8010
hhvm.server.type = proxygen
hhvm.server.default_document = index.php
hhvm.server.error_document404 = index.php
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
hhvm.log.use_log_file = false
hhvm.hack.lang.auto_typecheck=0
hhvm.hack.lang.look_for_typechecker=0
6 changes: 6 additions & 0 deletions tests/support/CoverGuy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public function seeCoverageStatsNotEmpty()
<<<EOF
index
Methods: 50.00% ( 1/ 2) Lines: 50.00% ( 2/ 4)
EOF
);
$this->seeInShellOutput(
<<<EOF
info
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 4/ 4)
EOF
);
}
Expand Down
9 changes: 0 additions & 9 deletions tests/unit/Codeception/Lib/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,6 @@ public function testParseFileWhichUnsetsFileVariable()
$classes = Parser::getClassesFromFile(codecept_data_dir('unsetFile.php'));
$this->assertEquals([], $classes);
}
/**
* @group core
* @throws \Codeception\Exception\TestParseException
*/
public function testCeptValidation()
{
$this->setExpectedException('Codeception\Exception\TestParseException');
Parser::validate(codecept_data_dir('Invalid.php'));
}

/**
* @group core
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Codeception/Module/AMQPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setUp()
{
$this->module = new \Codeception\Module\AMQP(make_container());
$this->module->_setConfig($this->config);
$res = stream_socket_client("tcp://localhost:5672");
$res = @stream_socket_client("tcp://localhost:5672");
if ($res === false) {
$this->markTestSkipped('AMQP is not running');
}
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/Codeception/Module/PhpBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ public function testSetMultipleCookies()
$this->module->dontSeeCookie($cookie_name_2);
}

public function testSessionsHaveIndependentCookies()
{
$this->module->amOnPage('/');
$cookie_name_1 = 'test_cookie';
$cookie_value_1 = 'this is a test';
$this->module->setCookie($cookie_name_1, $cookie_value_1);

$session = $this->module->_backupSession();
$this->module->_initializeSession();

$this->module->dontSeeCookie($cookie_name_1);

$cookie_name_2 = '2_test_cookie';
$cookie_value_2 = '2 this is a test';
$this->module->setCookie($cookie_name_2, $cookie_value_2);

$this->module->_loadSession($session);

$this->module->dontSeeCookie($cookie_name_2);
$this->module->seeCookie($cookie_name_1);
}

public function testSubmitFormGet()
{
$I = $this->module;
Expand Down
50 changes: 50 additions & 0 deletions wercker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
box: hhvm/hhvm-proxygen
# Build definition

build:
# The steps that will be executed on build
steps:
- script:
name: disable interactive install
code: |
export DEBIAN_FRONTEND=noninteractive
- install-packages:
packages: curl git mysql-server mysql-server-5.5 redis-server postgresql
- script:
name: start database servers
code: |
/etc/init.d/mysql start
/etc/init.d/redis-server start
sed -i "s/ peer/ trust/g" /etc/postgresql/*/main/pg_hba.conf
sed -i "s/ md5/ trust/g" /etc/postgresql/*/main/pg_hba.conf
/etc/init.d/postgresql start
- script:
name: install composer
code: |
rm -f composer.lock
export COMPOSER_CACHE_DIR=$WERCKER_CACHE_DIR
curl -sS https://getcomposer.org/installer | hhvm --php -- --install-dir=/usr/local/bin/
composer.phar remove mongodb/mongodb --no-update --dev
composer.phar install
echo "xdebug.enable = On" >> /etc/hhvm/php.ini
- script:
name: setup HHVM servers
code: |
echo ${WERCKER_ROOT}/tests/data/app
echo "hhvm.server.source_root=${WERCKER_ROOT}/tests/data/app" >> tests/data/app/hhvm-server.ini
cat tests/data/app/hhvm-server.ini
hhvm -m server -c tests/data/app/hhvm-server.ini -c /etc/hhvm/site.ini &
echo "hhvm.server.source_root=${WERCKER_ROOT}/tests/data/rest" >> tests/data/rest/hhvm-server.ini
hhvm -m server -c tests/data/rest/hhvm-server.ini -c /etc/hhvm/site.ini &
- script:
name: prepare databases
code: |
mysql -e 'create database codeception_test;'
su postgres -c "psql -c 'create database codeception_test;' -U postgres"
# A custom script step, name value is used in the UI
# and the code value contains the command that get executed
- script:
name: codeception tests
code: |
php codecept run cli,unit

0 comments on commit 22b43de

Please sign in to comment.