·

phpunit

Unit Test your custom module in Magento 2

Magento 2 comes with a great set of unit tests out-of-the-box. You can add these tests to your module as described by Ash Smith in this article, but that means you need to run your unit test with the –filter  attribute like so: This is great of course, but it still means the entire test read further ...

Generating dummy products for unit tests in Magento

I already wrote a number of posts about unit testing in Magento, but as with everything in Magento, some things are tricky to do, especially when it comes to unit tests. So the other day I wrote a module that needed to do certain actions according to the value of some product attributes. Needless to read further ...

How to enable PHPUnit code completion in PhpStorm

So you’ve got PhpStorm and you’re writing your tests with PHPUnit. But how do you get the code completion to work? Well, the solution is very simple:read further ...

How I run unit tests in Vagrant, in Jenkins

As some of you might know, I use Vagrant to setup my local environment, and Jenkins for my continuous integration. One major part of this setup is to automatically run tests after Jenkins is done building – and before it deploys the website to the production server. In this article I am going to share with read further ...

PHPUnit setup and teardown for tables

When you’re unit testing your code with PHPUnit, chances are that at some point you have to test some methods that involve manipulation on the database. Of course, you’ve written some test that validate the data in the database afterwards, and you might already have written a bootstrap that prepares the database for each testrun, but what read further ...

Unit testing frontend events in Magento

When you are creating unit tests for Magento and you want to test the events you’re dispatching you can use the following code to manually trigger your events: However, you’ll find that when you’re running this test, your event doesn’t get fired at all! That’s because this particular event (and many others) are fired read further ...

Magento unit testing with specific customers

Sometimes you have the situation where you have to write unit tests for Magento that involves Magento customers. If – for example – you have some business logic that depends on certain customer- (or address-) attributes, you want to make sure your code works as expected before you’re deploying it to a live server. Unit testing read further ...

Unit testing Magento with the database

This year I want to dive more into unit testing in PHP. Writing good, test-driven code is important for the stability and guarantee of your project, but it also helps you – as a developer – sleep a little better at night. You might have seen earlier posts regarding unit testing in PHP in the past, read further ...

Change Magento configuration on the fly

Sometimes you have a situation where you need to change the configuration of Magento on the fly. Just for your single request, without saving it. This can be easily done with the Magento configuration Model: If you want to change a configuration value on the fly on store-level, you can do this as follows: read further ...

1 2