-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-57726: [GitHub] Exception is created but not thrown #6320
- Added unit and integration tests
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
app/code/Magento/Reports/Test/Unit/Block/Product/ComparedTest.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,66 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Reports\Test\Unit\Block\Product; | ||
|
||
use \Magento\Reports\Block\Product\Compared; | ||
use \Magento\Reports\Model\Product\Index\Factory; | ||
|
||
class ComparedTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @var \Magento\Reports\Block\Product\Compared; | ||
*/ | ||
private $sut; | ||
|
||
/** | ||
* @var Factory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $factoryMock; | ||
|
||
protected function setUp() | ||
{ | ||
$contextMock = $this->getMockBuilder(\Magento\Catalog\Block\Product\Context::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$visibilityMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Visibility::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->factoryMock = $this->getMockBuilder(\Magento\Reports\Model\Product\Index\Factory::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['get']) | ||
->getMock(); | ||
|
||
$this->sut = new Compared($contextMock, $visibilityMock, $this->factoryMock); | ||
} | ||
|
||
/** | ||
* Assert that getModel method throws LocalizedException | ||
* | ||
* @expectedException \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function testGetModelException() | ||
{ | ||
$this->factoryMock->expects($this->once())->method('get')->willThrowException(new \InvalidArgumentException); | ||
|
||
$this->sut->getModel(); | ||
} | ||
|
||
/** | ||
* Assert that getModel method returns AbstractIndex | ||
*/ | ||
public function testGetModel() | ||
{ | ||
$indexMock = $this->getMockBuilder(\Magento\Reports\Model\Product\Index\AbstractIndex::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->factoryMock->expects($this->once())->method('get')->willReturn($indexMock); | ||
|
||
$this->assertSame($indexMock, $this->sut->getModel()); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...gration/testsuite/Magento/Reports/Model/ResourceModel/Product/Lowstock/CollectionTest.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,68 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection; | ||
|
||
|
||
class CollectionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @var \Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection | ||
*/ | ||
private $collection; | ||
|
||
protected function setUp() | ||
{ | ||
/** | ||
* @var \Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection | ||
*/ | ||
$this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( | ||
\Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection::class | ||
); | ||
} | ||
|
||
/** | ||
* Assert that filterByProductType method throws LocalizedException if not String or Array is passed to it | ||
* | ||
* @expectedException \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function testFilterByProductTypeException() | ||
{ | ||
$this->collection->filterByProductType(100); | ||
} | ||
|
||
/** | ||
* Assert that String argument passed to filterByProductType method is correctly passed to attribute adder | ||
* | ||
* @expectedException \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function testFilterByProductTypeString() | ||
{ | ||
$this->collection->filterByProductType('simple'); | ||
$whereParts = $this->collection->getSelect()->getPart(\Zend_Db_Select::WHERE); | ||
$this->assertContains('simple', $whereParts[0]); | ||
} | ||
|
||
/** | ||
* Assert that Array argument passed to filterByProductType method is correctly passed to attribute adder | ||
* | ||
* @expectedException \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function testFilterByProductTypeArray() | ||
{ | ||
$this->collection->filterByProductType(['simple', 'configurable']); | ||
$whereParts = $this->collection->getSelect()->getPart(\Zend_Db_Select::WHERE); | ||
|
||
$this->assertThat( | ||
$whereParts[0], | ||
$this->logicalAnd( | ||
$this->stringContains('simple'), | ||
$this->stringContains('configurable') | ||
) | ||
); | ||
} | ||
} |