2017 © Pedro Peláez
 

utility prophet

Zero footprint Module testing for Magento Modules

image

linusshops/prophet

Zero footprint Module testing for Magento Modules

  • Wednesday, April 20, 2016
  • by linusshops
  • Repository
  • 6 Watchers
  • 3 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 13 Open issues
  • 29 Versions
  • 0 % Grown

The README.md

prophet

Objective: provide a test harness that does not require modifying Magento core, and allows testing by module. The only thing that should exist is config files, and the tests themselves., (*1)

Prophet accomplishes this by finding Mage.php and the bootstrapping functions for the Varien autoloader, and instantiates them. By doing this, it is able to instantiate the Magento environment in which tests can be run. It then loads PHPUnit and executes tests for the provided module list., (*2)

To ensure that the test context for each module's tests is clean, it creates a subprocess of prophet to run the module tests. This ensures that there is no shared state between module test suites., (*3)

As Magento was never designed with testing in mind, certain classes and states are very difficult to test. Prophet solves this by creating a custom class mechanism that essentially creates class rewrites and overrides that will only be used in the test execution context, and NEVER during normal execution. This ensures that your testing system can never adversely affect your site when not executing via Prophet., (*4)

Impetus

As mentioned above, Magento was never designed with unit testing in mind (and according to the core team, does not have automated tests to this day). This problem has been tackled before by other packages, but all of them require installing a module to handle testing, or modifying core., (*5)

This is non-ideal, as it is injecting code that could potentially cause conflicts. Ideally, a testing system should not have any chance of changing the functionality of the system under test unless it is being executed in the test context., (*6)

Prophet seeks to solve this problem by focusing on testing on a module basis, and by focusing on the Firegento/Composer Magento ecosystem. Prophet expects tests to be written on a module by module basis, and seeks to execute them with the modules in isolation. Since test code is confined to a test directory of a module, it is not ever going to be invoked by Magento under normal execution conditions., (*7)

Prophet's footprint becomes only the config files and the test cases the developer creates- it adds nothing to Magento core or the local code pool., (*8)

Installation

Prophet should be installed via composer. It is recommended to install it globally., (*9)

composer global require linusshops/prophet, (*10)

For best results, your Magento installation should be managed with magento-composer-installer., (*11)

Commands

Prophet must be executed from the command line at the Magento root., (*12)

prophet: Run tests, default to phpunit., (*13)

prophet validate: Confirm that all modules in prophet.json are testable., (*14)

prophet show: Display all modules in prophet.json, and their available tests., (*15)

prophet init: Initialize any modules in prophet.json that do not have the expected test structure., (*16)

prophet analyze: Search your vendor directory for testable modules, and attempt to create a prophet.json, (*17)

prophet inspect: Bootstrap Magento and then start PsySH in that context. Useful for REPL testing., (*18)

prophet list: View all commands, (*19)

prophet run: Run tests using a specified test framework., (*20)

prophet generate:ide-helper: Create a hint file to include in your project for autocomplete of contexts and functions provided when executing tests via Prophet., (*21)

prophet help [command]: View help for a specific command., (*22)

For troubleshooting, you can increase verbosity with -vvv, as with any symfony/console app., (*23)

Events and Bootstrapping

TODO: event-dispatcher no longer used, update with new instructions., (*24)

Prophet will check for the existence of a tests/ProphetEvents.php file in your module. If it exists, it will be included. The check for this occurs immediately prior to the registration of custom autoloaders and the firing of the premodule event., (*25)

This file is included, so it is executed within the same context as your tests and Prophet. It can serve as a module bootstrap file, though it is not recommended as the premodule event should be used for this, or the PHPUnit setUp functions., (*26)

Autoloader

TODO: Prophet does way more than just controllers now, expand this section., (*27)

The Varien autoloader is not able to directly load controllers. To allow these controllers to be instantiated for testing, Prophet creates its own autoloader functions, and prepends them on the autoloader stack. This means that Prophet's autoloader has priority over the Varien autoloader., (*28)

This is due to the fact that the Varien autoloader dies if it can't instantiate the class. Prophet will still use the Varien autoloader; the custom autoloaders just have priority., (*29)

Custom Classes

TODO: Add notes on custom overrides provided by Prophet, (*30)

Prophet includes some classes for testing that can be used in place of the regular classes. See the overrides dir. Generally, they extend the existing class, and rewrite methods that are problematic for testing, without changing the expected interface., (*31)

These classes can be instantiated in your tests using the Classes helper. Remember, Prophet executes in the same context as your tests, so therefore all of its helpers and classes are available in your test cases!, (*32)

You can also include custom test classes by adding them to a tests/classes directory. Prophet injects a general autoloader that will look in this directory for a class before anything else., (*33)

Prophet loaders have priority over the Varien autoloader. Essentially, this allows you to do testing-specific rewrites and overrides, without any risk of it being used in normal execution., (*34)

Controller test example

TODO, (*35)

Behat

http://dannorth.net/whats-in-a-story/, (*36)

Prophet can run functional tests using Behat and Mink., (*37)

Prophet does not configure any browsers or drivers; this is all configured via your behat.yml file. If you have not already configured something, the elgalu/selenium docker container provides a preconfigured Selenium hub with Firefox and Chrome., (*38)

Recommended to use Parallels instead of Virtualbox if using docker-machine, unless you like tests running as slow as molasses. Also recommended to give the docker-machine at least 4GB of RAM to satiate Chrome's hunger for memory., (*39)

https://github.com/Parallels/docker-machine-parallels/, (*40)

TODO: add instructions on setting up elgalu container with prophet and behat, setting up docker-machine- write script, (*41)

```bash #Create the docker container (assuming you already pulled elgalu/selenium docker run --rm --name=grid --add-host='develop.vagrant.dev:192.168.80.80' -p 4444:24444 -p 5920:25900 \ -v /dev/shm:/dev/shm -e VNC_PASSWORD=hola elgalu/selenium, (*42)

#View the browser live during a test open vnc://:hola@$(docker-machine ip default):5920 ```, (*43)

Prophet makes all of the contexts from linusshops/behat-contexts available to Behat via its custom loaders. See the behat-contexts repository for more information. Remember that you can generate an ide helper file to give you autocomplete (prophet generate:ide-helper)., (*44)

Author

Samuel Schmidt, (*45)

Contributors

Dane MacMillan, (*46)

License

This tool was created by Linus Shops and licensed under the MIT License., (*47)

The Versions

20/04 2016

dev-master

9999999-dev https://github.com/linusshops/prophet

Zero footprint Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

The Development Requires

module utility magento linus shops canadas motorcycle mx canada prophet

07/04 2016

v0.8.5

0.8.5.0 https://github.com/linusshops/prophet

Zero footprint Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

01/04 2016

v0.8.4

0.8.4.0 https://github.com/linusshops/prophet

Zero footprint Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

18/03 2016

v0.8.2

0.8.2.0 https://github.com/linusshops/prophet

Zero footprint Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

17/03 2016

v0.8.1.1

0.8.1.1 https://github.com/linusshops/prophet

Zero footprint Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

17/03 2016

v0.8.1

0.8.1.0 https://github.com/linusshops/prophet

Zero footprint Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

17/03 2016

v0.8.0

0.8.0.0 https://github.com/linusshops/prophet

Zero footprint Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

12/02 2016
01/12 2015
30/11 2015
06/11 2015
05/11 2015
14/10 2015

0.5.1

0.5.1.0 https://github.com/linusshops/prophet

Zero footprint Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

14/10 2015

0.5.0

0.5.0.0 https://github.com/linusshops/prophet

Zero footprint Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

07/10 2015

0.4.0

0.4.0.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

18/06 2015

0.3.8

0.3.8.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

16/06 2015

0.3.7

0.3.7.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

16/06 2015

0.3.6

0.3.6.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

15/06 2015

0.3.5

0.3.5.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

15/06 2015

0.3.4

0.3.4.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

15/06 2015

0.3.2

0.3.2.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

08/05 2015

0.3.1

0.3.1.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

05/05 2015

0.3.0

0.3.0.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

30/04 2015
28/04 2015

0.2.0

0.2.0.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet

20/04 2015

0.1.0

0.1.0.0 https://github.com/linusshops/prophet

Module testing for Magento Modules

  Sources   Download

MIT

The Requires

 

module utility magento linus shops canadas motorcycle mx canada prophet