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
34 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\...
0 votes
0 answers
35 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.
0 votes
1 answer
44 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\...
  • 484
0 votes
1 answer
91 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 ...
1 vote
1 answer
175 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 ...
2 votes
3 answers
835 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 ^...
  • 1,753
1 vote
3 answers
3k 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 -> ...
  • 282
1 vote
0 answers
293 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\...
  • 4,672
7 votes
1 answer
951 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\...
  • 3,854
2 votes
2 answers
257 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 ) { ...
  • 3,736
0 votes
1 answer
137 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->...
  • 3,736
2 votes
0 answers
49 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 ? ...
  • 180
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 ...
  • 149
1 vote
0 answers
74 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 = ...
  • 149
0 votes
1 answer
69 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.
  • 3
0 votes
0 answers
435 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-...
  • 369
6 votes
2 answers
245 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 ...
0 votes
2 answers
696 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 ...
  • 8,848
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-...
  • 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 ...
  • 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 ...
  • 450
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 { ...
  • 783
1 vote
0 answers
25 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?
2 votes
0 answers
525 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....
0 votes
1 answer
194 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\...
1 vote
1 answer
584 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/...
  • 33
2 votes
0 answers
117 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 ...
  • 21
1 vote
0 answers
257 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() { ...
1 vote
1 answer
279 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 ...
0 votes
1 answer
1k 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 ...
  • 1,127
4 votes
0 answers
670 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, ...
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 ...
  • 379
0 votes
1 answer
71 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": "...
  • 11
3 votes
1 answer
71 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 ...
4 votes
1 answer
190 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/...
  • 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 ...
4 votes
1 answer
393 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 ?
2 votes
1 answer
947 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 ...
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 ...
  • 178
1 vote
1 answer
236 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 $...
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 ...
  • 171
6 votes
1 answer
1k views

Unit test Issue on getting value

I am creating a unit test for my simple method, this method get the value from requestHeader here is my class which I want to create test class namespace Vendor\Module\Helper; use Magento\Framework\...
  • 17.7k
3 votes
1 answer
6k views

What is the correct way to create mock object in unit test

Now days I am focusing on TDD development, and I am following the Magento test class for reference. So firstly I look into Contact module (as it is the small module) and I found that in DataTest.php ...
  • 17.7k
4 votes
1 answer
775 views

Running an integration test doesn't create a new Magento Installation

When I read the documentation, it is my understanding that when I want to run an integration test, Magento should create a fresh new installation. So I copied install-config-mysql.php.dist to install-...
0 votes
1 answer
185 views

Magento 2 Travis Unit tests errors

I've set up Travis with Magento 2 unit tests to test our code. My PHPunit config is like this: File dev/tests/unit/phpunit.custom.xml.dis: <testsuite name="Magento Unit Tests"> <...
  • 1,248
0 votes
1 answer
2k views

How can I run phpunit commands from any location in CLI?

In Magento 2 documentation "Running Unit Tests in the CLI" is text: To run all tests, navigate to the Magento base directory and execute the following command: $ ./vendor/bin/phpunit -c dev/...
1 vote
1 answer
1k views

Unit test case for custom module REST API

I wanted to write unit test case for custom REST API in magento2. I have already gone through the : http://devdocs.magento.com/guides/v2.0/get-started/web-api-functional-testing.html I am getting ...
1 vote
1 answer
167 views

Set up Magento block as a SUT for PHPUnit

I'd like to unit test my Magento blocks using PHPUnit, how can I properly instantiate my models using the Magento framework to be used as a System Under Test? I include the path to my class, but it ...
  • 27
1 vote
1 answer
461 views

Magento 2 - PHPUnit skip classes that are extended by \PHPUnit_Framework_TestCase

Today is my first day using PHPUnit, I've installed phpunit6.1, php7.1 and trying to write simple assertEquals test. When I extend my test class with \PHPUnit\Framework\TestCase - everything works ...
2 votes
1 answer
1k 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. ...
  • 532