Download the PHP package webgriffe/functional-test-trait without Composer
On this page you can find all versions of the php package webgriffe/functional-test-trait. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webgriffe/functional-test-trait
More information about webgriffe/functional-test-trait
Files in webgriffe/functional-test-trait
Package functional-test-trait
Short Description Trait which enables functional testing in Magento with EcomDev_PHPUnit and using a CgiHttpKernel.
License MIT
Informations about the package functional-test-trait
Webgriffe Functional Test Trait
Trait which enables functional testing in Magento with EcomDev_PHPUnit and using a CgiHttpKernel.
Installation
Import it using Composer (note, it's a dev dependency):
Usage
The suggested usage of this trait is in combination with EcomDev_PHPUnit and the Webgriffe's Magento Config Extension. So, first of all, add these dependencies to your Magento project:
Another suggested dependency is symfony/css-selector
, which allows to select DOM elements using CSS selectors in your functional tests:
Then setup your test suite as usual with EcomDev_PHPUnit.
Also you can add a <testsuite>
node to your phpunit.xml.dist
to group your functional tests in a dedicated test suite:
Also, to avoid session issues, you should make sure that the base_url
is always the same during tests setup and tests run. You can do this by setting the MAGE_ENVIRONMENT
server variable through your phpunit.xml.dist
:
And then set the base_url
with the override configuration file for that environment (app/etc/config-override.test.xml.dist
), with the content:
Now you're ready to write your first Magento functional test.
Put a test your tests/
directory. For example, HomepageTest.php
:
It's important that your test extends the EcomDev_PHPUnit_Test_Case_Controller
class to correctly load Magento's frontend area configuration.
As you may notice there is the @loadFixture
annotation which loads data from category.yaml
file located at tests/HomepageTest/fixtures/category.yaml
which content could be:
Multiple website supported
If you want you can create a client for different websites:
This will use the secondary website base URL and sets the MAGE_RUN_TYPE
and MAGE_RUN_CODE
environment variables.
Test debug with xDebug
Sometimes you need to debug your application during functional test execution. To do so you create an xDebug enabled client by passing true
to the createClient()
method:
Don't forget to configure the XDEBUG_SESSION
cookie value in your app/etc/local.xml
file according your IDE settings. For example for PHPStorm on MAC this value should be PHPSTORM
:
Open response in browser
Sometimes is useful to open last response returned by Magento in your browser for further analysis. To do so you can use the openResponseInBrowser()
method, for example:
This will dump the last response's content in a temporary file and opens it with a system command. Don't forget to configure the open file in browser command for your system in the app/etc/local.xml
(the %s
placeholder will be replaced with the temporary file path). For example on MAC you can use open %s
:
Different front controller
It's also possible to specify an alternative front controller instead of index.php
. This is extremely useful when you have to serve static file through the front controller get.php
provided by Magento:
License
This library is under the MIT license. See the complete license in the LICENSE file.
Credits
Developed by Webgriffe®. Please, report to us any bug or suggestion by GitHub issues.