We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [unit-tests]

Denotes questions related to unit testing on Magento.

Filter by
Sorted by
Tagged with
3
votes
1answer
420 views

Magento Unit Test Error

Following is the Unit Test error that I get Expectation failed for method name is equal to when invoked zero or more times Parameter 0 for invocation Magento\Framework\App\Config\...
5
votes
1answer
275 views

Magento 2 Functional Testing using Phantom JS (or other headless)

Curious as to if there is a way to configure the functional testing xml, in order to allow for other web-drivers such as Phatomjs? I already know of the way to change them to Chome and Firefox, but ...
1
vote
1answer
272 views

Testing magento 2 admin user _isAllowed

Started off building my first module in M2. I'm trying to write a test to prove whether an admin role has the correct resource for the module im building and if not check that the correct return ...
0
votes
1answer
2k views

Mock products and setting values on unit testing

I've created an API extension that manages gallery easily for our demands and now I wanted to create a unit testing. For example, one functionality is: give an 'sku' and 'entry' object (with base64 ...
2
votes
1answer
335 views

Magento 2: how to use the CommandTester

So I've developed a small module that creates a new CLI to be able to change the customer password. Here's my DigitalPianism\ChangePassword\Console\Command\ChangePassword.php class: <?php ...
1
vote
1answer
291 views

Magento 2 : mocking `getParam()` in unit test not working

I'm breaking my head for hours now over a simple thing I've done hundreds of times: mocking another model. Can anyone see what's wrong with this? $mockedRequest = $this ->...
11
votes
2answers
6k views

Best practice for unit tests in Magento 1.9

I maintain a Magento 1.9 site with several custom modules. Some of the functionality is business critical and in dire need of some unit tests. E.g. a unit price calculator. I usually develop in ...
6
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 ...
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\...
2
votes
2answers
1k views

Magento 2 - run phpunit to test

I tried to run a unit but failed with the following error. My test class <?php namespace Vendor\Module\Test\Unit\Observer; class CheckoutOnepageControllerSuccessActionObserverTest extends \...
0
votes
1answer
82 views

Magento EE 2.1 : error of parameter type in Unit Test

Using this post, I tried my first Unit Test. The goal is to test a repository. However, despite mocking all required dependancies of the repository, I get this error: PHP Fatal error: Uncaught ...
7
votes
2answers
611 views

PHP Static tests for front-end devs

I'm trying to add PHP Static test at Frontools to simplify and improve testing process and if it's possible increase performance, b/c it takes so long to get any results. GH Issue - https://github....
3
votes
2answers
582 views

Unit Test or Integration Test for this kind of functions?

I have the following resolve function in one of my classes: public function __construct( \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository, \Magento\Framework\Webapi\...
2
votes
1answer
110 views

Magento2 javascript tests only possible through phpstorm?

I don't quite understand how magento2 implements tests in javascript. From this doc: http://devdocs.magento.com/guides/v2.1/extension-dev-guide/test/test_js-unit.html it looks like it is possible to ...
0
votes
1answer
1k views

Magento 2 Retrieved core_config_data value is null

I am having similar problem as this stackexchange post. I have looked that the database table core_config_data contains the value i need to retrieve. But $configValue=$this->_scopeConfig->...
1
vote
1answer
246 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=...
3
votes
1answer
393 views

How to mock a class property in Magento 2 Unit Test

How can I mock a class attribute such as a particular object (Ex: \Magento\Catalog\Model\Product)
6
votes
1answer
355 views

Instantiating models for unit tests

This question came to mind after I've seen the edits made by Vinai to my answer here. Let's say we have a class to test with a constructor like this namespace Some\Namespace; class SomeClass { ...
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
384 views

Unit tests custom module not executed - Magento 2

I have created a file under \Vendor\Module\Test\Unit\Block\Catalog\Product\ProductList\Toolbar.php namespace Vendor\Module\Test\Unit\Block\Catalog\Product\ProductList; class Toolbar extends \...
0
votes
1answer
469 views

How to write Unit Test for a function which uses a variable defined in Constructor

I'm trying to write a Unit Test in Magento 2 which uses a variable defined in __construct(). The variable gets its value in another function. Thus when I run my test it gives me an error that the ...
4
votes
1answer
744 views

How to properly use getCollectionMock

TL;DR: I would love an example of how Magento\Framework\TestFramework\Unit\Helper\ObjectManager::getCollectionMock() can be used for unit tests that involve collections and/or collection factories and ...
0
votes
1answer
313 views

Magento 1 - MTF How to run functional test ?

Magento 1 ships with a /tests/ folder containing functional test based on PHPUnit and Selenium ( note: you shouldn't deploy this folder to live site :) I'm looking for some information in order to ...
10
votes
3answers
1k views

Unit testing source models

I have several models in my custom extension that only serve the purpose filling in some selects and/or multiselects in the add/edit form of my entities. So they are what magento calls "source models"....
8
votes
2answers
4k views

How to get ScopeConfigInterface through the object manager of unit tests in magento 2?

I'm trying to read a row in my unit test from core_config_table in magento 2 database. I know that to accomplish this job as I have read this link. I have to use: \Magento\Framework\App\Config\...
7
votes
3answers
2k views

Generate factory or proxy in unit tests: “ReflectionException: Class …Factory does not exist”

As far as I understand, Factory and Proxy classes are generated on the fly by the autoloader if they do not exist yet in var/generation (see: What Triggers the Generation of a Factory in Magento 2) ...
1
vote
2answers
1k views

Magento Test Framework(MTF) vs Selenium with Java - Magento 2.0.1

I am a newbie in magento testing framework, I had good knowledge about selenium webdriver with Java. I put some little research about MTF sample test module(CreateWidgetEntity), When I run this its ...
3
votes
1answer
614 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 ...
0
votes
1answer
329 views

Magento2 Unit Test - Mock setExtensionAttributes()

I cannot mock ProductOptionInterface::setExtensionAttributes, I get this error: PHPUnit_Framework_MockObject_RuntimeException : Cannot mock Magento\Catalog\Api\Data\ProductOptionInterface::...
0
votes
2answers
134 views

Cannot retrieve EAV product data

I'm facing a strange issue (on Magento EE 1.14.2.1) where I cannot retrieve EAV product data after setting up a fixture. My test: /** * @loadFixture */ public function testExample() { $product ...
1
vote
1answer
177 views

Fixture for a product's group price not working

I'm using EcomDev_PHPUnit on Magento EE 1.14.2.1, and am trying to set up a simple unit test for a configurable and simple product which have group prices associated, but I'm not having any luck ...
5
votes
1answer
2k views

How to obtain the Object Manager in Unit-Tests?

I've created the second unit-test for my second class. The second class will take a dependency of a first class instance and in one test I'd like to use the object manager to create the second class. ...
1
vote
2answers
1k views

Unit Test for overwrite collection class in magento2

Suppose I overwrite 'Magento\Sales\Model\Resource\Order\Collection' to 'SR\RewriteSales\Model\Resource\Order\Collection', code looks like public function addFieldToFilter($field, $condition = null) ...
4
votes
0answers
72 views

Writing Magento 2 Unit Tests [duplicate]

I have written unit tests for a custom module which i have created. I have put the test in the Module directory like the core modules. Now the tricky part is that,dev\tests\functional\tests\app ...
5
votes
1answer
2k views

How we can create unit tests to everything we have created for our custom module in Magento 2?

I have created a module in magento 2. And need to create the Unit tests for it. I can see that Each core module has its own Test folder containing tests for each component like Controller, Block,Model,...
52
votes
3answers
7k views

Run tests for a specific module in Magento2

Running the tests for Magento to using php bin/magento dev:tests:run takes a lot of time. Is there a way to run the tests for a specific module only? I'm a noob in (unit) testing so have mercy.
0
votes
1answer
2k views

How To use Test in /dev/ folder?

Magento 1.9.x comes with a /dev/ folder (not meant to land in production!) containing many unit tests based on phpunit. How can I use these tests and how to implement my own?
2
votes
1answer
105 views

Which is the best way to test my Magento system after developed [closed]

I just recently develop Magento system for personal use. I want to know about how to test my Magento system. Want to know about some tools or testing flow.
0
votes
1answer
153 views

How can I install and use the Magento Test Framework (without using pear to install phpunit, on Linux Mint 17)

I am trying to set up some sort of automated application testing for Magento stores using the MTAF package described at these links: Guide, Docs These guides tell you to install PHPUnit using pear, ...
7
votes
1answer
407 views

Magento enterprise edition 1.14 automation functional tests

Does Magento enterprise edition 1.14 have pre written functional automation tests? We use Magento 1.14 and I have to decide if I have to start building functional end-to-end user journey tests from ...
2
votes
1answer
198 views

EcomDev PHPUnit Translation not Working with Mocked Helper

I noticed that translations are not working with the EcomDev_PHPUnit Unit Test framework if you replace a helper with a mocked helper, using mockHelper() and replaceByMock(). Shouldn't any call to the ...
1
vote
2answers
103 views

Mage::getModel instance overriden

I managed to put up a EcomDev_PHPUnit_Test_Case with this: public function testGetModelMemoryTrace() { $model = Mage::getModel('catalog/product'); $product = $model->load(10); $this-&...
1
vote
1answer
124 views

EcomDev_PHPUnit assert block property contains

I am having a problem asserting that a blocks property contains an array key. I have added a link to the my customer account area using the following XML: <customer_account> <reference ...
1
vote
1answer
161 views

Testing Parent-Child Self Relationship With EcomDev_PHPUnit

I am working on my first extension that uses TDD principles and I am having trouble figuring out how best to write this particular test. In the module's database table, I have a column called ...
1
vote
2answers
586 views

EcomDev_PHPUnit displaying errors after setup

I have set up EcomDevs' Magento testing solution using this manual. I have found it a bit of a struggle to get everything that I need to work, so when I ran phpunit in the root of my project and it ...
4
votes
3answers
505 views

setting up ecomdev install error 'host is not set for base url'

I am trying to install ecomdevs' unit testing with my copy of magento. I have added the folders manually to the relevant directories and added the below in app/etc/local.xml.phpunit <default> ...
3
votes
2answers
926 views

Why is this test script for eav visibility attribute failing?

During the course of work, I ran into some issues with the visibility attribute in Magento 1.8 and decided to write a test script. Unfortunately, the results have only made me MORE confused. Basically,...
14
votes
1answer
1k views

Unit Testing Observers in Magento

How do you approach unit testing Observers in Magento? (working with EcomDev_PHPUnit) What kind of assertions do include? check if the event is being dispatched (assertEventDispatched()) check the ...
3
votes
1answer
660 views

Problem creating mock method for “core/store” with ecomdev phpunit

I'm trying to mock this method: getCurrentCurrency() from "core/store" (Mage_Core_Model_Store) in my unit test. Just a simple stub, nothing more. private function _stubGetCurrentCurrency() { $...
23
votes
4answers
3k views

Tools for Unit Testing in Magento

What do you use for Unit Testing in Magento? Or what do you know about Unit Testing and Magento? Whether you do TDD or you just want to have unit test coverage for your project components, you need ...