Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of "Internal classes cannot be mocked without invoking their constructor in PHP 5.4.29/5.5.13" unit tests failure on Travis CI #618

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ protected function setUp()
false
);

$this->_menuMock = $this->getMock('Magento\Backend\Model\Menu', array(), array(), '', false);
$this->_menuMock = $this->getMock(
'Magento\Backend\Model\Menu',
[],
[$this->getMock('Magento\Framework\Logger', [], [], '', false)]
);

$this->_menuBuilderMock = $this->getMock('Magento\Backend\Model\Menu\Builder', array(), array(), '', false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ public function testIsAllowedReturnsFalseIfResourceIsNotAvailable()

public function testGetChildrenCreatesSubmenuOnFirstCall()
{
$menuMock = $this->getMock('Magento\Backend\Model\Menu', array(), array(), '', false);
$menuMock = $this->getMock(
'Magento\Backend\Model\Menu',
[],
[$this->getMock('Magento\Framework\Logger', [], [], '', false)]
);

$this->_menuFactoryMock->expects($this->once())->method('create')->will($this->returnValue($menuMock));

Expand Down
14 changes: 11 additions & 3 deletions dev/tests/unit/testsuite/Magento/Backend/Model/MenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testAddDoLogAddAction()

public function testAddToItem()
{
$subMenu = $this->getMock("Magento\Backend\Model\Menu", array(), array($this->_logger));
$subMenu = $this->getMock('Magento\Backend\Model\Menu', array(), array($this->_logger));
$subMenu->expects($this->once())->method("add")->with($this->_items['item2']);

$this->_items['item1']->expects($this->once())->method("getChildren")->will($this->returnValue($subMenu));
Expand Down Expand Up @@ -152,7 +152,11 @@ public function testMove()
$this->_model->add($this->_items['item2']);
$this->_model->add($this->_items['item3']);

$subMenu = $this->getMock("Magento\Backend\Model\Menu", array(), array(), '', false);
$subMenu = $this->getMock(
'Magento\Backend\Model\Menu',
[],
[$this->getMock('Magento\Framework\Logger', [], [], '', false)]
);
$subMenu->expects($this->once())->method("add")->with($this->_items['item3']);

$this->_items['item1']->expects($this->once())->method("getChildren")->will($this->returnValue($subMenu));
Expand Down Expand Up @@ -201,7 +205,11 @@ public function testRemoveRemovesMenuItem()

public function testRemoveRemovesMenuItemRecursively()
{
$menuMock = $this->getMock('Magento\Backend\Model\Menu', array(), array(), '', false);
$menuMock = $this->getMock(
'Magento\Backend\Model\Menu',
[],
[$this->getMock('Magento\Framework\Logger', [], [], '', false)]
);
$menuMock->expects($this->once())->method('remove')->with($this->equalTo('item2'));

$this->_items['item1']->expects($this->any())->method('hasChildren')->will($this->returnValue(true));
Expand Down
6 changes: 5 additions & 1 deletion dev/tests/unit/testsuite/Magento/Backend/Model/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ class UrlTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
$this->_menuMock = $this->getMock('Magento\Backend\Model\Menu', array(), array(), '', false);
$this->_menuMock = $this->getMock(
'Magento\Backend\Model\Menu',
[],
[$this->getMock('Magento\Framework\Logger', [], [], '', false)]
);

$this->_menuConfigMock = $this->getMock('Magento\Backend\Model\Menu\Config', array(), array(), '', false);
$this->_menuConfigMock->expects($this->any())->method('getMenu')->will($this->returnValue($this->_menuMock));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testCreateNegative()
{
$captchaType = 'wrong_instance';

$defaultCaptchaMock = $this->getMock('stdClass', array(), array(), '', false);
$defaultCaptchaMock = $this->getMock('stdClass');

$this->_objectManagerMock->expects(
$this->once()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ protected function _getSourceDataMocks($addExpectations, $doubleOptions)
false
);

$productModelMock = $this->getMock('stdClass', array('getProductEntitiesInfo'), array(), '', false);
$productModelMock = $this->getMock('stdClass', array('getProductEntitiesInfo'));
$productModelMock->expects(
$this->any()
)->method(
Expand Down Expand Up @@ -884,7 +884,7 @@ public function validateAmbiguousDataDataProvider()

public function testParseRequiredData()
{
$modelData = $this->getMock('stdClass', array('getNextBunch'), array(), '', false);
$modelData = $this->getMock('stdClass', array('getNextBunch'));
$modelData->expects(
$this->at(0)
)->method(
Expand All @@ -896,7 +896,7 @@ public function testParseRequiredData()
);
$modelData->expects($this->at(1))->method('getNextBunch')->will($this->returnValue(null));

$productModel = $this->getMock('stdClass', array('getProductEntitiesInfo'), array(), '', false);
$productModel = $this->getMock('stdClass', array('getProductEntitiesInfo'));
$productModel->expects($this->any())->method('getProductEntitiesInfo')->will($this->returnValue(array()));

$productEntity = $this->getMock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ protected function setUp()
$layoutMock = $this->getMock('Magento\Framework\View\Layout', array(), array(), '', false, false);
$helperMock = $this->getMock('Magento\Backend\Helper\Data', array(), array(), '', false, false);
$menuConfigMock = $this->getMock('Magento\Backend\Model\Menu\Config', array(), array(), '', false, false);
$menuMock = $this->getMock('Magento\Backend\Model\Menu', array(), array(), '', false, false);
$menuMock = $this->getMock(
'Magento\Backend\Model\Menu',
[],
[$this->getMock('Magento\Framework\Logger', [], [], '', false)]
);
$menuItemMock = $this->getMock('Magento\Backend\Model\Menu\Item', array(), array(), '', false, false);
$urlBuilder = $this->getMock('Magento\Backend\Model\Url', array(), array(), '', false, false);
$this->_configStructureMock = $this->getMock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,7 @@ public function providerGetElementHtmlDateFormat()
protected function getFormMock($exactly)
{
$functions = array('getFieldNameSuffix', 'getHtmlIdPrefix', 'getHtmlIdSuffix');
$formMock = $this->getMock(
'stdClass',
$functions,
array(),
'',
false
);
$formMock = $this->getMock('stdClass', $functions);
foreach ($functions as $method) {
switch($exactly) {
case 'once':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function testWrongInstance()
'',
false
);
$imageAdapterMock = $this->getMock($class, array('checkDependencies'), array(), '', false);
$imageAdapterMock = $this->getMock($class, array('checkDependencies'));

$objectManagerMock->expects(
$this->once()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SaveHandlerFactoryTest extends \PHPUnit_Framework_TestCase
*/
public function testCreate($handlers, $saveClass, $saveMethod)
{
$saveHandler = $this->getMock($saveClass, array(), array(), '', false);
$saveHandler = $this->getMock($saveClass);
$objectManager = $this->getMock(
'\Magento\Framework\ObjectManager\ObjectManager',
array('create'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,11 @@ protected function _createIntegrationController()
// for _setActiveMenu
$this->_viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->_layoutMock));
$blockMock = $this->getMockBuilder('Magento\Backend\Block\Menu')->disableOriginalConstructor()->getMock();
$menuMock = $this->getMockBuilder('Magento\Backend\Model\Menu')->disableOriginalConstructor()->getMock();
$menuMock = $this->getMock(
'Magento\Backend\Model\Menu',
[],
[$this->getMock('Magento\Framework\Logger', [], [], '', false)]
);
$loggerMock = $this->getMockBuilder('Magento\Framework\Logger')->disableOriginalConstructor()->getMock();
$loggerMock->expects($this->any())->method('logException')->will($this->returnSelf());
$menuMock->expects($this->any())->method('getParentItems')->will($this->returnValue(array()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ public function testSaveAction()

public function testIndexAction()
{
$menuModel = $this->getMock('\Magento\Backend\Model\Menu', array(), array(), '', false);
$menuModel = $this->getMock(
'Magento\Backend\Model\Menu',
[],
[$this->getMock('Magento\Framework\Logger', [], [], '', false)]
);
$menuModel->expects($this->once())
->method('getParentItems')
->with($this->equalTo('Magento_Theme::system_design_theme'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testAddComplexTypeSimpleParameters($type, $data)

$this->_wsdl->expects($this->any())->method('toDomDocument')->will($this->returnValue(new \DOMDocument()));

$schemaMock = $this->_getDomElementMock();
$schemaMock = $this->getMock('DOMElement', [], ['a']);
$schemaMock->expects($this->any())->method('appendChild');
$this->_wsdl->expects($this->any())->method('getSchema')->will($this->returnValue($schemaMock));

Expand Down Expand Up @@ -244,7 +244,7 @@ public function testAddComplexTypeComplexParameters()
);

$this->_wsdl->expects($this->any())->method('toDomDocument')->will($this->returnValue(new \DOMDocument()));
$schemaMock = $this->_getDomElementMock();
$schemaMock = $this->getMock('DOMElement', [], ['a']);
$schemaMock->expects($this->any())->method('appendChild');
$this->_wsdl->expects($this->any())->method('getSchema')->will($this->returnValue($schemaMock));
$this->_typeProcessor->expects(
Expand Down Expand Up @@ -285,14 +285,4 @@ public function testAddAnnotationToComplexType()
$complexType->getElementsByTagName("xsd:documentation")->item(0)->nodeValue
);
}

/**
* Create mock for DOMElement.
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function _getDomElementMock()
{
return $this->getMockBuilder('DOMElement')->disableOriginalConstructor()->getMock();
}
}