oxid-esales / testing-library
OXID eShop testing library
Installs: 345 209
Dependents: 11
Suggesters: 0
Security: 0
Stars: 13
Watchers: 31
Forks: 22
Open Issues: 0
Requires
- php: ^7.3 || ^8.0
- behat/mink: ~1.5.0
- codeception/codeception: ^4
- codeception/module-asserts: ^1.3
- codeception/module-db: ^1.0
- codeception/module-filesystem: ^1.0
- codeception/module-webdriver: ^1.1
- incenteev/composer-parameter-handler: ^2.1.4
- mikey179/vfsstream: ~1.6.8
- oxid-esales/codeception-modules: ^v2.0.0
- oxid-esales/codeception-page-objects: ^v3.0.0
- oxid-esales/developer-tools: ^v2.0.0
- oxid-esales/mink-selenium-driver: ~v1.1.2
- oxid-esales/oxideshop-facts: ^v3.0.0
- oxid-esales/oxideshop-unified-namespace-generator: ^v3.0.0
- pdepend/pdepend: 2.7.0
- phpspec/prophecy-phpunit: ^v2.0.1
- phpunit/php-code-coverage: ^9
- phpunit/phpcov: ^8
- phpunit/phpunit: ^9.1.1
- symfony/dom-crawler: v2.7.*
- symfony/filesystem: ^5.0.4
- symfony/yaml: ^5.0.4
- dev-b-8.0.x
- v9.0.0
- v8.2.0
- v8.1.0
- v8.0.2
- v8.0.1
- v8.0.0
- v7.3.0
- v7.2.0
- v7.1.2
- v7.1.1
- v7.1.0
- v7.0.1
- v7.0.0
- 6.4.x-dev
- v6.0.1
- v6.0.0
- v5.0.8
- v5.0.7
- v5.0.6
- v5.0.5
- v5.0.4
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- v4.0.2
- v4.0.1
- v4.0.0
- v4.0.0-beta.3
- v4.0.0-beta.2
- v4.0.0-beta.1
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.1
- v3.0.0
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.0
- v2.0.0-rc.1
- v2.0-beta.3
- v2.0-beta.1
- v1.1.1
- v1.1.0
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v1.0.0-alpha18
- v1.0.0-alpha17
- v1.0.0-alpha16
- v1.0.0-alpha15
- v1.0.0-alpha14
- v1.0.0-alpha13
- v1.0.0-alpha12
- v1.0.0-alpha11
- v1.0.0-alpha10
- v1.0.0-alpha9
- v1.0.0-alpha8
- v1.0.0-alpha7
- v1.0.0-alpha6
- v1.0.0-alpha5
- v1.0.0-alpha4
- v1.0.0-alpha3
- v1.0.0-alpha2
- v1.0.0-alpha1
- v1.0.0-alpha
- 0.0.1
- dev-b-7.3.x
- dev-b-7.2.x
- dev-b-7.1.x
- dev-b-7.0.x
- dev-test_cache_invalidation
- dev-b-6.5.x
- dev-7.0.x-remove-testing-library-OXDEV-5164
- dev-b-7.0.x-do_not_store_module_data_in_db-OXDEV-5530
- dev-b-7.0.x-remove-tl-from-cc-OXDEV-5164
- dev-b-6.5.x_phpunit9
- dev-b-6.4.x_phpunit9
- dev-b-6.5-OXDEV-5164-remove-tl-from-cc-tests
- dev-b-6.4.x
- dev-b-6.3.x
- dev-b-7.0-remove_testing_library
- dev-b-6.3.x-fix-search-sorting-test
- dev-master-unstable-tests-debug
- dev-master-update_to_php8-OXDEV-4533
- dev-b-6.2.x
- dev-b-6.3.x-phpcov
- dev-b-6.2.x-extract-traditional-tests
- dev-master-extract-traditional-tests
- dev-extract_traditional_tests
- dev-b-6.2.x-make_module_services_available-OXDEV-4140
- dev-b-6.2.x-update_composer-OXDEV-4107
- dev-update-vfsstream
- dev-master-library-without-developer-tools
- dev-b-6.2.x-downgrade-polyfill-intl-idn
- dev-6.2.x-test-codeception-version
- dev-master-use-diff-cc-version
- dev-b-6.2.x-test-specific-cc-branch
- dev-b-6.1.x
- dev-b-6.2.x-codeception_master
- dev-b-6.x-improve_errors_checking
- dev-b-6.x_bak
- dev-temp_b2b_versions_new_buyer
- dev-b-6.x-display_all_issues-OXDEV-2371
- dev-b-6.x-temporary-codeception-versions
- dev-b-6.1.x-codeception
- dev-b-4.0.x-codeception
- dev-b-6.x_nginx_compatibility_OXDEV-2280
- dev-b-6.x-fix_php72-OXDEV-1821
- dev-b2b-compatible-branch
- dev-b-6.x_investigate-OXDEV-2040
- dev-b-6.x-detect_replication
- dev-dev-b-6.x_extract_rp-OXDEV-2040
- dev-REBASED_b-6.x_extract_rp-OXDEV-1387
- dev-master_rp_final-OXDEV-1387
- dev-master_rp-OXDEV-1387
- dev-php7_master-OXDEV-1387
- dev-OXDEV-1501_Update_DI_Container-II
- dev-OXDEV-1501_Update_DI_Container
- dev-OXDEV-1393_separating_acceptance_tests
- dev-OXDEV-1359-Update_php_unit
- dev-OXDEV-1309_Update_DI_container
This package is auto-updated.
Last update: 2024-11-10 14:08:04 UTC
README
Warning! Testing library is deprecated. Please use native PHPUnit for testing.
The OXID eShop testing library can be used to test OXID eShop with existing or new Unit, Integration, Mink or QUnit tests. Furthermore, it can also be very helpful to developers who create a module for the OXID eShop.
This library is meant to help developers check their shop/module code with ease. It contains all the required tools and dependencies to execute unit tests, selenium tests, metrics.
Requirements
- Latest Composer version
- PHP cURL extension
- Not compatible with Windows (use VM instead)
This library can be used to test modules with earlier shop versions, but it will not be possible to run shop tests.
Installation
Testing library setup uses composer to get required packages, so make sure to have composer installed and accessible. You can find composer installation guide here.
Selecting where to install testing library
Testing library can be installed directly within shop or to any other directory. However, installation varies slightly depending on selected location. We advise to install it using shop directory.
Option 1: Selecting shop directory for installation (preferred way)
To install testing library within shop directory, update/create
composer.json
with following values:
{ "name": "oxid-esales/eshop", "description": "OXID eShop", "type": "project", "keywords": ["oxid", "modules", "eShop"], "homepage": "https://www.oxid-esales.com/en/home.html", "license": [ "GPL-3.0", "proprietary" ], "require-dev": { "oxid-esales/testing-library": "dev-master", "incenteev/composer-parameter-handler": "~2.0" }, "minimum-stability": "dev", "prefer-stable": true, "scripts": { "post-install-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters" ], "post-update-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters" ] }, "extra": { "incenteev-parameters": { "file": "test_config.yml", "dist-file": "vendor/oxid-esales/testing-library/test_config.yml.dist", "parameter-key": "mandatory_parameters", "env-map": { "shop_path": "SHOP_PATH", "shop_tests_path": "SHOP_TESTS_PATH", "module_ids": "MODULE_IDS" } } } }
Installing this way, binaries will be accessible from
shop_source_path/vendor/bin
. Latest development shop version already
includes composer.json file in its source, so no changes need to be
made.
Option 2: Selecting any directory for installation (alternative way)
To install testing library to any directory, you need to checkout
testing library from Github into desired directory
(git clone https://github.com/OXID-eSales/testing_library
).
Installing this way, binaries will be accessible from
testing_library/bin
.
Installing testing library
After you selected where you want to install the testing library, follow these steps:
- Navigate to the directory that you picked for installation.
- Use composer to setup testing library components
(
composer install
). Ensure you do this from within the directory wherecomposer.json
is located. During setup you will be asked several questions regarding testing library configuration. These options will be explained in more detail here: Parameter explanation
Running tests
First and foremost - make sure you have a working shop, meaning:
- Shop is installed/configured (
config.inc.php
is filled in with database connection details and so) - Shop can be accessed through url (used for shop installation).
Several test runners are available for use once testing library is prepared.
These are available in bin
or vendor/bin
directory:
runtests
- run shop/module unit and integration tests.runtests-selenium
- run shop/module selenium tests.runmetrics
- execute code metrics test for shop/module.
Additionally you can pass parameters to these scripts. runmetrics
uses pdepend
, and all runtests
uses phpunit
. You can add
phpunit
parameters to runtests
, runtests-selenium
.
You can add pdepend
parameters to
runmetrics
. To see which additional options can be passed to test
runner, add --help
option to the command (i.e.
./runtests --help
, ./runmetrics --help
). This will show
available options for desired tool.
Some usage examples:
- Running only a single file tests -
bin/runtests path/to/test/fileTest.php
- Running only specific pattern matching tests from specified file -
bin/runtests --filter match_pattern path/to/test/fileTest.php
- Running one or multiple test suites -
TEST_DIRS=unit,integration bin/runtests
One thing to note when adding parameters to these tools - always provide file/folder at the end as it will no longer be picked automatically. Use AllTestsUnit or AllTestsSelenium respectively to run all tests.
Run with PHPStorm
You need to setup path to bootstrap and configuration file in order to run tests with PHPStorm.
- Open PHPStorm.
- Open Run/Debug configurations window.
- Press on configuration icon (wrench) right after the "Use alternative configuration file" input.
- New PHPUnit window pops up. Check "Default bootstrap file" and "Default configuration file" checkbox and choose paths to bootstrap and configuration file. Path to bootstrap: {source}/vendor/oxid-esales/testing-library/bootstrap.php Path to the configuration file: {source}/vendor/oxid-esales/testing-library/phpunit.xml
Configuration
Configuration file is named test_config.yml
and is placed in the
root directory of this library or shop (when installing with shop
composer.json). During setup you will be asked several questions
regarding testing library and shop/module installation. After setup
test_config.yml
will be created, and later can be edited if some
configuration values need to be changed.
All of the parameters can be set with environmental variables. Environmental parameter names are the same as in the configuration file, but should be all uppercase: shop_path => SHOP_PATH, browser_name => BROWSER_NAME, etc.
Configuration parameters
Mandatory parameters
These parameters are required for testing library to work properly.
Optional parameters
These parameters are not required in order to work, but they provide additional functionality and options when testing.
Changing PHPUnit parameters
To change PHPUnit parameters, add phpunit.xml file inside tests directory and it will be used.
Execution before UNIT test run with additional.inc.php
Testing library gives possibility to make some actions before UNIT test run. So if there is a need to to do that, add additional.inc.php file into tests directory and it will be executed.
Note:
Use addTestData() method and testSql directory to change environment for Acceptance tests. Read more in a section Writing acceptance tests.
Writing Tests
Directory Structure
Module tests should be placed in module root directory:
path/to/shop/modules/my_module/tests
. Tests can by placed in three
directories: unit, integration and acceptance depending on tests type.
./runtests
collects tests from unit and integration directories,
while ./runtests-selenium
- from acceptance. Code coverage is
calculated from both unit and integration tests.
Writing unit and integration tests
Unit and integration should be placed under tests/unit
and
tests/integration
directories. Any number of subdirectories can be
created inside - all tests will be collected. Unit and integration tests
should extend OxidEsales\TestingLibrary\UnitTestCase
class so that
database, registry, configuration parameters restoration, module
activation would work. If unit tests are not relying on database or
registry and are real clean unit tests, PHPUnit\Framework\TestCase
class can be extended, but have in mind that autoloading of module
classes and correct shop classes extension will not work. All
preparation works can be done in additional.inc.php
file. This file
is loaded before database dump creation and before running any of the
test, so can be used autoloaders registration, demodata preparation,
etc. For unit testing shop is installed without default demodata added.
Methods usage
Run unit and integration test dependent if Subshops is enabled:
public function testCase_forSubShops() { $this->markTestSkippedIfSubShop(); ... } public function testCase_forNoSubShops() { $this->markTestSkippedIfNoSubShop(); ... }
Rest of the methods can be found in class: OxidEsales\TestingLibrary\UnitTestCase
.
Writing acceptance tests
Currently for acceptance testing Mink library and selenium driver is used.
Note:
selenium-server-standalone-jar 2.47.1 is used for testing. There might be some issues with older versions issue #13
Acceptance tests should be placed under
tests/acceptance
directory and extend
OxidEsales\TestingLibrary\AcceptanceTestCase
.
Tested module will be activated by default.
Some data might be also added by extending
AcceptanceTestCase::addTestData()
method and activating module
manually. This method will be run before any test and before database
dump creation, once per tests suite.
For acceptance testing
shop is installed with default demodata. Additional demodata can be
added to testSql
directory by the name of demodata_EE.sql
,
demodata_PE_CE.sql
or demodata_EE_mall.sql
(when subshop
functionality is enabled in test_config). These files will be loaded on
top of the database depending on the shop edition. Any additional files,
needed for testing can be placed under testData
directory - all
content will be copied onto the shop source before running tests.
A useful method for preparing the shop is
AcceptanceTestCase::callShopSC()
. With this method
you can e.g. insert a new article or modify config variables. For detailed
usage examples have a look at the OXID eShop acceptance tests.
Methods usage
Testing library provides methods which allows write tests easier. Some methods usages are described bellow:
Activating theme:
// This will activate azure theme. $this->activateTheme('azure');
Add article to basket:
// This will add article with ID 1001 to basket. $this->addToBasket("1001");
Update items amount in basket: (Note that item must be in basket in order to change it)
// This will update article with ID 1001 in basket to have 2 items. $this->changeBasket("1001", 2);
// This will remove an item from basket. $this->changeBasket("1001", 0);
Login user in front end side:
$this->loginInFrontend("example_test@oxid-esales.dev", "useruser");
Rest of the methods can be found in class: OxidEsales\TestingLibrary\AcceptanceTestCase
.
Changing database restoration mechanism
Currently there are two database restoration classes available -
DatabaseRestorer
and LocalDatabaseRestorer
. Both of these are
truncating changed tables and adding all the information back in. If
provided solutions are not fitting your needs, it can be changed by
implementing
OxidEsales\TestingLibrary\DatabaseRestorer\DatabaseRestorerInterface
interface and registering new class in
test_config.yml::database_restoration_class
.
Library API
test_config.yml
parametersOxidEsales\TestingLibrary\AcceptanceTestCase
OxidEsales\TestingLibrary\UnitTestCase
\OxidEsales\TestingLibrary\ServiceCaller
OxidEsales\TestingLibrary\Services
called via\OxidEsales\TestingLibrary\ServiceCaller
Testing library branch names
Testing library branch names follow the OXID eShop component branch names. Which means that branch names do not follow testing library version numbers, but represent the target version of the OXID eShop compilation. For example:
Tests running workflow
Graphically visualized workflow can be found in workflow.puml. This file can be opened with tool called PlantUml (http://plantuml.com/).