-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from bitExpert/fix/test_coverage
Increase test coverage
- Loading branch information
Showing
20 changed files
with
1,274 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Test/Unit/Model/Resource/WhitelistEntry/CollectionFactoryUnitTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Test/Unit/Model/WhitelistEntrySearchResultInterfaceFactoryUnitTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.