Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
27 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 ...
0
votes
1answer
30 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-...
0
votes
1answer
28 views

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 ...
1
vote
1answer
40 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 ...
0
votes
1answer
78 views

Magento 2.3: Write unit test for Observer

I am writing a unit test for an observer invoking sales_order_place_after event. SampleObserver class SampleObserver extends \PHPUnit\Framework\TestCase { public function __construct( \...
1
vote
0answers
16 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?
1
vote
0answers
71 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
0answers
24 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\...
0
votes
1answer
89 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/...
2
votes
0answers
55 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 ...
0
votes
0answers
12 views

Magento2 with PHPUnit

Is anyone knows why we have test folder inside Magento core module?? If this is for a testing purpose than I need to understand how we can test Payment gateways with this PHPUnit. Actually, I need ...
1
vote
0answers
48 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
1answer
65 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
1answer
350 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 ...
0
votes
0answers
146 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
0answers
263 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 ...
0
votes
1answer
44 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": "...
3
votes
1answer
37 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
1answer
119 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/...
2
votes
2answers
1k 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 ...
2
votes
0answers
120 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
1answer
384 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
1answer
416 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 ...
1
vote
1answer
92 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
2answers
369 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 ...
7
votes
1answer
347 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\...
4
votes
1answer
2k 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 ...
5
votes
1answer
433 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
1answer
91 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"> <...
0
votes
1answer
652 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 ...
1
vote
1answer
470 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
1answer
108 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 ...
1
vote
1answer
221 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
1answer
732 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. ...
0
votes
1answer
81 views

composer won't run due to phpunit

Struggling to update or do anything with composer and get the same error every time: [Seld\JsonLint\ParsingException] "./composer.json" does not contain valid JSON Parse error on line 15: ...
1
vote
1answer
94 views

How to run unit tests without using Selenium?

Is it possible to run MTF without using Selenium? The main aim is to run tests on the web-server (Running Debian), we don't have any web browsers on the web server.
1
vote
1answer
584 views

how to call a controller in phpunit test? [duplicate]

I'm using phpunit and need to test the method in a controller but when I try to call it like this: Vendor_Module_Adminhtml_SomecontrollerController::someMethod(); phpunit fails with this error: PHP ...
3
votes
2answers
390 views

Magento 2 : Unable to Run Integration Tests

I have a fresh installation of magento2 enterprise on my server, and just to get a feel for how unit tests work. I attempted to run these tests by executing following command. But before I executed ...
2
votes
1answer
395 views

Unit Test for Repository Functions in Magento 2

I have a class utilizing the Magento 2 AttributeRepository. Can I write a unit test for my class which gets the attribute based on the attribute code? namespace Company\Catalog\Test\Unit\Model; use ...
23
votes
2answers
949 views

What is the proper way for unit testing PHP7 code with PHPUnit 4.1 in Magento 2?

When I'm writing my modules, I'm trying to supply them with unit-tests for the most critical parts of the application. However, there are at the moment (Magento 2.1.3) several ways on how to write ...
0
votes
3answers
373 views

Magento CE 1.9.x Testing

We're working on several Magento projects with CE 1.9.X and we're looking for a testing framework to do unit and functional testing. I've done a little research and I've seen posts talking about ...
3
votes
1answer
357 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\...
1
vote
1answer
326 views

Magento2 Integration Tests fails when installing data for Magento_Catalog test db throwing Asymmetric transaction rollback

I am trying to run the full set of standard integration tests, which I want to run before deployments on an continuous integration server. (Whilst developing I will run just for my own module using ...
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 ...
3
votes
1answer
653 views

In magento 2, How to use inbuild PHPunit testing tool for jenkins

I am working on magento 2 project. I am using Jenkins as continuous integration tool. How can I use Jenkins for PHP unit testing for Magento 2. I know Magento 2 has inbuilt tool for unit testing. How ...
1
vote
1answer
211 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
5k 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
1k 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\...
1
vote
2answers
977 views

PHPUnit code coverage

I am trying to generate the code coverage report in HTML format for a module I am writing so I can work out where I need to improve coverage. Normally when I run tests for my module I use the ...