-
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.
Merge pull request #335 from magento-east/MAGETWO-57726
[EAST] MAGETWO-57726 [GitHub] Exception is created but not thrown #6320
- Loading branch information
Showing
4 changed files
with
139 additions
and
3 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
68 changes: 68 additions & 0 deletions
68
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,68 @@ | ||
<?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(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()); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...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,67 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Reports\Model\ResourceModel\Product\Lowstock; | ||
|
||
/** | ||
* Class CollectionTest | ||
*/ | ||
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 | ||
* | ||
*/ | ||
public function testFilterByProductTypeString() | ||
{ | ||
$this->collection->filterByProductType('simple'); | ||
$whereParts = $this->collection->getSelect()->getPart(\Magento\Framework\DB\Select::WHERE); | ||
$this->assertContains('simple', $whereParts[0]); | ||
} | ||
|
||
/** | ||
* Assert that Array argument passed to filterByProductType method is correctly passed to attribute adder | ||
* | ||
*/ | ||
public function testFilterByProductTypeArray() | ||
{ | ||
$this->collection->filterByProductType(['simple', 'configurable']); | ||
$whereParts = $this->collection->getSelect()->getPart(\Magento\Framework\DB\Select::WHERE); | ||
|
||
$this->assertThat( | ||
$whereParts[0], | ||
$this->logicalAnd( | ||
$this->stringContains('simple'), | ||
$this->stringContains('configurable') | ||
) | ||
); | ||
} | ||
} |