Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Horn committed Oct 25, 2017
1 parent b4d7e19 commit 5e9d0de
Show file tree
Hide file tree
Showing 20 changed files with 1,274 additions and 7 deletions.
1 change: 1 addition & 0 deletions Controller/Adminhtml/Manage/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function execute()

/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
protected function _isAllowed()
{
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Manage/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function execute()

/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
protected function _isAllowed()
{
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Manage/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function execute()

/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
protected function _isAllowed()
{
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Manage/RestoreDefault.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ protected function getWhiteListEntriesIndexedByPath()

/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
protected function _isAllowed()
{
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Manage/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function execute()

/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
protected function _isAllowed()
{
Expand Down
53 changes: 53 additions & 0 deletions Test/Unit/Controller/Adminhtml/Manage/CreateUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of the Force Login module for Magento2.
*
* (c) bitExpert AG
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace bitExpert\ForceCustomerLogin\Test\Unit\Controller\Adminhtml\Manage;

use bitExpert\ForceCustomerLogin\Controller\Adminhtml\Manage\Create;
use Magento\Store\Model\ScopeInterface;

/**
* Class ModuleCheckUnitTest
* @package bitExpert\ForceCustomerLogin\Test\Unit\Controller
*/
class CreateUnitTest extends \PHPUnit\Framework\TestCase
{
/**
* @test
*/
public function executeSuccessfully()
{
$view = $this->createMock('\Magento\Framework\App\ViewInterface');
$view->expects($this->once())
->method('loadLayout');
$view->expects($this->once())
->method('renderLayout');

$context = $this->getContext();
$context->expects($this->atLeastOnce())
->method('getView')
->willReturn($view);

$action = new Create(
$context
);
$action->execute();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\App\Action\Context
*/
protected function getContext()
{
return $this->getMockBuilder('\Magento\Backend\App\Action\Context')
->disableOriginalConstructor()
->getMock();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Force Login module for Magento2.
*
* (c) bitExpert AG
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace bitExpert\ForceCustomerLogin\Test\Unit\Model\Resource\WhitelistEntry;

use bitExpert\ForceCustomerLogin\Model\ResourceModel\WhitelistEntry\CollectionFactory;

/**
* Class CollectionFactoryUnitTest
* @package bitExpert\ForceCustomerLogin\Test\Unit\Model\Resource\WhitelistEntry
*/
class CollectionFactoryUnitTest extends \PHPUnit\Framework\TestCase
{
/**
* @test
*/
public function createEntitySuccessfully()
{
$expectedEntity = $this->createMock('\bitExpert\ForceCustomerLogin\Model\ResourceModel\WhitelistEntry\Collection');

$om = $this->getObjectManager();
$om->expects($this->once())
->method('create')
->with('\\bitExpert\\ForceCustomerLogin\\Model\\ResourceModel\\WhitelistEntry\\Collection', ['foo' => 'bar'])
->willReturn($expectedEntity);

$factory = new CollectionFactory($om);

$this->assertEquals($expectedEntity, $factory->create(['foo' => 'bar']));
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface
*/
protected function getObjectManager()
{
return $this->createMock('\Magento\Framework\ObjectManagerInterface');
}
}
37 changes: 37 additions & 0 deletions Test/Unit/Model/Resource/WhitelistEntryUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Force Login module for Magento2.
*
* (c) bitExpert AG
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace bitExpert\ForceCustomerLogin\Test\Unit\Model\Resource;

use bitExpert\ForceCustomerLogin\Model\ResourceModel\WhitelistEntry;

/**
* Class WhitelistEntryUnitTest
* @package bitExpert\ForceCustomerLogin\Test\Unit\Model\Resource
*/
class WhitelistEntryUnitTest extends \PHPUnit\Framework\TestCase
{
/**
* @test
*/
public function createEntitySuccessfully()
{
$resource = new WhitelistEntry($this->getDatabaseContext());
$this->assertEquals('whitelist_entry_id', $resource->getIdFieldName());
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Model\ResourceModel\Db\Context
*/
protected function getDatabaseContext()
{
return $this->createMock('\Magento\Framework\Model\ResourceModel\Db\Context');
}
}
46 changes: 46 additions & 0 deletions Test/Unit/Model/WhitelistEntryFactoryUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Force Login module for Magento2.
*
* (c) bitExpert AG
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace bitExpert\ForceCustomerLogin\Test\Unit\Model;

use bitExpert\ForceCustomerLogin\Model\WhitelistEntryFactory;

/**
* Class WhitelistEntryFactoryUnitTest
* @package bitExpert\ForceCustomerLogin\Test\Unit\Model
*/
class WhitelistEntryFactoryUnitTest extends \PHPUnit\Framework\TestCase
{
/**
* @test
*/
public function createEntitySuccessfully()
{
$expectedEntity = $this->createMock('\bitExpert\ForceCustomerLogin\Model\WhitelistEntry');

$om = $this->getObjectManager();
$om->expects($this->once())
->method('create')
->with('\\bitExpert\\ForceCustomerLogin\\Model\\WhitelistEntry', ['foo' => 'bar'])
->willReturn($expectedEntity);

$factory = new WhitelistEntryFactory($om);

$this->assertEquals($expectedEntity, $factory->create(['foo' => 'bar']));
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface
*/
protected function getObjectManager()
{
return $this->createMock('\Magento\Framework\ObjectManagerInterface');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Force Login module for Magento2.
*
* (c) bitExpert AG
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace bitExpert\ForceCustomerLogin\Test\Unit\Model;

use bitExpert\ForceCustomerLogin\Model\WhitelistEntrySearchResultInterfaceFactory;

/**
* Class WhitelistEntrySearchResultInterfaceFactoryUnitTest
* @package bitExpert\ForceCustomerLogin\Test\Unit\Model
*/
class WhitelistEntrySearchResultInterfaceFactoryUnitTest extends \PHPUnit\Framework\TestCase
{
/**
* @test
*/
public function createEntitySuccessfully()
{
$expectedEntity = $this->createMock('\bitExpert\ForceCustomerLogin\Api\Data\Collection\WhitelistEntrySearchResultInterface');

$om = $this->getObjectManager();
$om->expects($this->once())
->method('create')
->with(
'\\bitExpert\\ForceCustomerLogin\\Api\\Data\\Collection\\WhitelistEntrySearchResultInterface',
['foo' => 'bar']
)
->willReturn($expectedEntity);

$factory = new WhitelistEntrySearchResultInterfaceFactory($om);

$this->assertEquals($expectedEntity, $factory->create(['foo' => 'bar']));
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface
*/
protected function getObjectManager()
{
return $this->createMock('\Magento\Framework\ObjectManagerInterface');
}
}
95 changes: 95 additions & 0 deletions Test/Unit/Model/WhitelistEntryUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/*
* This file is part of the Force Login module for Magento2.
*
* (c) bitExpert AG
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace bitExpert\ForceCustomerLogin\Test\Unit\Model;

use bitExpert\ForceCustomerLogin\Model\WhitelistEntry;

/**
* Class WhitelistEntryUnitTest
* @package bitExpert\ForceCustomerLogin\Test\Unit\Model
*/
class WhitelistEntryUnitTest extends \PHPUnit\Framework\TestCase
{
/**
* @test
*/
public function testGettersAndSetters()
{
$resource = $this->getResourceModel();
$resource->expects($this->atLeastOnce())
->method('getIdFieldName')
->willReturn('whitelist_entry_id');

$entity = new WhitelistEntry(
$this->getContext(),
$this->getRegistry(),
$resource,
$this->getDatabase(),
[]
);

$entity->setStoreId(42);
$this->assertEquals(42, $entity->getStoreId());
$entity->setLabel('label');
$this->assertEquals('label', $entity->getLabel());
$entity->setUrlRule('url-rule');
$this->assertEquals('url-rule', $entity->getUrlRule());
$entity->setStrategy('strategy');
$this->assertEquals('strategy', $entity->getStrategy());
$entity->setEditable(false);
$this->assertFalse($entity->getEditable());
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Model\Context
*/
protected function getContext()
{
return $this->getMockBuilder('\Magento\Framework\Model\Context')
->disableOriginalConstructor()
->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Registry
*/
protected function getRegistry()
{
return $this->getMockBuilder('\Magento\Framework\Registry')
->disableOriginalConstructor()
->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Model\ResourceModel\AbstractResource
*/
protected function getResourceModel()
{
return $this->getMockBuilder('\Magento\Framework\Model\ResourceModel\AbstractResource')
->disableOriginalConstructor()
->setMethods([
'_construct',
'getConnection',
'getIdFieldName'
])
->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Data\Collection\AbstractDb
*/
protected function getDatabase()
{
return $this->getMockBuilder('\Magento\Framework\Data\Collection\AbstractDb')
->disableOriginalConstructor()
->getMock();
}
}
4 changes: 2 additions & 2 deletions Test/Unit/Plugin/AfterLoginPluginUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace bitExpert\ForceCustomerLogin\Test\Unit\Observer;
namespace bitExpert\ForceCustomerLogin\Test\Unit\Plugin;

use bitExpert\ForceCustomerLogin\Plugin\AfterLoginPlugin;

/**
* Class AfterLoginPluginUnitTest
* @package bitExpert\ForceCustomerLogin\Test\Unit\Observer
* @package bitExpert\ForceCustomerLogin\Test\Unit\Plugin
*/
class AfterLoginPluginUnitTest extends \PHPUnit\Framework\TestCase
{
Expand Down
Loading

0 comments on commit 5e9d0de

Please sign in to comment.