cancel
Showing results for 
Search instead for 
Did you mean: 

Unit testing Plugin in Magento 2

Unit testing Plugin in Magento 2

Hello;

I got a problem in my Testunit in Magento I can't figure out the problem

This is the File Mode.php

<?phpnamespace Mxxxx\Category\Plugin\Model\Category\Attribute\Source;

use Mxxxx\Category\Model\Category\Category;

/**
 * Class Mode
 * @package Mxxxx\Category\Plugin\Model\Category\Attribute\Source
 */
class Mode
{
    /**
     * @param \Magento\Catalog\Model\Category\Attribute\Source\Mode $subject
     * @param $result
     * @return mixed
     */
    public function afterGetAllOptions(        \Magento\Catalog\Model\Category\Attribute\Source\Mode $subject,        $result
    ) {        $result[] = ['value' => Category::DM_BUFFER_PAGE, 'label' => 'Buffer page'];
        return $result;
    }
}

This is the File of Unit Test ModeTest.php

<?phpnamespace Mxxxx\Category\Test\Unit\Plugin\Model\Category\Attribute\Source;

use Mxxxx\Category\Model\Category\Category;
use Mxxxx\Category\Plugin\Model\Category\Attribute\Source\Mode;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

class ModeTest extends \PHPUnit\Framework\TestCase{
    private $model;

    public function testAfterGetAllOptions($subject, $validResult)
    {        $validResult = ['value' => Category::DM_BUFFER_PAGE, 'label' => 'Buffer page'];        $this->assertEquals(\Magento\Catalog\Model\Category\Attribute\Source\Mode );
    }

    protected function setUp()
    {        $helper = new ObjectManager($this);        $this->model = $helper->getObject(
            Mode::class
        );
    }
}

When I run the unit test using this command

./vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Mxxxx/Category/Test/Unit/Plugin/Model/Category/Attribute/Source/ModeTest

I got this error

E                                                                   1 / 1 (100%)

Time: 14.26 seconds, Memory: 10.00MB

There was 1 error:

1) Mxxxx\Category\Test\Unit\Plugin\Model\Category\Attribute\Source\ModeTest::testAfterGetAllOptionsArgumentCountError: Too few arguments to function Mxxxx\Category\Test\Unit\Plugin\Model\Category\Attribute\Source\ModeTest::testAfterGetAllOptions(), 0 passed and exactly 2 expected

/shared/httpd/Mxxxx/magento-v2/app/code/Mxxxx/Category/Test/Unit/Plugin/Model/Category/Attribute/Source/ModeTest.php:12ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

Thanks in advance