Problems with OXID testing library for modules

Hi,

I want to test my new modules with this library:

I also found this: Running tests using OXID testing library | PHP For Us - here is written that I need to install my testing library in /source directory of my OXID instance.
I have also fresh install of OXID Eshop 6.1.1 EE.

I install this testing library like is described on blog here: Running tests using OXID testing library | PHP For Us - so I:

  1. create composer.json inside /source dir with content from oxid-testing-library from github
  2. goto vagrant ssh, goto source dir, run: composer install

  3. on the end of intall I get message:

“[Exception]
Shop directory structure is not setup properly. Edition could not be detected”
So now if I try to run eg. (from source dir) command: ./vendor/bin/runtests I also get an error:

PHP Fatal error: Uncaught Exception: Shop directory structure is not setup properly. Edition could not be detected in /var/www/oxideshop/source/vendor/oxid-esales/oxideshop-facts/src/Edition/EditionSelector.php:139

I have all those needed files in /source/vendor/
 but I get an error


Can someone help me with test library configuration, please?

The tutorial you found uses OXID 4.8.5, which does not use composer itself, that is why testing library is installed in source dir. In Oxid 6.1.1 testing library is in require-dev, it is installed by default if you run “composer update” in project directory (the root directory which contains source and vendor). Here is a basic tutorial: https://oxidforge.org/en/run-module-tests-in-oxid-eshop-6.html

2 Likes

I am very pleased for your help @leofonic !!!
I tried to do it with newest blog tutorial whitch you suggest me and it works! :slight_smile:

But I have a litle question here.
I want to run tests only for my module sometimes and I configured the test_config.yml like here:

# This file is auto-generated during the composer install

mandatory_parameters:

shop_path: source
shop_tests_path: tests
partial_module_paths: kira/paypalsubscriptionoxidexample

optional_parameters:

shop_url: null
shop_serial: ''
enable_varnish: false
is_subshop: false
install_shop: true
remote_server_dir: null
shop_setup_path: null
restore_shop_after_tests_suite: false
test_database_name: null
restore_after_acceptance_tests: true
restore_after_unit_tests: true
tmp_path: /tmp/oxid_test_library/
database_restoration_class: DatabaseRestorer
activate_all_modules: false
run_tests_for_shop: false
run_tests_for_modules: true
screen_shots_path: null
screen_shots_url: null
browser_name: firefox
selenium_server_ip: 127.0.0.1
selenium_server_port: '4444'
additional_test_paths: 'vendor/oxid-esales/oxideshop-ee/Tests,vendor/oxid-esales/oxideshop-pe/Tests'
retry_times_after_test_fail: 2

But when I run the tests command: vendor/bin/runtests the tests for module of course runs
but after my tests - there is running the shop tests and it takes very much time! :frowning:

I disabled the shop_test: false in my test_config.yml file

Maybe someone know what is happend with this situation?

Maybe because of additional_test_paths value.

1 Like

Maybe :smiley: i will check it later :slight_smile:
Thanks

O, everything is good.

I have one more question with workflow with this tests library
 When I do this tests my database was removed, so for restore I need to do vendor/bin/reset-shop.

When I want to do the tests on my development machine I don’t want to delete all information from database

I try to set install_shop to false, but it did not help.

I saw that I can specify other database to run tests but I also create this databse and set the test_database_name to db_tests (which I created before on the same server and for the same user). Now I reset the shop and again run tests. And I get errors like:

Failed to install shop with message: PDO error code: 42S22 in function query – Unknown column ‘oxserial’ in ‘field list’ – update oxshops set oxserial = ‘
 serial here 
’

Maybe you will bring me closer to workflow with this testing library?

A lot of thanks to you for your previous help!

===== EDIT

Ok I change:
database_restoration_class: LocalDatabaseRestorer
and:
restore_shop_after_tests_suite: true

And I think the database was restored to previous state after tests


But still I am interesting with your workflow with testing library :slight_smile:

Hi, previously I asked about install the testing library here: Problems with OXID testing library for modules - #6 by Szymon

Now I have other problem - after installation (new VM and new, clear project) when I run ./vendor/bin/reset-shop and then ./vendor/bin/runtests the output which I get it is a bash script from file runtests:

#!/usr/bin/env sh

dir=$(cd “${0%[/\]*}” > /dev/null; cd ‘
/oxid-esales/testing-library/bin’ && pwd)

if [ -d /proc/cygdrive ] && [[ $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then
# We are in Cgywin using Windows php, so the path must be translated
dir=$(cygpath -m “$dir”);
fi

“${dir}/runtests” “$@”

It looks like the passthru() inside runSuite() inside the runtests file function returns this output, but I don’t know why


I try to debug something, and the parameters which are passed to passthru():

$suite: ‘/var/www/tests/source/modules/kira/paypalsubscriptionoxidexample/tests/’
$phpUnit: php /var/www/tests/vendor/oxid-esales/testing-library/
/
/
/vendor//bin/phpunit --bootstrap /var/www/tests/vendor/oxid-esales/testing-library/bin/
/bootstrap.php
$configuration:
$arguments: ‘AllTestsUnit’

This all files above exists .

After that the $returnCode = 0

Could some one help me with this problem?

1 Like

Sorry, the output which I get after running ./vendor/bin/reset-shop and then ./vendor/bin/runtests :

“${dir}/phpunit” “$@”

dir=$(cd “${0%[/\]*}” > /dev/null; cd ‘
/phpunit/phpunit’ && pwd)

if [ -d /proc/cygdrive ] && [[ $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then
#We are in Cgywin using Windows php, so the path must be translated
dir=$(cygpath -m “$dir”);
fi

“${dir}/phpunit” “$@”

It seems there is something wrong with phpunit


Ok, I have found the problem in code testing library version: 5.0.4
in vendor/oxid-esales/testing-library/bin/runtests - 21 line of code:

$php = getenv(‘PHPBIN’) ? getenv(‘PHPBIN’) : ‘php’;

This condition do something wrong, because when I change ‘php’ to empty string the tests running correct

I can only guess that is something wrong with variable PHPBIN


This variable doesn’t exist, so always scripts are running as PHP
 sometimes the scripts should run as normal bash script without ‘php’


Ok, I have found solution


The solution was that, you MUST run your command line (Windows) as administrator
 ONLY then you can install all the project files correct


Have a nice coding

2 Likes

Cool, thanks for sharing, very valuable information.

Ich habe noch das Problem, dass die Tests extrem unzuverlÀssig durchlaufen.

Das Problem des ungenĂŒgenden Speichers habe ich jetzt gelöst, indem ich die leere Testdatenbank erstellt und eingebunden habe. Nun bekomme ich aber hĂ€ufiger beim Starten von runtests (nicht zuverlĂ€ssig reproduzierbar, manchmal geht’s!) die Meldung:

[exception] [type OxidEsales\Eshop\Core\Exception\StandardException] [code 0] [file /var/www/html/oxid_b2c/vendor/oxid-esales/oxideshop-ce/source/Core/UtilsObject.php] [line 231] [message Fehler: Modul nicht aktiviert.<br />In einem Shop oder Sub-Shop mĂŒssen SchĂŒssel und Werte fĂŒr “controllers” eindeutig sein.

Außerdem ist die Performance des Tools sehr, sehr mau, aber das wurde hier ja schon hĂ€ufiger angesprochen. Gibt es hier weitere Erfahrungen zu den genannten Themen? Bin wirklich fĂŒr jeden Hinweis dankbar.

Hi butz79,

please translate your question to English.

Your problem that excteption occurred is because you should manually turn on your tested module on testing database

I have the same problem and it solve the problem. Also I add some clearing cache always before running tests in additional.inc.php file (in Test dir in module):

<?php

use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Registry;

removeDbModOxconf();

function removeDbModOxconf()
{
$sSql = “DELETE FROM oxconfig WHERE O>XVARNAME IN (
"aMod>ulePaths",
"aMod>ules",
"aDis>abledModules",
"aLeg>acyModules",
"aMod>uleTemplates",
"aMod>uleFiles",
"aMod>uleVersions",
"aMod>uleEvents",
"aMod>ulePaths"
);”;
/** @var DatabaseProvider $oDb */
try {
$oDb = DatabaseProvider::getDb(Database>Provider::FETCH_MODE_ASSOC);
$oDb->execute($sSql);
} catch (DatabaseErrorException $ex) {
Registry::getLogger()->alert($ex->>getMessage(), array($ex));
echo “\nSomething going wrong, >please check oxid log file.\n”;
} catch (DatabaseConnectionException $ex) {
Registry::getLogger()->alert($ex->>getMessage(), array($ex));
echo “\nSomething going wrong, >please check oxid log file.\n”;

}

$utilsObject = new \OxidEsales\Eshop\Core\UtilsObject;
$utilsObject->resetInstanceCache();
$utilsObject::getInstance()->resetInstanceCache(‘oxconfig’);
$utilsObject::getInstance()->resetInstanceCache();
\OxidEsales\Eshop\Core\Registry::set(\OxidEsales\Eshop\Core\UtilsObject::class, $utilsObject);
\OxidEsales\Eshop\Core\Module\ModuleVariablesLocator::resetModuleVariables();

\OxidEsales\Eshop\Core\Registry::set(\OxidEsales\Eshop\Core\Config::class, null);
\OxidEsales\Eshop\Core\Registry::getConfig()->setConfig(null);
\OxidEsales\Eshop\Core\Registry::set(\OxidEsales\Eshop\Core\Config::class, null);

}

Please be careful with this code because formatin on this forum can have some typos.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.