Skip to content

Commit

Permalink
MAGETWO-57726: [GitHub] Exception is created but not thrown #6320
Browse files Browse the repository at this point in the history
- Added unit and integration tests
  • Loading branch information
odubovyk committed Sep 1, 2016
1 parent 873a123 commit fc20d3e
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
66 changes: 66 additions & 0 deletions app/code/Magento/Reports/Test/Unit/Block/Product/ComparedTest.php
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());
}
}
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')
)
);
}
}

0 comments on commit fc20d3e

Please sign in to comment.