Download the PHP package o3-shop/testing-library without Composer

On this page you can find all versions of the php package o3-shop/testing-library. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package testing-library

O3-Shop Testing Library

The O3-Shop testing library can be used to test O3-Shop 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 O3-Shop.

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

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:

json

{ "name": "o3-shop/eshop", "description": "O3-Shop", "type": "project", "keywords": ["o3-shop", "modules", "eShop"], "homepage": "https://www.o3-shop.com/" "license": [ "GPL-3.0", "proprietary" ], "require-dev": { "o3-shop/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/o3-shop/testing-library/test_config.yml.dist", "parameter-key": "mandatory_parameters", "env-map": { "shop_path": "SHOP_PATH", "shop_tests_path": "SHOP_TESTS_PATH", "partial_module_paths": "PARTIAL_MODULE_PATHS" } } } }

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://gitlab.o3-shop.com/o3/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:

  1. Navigate to the directory that you picked for installation.
  2. Use composer to setup testing library components (composer install). Ensure you do this from within the directory where composer.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:

  1. Shop is installed/configured (config.inc.php is filled in with database connection details and so)
  2. 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:

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, runtests-coverage. 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:

  1. Running only a single file tests - bin/runtests path/to/test/fileTest.php
  2. Running only specific pattern matching tests from specified file - bin/runtests --filter match_pattern path/to/test/fileTest.php
  3. Running one or multiple test suites - TEST_DIRS=unit,integration bin/runtests
  4. Running all Codeception tests - bin/runtests-codeception
  5. Running a specific Codeception test from the main (shop) suite - bin/runtests-codeception-shop GiftRegistryCest::addProductToUserGiftRegistry

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 in order to run tests with PHPStorm.

  1. Open PHPStorm.
  2. Open Run/Debug configurations window.
  3. Press on configuration icon (wrench) right after the "Use alternative configuration file" input.
  4. New PHPUnit window pops up. Check "Default bootstrap file" checkbox and choose path to bootstrap. Path to bootstrap: {source}/vendor/o3-shop/testing-library/bootstrap.php

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.

Parameter nameDescription
shop\_pathPath to eShop source. Defaults to the same directory as to where vendor is located. Supports relative and absolute paths. Can be left empty when installed from shop or module directory.
shop\_tests\_pathPath to eShop tests. If shop resides in /var/www/shop/source and tests are in /var/www/shop/tests, this should be set to ../tests. Supports relative and absolute paths.
partial\_module\_pathsWhen testing not activated module, specify module path in shop. Module path in shop, e.g. if module is in shop/modules/oe/mymodule directory, value here should be oe/mymodule. Multiple modules can be specified separated by comma: oe/module1,module2,tt/module3. If no modules will be tested, leave this field empty or null. Default null

Optional parameters

These parameters are not required in order to work, but they provide additional functionality and options when testing.

Parameter nameDescription
shop\_urleShop base url (if not set, takes it from shop's config.inc.php file). Default null.
enable\_varnishRun tests with varnish on or off. Shop has to be configured to work with varnish, correct serial must be used. Default false
is\_subshopWhether to run subshop tests. Currently only used when running selenium tests. Default false.
install\_shopWhether to prepare shop database for testing. Shop config.ing.php file must be correct. Default true.
remote\_server\_dirIf defined, testing services will be copied to this directory and called via url instead of used locally. Example: [email protected]:/path/to/shop.
shop\_setup\_patheShop setup directory. After setting up the shop, setup directory will be deleted. For shop installation to work during tests run, path to this directory must be specified. If not set, uses default (i.e. shop dir /var/www/eshop/source/, default setup dir /var/www/eshop/source/setup ).
restore\_shop\_after\_tests\_suiteWhether to restore shop data after running all tests. If this is set to false, shop will be left with tests data added on it. Default false.
restore\_after\_acceptance\_testsWhether to dump and restore the database after a single acceptance test. Default true.
restore\_after\_unit\_testsWhether to dump and restore the database after all tests are finished in a single unit, integration test suite. Default true.
test\_database\_nameIf specified, this database is used instead of real one for unit and integration tests
tmp\_pathIf php has no write access to /tmp folder, provide alternative temp folder for tests.
database\_restoration\_classCurrently exists DatabaseRestorer and LocalDatabaseRestorer. LocalDatabaseRestorer - is faster, but does not work with remote databases, DatabaseRestorer - can be used with external database. Default DatabaseRestorer.
activate\_all\_modulesWhether to activate all modules defined in modules\_path when running tests. Normally only tested module is activated during test run. Modules will be activated in the specified order. Default false.
run\_tests\_for\_shopWhether to run shop unit tests. This applies only when correct shop\_tests\_path are set. Default true.
run\_tests\_for\_modulesWhether to run modules unit tests. All modules provided in modules\_path will be tested. If shop\_tests\_path and run\_shop\_tests are set, shop tests will be run with module tests. Default true.
screen\_shots\_pathFolder where to save selenium screen shots. If not specified, screenshots will not be taken. Default null. Default false.
screen\_shots\_urlUrl, where selenium screen shots should be available. Default null.
browser\_nameBrowser name which will be used for acceptance testing. Possible values: *iexplore, *iehta, *firefox, *chrome, *piiexplore, *pifirefox, *safari, *opera. make sure that path to browser executable is known for the system. Default firefox.
selenium\_server\_ipSelenium server IP address. Used to connect to selenium server when Mink selenium driver is used for acceptance tests. Default 127.0.0.1.
additional\_test\_pathsUsed for running additional tests. It's possible to add paths separated by comma. Loads tests in same manner as eShop or modules tests.
retry\_times\_after\_test\_failHow many times to try test before marking it as failure. Could be used for unstable tests which fails randomly.

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:

Add article to basket:

Update items amount in basket: (Note that item must be in basket in order to change it)

Login user in front end side:

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

Testing library branch names

Testing library branch names follow the O3-Shop component branch names. Which means that branch names do not follow testing library version numbers, but represent the target version of the O3-Shop compilation. For example:

Branch Name ----------- b-6.2.x b-6.3.x masterO3-Shop Compilation Target Version ----------------------------------------------------------- v6.2. (Next patch release of O3-Shop compilation v6.2) v6.3. (Next patch release of O3-Shop compilation v6.3) O3-Shop compilation master branch

Tests running workflow

Graphically visualized workflow can be found in workflow.puml. This file can be opened with tool called PlantUml (http://plantuml.com/).


All versions of testing-library with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
phpunit/phpunit Version ^8.5.14
pdepend/pdepend Version 2.6.0
mikey179/vfsstream Version ~1.6.8
behat/mink Version ~1.5.0
o3-shop/mink-selenium-driver Version ~v1.0.0
symfony/yaml Version ~3.0
incenteev/composer-parameter-handler Version ~2.0
symfony/dom-crawler Version v2.7.*
symfony/filesystem Version ^4.4.17
o3-shop/shop-facts Version ^1.0.0
o3-shop/shop-unified-namespace-generator Version ^1.0.0
phpunit/php-code-coverage Version ^7.0.12
codeception/codeception Version ^4
codeception/module-asserts Version ^1.3
codeception/module-webdriver Version ^1.1
codeception/module-db Version ^1.0
codeception/module-filesystem Version ^1.0
o3-shop/codeception-modules Version ^1.0.0
o3-shop/codeception-page-objects Version ^v1.0.0
o3-shop/developer-tools Version ^1.0.0
o3-shop/shop-ce Version ^1.2 || dev-dev-b-1.x
symfony/polyfill-intl-idn Version 1.17.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package o3-shop/testing-library contains the following files

Loading the files please wait ....