Skip to main content

Questions tagged [unit-tests]

Denotes questions related to unit testing on Magento.

Filter by
Sorted by
Tagged with
0 votes
1 answer
22 views

Should I Include Magento Core Unit, Functional, and Integration Tests in My Custom Project Pipeline?

I’m currently setting up a custom project pipeline for my Magento application and have a question regarding the inclusion of Magento Core tests. Specifically, I am debating whether to include Unit, ...
Tommy J's user avatar
3 votes
2 answers
100 views

Magento 2 and TDD good practices to implement tests

here is my concern, when it comes to testing in Magento 2, I find documentation is quite obselete or very difficult to understand. If PhpUnit offers ways to test a simple method...I feel like as soon ...
Claims's user avatar
  • 1,211
0 votes
1 answer
96 views

PhpUnit error Class Qameta\Allure\PHPUnit\AllureExtension does not have a constructor, so you cannot pass any constructor arguments

I am getting the below error while running PHPUnit command in Magento 2 Class Qameta\Allure\PHPUnit\AllureExtension does not have a constructor, so you cannot pass any constructor arguments How to ...
Smita Kagwade's user avatar
0 votes
0 answers
12 views

Test class with collection and save

i'm trying to test if a class method is doing her job. Basically here it is. public function __construct(SaveCommand $saveCommand, SubscriptionData $entityDataFactory, ...
Claims's user avatar
  • 1,211
1 vote
0 answers
16 views

Unit Test a CMS block collection factory

I am currently exploring the unit testing in Magento 2. I have grasp some of the fundamentals by basing on the core code but I cannot seem to create a unit test on the code below $blocks = $this->...
Ricky Aldea's user avatar
1 vote
0 answers
27 views

How to validate the Meta Title of any page using some Automated tests?

I am just wondering if we can validate the Meta title of a page using some automated tests like MFTF. Can someone please suggest to me if it is possible? Thanks
Abhinav's user avatar
  • 45
0 votes
0 answers
24 views

Unit Test Case Error For Observer Class Sales Order

Hi Can anyone help me on this. I have created the unit test for the observer class sales order . When I am running the Unit test I am getting below error I tried but didn't get any solution. There ...
Jack's user avatar
  • 440
0 votes
1 answer
113 views

Create Unit Test for Observer Class

I wants to create the unit test for this observer class. I tried diff-2 ways but didn't get any help. Can anyone create the unit test for this it would be helpful <?php declare(...
Jack's user avatar
  • 440
1 vote
0 answers
133 views

phpunit test case in magento 2

I want to add the phpunit test case for the following file, as I am new to magento, don't know how to add the test case in the magento module. <?php namespace Test\Rma\Block\Adminhtml\Rma\Edit\Tab\...
Mitul Vadalia's user avatar
0 votes
1 answer
159 views

Unit Test Case for updateOrderStatus($orderId)

I am new in writing unit testing in Magento 2. I want to write a test case for getting an order by the order_id. Below is my model function: /** * Initialize dependencies * @param \Magento\Framework\...
Rik Patel's user avatar
  • 484
1 vote
1 answer
395 views

Magento 2 Unit Test With CustomerFactory

I'm trying to write a test for a function and having the issue: There was 1 error: 1) *******\****\Test\Unit\Api\ShopperDataManagementTest::testGetShopperDataReturnArray Error: Call to a member ...
Fred August's user avatar
0 votes
0 answers
141 views

MFTF magento test failed

I am getting extension back from market place because of having the MTFT test failes From summary the following two test cases are failed { "...
Syed Hassan Zamir's user avatar
-1 votes
1 answer
975 views

Error on Di compile magento 2

I have set up Magento 2.4.4. On di:compile I am getting this error. Class "Hybrid_Provider_Model_OAuth2" not found#0 /var/www/vhosts/any.com/dev2.any.com/vendor/composer/ClassLoader.php(571) ...
Hamendra Sunthwal's user avatar
2 votes
1 answer
514 views

How to write unit test for controller front end which submits data in database using ajax?

This my code for the controller. <?php declare(strict_types=1); namespace Vendor\Module\Controller\Index; use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\...
Tanmay's user avatar
  • 790
2 votes
1 answer
465 views

Around Plugin Unit Testing

I need help modelling a unit test class for my around plugin for graphql resolver method. The plugin intercept error messages so that we can customize. namespace...applyCouponToCartplugin.php ...
Kbee's user avatar
  • 31
0 votes
1 answer
237 views

MFTF Run test not passing

I have installed Magento 2.4.3-p1 in the Ubuntu Apache server, Completed installation (fresh installation), and configuration for acceptance test case credentials. When I try to execute the MFTF it is ...
Rajesh Baskaran's user avatar
1 vote
1 answer
779 views

Proper way to mock a collection

I've asked this once already here: How to properly use getCollectionMock But that was for a different reason, and in the meantime the Magento\Framework\TestFramework\Unit\Helper\ObjectManager is ...
Marius's user avatar
  • 198k
0 votes
1 answer
301 views

Unit Test for getOrderByIncrementId question

I've started with writing and figure out unit testing in Magento 2. I want to write a test case for getting an order by the increment id. This is my function which I want to write a test for: /** * @...
Jake H.'s user avatar
1 vote
0 answers
430 views

Magento 2 Unit Testing with Helper dependency

I have a Helper class and a Model class, which looks like <?php # File: app/code/MagePsycho/Catalog/Helper/Data.php namespace MagePsycho\Catalog\Helper; use Magento\Framework\App\Helper\...
MagePsycho's user avatar
  • 4,628
1 vote
1 answer
123 views

How the unit tests in magento 2 are useful?

I'd like to know, what are the core benefits of running tests in magento ? How & what can be determined from the tests ? How to run a test ?
Hamendra Sunthwal's user avatar
1 vote
0 answers
290 views

Unit test 'non-existent' factory methods

Potentially same question has been asked but differently. You are testing something in isolation and assume no access to generated folder. Helper method class HelperClass extends AbstractHelper ...
Dominic Pixie's user avatar
1 vote
1 answer
2k views

Magento 2 API testing

I have created an API and I want to write test files for that API. How can it be done in Magento 2.3.5? I have referred the link - https://devdocs.magento.com/guides/v2.4/get-started/web-api-...
Mathanagopal S's user avatar
2 votes
1 answer
8k views

createMock vs createPartialMock vs createConfiguredMock (PHP unit methods in Magento 2)

What is the difference between createMock, createPartialMock and createConfiguredMock methods of PHPUnit\Framework\TestCase class in Magento 2?
Vineet Sajwan's user avatar
1 vote
0 answers
875 views

Executing Jasmine tests for frontend theme's

I can't get some of the Jasmine tests for the frontend (blank and luma themes) to work. I have generated the static files as described in the documentation. $ bin/magento setup:static-content:deploy ...
Densen's user avatar
  • 186
0 votes
1 answer
181 views

Magento2.3 : Unit Case writing for Observers

I was wondering what is best practice for Unit test case writing for observers ? I looked for examples in core , and found below file magento/module-sales/Test/Unit/Observer/...
Vishwas Bhatnagar's user avatar
1 vote
0 answers
621 views

Code Coverage with Jasmine Unittests in Magento2

I am trying to set up the jasmine Unittests for Magento 2. I've already edited the settings.json inside the dev/tests/js/jasmine/spec_runner directory, to only test my own unit tests because I don't ...
Ekk4rd's user avatar
  • 525
4 votes
2 answers
1k views

How to get base url in Unit Test?

This is my unit test in my custom module: namespace Star\Trek\Test\Unit\Model; class BeyondTest extends \PHPUnit\Framework\TestCase { } How can I get my Magento 2 base URL in there?
mileven's user avatar
  • 419
4 votes
1 answer
903 views

Class 'Magento\TestFramework\TestCase\AbstractController' not found when running unit test for custom module

I tried to make a unit test for my custom module like this: app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php namespace MyCompany\UnitTest\Controller; class SpinTest extends \Magento\...
blue's user avatar
  • 128
4 votes
5 answers
3k views

Fatal error: Class 'Codeception\Platform\Extension' not found. Issue occurred after magento 2.3.0 upgrade to 2.3.1

Preconditions (*) 1.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 ...
PhantomS's user avatar
  • 503
2 votes
1 answer
2k views

Magento 2 magic methods phpunit tests

I've started learning and at the same time writing tests for my Magento 2 custom development. Not a ride in the park. It feels like digging a pit in the sand sometimes. I got to the point where I need ...
Radu's user avatar
  • 460
1 vote
1 answer
3k views

Trying to mock Store getLocale, getting "Method cannot be configured..."

I have this Magento 2 unit test code: $storeInterfaceMockDe = $this->getMockBuilder(\Magento\Store\Model\Store::class) ->disableOriginalConstructor() ->setMethods(['...
Alex's user avatar
  • 13.9k
1 vote
1 answer
2k views

Magento 2.3: Write unit test for Observer

I am writing a unit test for an observer invoking sales_order_place_after event. SendOrderToVenuePay Observer class SendOrderToVenuePay implements \Magento\Framework\Event\ObserverInterface { ...
Adnan's user avatar
  • 853
0 votes
1 answer
221 views

@magentoDbIsolation triggers fatal errors

When running integration tests for my custom Magento module, usage of the annotation @magentoDbIsolation causes this error to be logged: PHP Fatal error: Uncaught Doctrine\Common\Annotations\...
strangerpixel's user avatar
0 votes
1 answer
506 views

What is the use of Test/Unit folder in module ? What is the purpose?

In magento 2, I see in so many modules that there are Test/Unit folder available. I know little bit about that it used for unit test purpose. But, I want to know that : What is the purpose of this ...
Rohan Hapani's user avatar
  • 17.5k
0 votes
1 answer
150 views

How to catch exeption in unit test and check it

I have a model class, that throw exception if some value is null. How I can test, that it condition is ok. $contact = $this->contactFactory->create() ->setEmail('testdelete@...
Павел Кушнеревич's user avatar
2 votes
0 answers
321 views

How to post form data from Unit Test controller to custom controller | Magento 2

I have a custom module with form. I want to post values from unit test file to my custom module controller. I tried $this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::...
Sharif Kareem's user avatar
-1 votes
2 answers
708 views

How to Write test-cases for more than one function in magento 2?

In my .php file I have more than one function , how I can write test cases for that?
ASHWINI MURTHY's user avatar
3 votes
0 answers
268 views

What is the correct way to create Mock input interface in Web-Api functional test?

I've already write successfully a Web-Api unit test for a Custom API. But I'm wondering if there is a way to automatically create a Mock for input data for the API? For example, AccountManagement ...
Federico Bollotta's user avatar
3 votes
0 answers
284 views

Cart observer unit testing

I created a module that has some logic to modify the price of certain items depending on a few conditions pertaining to the other items in the cart. I'm trying to write a unit test to test that the ...
Haim's user avatar
  • 2,144
4 votes
0 answers
417 views

Unit testing ina Magento 2 - Mocks and Assertions

Open file \Magento\Cms\Test\Unit\Model\PageRepositoryTest and take a look at the setUp() method /** * Initialize repository */ protected function setUp() { $this->pageResource = $this->...
Marjan's user avatar
  • 1,149
2 votes
0 answers
137 views

Unit Testing With Magento 2

Where should i start working with extension development using test driven approach, with Magento 2. I do not see any resources and tutorials from where I get idea. I believe I have a fair amount of ...
Ravi 's user avatar
  • 21
17 votes
3 answers
401 views

Magento2 Chrome Driver Service error in MTF

I am new to MTF. I have followed the magento2 tutorial based on the following link But When I am running the command vendor/bin/phpunit I am getting the following error - Fatal error: Uncaught ...
Tester's user avatar
  • 377
1 vote
1 answer
52 views

Magento2 Object Manager Issue in MTF test run windows

I am learning on how to use MTF in my test module. I am trying to run generator using command php generate.php But I am getting following error - Uncaught Error: Class 'Magento\Mtf\...
Gagan's user avatar
  • 1,478
1 vote
0 answers
311 views

Magento 2 : How can I test save and delete model?

I have the problem with writing unit tests. It's my first attempt and I don't know how can I test a couple of cases in my code. It's action in my controller: public function execute() { ...
maybe_vp's user avatar
2 votes
1 answer
497 views

Magento2 Unit Testing

I'm trying to understand the Unit Testing for Magento2. public function getPostUrl() { $ticketId = $this->getRequest()->getParam('ticket_id'); $params = ['ticket_id' => $ticketId]; ...
Johan's user avatar
  • 581
4 votes
2 answers
2k views

How to use collection factory model in Unit Test magento 2

I have a custom extension with model with structure like this in database: +----------------------------------+ |entity_id | customer_id | balance | +----------------------------------+ | 1 | ...
mileven's user avatar
  • 419
1 vote
2 answers
2k views

How to create mock for factory classes?

In unit testing I want to create mock object for factory classes e.g. $this->getMockBuilder(\Magento\Framework\Controller\Result\RawFactory::class)->disableOriginalConstructor()->getMock(); but I ...
Arshad Muhammad's user avatar
0 votes
0 answers
1k views

Unit test in magento 2 Error: Call to a member function getAllVisibleItems() on null

Am finding difficult to unit test my custom functions. Below is my custom module's model function which i used for fetching cart informations. <?php namespace Namespace\MiniCart\Model; use ...
Quasar M's user avatar
  • 409
4 votes
1 answer
193 views

Magento1 - tests - phpunit compatibility

I am currently working on a project (magento 1.9) where tests are developed using PHPUnit 4.8, ECOMDev and TechDivision/magento unit testing (https://packagist.org/packages/techdivision/...
Marien's user avatar
  • 41
2 votes
3 answers
5k views

Magento2 unit tests doesn't run using vendor/bin/phpunit or vendor/phpunit/phpunit/phpunit

Env: PHP 7.0.27-1+ubuntu16.04.1+Clear Magento 2.2.2 with sample data (downloaded in archive) I have created new test module that very simple with unit test for one class. When I run php bin/magento ...
Stepan Furman's user avatar