Problems with OXID testing library for modules

module
oxid6

#1

Hi,

I want to test my new modules with this library:


I also found this: http://phpforus.com/running-tests-using-oxid-testing-library/ - 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: http://phpforus.com/running-tests-using-oxid-testing-library/ - 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?


Next problems with instalation the testing library
#2

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


#3

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?


#4

Maybe because of additional_test_paths value.


#5

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


#6

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:


Next problems with instalation the testing library
#7

Hi, previously I asked about install the testing library here: Try to install testing library to test my module

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” “[email protected]

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?


#8

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

“${dir}/phpunit” “[email protected]

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” “[email protected]

It seems there is something wrong with phpunit…


#9

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’…


#10

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


#11

Cool, thanks for sharing, very valuable information.