#StackBounty: #magento2.3 #controllers #backend #wishlist #interceptor Wishlist ajax remove

Bounty: 50

I want to remove product from wishlist from a custom button on detail. I did a plugin for the MagentoWishlistControllerIndexRemove.php with an aroundExecute but for some reason I can’t load/create products as magento does in the default Remove controller. I posted my file

 use MagentoCustomerModelSession;
    use MagentoFrameworkControllerResultJsonFactory;
    use MagentoFrameworkExceptionNotFoundException;
    use MagentoWishlistControllerWishlistProviderInterface;
    use MagentoWishlistModelItem;
    use MagentoWishlistModelProductAttributeValueProvider;
    use MagentoWishlistModelWishlistFactory;

/**
 * Class Remove
 * @package CodesicleWishlistAjaxPluginWishlistControllerIndex
 */
class Remove
{
    /**
     * @var WishlistProviderInterface
     */
    protected $wishlistProvider;

    /**
     * @var AttributeValueProvider
     */
    private $attributeValueProvider;


    /**
     * @var Session
     */
    protected $customerSession;

    /**
     * @var JsonFactory
     */
    protected $jsonFactory;

    /**
     * @var WishlistFactory
     */
    protected $wishlistFactory;

    public function __construct(
        WishlistProviderInterface $wishlistProvider,
        AttributeValueProvider $attributeValueProvider = null,
        JsonFactory $jsonFactory,
        Session $customerSession,
        WishlistFactory $wishlistFactory
    )
    {
        $this->wishlistProvider = $wishlistProvider;
        $this->attributeValueProvider = $attributeValueProvider
            ?: MagentoFrameworkAppObjectManager::getInstance()->get(AttributeValueProvider::class);
        $this->jsonFactory = $jsonFactory;
        $this->customerSession = $customerSession;
        $this->wishlistFactory = $wishlistFactory;
    }

    public function aroundExecute($subject, $proceed)
    {

        $id = (int)$this->getRequest()->getParam('item');

        $item = $subject->_objectManager->create(Item::class)->load($id);

        if (!$item->getId()) {
            throw new NotFoundException(__('Page not found.'));
        }
        $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
        if (!$wishlist) {
            throw new NotFoundException(__('Page not found.'));
        }
        try {
            $item->delete();
            $wishlist->save();
            $productName = $this->attributeValueProvider
                ->getRawAttributeValue($item->getProductId(), 'name');

            $response = [
                'errors' => false,
                'message' => __('%1 has been removed from your Wish List.', $productName)
            ];
        } catch (MagentoFrameworkExceptionLocalizedException $exception) {
            $response = [
                'errors' => true,
                'message' => __('We can't delete the item from Wish List right now because of an error: %1.', $exception->getMessage())
            ];
        } catch (Exception $exception) {
            $response = [
                'errors' => true,
                'message' => __('We can't delete the item from the Wish List right now.')
            ];
        }
        $this->_objectManager->get(MagentoWishlistHelperData::class)->calculate();

        $resultJson = $this->jsonFactory->create();
        return $resultJson->setData($response);
    }

What am I missing or what did I do wrong?

LE:

Looks like the getItem method from WishlistFactory is returning NULL and I can’t get to find out why


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!