Hot answers tagged

8

TL;DR You are using the getCollectionMock() method correctly. The problem is that it only mocks the getIterator() method. Your code however calls toOptionArray() on the collection, not getIterator(). Because the collection is a mock, by default all its methods only return null, (including toOptionArray()). That is why your test fails with a null as the ...


5

It looks to me that you're mixing up 2 types of testing here: unit testing and integration testing. Unit Testing With unit testing, you're testing a single unit. Now what the definition of a "Unit" is differs from which developer you ask it to. Some will say a unit is a single class, other will say it's a single method. I've even met developers who group ...


2

The getParam method accepts 2 parameters, the second one defaulting to null public function getParam($key, $defaultValue = null); returnValueMap works like this. the first N-1 values in the array are treated as the parameters for the method and the Nth value is the returned result. So in your case it looks in the map for an array like this [a, null, ...


1

You created a mock ($learningHelper), but did not do anything with it. The object manager contains lots of magic, but not enough to know what you do in your test setup and what's your intention ;-) Now you passed the mock directly as constructor argument instead of using the object manager, and that's the correct approach in unit tests.


1

You assign the mock to a local variable $skuManager and then do nothing with it. When instantiating your component under test, you have to pass the mock as constructor parameter in place of the real ProductRepository. Note that you should not use the ObjectManager in unit tests to instantiate your component. Create or mock the dependencies explicitly ...


Only top voted, non community-wiki answers of a minimum length are eligible