Questions tagged [phpunit]

phpUnit is the standard base for doing unit tests in the php world. When used in Magento Context it most times includes the usage of the EcomDev_PHPUnit Magento module.

Filter by
Sorted by
Tagged with
27
votes
3answers
4k views

Creating Integration Tests for Magento 2 Modules

So far for my Magento 2 testing needs, I've been using PHP Unit as (more or less) an acceptance tester -- testing results of server and HTML requests made into a system with my module(s) installed. I'...
7
votes
2answers
1k views

Magento 2 : When to use Object Manager in Unit tests?

So I recently stumbled upon a problem while writing a unit test in Magento 2. You can read more about the problem in question here. Vinai told me it is generally bad practice to use the object ...
1
vote
1answer
2k views

Object Manager in Unit Testing in magento 2

I am trying to write UnitTests for my module for magento 2. For this purpose i need access to the objectManager->create method. i already tried what Marius suggested here: How to obtain the Object ...
0
votes
1answer
262 views

EcomDev PHPUnit with magento CE 1.9.x [closed]

Please, tell me, does EcomDev PHPUnit work with community edition?
6
votes
1answer
755 views

How to test magento module without magento core?

Imagine, that you creating new module (for example) and you have only your module files without magento core files. How do you run unit tests? What is the best build-process to run tests on this ...
7
votes
1answer
6k views

Magento 2: Fixing Call to Undefined Method Mock_BlockFactory_4b440480::create() Test Failures

I recently submitted a pull request to Magento to fix a single instance of an object manager being directly used. However, Magento's travis unit test run failed with the following error. PHP ...
8
votes
2answers
2k views

How to mock a Context object

I am trying to test a module which contains a context object as follows: public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Model\Product\...
3
votes
1answer
2k views

Magento 2 : Unit test with mock data don't work. Why?

I'm trying to write unit tests for my code, but for some reason I can't get it to work. To simplify it, I have the following: namespace Custom\Shipping\Model\Config\Source; use Custom\Foundation\...
3
votes
1answer
644 views

Simulating Order Data For a Unit Test

I am currently writing my first unit test. The basis of the test is I get all of the order information along with the items and create a JSON object from it. Is there a way to create dummy items and ...
2
votes
1answer
882 views

Setup scripts fail integration tests in Magento2

I have setup integration tests for app/code that was working fine. Now I have a module that adds some product attributes in a setup script, it doesn't have any tests but it is part of the project. ...
1
vote
1answer
264 views

How to mock an external resource in Magento 2?

I want to write unit test for a module which contains these functions: public function abc($Str) { $n = $this->def(); ... return x; } public function def() { ... $productRepo=...
1
vote
1answer
506 views

Error: Class “Yandex\Allure\Adapter\AllureAdapter” does not exist

Preconditions (*) Magento 2.3.1 upgraded from Magento 2.3.0 Php 7.2.15 OS : Ubuntu 18.04 Bionic Phpstorm 2019.1.1 Evnironemnt : Magento development Steps to reproduce (*) Issue appears after ...