1

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

This is the File Mode.php

<?php
namespace 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

<?php
namespace 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::testAfterGetAllOptions
ArgumentCountError: 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:12

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

Thanks in advance

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.