diff --git a/app/code/Magento/Backend/Test/Unit/App/UserConfigTest.php b/app/code/Magento/Backend/Test/Unit/App/UserConfigTest.php index 04873cb730437..5958ae65d94c7 100644 --- a/app/code/Magento/Backend/Test/Unit/App/UserConfigTest.php +++ b/app/code/Magento/Backend/Test/Unit/App/UserConfigTest.php @@ -10,7 +10,7 @@ class UserConfigTest extends \PHPUnit_Framework_TestCase { public function testUserRequestCreation() { - $factoryMock = $this->getMock('Magento\Config\Model\Config\Factory', [], [], '', false); + $factoryMock = $this->getMock('Magento\Config\Model\Config\Factory', ['create'], [], '', false); $responseMock = $this->getMock('Magento\Framework\App\Console\Response', [], [], '', false); $configMock = $this->getMock('Magento\Config\Model\Config', [], [], '', false); diff --git a/app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php b/app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php index fd3af33800233..1c89077b1b161 100644 --- a/app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php +++ b/app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php @@ -177,7 +177,7 @@ protected function setUp() ); $this->orderFactoryMock = $this->getMock( 'Magento\Sales\Model\OrderFactory', - [], + ['create'], [], '', false diff --git a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php index 4aaebd08b4add..21d27ef0c5a34 100755 --- a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php +++ b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php @@ -94,6 +94,7 @@ public function setUp() ->getMock(); $this->backupModelFactoryMock = $this->getMockBuilder('Magento\Backup\Model\BackupFactory') ->disableOriginalConstructor() + ->setMethods(['create']) ->getMock(); $this->backupModelMock = $this->getMockBuilder('Magento\Backup\Model\Backup') ->disableOriginalConstructor() diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleLoadOptionsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleLoadOptionsTest.php index 77d92ff634334..51f5e3ad572f8 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleLoadOptionsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleLoadOptionsTest.php @@ -35,6 +35,7 @@ protected function setUp() { $this->optionListMock = $this->getMock('\Magento\Bundle\Model\Product\OptionList', [], [], '', false); $this->productExtensionFactory = $this->getMockBuilder('\Magento\Catalog\Api\Data\ProductExtensionFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $this->model = new \Magento\Bundle\Model\Plugin\BundleLoadOptions( diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php index 3d107771e79d0..d2ad3414e6759 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php @@ -62,8 +62,8 @@ class PriceTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->ruleFactoryMock = $this->getMock( - '\Magento\CatalogRule\Model\Resource\RuleFactory', - [], + 'Magento\CatalogRule\Model\Resource\RuleFactory', + ['create'], [], '', false @@ -77,8 +77,20 @@ protected function setUp() $this->priceCurrency = $this->getMockBuilder('Magento\Framework\Pricing\PriceCurrencyInterface')->getMock(); $this->groupManagement = $this->getMockBuilder('Magento\Customer\Api\GroupManagementInterface') ->getMockForAbstractClass(); - $gpFactory = $this->getMock('Magento\Catalog\Api\Data\ProductGroupPriceInterfaceFactory', [], [], '', false); - $tpFactory = $this->getMock('Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory', [], [], '', false); + $gpFactory = $this->getMock( + 'Magento\Catalog\Api\Data\ProductGroupPriceInterfaceFactory', + ['create'], + [], + '', + false + ); + $tpFactory = $this->getMock( + 'Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory', + ['create'], + [], + '', + false + ); $scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface'); $objectManagerHelper = new ObjectManagerHelper($this); diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php index ae190c3b07266..faf53d7d6a787 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php @@ -105,9 +105,11 @@ protected function setUp() ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->bundleModelSelection = $this->getMockBuilder('Magento\Bundle\Model\SelectionFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $this->bundleFactory = $this->getMockBuilder('\Magento\Bundle\Model\Resource\BundleFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); diff --git a/app/code/Magento/Captcha/Test/Unit/Helper/DataTest.php b/app/code/Magento/Captcha/Test/Unit/Helper/DataTest.php index 2e4452bc09668..30bd742dc4ace 100644 --- a/app/code/Magento/Captcha/Test/Unit/Helper/DataTest.php +++ b/app/code/Magento/Captcha/Test/Unit/Helper/DataTest.php @@ -71,7 +71,7 @@ public function testGetCaptcha() new \Magento\Captcha\Model\DefaultModel( $this->getMock('Magento\Framework\Session\SessionManager', [], [], '', false), $this->getMock('Magento\Captcha\Helper\Data', [], [], '', false), - $this->getMock('Magento\Captcha\Model\Resource\LogFactory', [], [], '', false), + $this->getMock('Magento\Captcha\Model\Resource\LogFactory', ['create'], [], '', false), 'user_create' ) ) diff --git a/app/code/Magento/Captcha/Test/Unit/Model/CronTest.php b/app/code/Magento/Captcha/Test/Unit/Model/CronTest.php index 9fa468829dbd3..13914ccff98dc 100644 --- a/app/code/Magento/Captcha/Test/Unit/Model/CronTest.php +++ b/app/code/Magento/Captcha/Test/Unit/Model/CronTest.php @@ -69,7 +69,7 @@ public function setUp() ); $this->_model = new \Magento\Captcha\Model\Cron( - $this->getMock('Magento\Captcha\Model\Resource\LogFactory', [], [], '', false), + $this->getMock('Magento\Captcha\Model\Resource\LogFactory', ['create'], [], '', false), $this->_helper, $this->_adminHelper, $this->_filesystem, diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Category/Edit/FormTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Category/Edit/FormTest.php index c9117ab2985c4..7e155af62f3e1 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Category/Edit/FormTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Category/Edit/FormTest.php @@ -82,7 +82,7 @@ protected function setUp() ); $this->categoryFactoryMock = $this->getMock( 'Magento\Catalog\Model\CategoryFactory', - [], + ['create'], [], '', false diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Product/View/OptionsTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Product/View/OptionsTest.php index 6c76303404e4f..89334c976db3f 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Product/View/OptionsTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Product/View/OptionsTest.php @@ -59,7 +59,7 @@ public function testGetOptionHtml() $optValFactoryMock = $this->getMock( 'Magento\Catalog\Model\Product\Option\ValueFactory', - [], + ['create'], [], '', false diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Product/Compare/IndexTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Product/Compare/IndexTest.php index 81633cf019cbd..ce42e88b9d6df 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Product/Compare/IndexTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Product/Compare/IndexTest.php @@ -69,7 +69,8 @@ class IndexTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->contextMock = $this->getMock('Magento\Framework\App\Action\Context', + $this->contextMock = $this->getMock( + 'Magento\Framework\App\Action\Context', ['getRequest', 'getResponse', 'getResultRedirectFactory'], [], '', @@ -90,10 +91,16 @@ protected function setUp() ->method('getResultRedirectFactory') ->willReturn($this->redirectFactoryMock); - $this->itemFactoryMock = $this->getMock('Magento\Catalog\Model\Product\Compare\ItemFactory', [], [], '', false); + $this->itemFactoryMock = $this->getMock( + 'Magento\Catalog\Model\Product\Compare\ItemFactory', + ['create'], + [], + '', + false + ); $this->collectionFactoryMock = $this->getMock( 'Magento\Catalog\Model\Resource\Product\Compare\Item\CollectionFactory', - [], + ['create'], [], '', false @@ -131,10 +138,12 @@ public function testExecute() $beforeUrl = 'test_url'; $this->request->expects($this->any()) ->method('getParam') - ->willReturnMap([ + ->willReturnMap( + [ ['items', null, null], ['uenc', null, $beforeUrl], - ]); + ] + ); $this->decoderMock->expects($this->once()) ->method('decode') ->with($beforeUrl) @@ -152,10 +161,12 @@ public function testExecuteWithItems() { $this->request->expects($this->any()) ->method('getParam') - ->willReturnMap([ + ->willReturnMap( + [ ['items', null, '1,2,3'], ['uenc', null, null], - ]); + ] + ); $this->decoderMock->expects($this->never())->method('decode'); $this->catalogSession->expects($this->never())->method('setBeforeCompareUrl'); diff --git a/app/code/Magento/Catalog/Test/Unit/Helper/Product/Flat/IndexerTest.php b/app/code/Magento/Catalog/Test/Unit/Helper/Product/Flat/IndexerTest.php index 1c088e96e5f5f..6cd0026d570b6 100644 --- a/app/code/Magento/Catalog/Test/Unit/Helper/Product/Flat/IndexerTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Helper/Product/Flat/IndexerTest.php @@ -65,13 +65,13 @@ public function setUp() $resourceConfigFactoryMock = $this->getMock( 'Magento\Catalog\Model\Resource\ConfigFactory', - [], + ['create'], [], '', false ); - $eavFactoryMock = $this->getMock('Magento\Eav\Model\Entity\AttributeFactory', [], [], '', false); + $eavFactoryMock = $this->getMock('Magento\Eav\Model\Entity\AttributeFactory', ['create'], [], '', false); $this->_storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface'); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Entity/AttributeTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Entity/AttributeTest.php index ca53d6b6fec5f..512c804ed45f8 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Entity/AttributeTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Entity/AttributeTest.php @@ -141,6 +141,7 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); $this->typeFactoryMock = $this->getMockBuilder('Magento\Eav\Model\Entity\TypeFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface') @@ -153,6 +154,7 @@ protected function setUp() ->getMock(); $this->attributeOptionFactoryMock = $this->getMockBuilder('Magento\Eav\Api\Data\AttributeOptionInterfaceFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $this->dataObjectProcessorMock = $this->getMockBuilder('Magento\Framework\Reflection\DataObjectProcessor') diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ObserverTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ObserverTest.php index c8e0596241921..a7b9555426bd2 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ObserverTest.php @@ -66,17 +66,26 @@ public function setUp() $layerResolver = $this->_getCleanMock('Magento\Catalog\Model\Layer\Resolver'); $layerResolver->expects($this->once())->method('get')->willReturn(null); - $this->_observer = (new ObjectManager($this))->getObject('Magento\Catalog\Model\Observer', [ - 'categoryResource' => $this->_getCleanMock('\Magento\Catalog\Model\Resource\Category'), - 'catalogProduct' => $this->_getCleanMock('\Magento\Catalog\Model\Resource\Product'), - 'storeManager' => $this->_storeManager, - 'layerResolver' => $layerResolver, - 'indexIndexer' => $this->_getCleanMock('\Magento\Index\Model\Indexer'), - 'catalogCategory' => $this->_catalogCategory, - 'catalogData' => $this->_getCleanMock('\Magento\Catalog\Helper\Data'), - 'categoryFlatState' => $this->_categoryFlatState, - 'productResourceFactory' => $this->_getCleanMock('\Magento\Catalog\Model\Resource\ProductFactory'), - ]); + $this->_observer = (new ObjectManager($this))->getObject( + 'Magento\Catalog\Model\Observer', + [ + 'categoryResource' => $this->_getCleanMock('\Magento\Catalog\Model\Resource\Category'), + 'catalogProduct' => $this->_getCleanMock('\Magento\Catalog\Model\Resource\Product'), + 'storeManager' => $this->_storeManager, + 'layerResolver' => $layerResolver, + 'indexIndexer' => $this->_getCleanMock('\Magento\Index\Model\Indexer'), + 'catalogCategory' => $this->_catalogCategory, + 'catalogData' => $this->_getCleanMock('\Magento\Catalog\Helper\Data'), + 'categoryFlatState' => $this->_categoryFlatState, + 'productResourceFactory' => $this->getMock( + 'Magento\Catalog\Model\Resource\ProductFactory', + ['create'], + [], + '', + false + ) + ] + ); } /** diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Backend/GroupPrice/AbstractTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Backend/GroupPrice/AbstractTest.php index 43f6e7cc0861d..843b5789698bc 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Backend/GroupPrice/AbstractTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Backend/GroupPrice/AbstractTest.php @@ -24,7 +24,7 @@ protected function setUp() $this->_helper = $this->getMock('Magento\Catalog\Helper\Data', ['isPriceGlobal'], [], '', false); $this->_helper->expects($this->any())->method('isPriceGlobal')->will($this->returnValue(true)); - $currencyFactoryMock = $this->getMock('Magento\Directory\Model\CurrencyFactory', [], [], '', false); + $currencyFactoryMock = $this->getMock('Magento\Directory\Model\CurrencyFactory', ['create'], [], '', false); $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface', [], [], '', false); $productTypeMock = $this->getMock('Magento\Catalog\Model\Product\Type', [], [], '', false); $configMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface'); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/RepositoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/RepositoryTest.php index 0689f5062dcca..5bdbcde5c5ee4 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/RepositoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/RepositoryTest.php @@ -83,7 +83,7 @@ protected function setUp() ->willReturn(new \Magento\Framework\Object(['default_attribute_set_id' => 4])); $this->validatorFactoryMock = $this->getMock( 'Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory', - [], + ['create'], [], '', false); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php index 1637a14a764ed..1cbc3749362b2 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php @@ -201,9 +201,7 @@ protected function setUp() ->disableOriginalConstructor()->getMock(); $this->mimeTypeExtensionMapMock = $this->getMockBuilder('Magento\Catalog\Model\Product\Gallery\MimeTypeExtensionMap')->getMock(); - $this->contentFactoryMock = $this->getMockBuilder( - 'Magento\Framework\Api\Data\ImageContentInterfaceFactory' - )->disableOriginalConstructor()->setMethods(['create'])->getMockForAbstractClass(); + $this->contentFactoryMock = $this->getMock('Magento\Framework\Api\Data\ImageContentInterfaceFactory', ['create'], [], '', false); $this->contentValidatorMock = $this->getMockBuilder('Magento\Framework\Api\ImageContentValidatorInterface') ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/AbstractTypeTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/AbstractTypeTest.php index 4720ac9d890ed..5f4185031e587 100644 --- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/AbstractTypeTest.php +++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/AbstractTypeTest.php @@ -38,7 +38,7 @@ protected function setUp() ); $attrSetColFactory = $this->getMock( '\Magento\Eav\Model\Resource\Entity\Attribute\Set\CollectionFactory', - [], + ['create'], [], '', false @@ -52,7 +52,7 @@ protected function setUp() ); $attrColFactory = $this->getMock( '\Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory', - [], + ['create'], [], '', false diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AfterProductLoadTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AfterProductLoadTest.php index 77b8985cac84c..c81c51a770485 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AfterProductLoadTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AfterProductLoadTest.php @@ -35,6 +35,7 @@ protected function setUp() { $stockRegistryMock = $this->getMock('\Magento\CatalogInventory\Api\StockRegistryInterface'); $this->productExtensionFactoryMock = $this->getMockBuilder('\Magento\Catalog\Api\Data\ProductExtensionFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php b/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php index 12b4d2920847e..a5a38f3982c19 100644 --- a/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php @@ -51,15 +51,15 @@ protected function setUp() false ); $countryCollectionFactoryMock = $this->getMock( - '\Magento\Directory\Model\Resource\Country\CollectionFactory', - [], + 'Magento\Directory\Model\Resource\Country\CollectionFactory', + ['create'], [], '', false ); $regionCollectionFactoryMock = $this->getMock( - '\Magento\Directory\Model\Resource\Region\CollectionFactory', - [], + 'Magento\Directory\Model\Resource\Region\CollectionFactory', + ['create'], [], '', false diff --git a/app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php b/app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php index c94ce701b3ec8..377365e9294d2 100644 --- a/app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php @@ -38,19 +38,19 @@ public function setUp() */ public function testGetLastRealOrder($orderId, $incrementId, $orderMock) { - $orderFactory = $this->getMockBuilder( - 'Magento\Sales\Model\OrderFactory' - )->disableOriginalConstructor()->setMethods( - ['create'] - )->getMock(); + $orderFactory = $this->getMockBuilder('Magento\Sales\Model\OrderFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); $orderFactory->expects($this->once())->method('create')->will($this->returnValue($orderMock)); - $messageCollectionFactory = $this->getMockBuilder( - 'Magento\Framework\Message\CollectionFactory' - )->disableOriginalConstructor()->getMock(); - $quoteRepository = $this->getMockBuilder( - 'Magento\Quote\Model\QuoteRepository' - )->disableOriginalConstructor()->getMock(); + $messageCollectionFactory = $this->getMockBuilder('Magento\Framework\Message\CollectionFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $quoteRepository = $this->getMockBuilder('Magento\Quote\Model\QuoteRepository') + ->disableOriginalConstructor() + ->getMock(); $appState = $this->getMock('\Magento\Framework\App\State', [], [], '', false); $appState->expects($this->any())->method('isInstalled')->will($this->returnValue(true)); @@ -323,7 +323,7 @@ public function testReplaceQuote() $quoteIdMaskMock->expects($this->once())->method('setQuoteId')->with($replaceQuoteId)->willReturnSelf(); $quoteIdMaskMock->expects($this->once())->method('save'); - $quoteIdMaskFactoryMock = $this->getMock('\Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + $quoteIdMaskFactoryMock = $this->getMock('\Magento\Quote\Model\QuoteIdMaskFactory', ['create'], [], '', false); $quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($quoteIdMaskMock); $session = $this->_helper->getObject( diff --git a/app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php b/app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php index f06f1346e7b96..22a3e421ff3f3 100644 --- a/app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php +++ b/app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php @@ -165,7 +165,7 @@ protected function setUp() $this->_storageCollectionFactoryMock = $this->getMock( 'Magento\Cms\Model\Wysiwyg\Images\Storage\CollectionFactory', - [], + ['create'], [], '', false diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/AfterProductLoadTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/AfterProductLoadTest.php index af3e73f0b855e..0b56ba5abe068 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/AfterProductLoadTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/AfterProductLoadTest.php @@ -37,9 +37,13 @@ class AfterProductLoadTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->optionValueFactory = $this->getMockBuilder( - '\Magento\ConfigurableProduct\Api\Data\OptionValueInterfaceFactory' - )->disableOriginalConstructor()->getMock(); + $this->optionValueFactory = $this->getMock( + '\Magento\ConfigurableProduct\Api\Data\OptionValueInterfaceFactory', + ['create'], + [], + '', + false + ); $this->productMock = $this->getMockBuilder('Magento\Catalog\Model\Product') ->disableOriginalConstructor() ->getMock(); @@ -54,6 +58,7 @@ protected function setUp() ->method('getTypeInstance') ->willReturn($this->configurableProductTypeInstanceMock); $this->productExtensionFactory = $this->getMockBuilder('\Magento\Catalog\Api\Data\ProductExtensionFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php index 6e750f9e13fce..417cd7a48b07b 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php @@ -66,9 +66,13 @@ protected function setUp() $this->productOptionRepositoryMock = $this->getMock( 'Magento\ConfigurableProduct\Api\OptionRepositoryInterface' ); - $this->configurableTypeFactoryMock = $this->getMockBuilder( - '\Magento\ConfigurableProduct\Model\Resource\Product\Type\ConfigurableFactory' - )->disableOriginalConstructor()->getMock(); + $this->configurableTypeFactoryMock = $this->getMock( + '\Magento\ConfigurableProduct\Model\Resource\Product\Type\ConfigurableFactory', + ['create'], + [], + '', + false + ); $this->priceDataMock = $this->getMockBuilder( '\Magento\ConfigurableProduct\Model\Resource\Product\Type\Configurable\Attribute\Price\Data' )->disableOriginalConstructor()->getMock(); @@ -85,6 +89,7 @@ protected function setUp() }; $this->productFactoryMock = $this->getMockBuilder('\Magento\Catalog\Model\ProductFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); diff --git a/app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php b/app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php index f5404347c8c84..8e29f708c491e 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php @@ -76,6 +76,7 @@ protected function setUp() ->getMock(); $this->addressDataFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterfaceFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); @@ -207,7 +208,6 @@ public function testSetLayoutWithAlienAddress() ->getMock(); $this->addressDataFactoryMock->expects($this->once()) ->method('create') - ->with([]) ->willReturn($newAddressMock); $customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface') @@ -294,7 +294,6 @@ public function testSetLayoutWithoutAddressId() ->getMock(); $this->addressDataFactoryMock->expects($this->once()) ->method('create') - ->with([]) ->willReturn($newAddressMock); $customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface') @@ -387,7 +386,6 @@ public function testSetLayoutWithoutAddress() ->getMock(); $this->addressDataFactoryMock->expects($this->once()) ->method('create') - ->with([]) ->willReturn($newAddressMock); $customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface') diff --git a/app/code/Magento/Downloadable/Test/Unit/Model/Plugin/AfterProductLoadTest.php b/app/code/Magento/Downloadable/Test/Unit/Model/Plugin/AfterProductLoadTest.php index 305dacc61c95a..3ddb4ad86405f 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Model/Plugin/AfterProductLoadTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Model/Plugin/AfterProductLoadTest.php @@ -43,9 +43,10 @@ class AfterProductLoadTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->linkRepositoryMock = $this->getMock('Magento\Downloadable\Api\LinkRepositoryInterface'); - $this->sampleRepositoryMock = $this->getMock('Magento\Downloadable\Api\SampleRepositoryInterface'); - $this->productExtensionFactory = $this->getMockBuilder('Magento\Catalog\Api\Data\ProductExtensionFactory') + $this->linkRepositoryMock = $this->getMock('\Magento\Downloadable\Api\LinkRepositoryInterface'); + $this->sampleRepositoryMock = $this->getMock('Magento\Downloadable\Api\SampleRepositoryInterface'); + $this->productExtensionFactory = $this->getMockBuilder('\Magento\Catalog\Api\Data\ProductExtensionFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $this->model = new \Magento\Downloadable\Model\Plugin\AfterProductLoad( diff --git a/app/code/Magento/Eav/Test/Unit/Model/Attribute/GroupRepositoryTest.php b/app/code/Magento/Eav/Test/Unit/Model/Attribute/GroupRepositoryTest.php index 41dc92df72f0f..a429c5323e09d 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/Attribute/GroupRepositoryTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Attribute/GroupRepositoryTest.php @@ -183,7 +183,7 @@ public function testSaveThrowExceptionIfCannotSaveGroup() { $attributeSetId = 42; $groupId = 20; - $groupMock = $this->getMock('\Magento\Eav\Api\Data\AttributeGroupInterface'); + $groupMock = $this->getMock('\Magento\Eav\Model\Entity\Attribute\Group', [], [], '', false); $existingGroupMock = $this->getMock('\Magento\Eav\Model\Entity\Attribute\Group', [], [], '', false); $attributeSetMock = $this->getMock('\Magento\Eav\Api\Data\AttributeSetInterface'); $groupMock->expects($this->any())->method('getAttributeSetId')->willReturn($attributeSetId); @@ -195,6 +195,9 @@ public function testSaveThrowExceptionIfCannotSaveGroup() $this->groupResourceMock->expects($this->once())->method('load')->with($existingGroupMock, $groupId); $existingGroupMock->expects($this->any())->method('getId')->willReturn($groupId); $existingGroupMock->expects($this->once())->method('getAttributeSetId')->willReturn($attributeSetId); + $this->groupResourceMock->expects($this->once()) + ->method('save') + ->will($this->throwException(new \Exception())); $this->model->save($groupMock); } @@ -211,7 +214,7 @@ public function testSaveThrowExceptionIfGroupDoesNotBelongToProvidedSet() { $attributeSetId = 42; $groupId = 20; - $groupMock = $this->getMock('\Magento\Eav\Api\Data\AttributeGroupInterface'); + $groupMock = $this->getMock('\Magento\Eav\Model\Entity\Attribute\Group', [], [], '', false); $existingGroupMock = $this->getMock('\Magento\Eav\Model\Entity\Attribute\Group', [], [], '', false); $attributeSetMock = $this->getMock('\Magento\Eav\Api\Data\AttributeSetInterface'); $groupMock->expects($this->any())->method('getAttributeSetId')->willReturn($attributeSetId); @@ -238,7 +241,7 @@ public function testSaveThrowExceptionIfProvidedGroupDoesNotExist() { $attributeSetId = 42; $groupId = 20; - $groupMock = $this->getMock('\Magento\Eav\Api\Data\AttributeGroupInterface'); + $groupMock = $this->getMock('\Magento\Eav\Model\Entity\Attribute\Group', [], [], '', false); $existingGroupMock = $this->getMock('\Magento\Eav\Model\Entity\Attribute\Group', [], [], '', false); $attributeSetMock = $this->getMock('\Magento\Eav\Api\Data\AttributeSetInterface'); $groupMock->expects($this->any())->method('getAttributeSetId')->willReturn($attributeSetId); diff --git a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php index c18cab16cf584..47d4e8e0929ac 100644 --- a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php @@ -101,6 +101,7 @@ public function setUp() ->disableOriginalConstructor() ->getMock(); $this->emailFilterFactory = $this->getMockBuilder('Magento\Email\Model\Template\FilterFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $this->emailConfig = $this->getMockBuilder('Magento\Email\Model\Template\Config') diff --git a/app/code/Magento/GiftMessage/Test/Unit/Model/SaveTest.php b/app/code/Magento/GiftMessage/Test/Unit/Model/SaveTest.php index be2afab9ebc2b..728bcf9f426b2 100644 --- a/app/code/Magento/GiftMessage/Test/Unit/Model/SaveTest.php +++ b/app/code/Magento/GiftMessage/Test/Unit/Model/SaveTest.php @@ -21,7 +21,10 @@ class SaveTest extends \PHPUnit_Framework_TestCase protected function setUp() { $productRepositoryMock = $this->getMock('\Magento\Catalog\Api\ProductRepositoryInterface', [], [], '', false); - $this->messageFactoryMock = $this->getMock('\Magento\GiftMessage\Model\MessageFactory', [], [], '', false); + $this->messageFactoryMock = $this->getMockBuilder('\Magento\GiftMessage\Model\MessageFactory') + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); $sessionMock = $this->getMock('\Magento\Backend\Model\Session\Quote', [], [], '', false); $giftMessageHelperMock = $this->getMock('\Magento\GiftMessage\Helper\Message', [], [], '', false); $this->model = new \Magento\GiftMessage\Model\Save( diff --git a/app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/GroupedTest.php b/app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/GroupedTest.php index c01fa58cb6a64..e18667c5843ee 100644 --- a/app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/GroupedTest.php +++ b/app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/GroupedTest.php @@ -72,7 +72,7 @@ protected function setUp() $this->attrCollectionFactory = $this->getMock( 'Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory', - [], + ['create'], [], '', false diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php index c06926a086d71..77fdccf9bc594 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php @@ -44,14 +44,14 @@ protected function setUp() ->willReturn($stateMock); $this->objectManagerFactory->expects($this->once())->method('create')->willReturn($this->objectManager); - $this->collectionFactory = $this->getMock( - 'Magento\Indexer\Model\Indexer\CollectionFactory', - [], - [], - '', - false - ); - $this->indexerFactory = $this->getMock('Magento\Indexer\Model\IndexerFactory', [], [], '', false); + $this->collectionFactory = $this->getMockBuilder('Magento\Indexer\Model\Indexer\CollectionFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->indexerFactory = $this->getMockBuilder('Magento\Indexer\Model\IndexerFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); $this->objectManager ->expects($this->exactly(2)) diff --git a/app/code/Magento/Indexer/Test/Unit/Model/Resource/AbstractResourceTest.php b/app/code/Magento/Indexer/Test/Unit/Model/Resource/AbstractResourceTest.php index b35dd6e74c6a9..79e058df70375 100644 --- a/app/code/Magento/Indexer/Test/Unit/Model/Resource/AbstractResourceTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Model/Resource/AbstractResourceTest.php @@ -89,7 +89,10 @@ public function testSyncData() */ public function testSyncDataException() { + $describeTable = ['column' => 'column']; $connectionMock = $this->getMock('Magento\Framework\DB\Adapter\AdapterInterface', [], [], '', false); + $connectionMock->expects($this->any())->method('describeTable')->will($this->returnValue($describeTable)); + $connectionMock->expects($this->any())->method('select')->will($this->throwException(new \Exception())); $this->_resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock)); $this->_resourceMock->expects($this->any())->method('getTableName')->will($this->returnArgument(0)); $connectionMock->expects($this->once())->method('rollback'); diff --git a/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php b/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php index 0db32a17c3295..c6c40ab0b301f 100644 --- a/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php +++ b/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php @@ -32,7 +32,10 @@ public function setUp() public function testExecute() { $mutableConfig = $this->getMock('Magento\Framework\App\Config\MutableScopeConfigInterface', [], [], '', false); - $logFactory = $this->getMock('Magento\Log\Model\LogFactory', [], [], '', false); + $logFactory = $this->getMockBuilder('Magento\Log\Model\LogFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); $returnValueMap = [ [ 'Magento\Framework\App\Config\MutableScopeConfigInterface', diff --git a/app/code/Magento/Log/Test/Unit/Console/Command/LogStatusCommandTest.php b/app/code/Magento/Log/Test/Unit/Console/Command/LogStatusCommandTest.php index 7a7df444bb6a1..a7928b80c4fee 100644 --- a/app/code/Magento/Log/Test/Unit/Console/Command/LogStatusCommandTest.php +++ b/app/code/Magento/Log/Test/Unit/Console/Command/LogStatusCommandTest.php @@ -14,7 +14,10 @@ public function testExecute() { $objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); $objectManager = $this->getMock('Magento\Framework\App\ObjectManager', [], [], '', false); - $resourceFactory = $this->getMock('Magento\Log\Model\Resource\ShellFactory', [], [], '', false); + $resourceFactory = $this->getMockBuilder('Magento\Log\Model\Resource\ShellFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); $objectManager->expects($this->once())->method('create')->willReturn($resourceFactory); $resource = $this->getMock('Magento\Log\Model\Resource\Shell', [], [], '', false); $resourceFactory->expects($this->once())->method('create')->willReturn($resource); diff --git a/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Queue/PreviewTest.php b/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Queue/PreviewTest.php index db1bcddc9192c..5cfb59e64bd6e 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Queue/PreviewTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Queue/PreviewTest.php @@ -13,22 +13,27 @@ class PreviewTest extends \PHPUnit_Framework_TestCase protected $objectManager; /** - * @var \Magento\Newsletter\Model\Template + * @var \Magento\Newsletter\Model\Template|\PHPUnit_Framework_MockObject_MockObject */ protected $template; /** - * @var \Magento\Framework\App\RequestInterface + * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $request; /** - * @var \Magento\Newsletter\Model\Queue + * @var \Magento\Newsletter\Model\Subscriber|\PHPUnit_Framework_MockObject_MockObject + */ + protected $subscriber; + + /** + * @var \Magento\Newsletter\Model\Queue|\PHPUnit_Framework_MockObject_MockObject */ protected $queue; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $storeManager; @@ -39,14 +44,13 @@ class PreviewTest extends \PHPUnit_Framework_TestCase public function setUp() { - $templateFactory = $this->getMock('Magento\Newsletter\Model\TemplateFactory', ['create'], [], '', false); - $this->template = $this->getMock('Magento\Newsletter\Model\Template', [], [], '', false); - $templateFactory->expects($this->once())->method('create')->will($this->returnValue($this->template)); - $queueFactory = $this->getMock('Magento\Newsletter\Model\QueueFactory', ['create'], [], '', false); - $this->queue = $this->getMock('Magento\Newsletter\Model\Queue', ['load'], [], '', false); - $queueFactory->expects($this->any())->method('create')->will($this->returnValue($this->queue)); - + $context = $this->getMock('Magento\Backend\Block\Template\Context', [], [], '', false); + $eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false); + $context->expects($this->once())->method('getEventManager')->will($this->returnValue($eventManager)); + $scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false); + $context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig)); $this->request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); + $context->expects($this->once())->method('getRequest')->will($this->returnValue($this->request)); $this->storeManager = $this->getMock( 'Magento\Store\Model\StoreManager', ['getStores', 'getDefaultStoreView'], @@ -54,15 +58,30 @@ public function setUp() '', false ); + $context->expects($this->once())->method('getStoreManager')->will($this->returnValue($this->storeManager)); + $appState = $this->getMock('Magento\Framework\App\State', [], [], '', false); + $context->expects($this->once())->method('getAppState')->will($this->returnValue($appState)); + + $templateFactory = $this->getMock('Magento\Newsletter\Model\TemplateFactory', ['create'], [], '', false); + $this->template = $this->getMock('Magento\Newsletter\Model\Template', [], [], '', false); + $templateFactory->expects($this->once())->method('create')->will($this->returnValue($this->template)); + + $subscriberFactory = $this->getMock('Magento\Newsletter\Model\SubscriberFactory', ['create'], [], '', false); + $this->subscriber = $this->getMock('Magento\Newsletter\Model\Subscriber', [], [], '', false); + $subscriberFactory->expects($this->once())->method('create')->will($this->returnValue($this->subscriber)); + + $queueFactory = $this->getMock('Magento\Newsletter\Model\QueueFactory', ['create'], [], '', false); + $this->queue = $this->getMock('Magento\Newsletter\Model\Queue', ['load'], [], '', false); + $queueFactory->expects($this->any())->method('create')->will($this->returnValue($this->queue)); $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->preview = $this->objectManager->getObject( 'Magento\Newsletter\Block\Adminhtml\Queue\Preview', [ + 'context' => $context, 'templateFactory' => $templateFactory, + 'subscriberFactory' => $subscriberFactory, 'queueFactory' => $queueFactory, - 'request' => $this->request, - 'storeManager' => $this->storeManager ] ); } diff --git a/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Template/PreviewTest.php b/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Template/PreviewTest.php index a0c04a1af24c1..9b8fb3cfbfa30 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Template/PreviewTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Template/PreviewTest.php @@ -52,9 +52,15 @@ protected function setUp() '', false ); - $templateFactory = $this->getMock('Magento\Newsletter\Model\TemplateFactory', [], [], '', false); + $templateFactory = $this->getMock('Magento\Newsletter\Model\TemplateFactory', ['create'], [], '', false); $templateFactory->expects($this->once())->method('create')->willReturn($this->template); - $this->subscriberFactory = $this->getMock('Magento\Newsletter\Model\SubscriberFactory', [], [], '', false); + $this->subscriberFactory = $this->getMock( + 'Magento\Newsletter\Model\SubscriberFactory', + ['create'], + [], + '', + false + ); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->preview = $this->objectManagerHelper->getObject( @@ -71,10 +77,12 @@ protected function setUp() public function testToHtml() { - $this->request->expects($this->any())->method('getParam')->willReturnMap([ - ['id', null, 1], - ['store_id', null, 1] - ]); + $this->request->expects($this->any())->method('getParam')->willReturnMap( + [ + ['id', null, 1], + ['store_id', null, 1] + ] + ); $this->template->expects($this->atLeastOnce())->method('emulateDesign')->with(1); $this->template->expects($this->atLeastOnce())->method('revertDesign'); @@ -92,11 +100,13 @@ public function testToHtml() public function testToHtmlForNewTemplate() { - $this->request->expects($this->any())->method('getParam')->willReturnMap([ - ['type', null, TemplateTypesInterface::TYPE_TEXT], - ['text', null, 'Processed Template'], - ['styles', null, '.class-name{color:red;}'] - ]); + $this->request->expects($this->any())->method('getParam')->willReturnMap( + [ + ['type', null, TemplateTypesInterface::TYPE_TEXT], + ['text', null, 'Processed Template'], + ['styles', null, '.class-name{color:red;}'] + ] + ); $this->template->expects($this->once())->method('setTemplateType')->with(TemplateTypesInterface::TYPE_TEXT) ->willReturnSelf(); @@ -135,11 +145,13 @@ public function testToHtmlForNewTemplate() public function testToHtmlWithSubscriber() { - $this->request->expects($this->any())->method('getParam')->willReturnMap([ - ['id', null, 2], - ['store_id', null, 1], - ['subscriber', null, 3] - ]); + $this->request->expects($this->any())->method('getParam')->willReturnMap( + [ + ['id', null, 2], + ['store_id', null, 1], + ['subscriber', null, 3] + ] + ); $subscriber = $this->getMock('Magento\Newsletter\Model\Subscriber', [], [], '', false); $subscriber->expects($this->atLeastOnce())->method('load')->with(3)->willReturnSelf(); $this->subscriberFactory->expects($this->atLeastOnce())->method('create')->willReturn($subscriber); diff --git a/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php b/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php new file mode 100644 index 0000000000000..3b4da78c35557 --- /dev/null +++ b/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php @@ -0,0 +1,24 @@ +sendVary(); + } +} diff --git a/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php b/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php new file mode 100755 index 0000000000000..33e3b02e3d53b --- /dev/null +++ b/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php @@ -0,0 +1,25 @@ +getMockBuilder('Magento\Framework\App\Response\Http') + ->disableOriginalConstructor() + ->getMock(); + $responseMock->expects($this->once())->method('sendVary'); + $plugin = new HttpPlugin(); + $plugin->beforeSendResponse($responseMock); + } +} diff --git a/app/code/Magento/PageCache/etc/frontend/di.xml b/app/code/Magento/PageCache/etc/frontend/di.xml index 50779f57dd331..3bb0051df947e 100644 --- a/app/code/Magento/PageCache/etc/frontend/di.xml +++ b/app/code/Magento/PageCache/etc/frontend/di.xml @@ -20,4 +20,7 @@ + + + diff --git a/app/code/Magento/Quote/Test/Unit/Model/AddressDetailsManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/AddressDetailsManagementTest.php index 61e5e67bf09af..ab1e0e6c18be2 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/AddressDetailsManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/AddressDetailsManagementTest.php @@ -55,12 +55,18 @@ class AddressDetailsManagementTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->objectManager = new ObjectManager($this); - $this->billingAddressManagement = $this->getMock('\Magento\Quote\Api\BillingAddressManagementInterface'); - $this->shippingAddressManagement = $this->getMock('\Magento\Quote\Api\ShippingAddressManagementInterface'); - $this->paymentMethodManagement = $this->getMock('\Magento\Quote\Api\PaymentMethodManagementInterface'); - $this->shippingMethodManagement = $this->getMock('\Magento\Quote\Api\ShippingMethodManagementInterface'); - $this->addressDetailsFactory = $this->getMock('\Magento\Quote\Model\AddressDetailsFactory', [], [], '', false); - $this->dataProcessor = $this->getMock('\Magento\Quote\Model\AddressAdditionalDataProcessor', [], [], '', false); + $this->billingAddressManagement = $this->getMock('Magento\Quote\Api\BillingAddressManagementInterface'); + $this->shippingAddressManagement = $this->getMock('Magento\Quote\Api\ShippingAddressManagementInterface'); + $this->paymentMethodManagement = $this->getMock('Magento\Quote\Api\PaymentMethodManagementInterface'); + $this->shippingMethodManagement = $this->getMock('Magento\Quote\Api\ShippingMethodManagementInterface'); + $this->addressDetailsFactory = $this->getMock( + 'Magento\Quote\Model\AddressDetailsFactory', + ['create'], + [], + '', + false + ); + $this->dataProcessor = $this->getMock('Magento\Quote\Model\AddressAdditionalDataProcessor', [], [], '', false); $this->quoteRepository = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); $this->model = $this->objectManager->getObject( @@ -72,7 +78,7 @@ protected function setUp() 'shippingMethodManagement' => $this->shippingMethodManagement, 'addressDetailsFactory' => $this->addressDetailsFactory, 'dataProcessor' => $this->dataProcessor, - 'quoteRepository' => $this->quoteRepository, + 'quoteRepository' => $this->quoteRepository, ] ); } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php index c8f6074a62778..527839cb7a3fb 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php @@ -45,7 +45,10 @@ public function mockQuoteIdMask($maskedCartId, $cartId) '', false ); - $quoteIdMaskFactoryMock = $this->testCase->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + $quoteIdMaskFactoryMock = $this->testCase->getMockBuilder('Magento\Quote\Model\QuoteIdMaskFactory') + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); $quoteIdMaskFactoryMock->expects($this->testCase->once())->method('create')->willReturn($quoteIdMaskMock); $quoteIdMaskMock->expects($this->testCase->once())->method('load')->with($maskedCartId)->willReturnSelf(); $quoteIdMaskMock->expects($this->testCase->once())->method('getQuoteId')->willReturn($cartId); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Email/AsyncSendingTest.php b/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Email/AsyncSendingTest.php index 9359af03ee68d..0439e7ec6e26e 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Email/AsyncSendingTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Email/AsyncSendingTest.php @@ -39,7 +39,7 @@ protected function setUp() $this->config = $this->getMock('Magento\Framework\App\Config', [], [], '', false); - $this->eventManager = $this->getMock('Magento\Framework\Event\Manager\Proxy', [], [], '', false); + $this->eventManager = $this->getMock('Magento\Framework\Event\Manager', [], [], '', false); $this->context = $this->getMock('Magento\Framework\Model\Context', ['getEventDispatcher'], [], '', false); $this->context->expects($this->any())->method('getEventDispatcher')->willReturn($this->eventManager); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Grid/AsyncIndexingTest.php b/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Grid/AsyncIndexingTest.php index 729c19940ccff..78dca5c8d308b 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Grid/AsyncIndexingTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Grid/AsyncIndexingTest.php @@ -29,7 +29,7 @@ class AsyncIndexingTest extends \PHPUnit_Framework_TestCase protected $context; /** - * @var \Magento\Framework\Event\Manager\Proxy|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Event\Manager|\PHPUnit_Framework_MockObject_MockObject */ protected $eventManager; @@ -39,7 +39,7 @@ protected function setUp() $this->config = $this->getMock('Magento\Framework\App\Config', [], [], '', false); - $this->eventManager = $this->getMock('Magento\Framework\Event\Manager\Proxy', [], [], '', false); + $this->eventManager = $this->getMock('Magento\Framework\Event\Manager', [], [], '', false); $this->context = $this->getMock('Magento\Framework\Model\Context', ['getEventDispatcher'], [], '', false); $this->context->expects($this->any())->method('getEventDispatcher')->willReturn($this->eventManager); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/TransactionRepositoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/TransactionRepositoryTest.php index 0b9e28a977f3c..ae0a682d0c934 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/TransactionRepositoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/TransactionRepositoryTest.php @@ -42,7 +42,7 @@ protected function setUp() { $this->transactionFactory = $this->getMock( 'Magento\Sales\Model\Order\Payment\TransactionFactory', - [], + ['create'], [], '', false diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php index 6dbe6898ff1e8..fe5e70a1a7b81 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php @@ -182,21 +182,21 @@ function ($value) { $this->transactionFactory = $this->getMock( 'Magento\Sales\Model\Order\Payment\TransactionFactory', - [], + ['create'], [], '', false ); $this->transactionCollectionFactory = $this->getMock( 'Magento\Sales\Model\Resource\Order\Payment\Transaction\CollectionFactory', - [], + ['create'], [], '', false ); $this->serviceOrderFactory = $this->getMock( 'Magento\Sales\Model\Service\OrderFactory', - [], + ['create'], [], '', false diff --git a/app/code/Magento/Store/App/Response/Redirect.php b/app/code/Magento/Store/App/Response/Redirect.php index 6c156523c881a..de8025f07a2aa 100644 --- a/app/code/Magento/Store/App/Response/Redirect.php +++ b/app/code/Magento/Store/App/Response/Redirect.php @@ -203,21 +203,10 @@ public function redirect(\Magento\Framework\App\ResponseInterface $response, $pa protected function _isUrlInternal($url) { if (strpos($url, 'http') !== false) { - $unsecure = strpos( - $url, - $this->_storeManager->getStore()->getBaseUrl( - \Magento\Framework\UrlInterface::URL_TYPE_DIRECT_LINK, - false - ) - ) === 0; - $secure = strpos( - $url, - $this->_storeManager->getStore()->getBaseUrl( - \Magento\Framework\UrlInterface::URL_TYPE_DIRECT_LINK, - true - ) - ) === 0; - return $unsecure || $secure; + $directLinkType = \Magento\Framework\UrlInterface::URL_TYPE_DIRECT_LINK; + $unsecureBaseUrl = $this->_storeManager->getStore()->getBaseUrl($directLinkType, false); + $secureBaseUrl = $this->_storeManager->getStore()->getBaseUrl($directLinkType, true); + return (strpos($url, $unsecureBaseUrl) === 0) || (strpos($url, $secureBaseUrl) === 0); } return false; } diff --git a/app/code/Magento/Store/etc/di.xml b/app/code/Magento/Store/etc/di.xml index c1584145c2d3d..320253c316b88 100644 --- a/app/code/Magento/Store/etc/di.xml +++ b/app/code/Magento/Store/etc/di.xml @@ -52,7 +52,7 @@ - + diff --git a/app/code/Magento/Variable/Test/Unit/Controller/Adminhtml/System/Variable/ValidateTest.php b/app/code/Magento/Variable/Test/Unit/Controller/Adminhtml/System/Variable/ValidateTest.php index 4844820dcde52..cb653d6499d29 100644 --- a/app/code/Magento/Variable/Test/Unit/Controller/Adminhtml/System/Variable/ValidateTest.php +++ b/app/code/Magento/Variable/Test/Unit/Controller/Adminhtml/System/Variable/ValidateTest.php @@ -63,6 +63,7 @@ protected function setUp() ->method('getMessagesBlock') ->willReturn($messagesMock); $layoutFactoryMock = $this->getMockBuilder('Magento\Framework\View\LayoutFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $layoutFactoryMock->expects($this->any())->method('create')->willReturn($this->layoutMock); @@ -90,6 +91,7 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); $resultJsonFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JsonFactory') + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $resultJsonFactoryMock->expects($this->any())->method('create')->willReturn($this->resultJsonMock); @@ -103,9 +105,11 @@ protected function setUp() [ $contextMock, $coreRegistryMock, - $this->getMock('Magento\Backend\Model\View\Result\ForwardFactory', [], [], '', false), + $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor()->setMethods(['create'])->getMock(), $resultJsonFactoryMock, - $this->getMock('Magento\Framework\View\Result\PageFactory', [], [], '', false), + $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor()->setMethods(['create'])->getMock(), $layoutFactoryMock, ] )->setMethods(['_initVariable']) diff --git a/app/code/Magento/Wishlist/Test/Unit/Helper/RssTest.php b/app/code/Magento/Wishlist/Test/Unit/Helper/RssTest.php index 5a4959ba7e961..55435d1387050 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Helper/RssTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Helper/RssTest.php @@ -67,6 +67,7 @@ public function setUp() $this->customerFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterfaceFactory') ->disableOriginalConstructor() + ->setMethods(['create']) ->getMock(); $this->customerSessionMock = $this->getMockBuilder('Magento\Customer\Model\Session') @@ -109,7 +110,6 @@ public function testGetWishlistWithWishlistId() ->getMock(); $this->wishlistFactoryMock->expects($this->once()) ->method('create') - ->with([]) ->willReturn($wishlist); $this->requestMock->expects($this->once()) @@ -137,7 +137,6 @@ public function testGetWishlistWithCustomerId() ->getMock(); $this->wishlistFactoryMock->expects($this->once()) ->method('create') - ->with([]) ->willReturn($wishlist); $this->requestMock->expects($this->at(0)) @@ -163,7 +162,6 @@ public function testGetWishlistWithCustomerId() ->getMock(); $this->customerFactoryMock->expects($this->once()) ->method('create') - ->with([]) ->willReturn($customer); $this->customerRepositoryMock->expects($this->never()) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Code/_expected/SourceClassWithNamespaceInterceptor.php.sample b/dev/tests/integration/testsuite/Magento/Framework/Code/_expected/SourceClassWithNamespaceInterceptor.php.sample index 7b78299861058..a7a5a35de142c 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Code/_expected/SourceClassWithNamespaceInterceptor.php.sample +++ b/dev/tests/integration/testsuite/Magento/Framework/Code/_expected/SourceClassWithNamespaceInterceptor.php.sample @@ -68,6 +68,9 @@ class Interceptor extends \Magento\Framework\Code\GeneratorTest\SourceClassWithN public function __wakeup() { + if (method_exists(get_parent_class($this), '__wakeup')) { + parent::__wakeup(); + } $this->___init(); } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Url/Helper/DataTest.php b/dev/tests/integration/testsuite/Magento/Framework/Url/Helper/DataTest.php index a582be47759fb..ce94b1e855a8a 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Url/Helper/DataTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Url/Helper/DataTest.php @@ -23,12 +23,12 @@ protected function setUp() public function testGetCurrentBase64Url() { - $this->assertEquals('aHR0cDovL2xvY2FsaG9zdA,,', $this->_helper->getCurrentBase64Url()); + $this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MQ,,', $this->_helper->getCurrentBase64Url()); } public function testGetEncodedUrl() { - $this->assertEquals('aHR0cDovL2xvY2FsaG9zdA,,', $this->_helper->getEncodedUrl()); + $this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MQ,,', $this->_helper->getEncodedUrl()); $this->assertEquals('aHR0cDovL2V4YW1wbGUuY29tLw,,', $this->_helper->getEncodedUrl('http://example.com/')); } } diff --git a/dev/tests/integration/testsuite/Magento/Weee/Model/TaxTest.php b/dev/tests/integration/testsuite/Magento/Weee/Model/TaxTest.php index 8b1d329150edc..c423caff57b1e 100644 --- a/dev/tests/integration/testsuite/Magento/Weee/Model/TaxTest.php +++ b/dev/tests/integration/testsuite/Magento/Weee/Model/TaxTest.php @@ -36,7 +36,7 @@ protected function setUp() $attribute->expects($this->any())->method('getAttributeCodesByFrontendType')->will( $this->returnValue(['price']) ); - $attributeFactory = $this->getMock('Magento\Eav\Model\Entity\AttributeFactory', [], [], '', false); + $attributeFactory = $this->getMock('Magento\Eav\Model\Entity\AttributeFactory', ['create'], [], '', false); $attributeFactory->expects($this->any())->method('create')->will($this->returnValue($attribute)); $this->_model = $objectManager->create( 'Magento\Weee\Model\Tax', diff --git a/dev/tests/unit/framework/autoload.php b/dev/tests/unit/framework/autoload.php index 56021a2bb4acf..9f7aa040004fc 100644 --- a/dev/tests/unit/framework/autoload.php +++ b/dev/tests/unit/framework/autoload.php @@ -4,52 +4,10 @@ * See COPYING.txt for license details. */ -use Magento\Framework\Api\Code\Generator\DataBuilder; -use Magento\Framework\Api\Code\Generator\Mapper; -use Magento\Framework\Api\Code\Generator\ExtensionAttributesGenerator; -use Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator; -use Magento\Framework\Api\Code\Generator\SearchResults; -use Magento\Framework\Api\Code\Generator\SearchResultsBuilder; -use Magento\Framework\Interception\Code\Generator\Interceptor; -use Magento\Framework\ObjectManager\Code\Generator\Converter; -use Magento\Framework\ObjectManager\Code\Generator\Factory; -use Magento\Framework\ObjectManager\Code\Generator\Persistor; -use Magento\Framework\ObjectManager\Code\Generator\Proxy; -use Magento\Framework\ObjectManager\Code\Generator\Repository; -use Magento\Tools\Di\Code\Scanner; -use Magento\Tools\Di\Compiler\Log\Writer; -use Magento\Tools\Di\Definition\Compressor; - -/** - * Enable code generation for the undeclared classes. - */ -$generationDir = TESTS_TEMP_DIR . '/var/generation'; -$generatorIo = new \Magento\Framework\Code\Generator\Io( - new \Magento\Framework\Filesystem\Driver\File(), - $generationDir +$autoloader = new \Magento\Framework\TestFramework\Unit\Autoloader\ExtensionGeneratorAutoloader( + new \Magento\Framework\Code\Generator\Io( + new \Magento\Framework\Filesystem\Driver\File(), + TESTS_TEMP_DIR . '/var/generation' + ) ); -$generator = new \Magento\Framework\Code\Generator( - $generatorIo, - [ - Interceptor::ENTITY_TYPE => 'Magento\Framework\Interception\Code\Generator\Interceptor', - Proxy::ENTITY_TYPE => 'Magento\Framework\ObjectManager\Code\Generator\Proxy', - Factory::ENTITY_TYPE => 'Magento\Framework\ObjectManager\Code\Generator\Factory', - Mapper::ENTITY_TYPE => 'Magento\Framework\Api\Code\Generator\Mapper', - Persistor::ENTITY_TYPE => 'Magento\Framework\ObjectManager\Code\Generator\Persistor', - Repository::ENTITY_TYPE => 'Magento\Framework\ObjectManager\Code\Generator\Repository', - Converter::ENTITY_TYPE => 'Magento\Framework\ObjectManager\Code\Generator\Converter', - SearchResults::ENTITY_TYPE => 'Magento\Framework\Api\Code\Generator\SearchResults', - ExtensionAttributesInterfaceGenerator::ENTITY_TYPE => - 'Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator', - ExtensionAttributesGenerator::ENTITY_TYPE => 'Magento\Framework\Api\Code\Generator\ExtensionAttributesGenerator' - ] -); -/** Initialize object manager for code generation based on configs */ -$magentoObjectManagerFactory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $_SERVER); -$objectManager = $magentoObjectManagerFactory->create($_SERVER); -$generator->setObjectManager($objectManager); - -$autoloader = new \Magento\Framework\Code\Generator\Autoloader($generator); spl_autoload_register([$autoloader, 'load']); -$autoloadWrapper = \Magento\Framework\Autoload\AutoloaderRegistry::getAutoloader(); -$autoloadWrapper->addPsr4('Magento\\', $generationDir . '/Magento/'); diff --git a/lib/internal/Magento/Framework/App/Response/Http.php b/lib/internal/Magento/Framework/App/Response/Http.php index 6b510679daadc..55cda163252ab 100644 --- a/lib/internal/Magento/Framework/App/Response/Http.php +++ b/lib/internal/Magento/Framework/App/Response/Http.php @@ -52,19 +52,7 @@ public function __construct( } /** - * Send the response, including all headers, rendering exceptions if so - * requested. - * - * @return void - */ - public function sendResponse() - { - $this->sendVary(); - parent::sendResponse(); - } - - /** - * Send Vary coookie + * Send Vary cookie * * @return void */ @@ -74,12 +62,10 @@ public function sendVary() if (!empty($data)) { ksort($data); $cookieValue = sha1(serialize($data)); - $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata() - ->setPath('/'); + $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/'); $this->cookieManager->setSensitiveCookie(self::COOKIE_VARY_STRING, $cookieValue, $sensitiveCookMetadata); } else { - $cookieMetadata = $this->cookieMetadataFactory->createCookieMetadata() - ->setPath('/'); + $cookieMetadata = $this->cookieMetadataFactory->createCookieMetadata()->setPath('/'); $this->cookieManager->deleteCookie(self::COOKIE_VARY_STRING, $cookieMetadata); } } diff --git a/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php b/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php index d50721d4e52a1..679e3fde28927 100644 --- a/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php +++ b/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php @@ -144,7 +144,10 @@ protected function _getClassMethods() $methods[] = [ 'name' => '__wakeup', - 'body' => "\$this->___init();\n", + 'body' => "if (method_exists(get_parent_class(\$this), '__wakeup')) {\n" + . " parent::__wakeup();\n" + . "}\n" + . "\$this->___init();\n", ]; $methods[] = [ @@ -203,7 +206,6 @@ protected function _getClassMethods() $methods[] = $this->_getMethodInfo($method); } } - return $methods; } diff --git a/lib/internal/Magento/Framework/Reflection/Test/Unit/TypeProcessorTest.php b/lib/internal/Magento/Framework/Reflection/Test/Unit/TypeProcessorTest.php index b2e1940f123b1..4f6b76f302e93 100644 --- a/lib/internal/Magento/Framework/Reflection/Test/Unit/TypeProcessorTest.php +++ b/lib/internal/Magento/Framework/Reflection/Test/Unit/TypeProcessorTest.php @@ -203,4 +203,14 @@ public function testFindSetterMethodNameInvalidAttribute() $class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject"); $this->_typeProcessor->findSetterMethodName($class, 'InvalidAttribute'); } + + /** + * @expectedException \Exception + * @expectedExceptionMessageRegExp /Property :"InvalidAttribute" does not exist in the provided class: \w+/ + */ + public function testFindSetterMethodNameWrongCamelCasedAttribute() + { + $class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject"); + $this->_typeProcessor->findSetterMethodName($class, 'ActivE'); + } } diff --git a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php index 580be037ad206..2653248cec8dd 100644 --- a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php @@ -501,20 +501,7 @@ public function findGetterMethodName(ClassReflection $class, $camelCaseProperty) { $getterName = 'get' . $camelCaseProperty; $boolGetterName = 'is' . $camelCaseProperty; - if ($class->hasMethod($getterName)) { - $methodName = $getterName; - } elseif ($class->hasMethod($boolGetterName)) { - $methodName = $boolGetterName; - } else { - throw new \Exception( - sprintf( - 'Property :"%s" does not exist in the provided class: "%s".', - $camelCaseProperty, - $class->getName() - ) - ); - } - return $methodName; + return $this->findAccessorMethodName($class, $camelCaseProperty, $getterName, $boolGetterName); } /** @@ -547,10 +534,31 @@ public function findSetterMethodName(ClassReflection $class, $camelCaseProperty) { $setterName = 'set' . $camelCaseProperty; $boolSetterName = 'setIs' . $camelCaseProperty; - if ($class->hasMethod($setterName)) { - $methodName = $setterName; - } elseif ($class->hasMethod($boolSetterName)) { - $methodName = $boolSetterName; + return $this->findAccessorMethodName($class, $camelCaseProperty, $setterName, $boolSetterName); + } + + /** + * Find the accessor method name for a property from the given class + * + * @param ClassReflection $class + * @param string $camelCaseProperty + * @param string $accessorName + * @param bool $boolAccessorName + * @return string processed method name + * @throws \Exception If $camelCaseProperty has no corresponding setter method + */ + protected function findAccessorMethodName( + ClassReflection $class, + $camelCaseProperty, + $accessorName, + $boolAccessorName + ) { + if ($this->classHasMethod($class, $accessorName)) { + $methodName = $accessorName; + return $methodName; + } elseif ($this->classHasMethod($class, $boolAccessorName)) { + $methodName = $boolAccessorName; + return $methodName; } else { throw new \Exception( sprintf( @@ -560,6 +568,19 @@ public function findSetterMethodName(ClassReflection $class, $camelCaseProperty) ) ); } - return $methodName; + } + + /** + * Checks if method is defined + * + * Case sensitivity of the method is taken into account. + * + * @param ClassReflection $class + * @param string $methodName + * @return bool + */ + protected function classHasMethod(ClassReflection $class, $methodName) + { + return $class->hasMethod($methodName) && ($class->getMethod($methodName)->getName() == $methodName); } } diff --git a/lib/internal/Magento/Framework/Test/Unit/UrlTest.php b/lib/internal/Magento/Framework/Test/Unit/UrlTest.php index 69e2260002ce0..baa556bb19f78 100644 --- a/lib/internal/Magento/Framework/Test/Unit/UrlTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/UrlTest.php @@ -114,20 +114,16 @@ protected function getUrlModel($arguments = []) } /** - * @param $port mixed + * @param $httpHost string * @param $url string * @dataProvider getCurrentUrlProvider */ - public function testGetCurrentUrl($port, $url) + public function testGetCurrentUrl($httpHost, $url) { $requestMock = $this->getRequestMock(); - $requestMock->expects($this->at(0))->method('getServer')->with('SERVER_PORT') - ->will($this->returnValue($port)); - $requestMock->expects($this->at(1))->method('getServer')->with('REQUEST_URI') - ->will($this->returnValue('/fancy_uri')); + $requestMock->expects($this->once())->method('getServer')->with('REQUEST_URI')->willReturn('/fancy_uri'); $requestMock->expects($this->once())->method('getScheme')->will($this->returnValue('http')); - $requestMock->expects($this->once())->method('getHttpHost')->will($this->returnValue('example.com')); - + $requestMock->expects($this->once())->method('getHttpHost')->will($this->returnValue($httpHost)); $model = $this->getUrlModel(['request' => $requestMock]); $this->assertEquals($url, $model->getCurrentUrl()); } @@ -135,9 +131,9 @@ public function testGetCurrentUrl($port, $url) public function getCurrentUrlProvider() { return [ - 'without_port' => ['', 'http://example.com/fancy_uri'], - 'default_port' => [80, 'http://example.com/fancy_uri'], - 'custom_port' => [8080, 'http://example.com:8080/fancy_uri'] + 'without_port' => ['example.com', 'http://example.com/fancy_uri'], + 'default_port' => ['example.com:80', 'http://example.com/fancy_uri'], + 'custom_port' => ['example.com:8080', 'http://example.com:8080/fancy_uri'] ]; } diff --git a/lib/internal/Magento/Framework/TestFramework/Unit/Autoloader/ExtensionGeneratorAutoloader.php b/lib/internal/Magento/Framework/TestFramework/Unit/Autoloader/ExtensionGeneratorAutoloader.php new file mode 100644 index 0000000000000..9f14464d01c87 --- /dev/null +++ b/lib/internal/Magento/Framework/TestFramework/Unit/Autoloader/ExtensionGeneratorAutoloader.php @@ -0,0 +1,97 @@ +generatorIo = $generatorIo; + } + + /** + * Load an *Extension or *ExtensionInterface class. If it does not exist, create a stub file and load it. + * + * @param string $className + * @return void + */ + public function load($className) + { + if (!class_exists($className)) { + if (!$this->isExtension($className) && !$this->isExtensionInterface($className)) { + return false; + } + + $resultFileName = $this->generatorIo->getResultFileName($className); + + if (!$this->generatorIo->fileExists($resultFileName)) { + $this->generatorIo->makeResultFileDirectory($className); + + $classNameParts = explode('\\', $className); + + /* Split the type name and namespace for the file's contents. */ + $justTypeName = $classNameParts[count($classNameParts) - 1]; + + unset($classNameParts[count($classNameParts) - 1]); + $namespace = implode('\\', $classNameParts); + + if ($this->isExtension($className)) { + $content = "namespace $namespace;\n\nclass $justTypeName implements " + . "{$justTypeName}Interface\n{\n\n}"; + } else if ($this->isExtensionInterface($className)) { + $content = "namespace $namespace;\n\ninterface $justTypeName extends " + . "\\Magento\\Framework\\Api\\ExtensionAttributesInterface \n{\n\n}"; + } + + $this->generatorIo->writeResultFile($resultFileName, $content); + } + + include $resultFileName; + } + + return false; + } + + /** + * Determines if the passed in class name is an ExtensionInterface type. + * + * @param string $className + * @return bool + */ + private function isExtensionInterface($className) + { + $suffix = "ExtensionInterface"; + return substr($className, -strlen($suffix), strlen($suffix)) === $suffix; + } + + /** + * Determines if the passed in class name is an Extension type. + * + * @param string $className + * @return bool + */ + private function isExtension($className) + { + $suffix = "Extension"; + return substr($className, -strlen($suffix), strlen($suffix)) === $suffix; + } +} diff --git a/lib/internal/Magento/Framework/Url.php b/lib/internal/Magento/Framework/Url.php index 697e461df050f..7d4c4c33399ac 100644 --- a/lib/internal/Magento/Framework/Url.php +++ b/lib/internal/Magento/Framework/Url.php @@ -1031,17 +1031,21 @@ public function getRedirectUrl($url) */ public function getCurrentUrl() { - $port = $this->_request->getServer('SERVER_PORT'); - if ($port) { + $httpHostWithPort = $this->_request->getHttpHost(false); + $httpHostWithPort = explode(':', $httpHostWithPort); + $httpHost = isset($httpHostWithPort[0]) ? $httpHostWithPort[0] : ''; + $port = ''; + if (isset($httpHostWithPort[1])) { $defaultPorts = [ \Magento\Framework\App\Request\Http::DEFAULT_HTTP_PORT, \Magento\Framework\App\Request\Http::DEFAULT_HTTPS_PORT, ]; - $port = in_array($port, $defaultPorts) ? '' : ':' . $port; + if (!in_array($httpHostWithPort[1], $defaultPorts)) { + /** Custom port */ + $port = ':' . $httpHostWithPort[1]; + } } - $requestUri = $this->_request->getServer('REQUEST_URI'); - $url = $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . $port . $requestUri; - return $url; + return $this->_request->getScheme() . '://' . $httpHost . $port . $this->_request->getServer('REQUEST_URI'); } /**