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
1 vote
0 answers
12 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
0 votes
0 answers
35 views

Can I use separate database for phpunit integration tests of crons?

Sometimes I want to ensure that for some cases that records are written correctly upon database mostly in cron for bulk actions that read records from one table and written into another table for ...
Dimitrios Desyllas's user avatar
0 votes
1 answer
1k views

TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, first array member is not a valid class name or object

I upgraded my website from magento 2.3.6-p1 to 2.4.5-p1, When i run php unit test case for my custom module(This module overides the CreatePassword.php file from Customer module) throws error from ...
jaisa2's user avatar
  • 15
0 votes
2 answers
74 views

Magento 2 Testcase for fetching data from database

I had written the test case for my function which is fetching data from the cms_page table but I'm getting error when running my unit test cases this is my error Error: Call to a member function ...
Aakash Suresh's user avatar
0 votes
1 answer
83 views

Extension attributes and api functional testing

When running api functional tests on a module which uses non-scalar array extension attribute type, I've got the error ReflectionException: Class "ModuleName\Customer\Api\CustomAddressInterface[]&...
apedic's user avatar
  • 923
0 votes
1 answer
416 views

PHP unit causing failure when using at(0) and at(1) in magento 2.4.5

I upgraded my site from 2.3.6-p1 to 2.4.5-p1 enterprise edition. code : $serialNumber->expects($this->at(0)) ->method('getSerialnumber') ->willReturn(null); $...
Jaisa's user avatar
  • 2,596
1 vote
1 answer
322 views

Php unit test throws assertInternalType is undefined in magento 2.4.5

I upgraded the website from magento 2.3.6-p1 to magento 2.4.5-p1 , got the following error, when running PHP unite test for my custom module. Error: Call to undefined method ABC\Product\Test\Unit\...
Jaisa's user avatar
  • 2,596
0 votes
2 answers
304 views

PHPUnit\Framework\Exception: Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

When running php unit test case i got below error PHPUnit\Framework\Exception: Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in vendor/symfony/...
Jaisa's user avatar
  • 2,596
0 votes
1 answer
1k views

PHPUnit\Framework\TestCase::prophesize() is deprecated and will be removed in PHPUnit 10. Please use the trait provided by phpspec/prophecy-phpunit

While running php unit test, I got the following error. please help Vendor\yyy\Test\Unit\Service\ImporterTest::test_validatePath with data set #1 (true, false) PHPUnit\Framework\TestCase::prophesize() ...
Jaisa's user avatar
  • 2,596
1 vote
0 answers
108 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
1 vote
0 answers
119 views

Magento2 how to write PHP unit test cases for GraphQl?

Can any one provide me the steps, how to write PHP unit test cases for Magento2 Graphql API with simple example.
Nagaraju Kasa's user avatar
0 votes
1 answer
114 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
330 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
1 vote
1 answer
313 views

Unit Test for a plugin - Recieve object as parameter, modify it, return it

I'm new with unit testing and I'm trying to write a test for this plugin... /** * @param AccountManagement $subject * @param CustomerInterface $customer * @param null $password ...
Diego Sanabria's user avatar
2 votes
3 answers
1k views

Magento upgrade 2.4.4, phpunit issue

I am getting below issue while upgrading to Magento version 2.4.4 on php 8 Your requirements could not be resolved to an installable set of packages. Problem 1 - phpunit/phpunit 6.5.14 requires php ^...
Saphal Jha's user avatar
  • 1,863
2 votes
3 answers
4k views

Magento 2.4.3 and Composer error messages for allure phpunit and ramsey uuid - Can't continue with update

I'm getting some error messages from composer, when I try to upgrade from Magento 2.4.2 to Magento 2.4.3, and these are: - Root composer.json requires magento/product-community-edition 2.4.3 -> ...
Aknot's user avatar
  • 288
1 vote
0 answers
398 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,712
7 votes
1 answer
1k views

Uncaught Error: Cannot instantiate interface Magento\TwoFactorAuth\Api\UserConfigManagerInterface while running Integration Tests

Trying to Run all integration tests using ../../../vendor/bin/phpunit command. Getting an error - PHP Fatal error: Uncaught Error: Cannot instantiate interface Magento\TwoFactorAuth\Api\...
sandip's user avatar
  • 3,954
2 votes
2 answers
407 views

Writing php unit test in magento 2 issue

This is my class: class BillingAddress extends Template { public function __construct( Context $context, array $data = [], SessionFactory $customerSessionFactory ) { ...
Attila Naghi's user avatar
  • 3,963
0 votes
1 answer
175 views

Loading product in Magento 2 issue with PhpUnit tests

This is my method, for which I want to write a unit test: private $productRepository; public function __construct( ProductRepositoryInterface $productRepository ) { $this->...
Attila Naghi's user avatar
  • 3,963
2 votes
0 answers
63 views

Unit Test for XML code Changes in Magento 2

We can run Unit test cases for PHP classes in Magento 2 using phpUnit. I would like to know how to configure and run Unit test cases for XML files like cms_block_form.xml or any other XML files ? ...
Aji's user avatar
  • 190
1 vote
1 answer
2k views

PHPUnit testing a Method Internally calling a Helper Method

Testing in magento 1.9 is painful. But somehow I am trying to figure out using PHPUnit. I have a method which I want to test. And for unit testing I want to mock all the dependency that this method ...
arqam's user avatar
  • 149
1 vote
0 answers
76 views

What is Autoloader_Patch in Magento.php

I have setup phpunit using composer to do some testing in Magento. And after the setup I see the following lines added to my Mage.php file. /** AUTOLOADER PATCH **/ if (file_exists($autoloaderPath = ...
arqam's user avatar
  • 149
0 votes
1 answer
72 views

What is '-c' in the command ./vendor/bin/phpunit -c dev/tests/unit/phpunit.xml app/code/Vendor/Module/Test/Unit?

I just know I can execute my test file with this command through PHP-Unit framework but haven't figured out what '-c' is for.
Div S's user avatar
  • 3
0 votes
0 answers
475 views

Getting PHP Fatal error: Class 'IntlDateFormatter' not found

When I execute the phpunit cases for one of the model, I'm getting the error below, PHP Fatal error: Class 'IntlDateFormatter' not found in /Users/userone/Sites/Magento-CE/vendor/phpunit/phpunit-...
TS Guhan's user avatar
  • 369
7 votes
2 answers
342 views

Can @magentoDataFixture files be inside the module itself and not on default directory dev/tests/integration/testsuite?

A very good thing about Magento 2 is that we put together all files inside the module itself. Layout XML, Templates, Less/Sass, Blocks, Models, Helpers, API, SQL scripts and everything. It's important ...
Matheus Gontijo's user avatar
0 votes
2 answers
879 views

Set the if condition to true in PHPUnit test case

I have an if condition inside an observer as follows public function execute(Observer $observer) { if ($observer->getData('status') == Status::REQUIRED) { //implementation ...
Anshu Mishra's user avatar
  • 8,950
0 votes
1 answer
2k views

PHP Fatal error: Class Mock_LoggerInterface contains 8 abstract >methods and must therefore be declared abstract or implement the remaining

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 PHPUnit 6.5.0 magento/magento2-functional-testing-...
PhantomS's user avatar
  • 503
4 votes
1 answer
3k 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 ...
PhantomS's user avatar
  • 503
2 votes
2 answers
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
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
  • 843
1 vote
0 answers
47 views

Overriding the dev/tests/integration/framework/Magento/TestFramework/Config.php class

I want to override the dev/tests/integration/framework/Magento/TestFramework/Config.php class. Can anyone have an idea about how to override classes inside dev folder?
Rahul Hedaoo's user avatar
2 votes
0 answers
534 views

Magento 2 installation problem in Ubuntu using composer

I am extremely new and undereducated with Ubuntu. I am trying to install Magento using composer and getting below error: Problem 1 - Installation request for magento/product-community-edition 2....
user76833's user avatar
0 votes
1 answer
215 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
1 vote
1 answer
650 views

Run a PHPUnit static test only for the /app folder

Hi I am trying to Run a PHPUnit static test only for the /app folder and I do not know how to exclude the /vendor folder not to be tested. I am using the following command: php vendor/phpunit/phpunit/...
Costin's user avatar
  • 43
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
1 vote
0 answers
305 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
1 vote
1 answer
315 views

The method get($sku) of ProductRepository returns null in UnitTest

I've developed a module that must return some data by REST. When I call it by web browser everything works as well, but when I call it by test class, PHPUnit Test, the method get($sku) of interface ...
Blasquez's user avatar
0 votes
1 answer
2k views

How to write a unit test for an admin controller?

How can I test the content of my controller via a unit test? The controller has an execute-function. If my content phtml file contains "Hello World" or a page title "My Title" is configured in the ...
hey's user avatar
  • 1,137
4 votes
0 answers
862 views

Magento 2 : When running integration tests, how can I override some of the dependencies that are injected?

I am running an integration test for Magento 2, but I am at a certain point that my integration test needs a different dependency than my production code. Without going too much into detail as to why, ...
Giel Berkers's user avatar
  • 12.2k
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
0 votes
1 answer
75 views

How to copy phpunit test xml file of a module under dev/tests/unit/ with composer installation in Magento 2?

I wrote a module including phpunit test xml file. I want to automatically copy that xml file under dev/tests/unit/ after composer update. The composer.json of the module looks like { "name": "...
ronnie's user avatar
  • 11
3 votes
1 answer
74 views

2.2.3 : Are there situations when @magentoDbIsolation cannot be used in integration tests?

I'm currently experiencing a weird issue. I've written a bunch of integration tests, and it is my understanding that I can use the @magentoDbIsolation annotation to isolate my database transactions ...
Giel Berkers's user avatar
  • 12.2k
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
4 votes
1 answer
477 views

How to create an order using mock object in phpunit in Magento?

I am preparing phpunit tests. I need to create an order using mocking and that order i need to pass in my function. Please suggest, How can i achieve this ?
Tehmina Ansari's user avatar
2 votes
1 answer
1k views

Magento 2 - PHPUnit using mocking or without mocking?

I am developing an eCommerce web application using magento2. During the development I came to know magento2 useses mockbuilder or mock objects for testing it's modules functionality. Which is fare in ...
Kapil Yadav's user avatar
1 vote
1 answer
2k views

Magento 2 Unit Test error: Call to a member function getBaseUrl() on null

I am looking to write basic unit tests for some helper functions that I am working on for a Magento 2 module. I am able to execute my custom module unit tests but I am getting the following error for ...
Baber's user avatar
  • 190
1 vote
1 answer
347 views

unit test with phpunit

I create simple unit test with object manager with class name $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this) and object Name ModuleList like $...
Arshad Muhammad's user avatar
1 vote
2 answers
2k views

Magento 2 Unit test for exception

Got a basic question about handling Exceptions in Magento 2. I'm currently on Magento 2.2 with PHPUnit 6.2.4. I would like to write a test for a CouldNotSaveException. Got the following code example ...
Wokkel's user avatar
  • 181