Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module testing coverage #15

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_name: travis-ci
coverage_clover: tests/codeception/_output/coverage.xml
json_path: tests/codeception/_output/coverage.json
46 changes: 46 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
language: php
sudo: enabled

services:
- mysql
git:
depth: 3

php:
- 7.2

env:
global:
- HUMHUB_PATH=/opt/humhub

cache:
directories:
- $HOME/.composer/cache

install:
- .travis/install-dependencies.sh
- .travis/setup-humhub.sh

before_script:
- $HOME/chromedriver --url-base=/wd/hub &
- php --server 127.0.0.1:8080 --docroot ${HUMHUB_PATH} &>/dev/null &
- sleep 5
- curl --fail --head http://127.0.0.1:8080/index-test.php

script:
- cd tests
- ln -s ${HUMHUB_PATH}/protected/humhub/tests/config/env config/ # create symlink from /opt/humhub to config/
- sed -i -e "s|../../../humhub/tests/config/env|config/env|g" codeception.yml # fix relative path for codeception
- php ${HUMHUB_PATH}/protected/vendor/bin/codecept build
- php ${HUMHUB_PATH}/protected/vendor/bin/codecept run --env travis

after_failure:
- cd ..
- .travis/upload-failure.sh

after_success:
- test $TRAVIS_BRANCH = "tests" &&
test $TRAVIS_PULL_REQUEST = "false" &&
php ${HUMHUB_PATH}/protected/vendor/bin/codecept run --coverage-xml --env travis &&
cd .. &&
php ${HUMHUB_PATH}/protected/vendor/bin/php-coveralls -v
9 changes: 9 additions & 0 deletions .travis/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh

# -e = exit when one command returns != 0, -v print each command before executing
set -ev

# Install chomedriver
curl -s -L -o chromedriver_linux64.zip https://chromedriver.storage.googleapis.com/2.40/chromedriver_linux64.zip \
&& unzip -o -d $HOME chromedriver_linux64.zip \
&& chmod +x $HOME/chromedriver
35 changes: 35 additions & 0 deletions .travis/setup-humhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env sh

# -e = exit when one command returns != 0, -v print each command before executing
set -ev

old=$(pwd)

cd ..
git clone --depth 1 https://github.com/Coinsence/humhub-modules-xcoin

mkdir ${HUMHUB_PATH}
cd ${HUMHUB_PATH}

git clone --depth 1 https://github.com/Coinsence/humhub.git .
composer install --prefer-dist --no-interaction
composer require --dev php-coveralls/php-coveralls

npm install
grunt build-assets

cd ${HUMHUB_PATH}/protected/humhub/tests

set +v
sed -i -e "s|'installed' => true,|'installed' => true,\n\t'moduleAutoloadPaths' => ['$(dirname $old)'],\n\t'defaultAssetName' => '$DEFAULTASSETNAME',\n\t'apiCredentials' => '$APICREDENTIALS',\n\t'ethereum_api_base_uri' => '$ETHEREUMAPIBASEURI'|g" config/common.php
set -v
#cat config/common.php

mysql -e 'CREATE DATABASE humhub_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'
php codeception/bin/yii migrate/up --includeModuleMigrations=1 --interactive=0
mysql -e 'USE humhub_test; INSERT INTO module_enabled (module_id) VALUES ("xcoin");'
php codeception/bin/yii migrate/up --includeModuleMigrations=1 --interactive=0
php codeception/bin/yii installer/auto
php codeception/bin/yii search/rebuild

php ${HUMHUB_PATH}/protected/vendor/bin/codecept build
17 changes: 17 additions & 0 deletions .travis/upload-failure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

# -e = exit when one command returns != 0, -v print each command before executing
set -ev

# find _output folder and add to zip
find tests/ -type d -name "_output" -exec zip -r --exclude="*.gitignore" failure.zip {} +

# add logs to failure.zip
zip -ur coinsence-ethereum-travis-${TRAVIS_JOB_NUMBER}.zip ${HUMHUB_PATH}/protected/runtime/logs || true
zip -ur coinsence-ethereum-travis-${TRAVIS_JOB_NUMBER}.zip /tmp/phpserver.log || true

# upload file
curl -F "file=@coinsence-ethereum-travis-${TRAVIS_JOB_NUMBER}.zip" -s -w "\n" https://file.io

# delete zip
rm coinsence-ethereum-travis-${TRAVIS_JOB_NUMBER}.zip
9 changes: 9 additions & 0 deletions calls/Space.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Space
{
/**
* @param $event
* @return bool|void
* @throws GuzzleException
* @throws HttpException
* @throws Exception
Expand Down Expand Up @@ -84,10 +85,13 @@ public static function addMember($event)
'Could not add member to this space, will fix this ASAP !'
);
}

return true;
}

/**
* @param $event
* @return bool|void
* @throws GuzzleException
* @throws HttpException
*/
Expand Down Expand Up @@ -121,10 +125,13 @@ public static function removeMember($event)
'Could not remove member from this space, will fix this ASAP !'
);
}

return true;
}

/**
* @param $event
* @return bool|void
* @throws GuzzleException
* @throws HttpException
*/
Expand Down Expand Up @@ -158,6 +165,8 @@ public static function leaveSpace($event)
'Could not cancel membership from this space, will fix this ASAP !'
);
}

return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion component/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static function isXcoinEnabled($space)
return
$space instanceof Space &&
$space->isModuleEnabled('xcoin') &&
$space->id !== 1; // space with id = 1 is "Welcome Space" (this is the best way to check since it's the first space automatically created)
($space->id !== 1 || YII_ENV === 'test'); // space with id = 1 is "Welcome Space" (this is the best way to check since it's the first space automatically created) , skip if test env
}

static function isEthereumEnabled($space)
Expand Down
33 changes: 33 additions & 0 deletions tests/codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
actor: Tester
namespace: ethereum
coverage:
c3_url: 'http://127.0.0.1:8080/index-test.php'
enabled: true
remote: false
low_limit: 40
high_limit: 80
include:
- ../calls/*
- ../component/*
- ../controllers/*
- ../jobs/*
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
shuffle: false
memory_limit: 1024M
log: true

# This value controls whether PHPUnit attempts to backup global variables
# See https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.backupGlobals
backup_globals: true
paths:
tests: codeception
log: codeception/_output
data: codeception/_data
helpers: codeception/_support
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://127.0.0.1:8080/index-test.php
49 changes: 49 additions & 0 deletions tests/codeception/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* This is the initial test bootstrap, which will load the default test bootstrap from the humhub core
*/
// Parse the environment arguments (Note: only simple --env ENV is supported no comma sepration merge...)
$env = isset($GLOBALS['env']) ? $GLOBALS['env'] : [];

// If environment was set try loading special environment config else load default
if (count($env) > 0) {
\Codeception\Configuration::append(['environment' => $env]);


$envCfgFile = dirname(__DIR__) . '/config/env/test.' . $env[0][0] . '.php';

if (file_exists($envCfgFile)) {
$cfg = array_merge(require_once(__DIR__ . '/../config/test.php'), require_once($envCfgFile));
}
}

// If no environment is set we have to load the default config
if (!isset($cfg)) {
$cfg = require_once(__DIR__ . '/../config/test.php');
}

// If no humhub_root is given we assume our module is in the a root to be in /protected/humhub/modules/<module>/tests/codeception directory
$cfg['humhub_root'] = isset($cfg['humhub_root']) ? $cfg['humhub_root'] : dirname(__DIR__) . '/../../../../..';


// Load default test bootstrap
require_once($cfg['humhub_root'] . '/protected/humhub/tests/codeception/_bootstrap.php');

// Overwrite the default test alias
Yii::setAlias('@tests', dirname(__DIR__));
Yii::setAlias('@env', '@tests/config/env');
Yii::setAlias('@root', $cfg['humhub_root']);
Yii::setAlias('@humhubTests', $cfg['humhub_root'] . '/protected/humhub/tests');

// Load all supporting test classes needed for test execution
\Codeception\Util\Autoload::addNamespace('', Yii::getAlias('@humhubTests/codeception/_support'));
\Codeception\Util\Autoload::addNamespace('tests\codeception\fixtures', Yii::getAlias('@humhubTests/codeception/fixtures'));
\Codeception\Util\Autoload::addNamespace('', Yii::getAlias('@humhubTests/codeception/_pages'));
if(isset($cfg['modules'])) {
\Codeception\Configuration::append(['humhub_modules' => $cfg['modules']]);
}

if(isset($cfg['fixtures'])) {
\Codeception\Configuration::append(['fixtures' => $cfg['fixtures']]);
}
?>
4 changes: 4 additions & 0 deletions tests/codeception/_output/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
37 changes: 37 additions & 0 deletions tests/codeception/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* @link https://coinsence.org/
* @copyright Copyright (c) 2018 Coinsence
* @license https://www.humhub.com/licences
*
* @author Ghanmi Mortadha <[email protected] >
* @author Daly Ghaith <[email protected]>
*/

namespace ethereum;

/**
* 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 \AcceptanceTester
{
use _generated\AcceptanceTesterActions;

/**
* Define custom actions here
*/

}
Loading