예제 #1
0
    /**
     * Remove subscriptions
     *
     * @throws \Exception
     * @return ViewInterface
     */
    public function unsubscribe()
    {
        if ($this->getState()->getMode() != View\StateInterface::MODE_DISABLED) {
            try {
                // Remove subscriptions
                foreach ($this->getSubscriptions() as $subscriptionConfig) {
                    /** @var \Magento\Framework\Mview\View\SubscriptionInterface $subscription */
                    $subscriptionInstance = $this->subscriptionFactory->create(
                        [
                            'view' => $this,
                            'tableName' => $subscriptionConfig['name'],
                            'columnName' => $subscriptionConfig['column'],
                            'subscriptionModel' => !empty($subscriptionConfig['subscriptionModel'])
                                ? $subscriptionConfig['subscriptionModel']
                                : SubscriptionFactory::INSTANCE_NAME,
                        ]
                    );
                    $subscriptionInstance->remove();
                }

                // Drop changelog table
                $this->getChangelog()->drop();

                // Update view state
                $this->getState()->setVersionId(null)->setMode(View\StateInterface::MODE_DISABLED)->save();
            } catch (\Exception $e) {
                throw $e;
            }
        }

        return $this;
    }
    /**
     * @expectedException \Exception
     */
    public function testUnsubscribeWithException()
    {
        $this->stateMock->expects($this->once())
            ->method('getMode')
            ->will($this->returnValue(\Magento\Framework\Mview\View\StateInterface::MODE_ENABLED));

        $subscriptionMock = $this->getMock(
            'Magento\Framework\Mview\View\Subscription',
            ['remove'],
            [],
            '',
            false
        );
        $subscriptionMock->expects($this->exactly(1))
            ->method('remove')
            ->will($this->returnCallback(
                function () {
                    throw new \Exception();
                }
            ));
        $this->subscriptionFactoryMock->expects($this->exactly(1))
            ->method('create')
            ->will($this->returnValue($subscriptionMock));

        $this->loadView();
        $this->model->unsubscribe();
    }
 public function testCreate()
 {
     $subscriptionInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\View\\SubscriptionInterface', [], '', false);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\Mview\\View\\SubscriptionInterface', ['some_data'])->will($this->returnValue($subscriptionInterfaceMock));
     $this->assertEquals($subscriptionInterfaceMock, $this->model->create(['some_data']));
 }