From ccab782facc967a33cd0919d9a3d551bcc741f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20R=C3=B6ttig?= Date: Sat, 20 May 2017 13:44:13 +0200 Subject: [PATCH 01/66] Add new InventoryApi Module and implement Interfaces --- .../Api/Data/SourceExtensionInterface.php | 11 + .../InventoryApi/Api/Data/SourceInterface.php | 315 ++++++++++++++++++ .../Api/Data/SourceSearchResultsInterface.php | 11 + .../Api/SourceRepositoryInterface.php | 35 ++ app/code/Magento/InventoryApi/LICENSE.txt | 48 +++ app/code/Magento/InventoryApi/LICENSE_AFL.txt | 48 +++ app/code/Magento/InventoryApi/README.md | 0 app/code/Magento/InventoryApi/composer.json | 28 ++ app/code/Magento/InventoryApi/etc/module.xml | 16 + .../Magento/InventoryApi/registration.php | 11 + 10 files changed, 523 insertions(+) create mode 100644 app/code/Magento/InventoryApi/Api/Data/SourceExtensionInterface.php create mode 100644 app/code/Magento/InventoryApi/Api/Data/SourceInterface.php create mode 100644 app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php create mode 100644 app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php create mode 100644 app/code/Magento/InventoryApi/LICENSE.txt create mode 100644 app/code/Magento/InventoryApi/LICENSE_AFL.txt create mode 100644 app/code/Magento/InventoryApi/README.md create mode 100644 app/code/Magento/InventoryApi/composer.json create mode 100644 app/code/Magento/InventoryApi/etc/module.xml create mode 100644 app/code/Magento/InventoryApi/registration.php diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceExtensionInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceExtensionInterface.php new file mode 100644 index 000000000000..82c05acac2e1 --- /dev/null +++ b/app/code/Magento/InventoryApi/Api/Data/SourceExtensionInterface.php @@ -0,0 +1,11 @@ +" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/InventoryApi/LICENSE_AFL.txt b/app/code/Magento/InventoryApi/LICENSE_AFL.txt new file mode 100644 index 000000000000..f39d641b18a1 --- /dev/null +++ b/app/code/Magento/InventoryApi/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/InventoryApi/README.md b/app/code/Magento/InventoryApi/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/app/code/Magento/InventoryApi/composer.json b/app/code/Magento/InventoryApi/composer.json new file mode 100644 index 000000000000..661e80602ad4 --- /dev/null +++ b/app/code/Magento/InventoryApi/composer.json @@ -0,0 +1,28 @@ +{ + "name": "magento/module-inventory-api", + "description": "N/A", + "require": { + "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", + "magento/module-store": "100.2.*", + "magento/module-backend": "100.2.*", + "magento/module-customer": "100.2.*", + "magento/module-user": "100.2.*", + "magento/module-security": "100.2.*", + "magento/framework": "100.2.*", + "magento/module-authorization": "100.2.*" + }, + "type": "magento2-module", + "version": "100.2.0-dev", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\InventoryApi\\": "" + } + } +} diff --git a/app/code/Magento/InventoryApi/etc/module.xml b/app/code/Magento/InventoryApi/etc/module.xml new file mode 100644 index 000000000000..ef47fefb842c --- /dev/null +++ b/app/code/Magento/InventoryApi/etc/module.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/app/code/Magento/InventoryApi/registration.php b/app/code/Magento/InventoryApi/registration.php new file mode 100644 index 000000000000..ce0a9c85a875 --- /dev/null +++ b/app/code/Magento/InventoryApi/registration.php @@ -0,0 +1,11 @@ + Date: Sat, 20 May 2017 13:54:46 +0200 Subject: [PATCH 02/66] magento-engcom/magento2#25 Update dependencies --- .gitignore | 36 +++ app/code/Magento/InventoryApi/README.md | 5 + app/code/Magento/InventoryApi/composer.json | 10 +- app/code/Magento/InventoryApi/etc/module.xml | 8 +- composer.lock | 297 +++++++++---------- 5 files changed, 192 insertions(+), 164 deletions(-) diff --git a/.gitignore b/.gitignore index 90c60dfa39ca..f4a81c593afa 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,39 @@ atlassian* !/vendor/.htaccess /generated/* !/generated/.htaccess + +## Sample data +app/code/Magento/BundleSampleData +app/code/Magento/CatalogRuleSampleData +app/code/Magento/CatalogSampleData +app/code/Magento/CmsSampleData +app/code/Magento/ConfigurableSampleData +app/code/Magento/CustomerSampleData +app/code/Magento/DownloadableSampleData +app/code/Magento/GroupedProductSampleData +app/code/Magento/MsrpSampleData +app/code/Magento/OfflineShippingSampleData +app/code/Magento/ProductLinksSampleData +app/code/Magento/ReviewSampleData +app/code/Magento/SalesRuleSampleData +app/code/Magento/SalesSampleData +app/code/Magento/SwatchesSampleData +app/code/Magento/TaxSampleData +app/code/Magento/ThemeSampleData +app/code/Magento/WidgetSampleData +app/code/Magento/WishlistSampleData +app/code/Magento/_InventoryApi/ +dev/tests/functional/tests/app/Magento/BundleSampleData +dev/tests/functional/tests/app/Magento/CatalogSampleData +dev/tests/functional/tests/app/Magento/ConfigurableSampleData +dev/tests/functional/tests/app/Magento/CustomerSampleData +dev/tests/functional/tests/app/Magento/DownloadableSampleData +dev/tests/functional/tests/app/Magento/GroupedProductSampleData +dev/tests/functional/tests/app/Magento/SalesSampleData +dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/sample-data.xml +dev/tests/integration/testsuite/Magento/SampleData/Helper +dev/tests/integration/testsuite/Magento/SampleData/Model/TestLogger.php +dev/tests/integration/testsuite/Magento/SampleData/_files/fixtures +dev/tools/build-sample-data.php +pub/media/catalog +pub/media/wysiwyg diff --git a/app/code/Magento/InventoryApi/README.md b/app/code/Magento/InventoryApi/README.md index e69de29bb2d1..e10a610def87 100644 --- a/app/code/Magento/InventoryApi/README.md +++ b/app/code/Magento/InventoryApi/README.md @@ -0,0 +1,5 @@ +# InventoryApi + +**InventoryApi** provides interfaces for inventory management. +See [concept documentation](https://github.com/magento-engcom/magento2/wiki/Technical-Vision.-Catalog-Inventory) +for further information. diff --git a/app/code/Magento/InventoryApi/composer.json b/app/code/Magento/InventoryApi/composer.json index 661e80602ad4..36fb986952cb 100644 --- a/app/code/Magento/InventoryApi/composer.json +++ b/app/code/Magento/InventoryApi/composer.json @@ -3,16 +3,10 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-store": "100.2.*", - "magento/module-backend": "100.2.*", - "magento/module-customer": "100.2.*", - "magento/module-user": "100.2.*", - "magento/module-security": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-authorization": "100.2.*" + "magento/framework": "100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.0.0-dev", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/InventoryApi/etc/module.xml b/app/code/Magento/InventoryApi/etc/module.xml index ef47fefb842c..9b4ae307339b 100644 --- a/app/code/Magento/InventoryApi/etc/module.xml +++ b/app/code/Magento/InventoryApi/etc/module.xml @@ -6,11 +6,5 @@ */ --> - - - - - - - + diff --git a/composer.lock b/composer.lock index f4b32154e837..d89677ac32a6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,6 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "54e536d6a16773c0efc4d6a7a6e668d4", "content-hash": "83b07861c465af490d6cf0c75adc78fd", "packages": [ { @@ -52,7 +51,7 @@ } ], "description": "Braintree PHP Client Library", - "time": "2017-02-16 19:59:04" + "time": "2017-02-16T19:59:04+00:00" }, { "name": "colinmollenhour/cache-backend-file", @@ -88,7 +87,7 @@ ], "description": "The stock Zend_Cache_Backend_File backend has extremely poor performance for cleaning by tags making it become unusable as the number of cached items increases. This backend makes many changes resulting in a huge performance boost, especially for tag cleaning.", "homepage": "https://github.com/colinmollenhour/Cm_Cache_Backend_File", - "time": "2016-05-02 16:24:47" + "time": "2016-05-02T16:24:47+00:00" }, { "name": "colinmollenhour/cache-backend-redis", @@ -124,7 +123,7 @@ ], "description": "Zend_Cache backend using Redis with full support for tags.", "homepage": "https://github.com/colinmollenhour/Cm_Cache_Backend_Redis", - "time": "2017-03-25 04:54:24" + "time": "2017-03-25T04:54:24+00:00" }, { "name": "colinmollenhour/credis", @@ -163,7 +162,7 @@ ], "description": "Credis is a lightweight interface to the Redis key-value store which wraps the phpredis library when available for better performance.", "homepage": "https://github.com/colinmollenhour/credis", - "time": "2015-11-28 01:20:04" + "time": "2015-11-28T01:20:04+00:00" }, { "name": "colinmollenhour/php-redis-session-abstract", @@ -200,7 +199,7 @@ ], "description": "A Redis-based session handler with optimistic locking", "homepage": "https://github.com/colinmollenhour/php-redis-session-abstract", - "time": "2017-04-19 14:21:43" + "time": "2017-04-19T14:21:43+00:00" }, { "name": "composer/ca-bundle", @@ -259,7 +258,7 @@ "ssl", "tls" ], - "time": "2017-03-06 11:59:08" + "time": "2017-03-06T11:59:08+00:00" }, { "name": "composer/composer", @@ -336,7 +335,7 @@ "dependency", "package" ], - "time": "2017-03-10 08:29:45" + "time": "2017-03-10T08:29:45+00:00" }, { "name": "composer/semver", @@ -398,7 +397,7 @@ "validation", "versioning" ], - "time": "2016-08-30 16:08:34" + "time": "2016-08-30T16:08:34+00:00" }, { "name": "composer/spdx-licenses", @@ -459,7 +458,7 @@ "spdx", "validator" ], - "time": "2017-04-03 19:08:52" + "time": "2017-04-03T19:08:52+00:00" }, { "name": "container-interop/container-interop", @@ -490,20 +489,20 @@ ], "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", "homepage": "https://github.com/container-interop/container-interop", - "time": "2017-02-14 19:40:03" + "time": "2017-02-14T19:40:03+00:00" }, { "name": "justinrainbow/json-schema", - "version": "5.2.0", + "version": "5.2.1", "source": { "type": "git", "url": "https://github.com/justinrainbow/json-schema.git", - "reference": "e3c9bccdc38bbd09bcac0131c00f3be58368b416" + "reference": "429be236f296ca249d61c65649cdf2652f4a5e80" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/e3c9bccdc38bbd09bcac0131c00f3be58368b416", - "reference": "e3c9bccdc38bbd09bcac0131c00f3be58368b416", + "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/429be236f296ca249d61c65649cdf2652f4a5e80", + "reference": "429be236f296ca249d61c65649cdf2652f4a5e80", "shasum": "" }, "require": { @@ -512,7 +511,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^2.1", "json-schema/json-schema-test-suite": "1.2.0", - "phpdocumentor/phpdocumentor": "~2", + "phpdocumentor/phpdocumentor": "^2.7", "phpunit/phpunit": "^4.8.22" }, "bin": [ @@ -557,7 +556,7 @@ "json", "schema" ], - "time": "2017-03-22 22:43:35" + "time": "2017-05-16T21:06:09+00:00" }, { "name": "league/climate", @@ -606,7 +605,7 @@ "php", "terminal" ], - "time": "2015-01-18 14:31:58" + "time": "2015-01-18T14:31:58+00:00" }, { "name": "magento/composer", @@ -642,7 +641,7 @@ "AFL-3.0" ], "description": "Magento composer library helps to instantiate Composer application and run composer commands.", - "time": "2017-04-24 09:57:02" + "time": "2017-04-24T09:57:02+00:00" }, { "name": "magento/magento-composer-installer", @@ -721,7 +720,7 @@ "composer-installer", "magento" ], - "time": "2016-10-06 16:05:07" + "time": "2016-10-06T16:05:07+00:00" }, { "name": "magento/zendframework1", @@ -768,7 +767,7 @@ "ZF1", "framework" ], - "time": "2017-04-24 09:56:59" + "time": "2017-04-24T09:56:59+00:00" }, { "name": "monolog/monolog", @@ -846,7 +845,7 @@ "logging", "psr-3" ], - "time": "2017-03-13 07:08:03" + "time": "2017-03-13T07:08:03+00:00" }, { "name": "oyejorge/less.php", @@ -908,7 +907,7 @@ "php", "stylesheet" ], - "time": "2017-03-28 22:19:25" + "time": "2017-03-28T22:19:25+00:00" }, { "name": "paragonie/random_compat", @@ -956,7 +955,7 @@ "pseudorandom", "random" ], - "time": "2017-03-13 16:27:32" + "time": "2017-03-13T16:27:32+00:00" }, { "name": "pelago/emogrifier", @@ -1012,20 +1011,20 @@ ], "description": "Converts CSS styles into inline style attributes in your HTML code", "homepage": "http://www.pelagodesign.com/sidecar/emogrifier/", - "time": "2015-05-15 11:37:51" + "time": "2015-05-15T11:37:51+00:00" }, { "name": "phpseclib/phpseclib", - "version": "2.0.4", + "version": "2.0.5", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "ab8028c93c03cc8d9c824efa75dc94f1db2369bf" + "reference": "f8dd0e18d2328c447dd4190fecd11ef52680d968" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/ab8028c93c03cc8d9c824efa75dc94f1db2369bf", - "reference": "ab8028c93c03cc8d9c824efa75dc94f1db2369bf", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/f8dd0e18d2328c447dd4190fecd11ef52680d968", + "reference": "f8dd0e18d2328c447dd4190fecd11ef52680d968", "shasum": "" }, "require": { @@ -1104,7 +1103,7 @@ "x.509", "x509" ], - "time": "2016-10-04 00:57:04" + "time": "2017-05-08T05:58:35+00:00" }, { "name": "psr/container", @@ -1153,7 +1152,7 @@ "container-interop", "psr" ], - "time": "2017-02-14 16:28:37" + "time": "2017-02-14T16:28:37+00:00" }, { "name": "psr/log", @@ -1200,7 +1199,7 @@ "psr", "psr-3" ], - "time": "2016-10-10 12:19:37" + "time": "2016-10-10T12:19:37+00:00" }, { "name": "ramsey/uuid", @@ -1282,7 +1281,7 @@ "identifier", "uuid" ], - "time": "2017-03-26 20:37:53" + "time": "2017-03-26T20:37:53+00:00" }, { "name": "seld/cli-prompt", @@ -1330,7 +1329,7 @@ "input", "prompt" ], - "time": "2017-03-18 11:32:45" + "time": "2017-03-18T11:32:45+00:00" }, { "name": "seld/jsonlint", @@ -1379,7 +1378,7 @@ "parser", "validator" ], - "time": "2017-03-06 16:42:24" + "time": "2017-03-06T16:42:24+00:00" }, { "name": "seld/phar-utils", @@ -1423,7 +1422,7 @@ "keywords": [ "phra" ], - "time": "2015-10-13 18:44:15" + "time": "2015-10-13T18:44:15+00:00" }, { "name": "sjparkinson/static-review", @@ -1476,7 +1475,7 @@ } ], "description": "An extendable framework for version control hooks.", - "time": "2014-09-22 08:40:36" + "time": "2014-09-22T08:40:36+00:00" }, { "name": "symfony/console", @@ -1537,7 +1536,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2017-04-26 01:38:53" + "time": "2017-04-26T01:38:53+00:00" }, { "name": "symfony/debug", @@ -1594,7 +1593,7 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2016-07-30 07:22:48" + "time": "2016-07-30T07:22:48+00:00" }, { "name": "symfony/event-dispatcher", @@ -1654,7 +1653,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-04-26 16:56:54" + "time": "2017-04-26T16:56:54+00:00" }, { "name": "symfony/filesystem", @@ -1703,7 +1702,7 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2017-04-12 14:13:17" + "time": "2017-04-12T14:13:17+00:00" }, { "name": "symfony/finder", @@ -1752,7 +1751,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2017-04-12 14:13:17" + "time": "2017-04-12T14:13:17+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -1811,7 +1810,7 @@ "portable", "shim" ], - "time": "2016-11-14 01:06:16" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/process", @@ -1860,7 +1859,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2017-04-12 14:07:15" + "time": "2017-04-12T14:07:15+00:00" }, { "name": "tedivm/jshrink", @@ -1906,7 +1905,7 @@ "javascript", "minifier" ], - "time": "2015-07-04 07:35:09" + "time": "2015-07-04T07:35:09+00:00" }, { "name": "tubalmartin/cssmin", @@ -1954,7 +1953,7 @@ "minify", "yui" ], - "time": "2017-04-04 14:33:00" + "time": "2017-04-04T14:33:00+00:00" }, { "name": "zendframework/zend-captcha", @@ -2011,7 +2010,7 @@ "captcha", "zf2" ], - "time": "2017-02-23 08:09:44" + "time": "2017-02-23T08:09:44+00:00" }, { "name": "zendframework/zend-code", @@ -2064,7 +2063,7 @@ "code", "zf2" ], - "time": "2016-10-24 13:23:32" + "time": "2016-10-24T13:23:32+00:00" }, { "name": "zendframework/zend-config", @@ -2120,7 +2119,7 @@ "config", "zf2" ], - "time": "2016-02-04 23:01:10" + "time": "2016-02-04T23:01:10+00:00" }, { "name": "zendframework/zend-console", @@ -2172,7 +2171,7 @@ "console", "zf2" ], - "time": "2016-02-09 17:15:12" + "time": "2016-02-09T17:15:12+00:00" }, { "name": "zendframework/zend-crypt", @@ -2222,7 +2221,7 @@ "crypt", "zf2" ], - "time": "2016-02-03 23:46:30" + "time": "2016-02-03T23:46:30+00:00" }, { "name": "zendframework/zend-db", @@ -2279,7 +2278,7 @@ "db", "zf2" ], - "time": "2016-08-09 19:28:55" + "time": "2016-08-09T19:28:55+00:00" }, { "name": "zendframework/zend-di", @@ -2326,7 +2325,7 @@ "di", "zf2" ], - "time": "2016-04-25 20:58:11" + "time": "2016-04-25T20:58:11+00:00" }, { "name": "zendframework/zend-escaper", @@ -2370,7 +2369,7 @@ "escaper", "zf2" ], - "time": "2016-06-30 19:48:38" + "time": "2016-06-30T19:48:38+00:00" }, { "name": "zendframework/zend-eventmanager", @@ -2417,20 +2416,20 @@ "eventmanager", "zf2" ], - "time": "2016-02-18 20:49:05" + "time": "2016-02-18T20:49:05+00:00" }, { "name": "zendframework/zend-filter", - "version": "2.7.1", + "version": "2.7.2", "source": { "type": "git", "url": "https://github.com/zendframework/zend-filter.git", - "reference": "84c50246428efb0a1e52868e162dab3e149d5b80" + "reference": "b8d0ff872f126631bf63a932e33aa2d22d467175" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-filter/zipball/84c50246428efb0a1e52868e162dab3e149d5b80", - "reference": "84c50246428efb0a1e52868e162dab3e149d5b80", + "url": "https://api.github.com/repos/zendframework/zend-filter/zipball/b8d0ff872f126631bf63a932e33aa2d22d467175", + "reference": "b8d0ff872f126631bf63a932e33aa2d22d467175", "shasum": "" }, "require": { @@ -2438,10 +2437,10 @@ "zendframework/zend-stdlib": "^2.7 || ^3.0" }, "require-dev": { - "fabpot/php-cs-fixer": "1.7.*", "pear/archive_tar": "^1.4", - "phpunit/phpunit": "~4.0", - "zendframework/zend-crypt": "^2.6", + "phpunit/phpunit": "^6.0.10 || ^5.7.17", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-crypt": "^2.6 || ^3.0", "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", "zendframework/zend-uri": "^2.5" }, @@ -2477,20 +2476,20 @@ "filter", "zf2" ], - "time": "2016-04-18 18:32:43" + "time": "2017-05-17T20:56:17+00:00" }, { "name": "zendframework/zend-form", - "version": "2.10.1", + "version": "2.10.2", "source": { "type": "git", "url": "https://github.com/zendframework/zend-form.git", - "reference": "1ca3ab771abd533d440646ec1cc082fccad976a1" + "reference": "252db729887844025772bb8045f8df605850ed9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-form/zipball/1ca3ab771abd533d440646ec1cc082fccad976a1", - "reference": "1ca3ab771abd533d440646ec1cc082fccad976a1", + "url": "https://api.github.com/repos/zendframework/zend-form/zipball/252db729887844025772bb8045f8df605850ed9c", + "reference": "252db729887844025772bb8045f8df605850ed9c", "shasum": "" }, "require": { @@ -2554,7 +2553,7 @@ "form", "zf2" ], - "time": "2017-04-26 21:27:43" + "time": "2017-05-18T14:59:53+00:00" }, { "name": "zendframework/zend-http", @@ -2604,7 +2603,7 @@ "http", "zf2" ], - "time": "2017-01-31 14:41:02" + "time": "2017-01-31T14:41:02+00:00" }, { "name": "zendframework/zend-hydrator", @@ -2662,30 +2661,30 @@ "hydrator", "zf2" ], - "time": "2016-02-18 22:38:26" + "time": "2016-02-18T22:38:26+00:00" }, { "name": "zendframework/zend-i18n", - "version": "2.7.3", + "version": "2.7.4", "source": { "type": "git", "url": "https://github.com/zendframework/zend-i18n.git", - "reference": "b2db0d8246a865c659f93199f90f5fc2cd2f3cd8" + "reference": "d3431e29cc00c2a1c6704e601d4371dbf24f6a31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-i18n/zipball/b2db0d8246a865c659f93199f90f5fc2cd2f3cd8", - "reference": "b2db0d8246a865c659f93199f90f5fc2cd2f3cd8", + "url": "https://api.github.com/repos/zendframework/zend-i18n/zipball/d3431e29cc00c2a1c6704e601d4371dbf24f6a31", + "reference": "d3431e29cc00c2a1c6704e601d4371dbf24f6a31", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", + "php": "^7.0 || ^5.6", "zendframework/zend-stdlib": "^2.7 || ^3.0" }, "require-dev": { - "fabpot/php-cs-fixer": "1.7.*", - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "^6.0.8 || ^5.7.15", "zendframework/zend-cache": "^2.6.1", + "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-config": "^2.6", "zendframework/zend-eventmanager": "^2.6.2 || ^3.0", "zendframework/zend-filter": "^2.6.1", @@ -2729,31 +2728,31 @@ "i18n", "zf2" ], - "time": "2016-06-07 21:08:30" + "time": "2017-05-17T17:00:12+00:00" }, { "name": "zendframework/zend-inputfilter", - "version": "2.7.3", + "version": "2.7.4", "source": { "type": "git", "url": "https://github.com/zendframework/zend-inputfilter.git", - "reference": "0cf1bdcd8858a8583965310a7dae63ad75bd1237" + "reference": "699ab4916e0aa73104e1f9ff068ef6d33c5f5fe4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-inputfilter/zipball/0cf1bdcd8858a8583965310a7dae63ad75bd1237", - "reference": "0cf1bdcd8858a8583965310a7dae63ad75bd1237", + "url": "https://api.github.com/repos/zendframework/zend-inputfilter/zipball/699ab4916e0aa73104e1f9ff068ef6d33c5f5fe4", + "reference": "699ab4916e0aa73104e1f9ff068ef6d33c5f5fe4", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", + "php": "^7.0 || ^5.6", "zendframework/zend-filter": "^2.6", "zendframework/zend-stdlib": "^2.7 || ^3.0", "zendframework/zend-validator": "^2.6" }, "require-dev": { - "phpunit/phpunit": "^4.8", - "squizlabs/php_codesniffer": "^2.6.2", + "phpunit/phpunit": "^6.0.8 || ^5.7.15", + "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3" }, "suggest": { @@ -2784,7 +2783,7 @@ "inputfilter", "zf2" ], - "time": "2016-08-18 18:40:34" + "time": "2017-05-18T14:20:56+00:00" }, { "name": "zendframework/zend-json", @@ -2839,7 +2838,7 @@ "json", "zf2" ], - "time": "2016-02-04 21:20:26" + "time": "2016-02-04T21:20:26+00:00" }, { "name": "zendframework/zend-loader", @@ -2883,20 +2882,20 @@ "loader", "zf2" ], - "time": "2015-06-03 14:05:47" + "time": "2015-06-03T14:05:47+00:00" }, { "name": "zendframework/zend-log", - "version": "2.9.1", + "version": "2.9.2", "source": { "type": "git", "url": "https://github.com/zendframework/zend-log.git", - "reference": "115d75db1f8fb29efbf1b9a49cb91c662b7195dc" + "reference": "bf7489578d092d6ff7508117d1d920a4764fbd6a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-log/zipball/115d75db1f8fb29efbf1b9a49cb91c662b7195dc", - "reference": "115d75db1f8fb29efbf1b9a49cb91c662b7195dc", + "url": "https://api.github.com/repos/zendframework/zend-log/zipball/bf7489578d092d6ff7508117d1d920a4764fbd6a", + "reference": "bf7489578d092d6ff7508117d1d920a4764fbd6a", "shasum": "" }, "require": { @@ -2909,9 +2908,9 @@ "psr/log-implementation": "1.0.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~1.7.0", "mikey179/vfsstream": "^1.6", - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "^5.7.15 || ^6.0.8", + "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-db": "^2.6", "zendframework/zend-escaper": "^2.5", "zendframework/zend-filter": "^2.5", @@ -2954,7 +2953,7 @@ "logging", "zf2" ], - "time": "2016-08-11 13:44:10" + "time": "2017-05-17T16:03:26+00:00" }, { "name": "zendframework/zend-math", @@ -3004,7 +3003,7 @@ "math", "zf2" ], - "time": "2016-04-07 16:29:53" + "time": "2016-04-07T16:29:53+00:00" }, { "name": "zendframework/zend-modulemanager", @@ -3063,7 +3062,7 @@ "modulemanager", "zf2" ], - "time": "2016-05-16 21:21:11" + "time": "2016-05-16T21:21:11+00:00" }, { "name": "zendframework/zend-mvc", @@ -3150,7 +3149,7 @@ "mvc", "zf2" ], - "time": "2016-02-23 15:24:59" + "time": "2016-02-23T15:24:59+00:00" }, { "name": "zendframework/zend-serializer", @@ -3207,7 +3206,7 @@ "serializer", "zf2" ], - "time": "2016-06-21 17:01:55" + "time": "2016-06-21T17:01:55+00:00" }, { "name": "zendframework/zend-server", @@ -3253,7 +3252,7 @@ "server", "zf2" ], - "time": "2016-06-20 22:27:55" + "time": "2016-06-20T22:27:55+00:00" }, { "name": "zendframework/zend-servicemanager", @@ -3305,7 +3304,7 @@ "servicemanager", "zf2" ], - "time": "2016-12-19 19:14:29" + "time": "2016-12-19T19:14:29+00:00" }, { "name": "zendframework/zend-session", @@ -3371,7 +3370,7 @@ "session", "zf2" ], - "time": "2016-07-05 18:32:50" + "time": "2016-07-05T18:32:50+00:00" }, { "name": "zendframework/zend-soap", @@ -3423,7 +3422,7 @@ "soap", "zf2" ], - "time": "2016-04-21 16:06:27" + "time": "2016-04-21T16:06:27+00:00" }, { "name": "zendframework/zend-stdlib", @@ -3482,7 +3481,7 @@ "stdlib", "zf2" ], - "time": "2016-04-12 21:17:31" + "time": "2016-04-12T21:17:31+00:00" }, { "name": "zendframework/zend-text", @@ -3529,7 +3528,7 @@ "text", "zf2" ], - "time": "2016-02-08 19:03:52" + "time": "2016-02-08T19:03:52+00:00" }, { "name": "zendframework/zend-uri", @@ -3576,20 +3575,20 @@ "uri", "zf2" ], - "time": "2016-02-17 22:38:51" + "time": "2016-02-17T22:38:51+00:00" }, { "name": "zendframework/zend-validator", - "version": "2.9.0", + "version": "2.9.1", "source": { "type": "git", "url": "https://github.com/zendframework/zend-validator.git", - "reference": "b71641582297eab52753b72cd4eb45a5ded4485c" + "reference": "c9a8160a0191e34bb98ac1ecd4e453391c424bb3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-validator/zipball/b71641582297eab52753b72cd4eb45a5ded4485c", - "reference": "b71641582297eab52753b72cd4eb45a5ded4485c", + "url": "https://api.github.com/repos/zendframework/zend-validator/zipball/c9a8160a0191e34bb98ac1ecd4e453391c424bb3", + "reference": "c9a8160a0191e34bb98ac1ecd4e453391c424bb3", "shasum": "" }, "require": { @@ -3647,7 +3646,7 @@ "validator", "zf2" ], - "time": "2017-03-17 10:15:50" + "time": "2017-05-17T22:06:13+00:00" }, { "name": "zendframework/zend-view", @@ -3734,7 +3733,7 @@ "view", "zf2" ], - "time": "2017-03-21 15:05:56" + "time": "2017-03-21T15:05:56+00:00" } ], "packages-dev": [ @@ -3790,7 +3789,7 @@ "constructor", "instantiate" ], - "time": "2015-06-14 21:17:01" + "time": "2015-06-14T21:17:01+00:00" }, { "name": "friendsofphp/php-cs-fixer", @@ -3860,7 +3859,7 @@ } ], "description": "A tool to automatically fix PHP code style", - "time": "2017-03-31 12:59:38" + "time": "2017-03-31T12:59:38+00:00" }, { "name": "ircmaxell/password-compat", @@ -3902,7 +3901,7 @@ "hashing", "password" ], - "time": "2014-11-20 16:49:30" + "time": "2014-11-20T16:49:30+00:00" }, { "name": "lusitanian/oauth", @@ -3969,7 +3968,7 @@ "oauth", "security" ], - "time": "2016-07-12 22:15:40" + "time": "2016-07-12T22:15:40+00:00" }, { "name": "pdepend/pdepend", @@ -4009,7 +4008,7 @@ "BSD-3-Clause" ], "description": "Official version of pdepend to be handled with Composer", - "time": "2017-01-19 14:23:36" + "time": "2017-01-19T14:23:36+00:00" }, { "name": "phpmd/phpmd", @@ -4075,7 +4074,7 @@ "phpmd", "pmd" ], - "time": "2017-01-20 14:41:10" + "time": "2017-01-20T14:41:10+00:00" }, { "name": "phpunit/php-code-coverage", @@ -4137,7 +4136,7 @@ "testing", "xunit" ], - "time": "2015-10-06 15:47:00" + "time": "2015-10-06T15:47:00+00:00" }, { "name": "phpunit/php-file-iterator", @@ -4182,7 +4181,7 @@ "filesystem", "iterator" ], - "time": "2013-10-10 15:34:57" + "time": "2013-10-10T15:34:57+00:00" }, { "name": "phpunit/php-text-template", @@ -4223,7 +4222,7 @@ "keywords": [ "template" ], - "time": "2015-06-21 13:50:34" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", @@ -4272,7 +4271,7 @@ "keywords": [ "timer" ], - "time": "2017-02-26 11:10:40" + "time": "2017-02-26T11:10:40+00:00" }, { "name": "phpunit/php-token-stream", @@ -4321,7 +4320,7 @@ "keywords": [ "tokenizer" ], - "time": "2017-02-27 10:12:30" + "time": "2017-02-27T10:12:30+00:00" }, { "name": "phpunit/phpunit", @@ -4395,7 +4394,7 @@ "testing", "xunit" ], - "time": "2014-05-02 07:13:40" + "time": "2014-05-02T07:13:40+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -4451,7 +4450,7 @@ "mock", "xunit" ], - "time": "2015-10-02 06:51:40" + "time": "2015-10-02T06:51:40+00:00" }, { "name": "sebastian/comparator", @@ -4515,27 +4514,27 @@ "compare", "equality" ], - "time": "2017-01-29 09:50:25" + "time": "2017-01-29T09:50:25+00:00" }, { "name": "sebastian/diff", - "version": "1.4.1", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" + "reference": "3c7d21999e815cdfac70c6c7d79d3a9cb1bc7bc2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3c7d21999e815cdfac70c6c7d79d3a9cb1bc7bc2", + "reference": "3c7d21999e815cdfac70c6c7d79d3a9cb1bc7bc2", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.8" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" }, "type": "library", "extra": { @@ -4567,7 +4566,7 @@ "keywords": [ "diff" ], - "time": "2015-12-08 07:14:41" + "time": "2017-05-18T13:44:30+00:00" }, { "name": "sebastian/environment", @@ -4617,7 +4616,7 @@ "environment", "hhvm" ], - "time": "2016-08-18 05:49:44" + "time": "2016-08-18T05:49:44+00:00" }, { "name": "sebastian/exporter", @@ -4684,7 +4683,7 @@ "export", "exporter" ], - "time": "2016-06-17 09:04:28" + "time": "2016-06-17T09:04:28+00:00" }, { "name": "sebastian/finder-facade", @@ -4723,7 +4722,7 @@ ], "description": "FinderFacade is a convenience wrapper for Symfony's Finder component.", "homepage": "https://github.com/sebastianbergmann/finder-facade", - "time": "2016-02-17 07:02:23" + "time": "2016-02-17T07:02:23+00:00" }, { "name": "sebastian/phpcpd", @@ -4774,7 +4773,7 @@ ], "description": "Copy/Paste Detector (CPD) for PHP code.", "homepage": "https://github.com/sebastianbergmann/phpcpd", - "time": "2016-04-17 19:32:49" + "time": "2016-04-17T19:32:49+00:00" }, { "name": "sebastian/recursion-context", @@ -4827,7 +4826,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-10-03 07:41:43" + "time": "2016-10-03T07:41:43+00:00" }, { "name": "sebastian/version", @@ -4862,7 +4861,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-06-21 13:59:46" + "time": "2015-06-21T13:59:46+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -4937,7 +4936,7 @@ "phpcs", "standards" ], - "time": "2014-05-01 03:07:07" + "time": "2014-05-01T03:07:07+00:00" }, { "name": "symfony/config", @@ -4993,7 +4992,7 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2017-04-12 14:13:17" + "time": "2017-04-12T14:13:17+00:00" }, { "name": "symfony/dependency-injection", @@ -5053,7 +5052,7 @@ ], "description": "Symfony DependencyInjection Component", "homepage": "https://symfony.com", - "time": "2017-01-28 00:04:57" + "time": "2017-01-28T00:04:57+00:00" }, { "name": "symfony/polyfill-php54", @@ -5111,7 +5110,7 @@ "portable", "shim" ], - "time": "2016-11-14 01:06:16" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/polyfill-php55", @@ -5167,7 +5166,7 @@ "portable", "shim" ], - "time": "2016-11-14 01:06:16" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/polyfill-php70", @@ -5226,7 +5225,7 @@ "portable", "shim" ], - "time": "2016-11-14 01:06:16" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/polyfill-xml", @@ -5284,7 +5283,7 @@ "portable", "shim" ], - "time": "2016-11-14 01:06:16" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/stopwatch", @@ -5333,7 +5332,7 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2017-04-12 14:13:17" + "time": "2017-04-12T14:13:17+00:00" }, { "name": "symfony/yaml", @@ -5382,7 +5381,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-05-01 14:31:55" + "time": "2017-05-01T14:31:55+00:00" }, { "name": "theseer/fdomdocument", @@ -5422,7 +5421,7 @@ ], "description": "The classes contained within this repository extend the standard DOM to use exceptions at all occasions of errors instead of PHP warnings or notices. They also add various custom methods and shortcuts for convenience and to simplify the usage of DOM.", "homepage": "https://github.com/theseer/fDOMDocument", - "time": "2017-04-21 14:50:31" + "time": "2017-04-21T14:50:31+00:00" } ], "aliases": [], From 4a96bade07b31aebd75a69b58a8ecd24691aca7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20R=C3=B6ttig?= Date: Sat, 20 May 2017 14:07:33 +0200 Subject: [PATCH 03/66] magento-engcom/magento2#25 Add new Inventory Module --- app/code/Magento/Inventory/LICENSE.txt | 48 +++++++++++++++++++++ app/code/Magento/Inventory/LICENSE_AFL.txt | 48 +++++++++++++++++++++ app/code/Magento/Inventory/README.md | 5 +++ app/code/Magento/Inventory/composer.json | 22 ++++++++++ app/code/Magento/Inventory/etc/module.xml | 14 ++++++ app/code/Magento/Inventory/registration.php | 11 +++++ 6 files changed, 148 insertions(+) create mode 100644 app/code/Magento/Inventory/LICENSE.txt create mode 100644 app/code/Magento/Inventory/LICENSE_AFL.txt create mode 100644 app/code/Magento/Inventory/README.md create mode 100644 app/code/Magento/Inventory/composer.json create mode 100644 app/code/Magento/Inventory/etc/module.xml create mode 100644 app/code/Magento/Inventory/registration.php diff --git a/app/code/Magento/Inventory/LICENSE.txt b/app/code/Magento/Inventory/LICENSE.txt new file mode 100644 index 000000000000..49525fd99da9 --- /dev/null +++ b/app/code/Magento/Inventory/LICENSE.txt @@ -0,0 +1,48 @@ + +Open Software License ("OSL") v. 3.0 + +This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Open Software License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/Inventory/LICENSE_AFL.txt b/app/code/Magento/Inventory/LICENSE_AFL.txt new file mode 100644 index 000000000000..f39d641b18a1 --- /dev/null +++ b/app/code/Magento/Inventory/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/Inventory/README.md b/app/code/Magento/Inventory/README.md new file mode 100644 index 000000000000..2defd616b65f --- /dev/null +++ b/app/code/Magento/Inventory/README.md @@ -0,0 +1,5 @@ +# Inventory + +**Inventory** provides implementation for inventory management. +See [concept documentation](https://github.com/magento-engcom/magento2/wiki/Technical-Vision.-Catalog-Inventory) +for further information. diff --git a/app/code/Magento/Inventory/composer.json b/app/code/Magento/Inventory/composer.json new file mode 100644 index 000000000000..dd85f89e58ec --- /dev/null +++ b/app/code/Magento/Inventory/composer.json @@ -0,0 +1,22 @@ +{ + "name": "magento/module-inventory", + "description": "N/A", + "require": { + "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", + "magento/framework": "100.2.*" + }, + "type": "magento2-module", + "version": "100.0.0-dev", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\InventoryApi\\": "" + } + } +} diff --git a/app/code/Magento/Inventory/etc/module.xml b/app/code/Magento/Inventory/etc/module.xml new file mode 100644 index 000000000000..2ef165277a57 --- /dev/null +++ b/app/code/Magento/Inventory/etc/module.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/app/code/Magento/Inventory/registration.php b/app/code/Magento/Inventory/registration.php new file mode 100644 index 000000000000..55b1734a5250 --- /dev/null +++ b/app/code/Magento/Inventory/registration.php @@ -0,0 +1,11 @@ + Date: Sat, 20 May 2017 14:18:01 +0200 Subject: [PATCH 04/66] magento-engcom/magento2#25: Update dependencies between inventory and inventory-api module --- app/code/Magento/Inventory/composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Inventory/composer.json b/app/code/Magento/Inventory/composer.json index dd85f89e58ec..2d2c53977084 100644 --- a/app/code/Magento/Inventory/composer.json +++ b/app/code/Magento/Inventory/composer.json @@ -3,7 +3,8 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/framework": "100.2.*" + "magento/framework": "100.2.*", + "magento/module-inventory-api": "100.0.*" }, "type": "magento2-module", "version": "100.0.0-dev", @@ -16,7 +17,7 @@ "registration.php" ], "psr-4": { - "Magento\\InventoryApi\\": "" + "Magento\\Inventory\\": "" } } } From 930a5206e82f974325c521368e6257fcde9c55f9 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 14:43:38 +0200 Subject: [PATCH 05/66] magento-engcom/magento2#25 remove chagnes from .gitignore file --- .gitignore | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/.gitignore b/.gitignore index f4a81c593afa..90c60dfa39ca 100644 --- a/.gitignore +++ b/.gitignore @@ -65,39 +65,3 @@ atlassian* !/vendor/.htaccess /generated/* !/generated/.htaccess - -## Sample data -app/code/Magento/BundleSampleData -app/code/Magento/CatalogRuleSampleData -app/code/Magento/CatalogSampleData -app/code/Magento/CmsSampleData -app/code/Magento/ConfigurableSampleData -app/code/Magento/CustomerSampleData -app/code/Magento/DownloadableSampleData -app/code/Magento/GroupedProductSampleData -app/code/Magento/MsrpSampleData -app/code/Magento/OfflineShippingSampleData -app/code/Magento/ProductLinksSampleData -app/code/Magento/ReviewSampleData -app/code/Magento/SalesRuleSampleData -app/code/Magento/SalesSampleData -app/code/Magento/SwatchesSampleData -app/code/Magento/TaxSampleData -app/code/Magento/ThemeSampleData -app/code/Magento/WidgetSampleData -app/code/Magento/WishlistSampleData -app/code/Magento/_InventoryApi/ -dev/tests/functional/tests/app/Magento/BundleSampleData -dev/tests/functional/tests/app/Magento/CatalogSampleData -dev/tests/functional/tests/app/Magento/ConfigurableSampleData -dev/tests/functional/tests/app/Magento/CustomerSampleData -dev/tests/functional/tests/app/Magento/DownloadableSampleData -dev/tests/functional/tests/app/Magento/GroupedProductSampleData -dev/tests/functional/tests/app/Magento/SalesSampleData -dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/sample-data.xml -dev/tests/integration/testsuite/Magento/SampleData/Helper -dev/tests/integration/testsuite/Magento/SampleData/Model/TestLogger.php -dev/tests/integration/testsuite/Magento/SampleData/_files/fixtures -dev/tools/build-sample-data.php -pub/media/catalog -pub/media/wysiwyg From e16e339fa705ff599a11eb544fe752f7bd563129 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 14:45:19 +0200 Subject: [PATCH 06/66] magento-engcom/magento2#24: Implement web API route configuration --- app/code/Magento/Inventory/etc/acl.xml | 18 ++++++++++++ app/code/Magento/Inventory/etc/webapi.xml | 34 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 app/code/Magento/Inventory/etc/acl.xml create mode 100644 app/code/Magento/Inventory/etc/webapi.xml diff --git a/app/code/Magento/Inventory/etc/acl.xml b/app/code/Magento/Inventory/etc/acl.xml new file mode 100644 index 000000000000..6ee353447968 --- /dev/null +++ b/app/code/Magento/Inventory/etc/acl.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/app/code/Magento/Inventory/etc/webapi.xml b/app/code/Magento/Inventory/etc/webapi.xml new file mode 100644 index 000000000000..746582646932 --- /dev/null +++ b/app/code/Magento/Inventory/etc/webapi.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 2b0a551b155c494cdbfb284ccbb0445d8ab2aec1 Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Sat, 20 May 2017 15:05:47 +0200 Subject: [PATCH 07/66] magento-engcom/magento2#25: Source API Implementation --- .../Magento/InventoryApi/Api/Data/SourceInterface.php | 9 +++++++-- .../Api/Data/SourceSearchResultsInterface.php | 5 ++++- .../InventoryApi/Api/SourceRepositoryInterface.php | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index dd8a864b3088..acc63d213b42 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -1,11 +1,16 @@ Date: Sat, 20 May 2017 15:11:33 +0200 Subject: [PATCH 08/66] magento-engcom/magento2#24: Move ACL and WebApi routes to InterfaceApi module --- app/code/Magento/{Inventory => InventoryApi}/etc/acl.xml | 0 app/code/Magento/{Inventory => InventoryApi}/etc/webapi.xml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename app/code/Magento/{Inventory => InventoryApi}/etc/acl.xml (100%) rename app/code/Magento/{Inventory => InventoryApi}/etc/webapi.xml (100%) diff --git a/app/code/Magento/Inventory/etc/acl.xml b/app/code/Magento/InventoryApi/etc/acl.xml similarity index 100% rename from app/code/Magento/Inventory/etc/acl.xml rename to app/code/Magento/InventoryApi/etc/acl.xml diff --git a/app/code/Magento/Inventory/etc/webapi.xml b/app/code/Magento/InventoryApi/etc/webapi.xml similarity index 100% rename from app/code/Magento/Inventory/etc/webapi.xml rename to app/code/Magento/InventoryApi/etc/webapi.xml From 2acced57c147b8edf1fa7cb250a08b35b04ac95d Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 15:13:55 +0200 Subject: [PATCH 09/66] magento-engcom/magento2#25: Remove \Magento\InventoryApi\Api\Data\SourceExtensionInterface as it will be autogenerated --- .../Api/Data/SourceExtensionInterface.php | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 app/code/Magento/InventoryApi/Api/Data/SourceExtensionInterface.php diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceExtensionInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceExtensionInterface.php deleted file mode 100644 index 82c05acac2e1..000000000000 --- a/app/code/Magento/InventoryApi/Api/Data/SourceExtensionInterface.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Sat, 20 May 2017 15:25:00 +0200 Subject: [PATCH 10/66] magento-engcom/magento2#25: Source API Implementation --- .../Api/Data/SourceSearchResultsInterface.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php index 1cd94bedb6aa..2a24ead8fe56 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php @@ -5,10 +5,25 @@ */ namespace Magento\InventoryApi\Api\Data; +use Magento\Framework\Api\SearchResultsInterface; + /** * @api */ -interface SourceSearchResultsInterface +interface SourceSearchResultsInterface extends SearchResultsInterface { + /** + * Get sources list. + * + * @return \Magento\InventoryApi\Api\Data\SourceInterface[] + */ + public function getItems(); -} \ No newline at end of file + /** + * Set sources list. + * + * @param \Magento\InventoryApi\Api\Data\SourceInterface[] $items + * @return $this + */ + public function setItems(array $items); +} From bb10b2ae5db1ea5424773dd45bef7c7c46b04afc Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 20 May 2017 15:58:44 +0200 Subject: [PATCH 11/66] magento-engcom/magento2#7 Add missing empty interface class --- .../Api/Data/SourceCarrierLinkInterface.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php new file mode 100644 index 000000000000..57ada1c5788a --- /dev/null +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -0,0 +1,15 @@ + Date: Sat, 20 May 2017 16:09:33 +0200 Subject: [PATCH 12/66] Filled SourceCarrierLinkInterface with some methods --- .../Api/Data/SourceCarrierLinkInterface.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 57ada1c5788a..465601115393 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -9,7 +9,24 @@ namespace Magento\InventoryApi\Api\Data; +use Magento\Shipping\Model\Carrier\CarrierInterface; + interface SourceCarrierLinkInterface { + /** + * @param SourceInterface $source + * @return void + */ + public function setSource(SourceInterface $source); + + /** + * @param CarrierInterface $carrier + * @return void + */ + public function setCarrier(CarrierInterface $carrier); + /** + * @return $this + */ + public function getSourceCarrierLink(); } \ No newline at end of file From 4999f0d961b1e655d0182f5af9605824892845a9 Mon Sep 17 00:00:00 2001 From: Thomas Kreidenhuber Date: Sat, 20 May 2017 16:09:39 +0200 Subject: [PATCH 13/66] magento-engcom/magento2#25 Implemented Resourcemodel, Collection and part of the businessmodel for source --- .../Inventory/Model/Resource/Source.php | 27 + .../Model/Resource/Source/Collection.php | 31 ++ app/code/Magento/Inventory/Model/Source.php | 465 ++++++++++++++++++ 3 files changed, 523 insertions(+) create mode 100644 app/code/Magento/Inventory/Model/Resource/Source.php create mode 100644 app/code/Magento/Inventory/Model/Resource/Source/Collection.php create mode 100644 app/code/Magento/Inventory/Model/Source.php diff --git a/app/code/Magento/Inventory/Model/Resource/Source.php b/app/code/Magento/Inventory/Model/Resource/Source.php new file mode 100644 index 000000000000..5eeae65abdf7 --- /dev/null +++ b/app/code/Magento/Inventory/Model/Resource/Source.php @@ -0,0 +1,27 @@ +_init(InstallSchema::TABLE_NAME_SOURCE, SourceInterface::SOURCE_ID); + } +} \ No newline at end of file diff --git a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php new file mode 100644 index 000000000000..f1f8170a8bd3 --- /dev/null +++ b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php @@ -0,0 +1,31 @@ +_init(SourceModel::class, ResourceSource::class); + } + + /** + * Id field name getter + * + * @return string + */ + public function getIdFieldName() + { + return SourceInterface::SOURCE_ID; + } +} \ No newline at end of file diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php new file mode 100644 index 000000000000..3a3092e116c4 --- /dev/null +++ b/app/code/Magento/Inventory/Model/Source.php @@ -0,0 +1,465 @@ +_init('Magento\Inventory\Model\Resource\Source'); + } + + /** + * Get source id. + * + * @return int|null + */ + public function getSourceId() + { + return $this->getData(SourceInterface::SOURCE_ID); + } + + /** + * Set source id. + * + * @param int $sourceId + * + * @return $this + */ + public function setSourceId($sourceId) + { + $this->setData(SourceInterface::SOURCE_ID, $sourceId); + return $this; + } + + /** + * Get source name. + * + * @return string + */ + public function getName() + { + return $this->getData(SourceInterface::NAME); + } + + /** + * Set source name. + * + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->setData(SourceInterface::NAME, $name); + return $this; + } + + /** + * Get source email + * + * @return string + */ + public function getEmail() + { + return $this->getData(SourceInterface::EMAIL); + } + + /** + * Set source email + * + * @param string $email + * + * @return $this + */ + public function setEmail($email) + { + $this->setData(SourceInterface::EMAIL, $email); + return $this; + } + + /** + * Get source contact name. + * + * @return string + */ + public function getContactName() + { + return $this->getData(SourceInterface::CONTACT_NAME); + } + + /** + * Set source contact name. + * + * @param string $contactName + * + * @return $this + */ + public function setContactName($contactName) + { + $this->setData(SourceInterface::CONTACT_NAME, $contactName); + return $this; + } + + /** + * Check if source is enabled. + * + * @return bool + */ + public function getIsActive() + { + return $this->getData(SourceInterface::IS_ACTIVE); + } + + /** + * Enable or disable source. + * + * @param bool $active + * + * @return $this + */ + public function setIsActive($active) + { + $this->setData(SourceInterface::IS_ACTIVE, $active); + return $this; + } + + /** + * Get source description. + * + * @return string + */ + public function getDescription() + { + return $this->getData(SourceInterface::DESCRIPTION); + } + + /** + * Set source description. + * + * @param string $description + * + * @return $this + */ + public function setDescription($description) + { + $this->setData(SourceInterface::DESCRIPTION, $description); + return $this; + } + + /** + * Get source latitude. + * + * @return float + */ + public function getLatitude() + { + return $this->getData(SourceInterface::LATITUDE); + } + + /** + * Set source latitude. + * + * @param float $latitude + * + * @return $this + */ + public function setLatitude($latitude) + { + $this->setData(SourceInterface::LATITUDE, $latitude); + return $this; + } + + /** + * Get source longitude. + * + * @return int + */ + public function getLongitude() + { + return $this->getData(SourceInterface::LONGITUDE); + } + + /** + * Set source longitude. + * + * @param int $longitude + * + * @return $this + */ + public function setLongitude($longitude) + { + $this->setData(SourceInterface::LONGITUDE, $longitude); + return $this; + } + + /** + * Get source country id. + * + * @return string + */ + public function getCountryId() + { + return $this->getData(SourceInterface::COUNTRY_ID); + } + + /** + * Set source country id. + * + * @param string $countryId + * + * @return $this + */ + public function setCountryId($countryId) + { + $this->setData(SourceInterface::COUNTRY_ID, $countryId); + return $this; + } + + /** + * Get region id if source has registered region. + * + * @return int + */ + public function getRegionId() + { + return $this->getData(SourceInterface::REGION_ID); + } + + /** + * Set region id if source has registered region. + * + * @param int $regionId + * + * @return $this + */ + public function setRegionId($regionId) + { + $this->setData(SourceInterface::REGION_ID, $regionId); + return $this; + } + + /** + * Get region title if source has custom region + * + * @return string + */ + public function getRegion() + { + return $this->getData(SourceInterface::REGION); + } + + /** + * Set source region title. + * + * @param string $region + * + * @return $this + */ + public function setRegion($region) + { + $this->setData(SourceInterface::REGION, $region); + return $this; + } + + /** + * Get source city. + * + * @return string + */ + public function getCity() + { + return $this->getData(SourceInterface::CITY); + } + + /** + * Set source city. + * + * @param string $city + * + * @return $this + */ + public function setCity($city) + { + $this->setData(SourceInterface::CITY, $city); + return $this; + } + + /** + * Get source street name. + * + * @return string + */ + public function getStreet() + { + return $this->getData(SourceInterface::STREET); + } + + /** + * Set source street name. + * + * @param string $street + * + * @return $this + */ + public function setStreet($street) + { + $this->setData(SourceInterface::STREET, $street); + return $this; + } + + /** + * Get source post code. + * + * @return string + */ + public function getPostcode() + { + return $this->getData(SourceInterface::POSTCODE); + } + + /** + * Set source post code. + * + * @param string $postcode + * + * @return $this + */ + public function setPostcode($postcode) + { + $this->setData(SourceInterface::POSTCODE, $postcode); + return $this; + } + + /** + * Get source phone number. + * + * @return string + */ + public function getPhone() + { + return $this->getData(SourceInterface::PHONE); + } + + /** + * Set source phone number. + * + * @param string $phone + * + * @return $this + */ + public function setPhone($phone) + { + $this->setData(SourceInterface::PHONE, $phone); + return $this; + } + + /** + * Get source fax. + * + * @return string + */ + public function getFax() + { + return $this->getData(SourceInterface::FAX); + } + + /** + * Set source fax. + * + * @param string $fax + * + * @return $this + */ + public function setFax($fax) + { + $this->setData(SourceInterface::FAX, $fax); + return $this; + } + + /** + * Get source priority + * + * @return int + */ + public function getPriority() + { + return $this->getData(SourceInterface::PRIORITY); + } + + /** + * Set source priority + * + * @param int $priority + * + * @return $this + */ + public function setPriority($priority) + { + $this->setData(SourceInterface::PRIORITY, $priority); + return $this; + } + + /** + * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] + */ + public function getCarrierLinks() + { + // TODO: Implement getCarrierLinks() method. + } + + /** + * @param \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] $carrierLinks + * + * @return $this + */ + public function setCarrierLinks($carrierLinks) + { + // TODO: Implement setCarrierLinks() method. + } + + /** + * Retrieve existing extension attributes object or create a new one. + * + * @return \Magento\InventoryApi\Api\Data\SourceExtensionInterface|null + */ + public function getExtensionAttributes() + { + // TODO: Implement getExtensionAttributes() method. + } + + /** + * Set an extension attributes object. + * + * @param \Magento\InventoryApi\Api\Data\SourceExtensionInterface $extensionAttributes + * + * @return $this + */ + public function setExtensionAttributes( + \Magento\InventoryApi\Api\Data\SourceExtensionInterface $extensionAttributes + ) { + // TODO: Implement setExtensionAttributes() method. + } +} \ No newline at end of file From 17a3cde3c921e0372938cde2165621200cb9cb4f Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 16:16:10 +0200 Subject: [PATCH 14/66] magento-engcom/magento2#25: Implement repository model for inventory sources --- .../Inventory/Model/SourceRepository.php | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 app/code/Magento/Inventory/Model/SourceRepository.php diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php new file mode 100644 index 000000000000..76ec8e07f293 --- /dev/null +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -0,0 +1,135 @@ +resource = $resource; + $this->sourceFactory = $sourceFactory; + $this->collectionProcessor = $collectionProcessor; + $this->collectionFactory = $collectionFactory; + $this->sourceSearchResultsFactory = $sourceSearchResultsFactory; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * Save Source data. + * + * @param SourceInterface $source + * @return SourceInterface + * + * @throws CouldNotSaveException + */ + public function save(SourceInterface $source) + { + try { + $this->resource->save($source); + } catch (\Exception $exception) { + throw new CouldNotSaveException(__($exception->getMessage())); + } + return $source; + } + + /** + * Load Source data by given sourceId. + * + * @param int $sourceId + * @return SourceInterface + */ + public function get($sourceId) + { + + } + + /** + * Load source data collection by given search criteria + * + * @param SearchCriteriaInterface $searchCriteria + * @return SourceSearchResultsInterface + */ + public function getList(SearchCriteriaInterface $searchCriteria = null) + { + /** @var \Magento\Inventory\Model\Resource\Source\Collection $collection */ + $collection = $this->collectionFactory->create(); + $this->collectionProcessor->process($searchCriteria, $collection); + + /** @var SourceInterface[] $sources */ + $sources = []; + /** @var SourceInterface $source */ + foreach ($collection->getItems() as $source) { + $addresses[] = $source; + } + + /** @var SourceSearchResultsInterface $searchResults */ + $searchResults = $this->sourceSearchResultsFactory->create(); + $searchResults->setItems($sources); + $searchResults->setSearchCriteria($searchCriteria); + $searchResults->setTotalCount($collection->getSize()); + return $searchResults; + } +} From 8e26b843b75bc83d096c06a4a8337aa8b81383c1 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 16:40:28 +0200 Subject: [PATCH 15/66] magento-engcom/magento2#25: Implement get() method in SourceRepository --- app/code/Magento/Inventory/Model/SourceRepository.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 76ec8e07f293..8759f466da9c 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -9,6 +9,7 @@ use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; +use Magento\Framework\Model\AbstractModel; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; use Magento\InventoryApi\Api\SourceRepositoryInterface; @@ -103,7 +104,10 @@ public function save(SourceInterface $source) */ public function get($sourceId) { - + /** @var SourceInterface|AbstractModel $model */ + $model = $this->sourceFactory->create(); + $this->resource->load($model, SourceInterface::SOURCE_ID, $sourceId); + return $model; } /** From 8eaeb062b323d7622d64788041c2770b81147af5 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 16:52:54 +0200 Subject: [PATCH 16/66] magento-engcom/magento2#25: Change protected properties to private --- .../Magento/Inventory/Model/SourceRepository.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 8759f466da9c..535e681036a2 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -26,32 +26,32 @@ class SourceRepository implements SourceRepositoryInterface /** * @var ResourceSource */ - protected $resource; + private $resource; /** * @var SourceFactory */ - protected $sourceFactory; + private $sourceFactory; /** * @var CollectionProcessorInterface */ - protected $collectionProcessor; + private $collectionProcessor; /** * @var CollectionFactory */ - protected $collectionFactory; + private $collectionFactory; /** * @var SourceSearchResultsFactory */ - protected $sourceSearchResultsFactory; + private $sourceSearchResultsFactory; /** * @var SearchCriteriaBuilder */ - protected $searchCriteriaBuilder; + private $searchCriteriaBuilder; /** * SourceRepository constructor. From fce8cc468ecf5c360bbdb46b2acc4405a39a5979 Mon Sep 17 00:00:00 2001 From: Oleksii Korshenko Date: Sat, 20 May 2017 16:53:41 +0200 Subject: [PATCH 17/66] magento-engcom/magento2#25: Source API Implementation - fixed code style issues --- .../Inventory/Model/Resource/Source.php | 2 +- .../Model/Resource/Source/Collection.php | 8 +++- app/code/Magento/Inventory/Model/Source.php | 47 +++++-------------- .../Api/Data/SourceCarrierLinkInterface.php | 13 ++++- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/app/code/Magento/Inventory/Model/Resource/Source.php b/app/code/Magento/Inventory/Model/Resource/Source.php index 5eeae65abdf7..e955eecadf16 100644 --- a/app/code/Magento/Inventory/Model/Resource/Source.php +++ b/app/code/Magento/Inventory/Model/Resource/Source.php @@ -24,4 +24,4 @@ protected function _construct() { $this->_init(InstallSchema::TABLE_NAME_SOURCE, SourceInterface::SOURCE_ID); } -} \ No newline at end of file +} diff --git a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php index f1f8170a8bd3..0c5c6dd069a4 100644 --- a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php +++ b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php @@ -1,4 +1,10 @@ _init('Magento\Inventory\Model\Resource\Source'); + $this->_init(\Magento\Inventory\Model\Resource\Source::class); } /** @@ -45,7 +44,6 @@ public function getSourceId() * Set source id. * * @param int $sourceId - * * @return $this */ public function setSourceId($sourceId) @@ -68,7 +66,6 @@ public function getName() * Set source name. * * @param string $name - * * @return $this */ public function setName($name) @@ -78,7 +75,7 @@ public function setName($name) } /** - * Get source email + * Get source email. * * @return string */ @@ -90,8 +87,7 @@ public function getEmail() /** * Set source email * - * @param string $email - * + * @param string $email. * @return $this */ public function setEmail($email) @@ -102,7 +98,6 @@ public function setEmail($email) /** * Get source contact name. - * * @return string */ public function getContactName() @@ -114,7 +109,6 @@ public function getContactName() * Set source contact name. * * @param string $contactName - * * @return $this */ public function setContactName($contactName) @@ -137,7 +131,6 @@ public function getIsActive() * Enable or disable source. * * @param bool $active - * * @return $this */ public function setIsActive($active) @@ -160,7 +153,6 @@ public function getDescription() * Set source description. * * @param string $description - * * @return $this */ public function setDescription($description) @@ -183,7 +175,6 @@ public function getLatitude() * Set source latitude. * * @param float $latitude - * * @return $this */ public function setLatitude($latitude) @@ -206,7 +197,6 @@ public function getLongitude() * Set source longitude. * * @param int $longitude - * * @return $this */ public function setLongitude($longitude) @@ -229,7 +219,6 @@ public function getCountryId() * Set source country id. * * @param string $countryId - * * @return $this */ public function setCountryId($countryId) @@ -252,7 +241,6 @@ public function getRegionId() * Set region id if source has registered region. * * @param int $regionId - * * @return $this */ public function setRegionId($regionId) @@ -262,7 +250,7 @@ public function setRegionId($regionId) } /** - * Get region title if source has custom region + * Get region title if source has custom region. * * @return string */ @@ -275,7 +263,6 @@ public function getRegion() * Set source region title. * * @param string $region - * * @return $this */ public function setRegion($region) @@ -298,7 +285,6 @@ public function getCity() * Set source city. * * @param string $city - * * @return $this */ public function setCity($city) @@ -321,7 +307,6 @@ public function getStreet() * Set source street name. * * @param string $street - * * @return $this */ public function setStreet($street) @@ -344,7 +329,6 @@ public function getPostcode() * Set source post code. * * @param string $postcode - * * @return $this */ public function setPostcode($postcode) @@ -367,7 +351,6 @@ public function getPhone() * Set source phone number. * * @param string $phone - * * @return $this */ public function setPhone($phone) @@ -390,7 +373,6 @@ public function getFax() * Set source fax. * * @param string $fax - * * @return $this */ public function setFax($fax) @@ -400,7 +382,7 @@ public function setFax($fax) } /** - * Get source priority + * Get source priority. * * @return int */ @@ -410,10 +392,9 @@ public function getPriority() } /** - * Set source priority + * Set source priority. * * @param int $priority - * * @return $this */ public function setPriority($priority) @@ -422,8 +403,7 @@ public function setPriority($priority) return $this; } - /** - * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] + /** @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] */ public function getCarrierLinks() { @@ -432,7 +412,6 @@ public function getCarrierLinks() /** * @param \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] $carrierLinks - * * @return $this */ public function setCarrierLinks($carrierLinks) @@ -447,7 +426,7 @@ public function setCarrierLinks($carrierLinks) */ public function getExtensionAttributes() { - // TODO: Implement getExtensionAttributes() method. + return $this->_getExtensionAttributes(); } /** @@ -460,6 +439,6 @@ public function getExtensionAttributes() public function setExtensionAttributes( \Magento\InventoryApi\Api\Data\SourceExtensionInterface $extensionAttributes ) { - // TODO: Implement setExtensionAttributes() method. + return $this->_setExtensionAttributes($extensionAttributes); } -} \ No newline at end of file +} diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 465601115393..7b56bf08ccf5 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -8,25 +8,34 @@ namespace Magento\InventoryApi\Api\Data; - use Magento\Shipping\Model\Carrier\CarrierInterface; +/** + * Linkage interface between sources and carrier. + * @api + */ interface SourceCarrierLinkInterface { /** + * Set source. + * * @param SourceInterface $source * @return void */ public function setSource(SourceInterface $source); /** + * Set carrier. + * * @param CarrierInterface $carrier * @return void */ public function setCarrier(CarrierInterface $carrier); /** + * Get link. + * * @return $this */ public function getSourceCarrierLink(); -} \ No newline at end of file +} From de622ffbbb8c110bd3e84c0207a0e22ec63d00ca Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 17:13:31 +0200 Subject: [PATCH 18/66] magento-engcom/magento2#25: Update docblock for method in order to follow the inherit doc from interface --- .../Inventory/Model/Resource/Source.php | 7 +- .../Model/Resource/Source/Collection.php | 20 +- app/code/Magento/Inventory/Model/Source.php | 201 ++++-------------- .../Inventory/Model/SourceRepository.php | 18 +- .../CollectionProcessorInterface.php | 2 +- 5 files changed, 62 insertions(+), 186 deletions(-) diff --git a/app/code/Magento/Inventory/Model/Resource/Source.php b/app/code/Magento/Inventory/Model/Resource/Source.php index 5eeae65abdf7..8870f20abbff 100644 --- a/app/code/Magento/Inventory/Model/Resource/Source.php +++ b/app/code/Magento/Inventory/Model/Resource/Source.php @@ -13,12 +13,7 @@ class Source extends AbstractDb { /** - * Initialize resource model - * - * @return void - * - * @codingStandardsIgnore - * @codeCoverageIgnore + * @inheritdoc */ protected function _construct() { diff --git a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php index f1f8170a8bd3..de45b3c231d6 100644 --- a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php +++ b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php @@ -1,18 +1,24 @@ Date: Sat, 20 May 2017 17:18:44 +0200 Subject: [PATCH 19/66] magento-engcom/magento2#25: Update interfaces in order to use USE statements --- .../Inventory/Model/SourceRepository.php | 16 ++++++------- .../Api/Data/SourceCarrierLinkInterface.php | 11 +++++---- .../Api/SourceRepositoryInterface.php | 23 ++++++++++++------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 585662e9b688..2a7614508a95 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -10,6 +10,7 @@ use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Model\AbstractModel; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; @@ -49,11 +50,6 @@ class SourceRepository implements SourceRepositoryInterface */ private $sourceSearchResultsFactory; - /** - * @var SearchCriteriaBuilder - */ - private $searchCriteriaBuilder; - /** * SourceRepository constructor. * @param ResourceSource $resource @@ -61,22 +57,19 @@ class SourceRepository implements SourceRepositoryInterface * @param CollectionProcessorInterface $collectionProcessor * @param CollectionFactory $collectionFactory * @param SourceSearchResultsFactory $sourceSearchResultsFactory - * @param SearchCriteriaBuilder $searchCriteriaBuilder */ public function __construct( ResourceSource $resource, SourceFactory $sourceFactory, CollectionProcessorInterface $collectionProcessor, CollectionFactory $collectionFactory, - SourceSearchResultsFactory $sourceSearchResultsFactory, - SearchCriteriaBuilder $searchCriteriaBuilder + SourceSearchResultsFactory $sourceSearchResultsFactory ) { $this->resource = $resource; $this->sourceFactory = $sourceFactory; $this->collectionProcessor = $collectionProcessor; $this->collectionFactory = $collectionFactory; $this->sourceSearchResultsFactory = $sourceSearchResultsFactory; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; } /** @@ -100,6 +93,11 @@ public function get($sourceId) /** @var SourceInterface|AbstractModel $model */ $model = $this->sourceFactory->create(); $this->resource->load($model, SourceInterface::SOURCE_ID, $sourceId); + + if (!$model->getId()) { + NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId); + } + return $model; } diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 465601115393..506ffaa6f891 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -1,16 +1,17 @@ Date: Sat, 20 May 2017 17:24:23 +0200 Subject: [PATCH 20/66] Wip --- .../Magento/Inventory/Setup/InstallSchema.php | 216 ++++++++++++++++++ .../Api/Data/SourceCarrierLinkInterface.php | 3 - 2 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/Inventory/Setup/InstallSchema.php diff --git a/app/code/Magento/Inventory/Setup/InstallSchema.php b/app/code/Magento/Inventory/Setup/InstallSchema.php new file mode 100644 index 000000000000..467d276e0911 --- /dev/null +++ b/app/code/Magento/Inventory/Setup/InstallSchema.php @@ -0,0 +1,216 @@ +startSetup(); + + $tableNameSourceEntity = $installer->getTable(InstallSchema::TABLE_NAME_SOURCE); + if (!$installer->getConnection()->isTableExists($tableNameSourceEntity)) { + + $table = $installer->getConnection()->newTable($tableNameSourceEntity); + + $options = [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_PRIMARY => true + ]; + $table->addColumn(SourceInterface::SOURCE_ID, Table::TYPE_INTEGER, null, $options, 'Source ID'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::NAME, Table::TYPE_TEXT, null, $options, 'Source Name'); + + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::CONTACT_NAME, Table::TYPE_TEXT, null, $options, 'Contact Name'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::EMAIL, Table::TYPE_TEXT, null, $options, 'Email'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_DEFAULT => 1 + ]; + $table->addColumn(SourceInterface::IS_ACTIVE, + Table::TYPE_SMALLINT, + null, + $options, + 'Defines Is Source Active'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::DESCRIPTION, Table::TYPE_TEXT, null, $options, 'Description'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::LATITUDE, Table::TYPE_TEXT, null, $options, 'Latitude'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::LONGITUDE, Table::TYPE_TEXT, null, $options, 'Longitude'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_DEFAULT => 1 + ]; + + $table->addColumn(SourceInterface::COUNTRY_ID, Table::TYPE_SMALLINT, null, $options, 'Country Id'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_DEFAULT => 1 + ]; + + $table->addColumn(SourceInterface::REGION_ID, Table::TYPE_SMALLINT, null, $options, 'Region Id'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::REGION, Table::TYPE_TEXT, null, $options, 'Region'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::CITY, Table::TYPE_TEXT, null, $options, 'City'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::STREET, Table::TYPE_TEXT, null, $options, 'Street'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::POSTCODE, Table::TYPE_TEXT, null, $options, 'Postcode'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::PHONE, Table::TYPE_TEXT, null, $options, 'Phone'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + $table->addColumn(SourceInterface::FAX, Table::TYPE_TEXT, null, $options, 'Fax'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_DEFAULT => 1 + ]; + + $table->addColumn(SourceInterface::PRIORITY, Table::TYPE_SMALLINT, null, $options, 'Priority'); + + + $table->setComment('Inventory Source Entity Table')->setOption('type', 'InnoDB')->setOption('charset', + 'utf8'); + $installer->getConnection()->createTable($table); + } + + $tableNamePipelineEntity = $installer->getTable(InstallSchema::TABLE_NAME_SOURCE); + if (!$installer->getConnection()->isTableExists($tableNamePipelineEntity)) { + + $table = $installer->getConnection()->newTable($tableNameSourceEntity); + + $options = [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + ]; + $table->addColumn('source_carrier_link_id', + Table::TYPE_INTEGER, + null, + $options, + 'Source ID' + ); + + $options = [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_PRIMARY => true + ]; + $table->addColumn(SourceInterface::SOURCE_ID, Table::TYPE_INTEGER, null, $options, 'Source ID'); + + $options = [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ]; + + $table->addColumn( + + Table::TYPE_TEXT, + null, + $options, + 'Source Name' + ); + + } + + + $setup->endSetup(); + } +} diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 465601115393..d4e562329ff3 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -8,9 +8,6 @@ namespace Magento\InventoryApi\Api\Data; - -use Magento\Shipping\Model\Carrier\CarrierInterface; - interface SourceCarrierLinkInterface { /** From 7d0c54bffbbb5b7c14423037a056bff722f0f885 Mon Sep 17 00:00:00 2001 From: Thomas Kreidenhuber Date: Sat, 20 May 2017 17:35:11 +0200 Subject: [PATCH 21/66] magento-engcom/magento2#25 Implemented Resourcemodel, Collection and part of the businessmodel for sourcecarrierlink, updated carrierlink-interface, implemented part of source-businessmodel --- .../Model/Resource/Source/Collection.php | 5 ++ .../Model/Resource/SourceCarrierLink.php | 27 ++++++ .../Resource/SourceCarrierLink/Collection.php | 36 ++++++++ app/code/Magento/Inventory/Model/Source.php | 10 ++- .../Inventory/Model/SourceCarrierLink.php | 86 +++++++++++++++++++ .../Api/Data/SourceCarrierLinkInterface.php | 65 ++++++++++---- 6 files changed, 210 insertions(+), 19 deletions(-) create mode 100644 app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php create mode 100644 app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php create mode 100644 app/code/Magento/Inventory/Model/SourceCarrierLink.php diff --git a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php index f1f8170a8bd3..5740517edb9e 100644 --- a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php +++ b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php @@ -1,4 +1,9 @@ _init(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK, 'source_carrier_link_id'); + } +} \ No newline at end of file diff --git a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php b/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php new file mode 100644 index 000000000000..504845bd0012 --- /dev/null +++ b/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php @@ -0,0 +1,36 @@ +_init(SourceCarrierLinkModel::class, ResourceSourceCarrierLink::class); + } + + /** + * Id field name getter + * + * @return string + */ + public function getIdFieldName() + { + return 'source_carrier_link_id'; + } +} \ No newline at end of file diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index 3a3092e116c4..abdec0065208 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -427,7 +427,7 @@ public function setPriority($priority) */ public function getCarrierLinks() { - // TODO: Implement getCarrierLinks() method. + return $this->getData(SourceInterface::PRIORITY); } /** @@ -437,7 +437,8 @@ public function getCarrierLinks() */ public function setCarrierLinks($carrierLinks) { - // TODO: Implement setCarrierLinks() method. + $this->setData(SourceInterface::CARRIER_LINKS, $carrierLinks); + return $this; } /** @@ -447,7 +448,7 @@ public function setCarrierLinks($carrierLinks) */ public function getExtensionAttributes() { - // TODO: Implement getExtensionAttributes() method. + return $this->getData(SourceInterface::EXTENSION_ATTRIBUTES_KEY); } /** @@ -460,6 +461,7 @@ public function getExtensionAttributes() public function setExtensionAttributes( \Magento\InventoryApi\Api\Data\SourceExtensionInterface $extensionAttributes ) { - // TODO: Implement setExtensionAttributes() method. + $this->setData(SourceInterface::EXTENSION_ATTRIBUTES_KEY, $extensionAttributes); + return $this; } } \ No newline at end of file diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/SourceCarrierLink.php new file mode 100644 index 000000000000..1c66cc1d8b67 --- /dev/null +++ b/app/code/Magento/Inventory/Model/SourceCarrierLink.php @@ -0,0 +1,86 @@ +_init('Magento\Inventory\Model\Resource\SourceCarrierLink'); + } + + + /** + * @inheritDoc + */ + public function getCarrierCode() + { + $this->getData(SourceCarrierLinkInterface::CARRIER_CODE); + } + + /** + * @inheritDoc + */ + public function setCarrierCode($carrierCode) + { + $this->setData(SourceCarrierLinkInterface::CARRIER_CODE, $carrierCode); + return $this; + } + + /** + * @inheritDoc + */ + public function getPosition() + { + $this->getData(SourceCarrierLinkInterface::POSITION); + } + + /** + * @inheritDoc + */ + public function setPosition($position) + { + $this->setData(SourceCarrierLinkInterface::POSITION, $position); + return $this; + } + + /** + * @inheritDoc + */ + public function getExtensionAttributes() + { + $this->getData(SourceCarrierLinkInterface::EXTENSION_ATTRIBUTES_KEY); + } + + /** + * @inheritDoc + */ + public function setExtensionAttributes( + \Magento\InventoryApi\Api\Data\SourceCarrierLinkExtensionInterface $extensionAttributes + ) { + $this->getData(SourceCarrierLinkInterface::EXTENSION_ATTRIBUTES_KEY); + return $this; + } +} \ No newline at end of file diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 465601115393..4a976ee33eb9 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -1,32 +1,67 @@ Date: Sat, 20 May 2017 18:33:38 +0200 Subject: [PATCH 22/66] magento-engcom/magento2#25: Source API Implementation - Created stub for api-functional test for SourceRepository --- .../InventoryApi/Api/SourceRepositoryTest.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php new file mode 100644 index 000000000000..60c76d462f3e --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -0,0 +1,55 @@ + Date: Sat, 20 May 2017 18:36:31 +0200 Subject: [PATCH 23/66] magento-engcom/magento2#25: Implement SourceSearchResults --- .../Inventory/Model/SourceSearchResults.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/code/Magento/Inventory/Model/SourceSearchResults.php diff --git a/app/code/Magento/Inventory/Model/SourceSearchResults.php b/app/code/Magento/Inventory/Model/SourceSearchResults.php new file mode 100644 index 000000000000..f8fec226556f --- /dev/null +++ b/app/code/Magento/Inventory/Model/SourceSearchResults.php @@ -0,0 +1,17 @@ + Date: Sat, 20 May 2017 18:36:58 +0200 Subject: [PATCH 24/66] magento-engcom/magento2#25: Add di.xml and define preferences for interfaces --- app/code/Magento/Inventory/etc/di.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/code/Magento/Inventory/etc/di.xml diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml new file mode 100644 index 000000000000..a4a5bf0b172f --- /dev/null +++ b/app/code/Magento/Inventory/etc/di.xml @@ -0,0 +1,12 @@ + + + + + + + From afe210bd9288864c1584133a264f8715e06c3ae3 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 18:37:31 +0200 Subject: [PATCH 25/66] magento-engcom/magento2#25: Implement unit tests for SourceRepository --- .../Inventory/Model/SourceRepository.php | 4 +- .../Test/Unit/Model/SourceRepositoryTest.php | 195 ++++++++++++++++++ 2 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 2a7614508a95..b790530cf22a 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -6,7 +6,6 @@ namespace Magento\Inventory\Model; -use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; @@ -15,6 +14,7 @@ use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; use Magento\InventoryApi\Api\SourceRepositoryInterface; +use Magento\Inventory\Model\SourceSearchResultsFactory; use Magento\Inventory\Model\Resource\Source as ResourceSource; use Magento\Inventory\Model\Resource\Source\CollectionFactory; use Magento\Inventory\Model\SourceFactory; @@ -94,7 +94,7 @@ public function get($sourceId) $model = $this->sourceFactory->create(); $this->resource->load($model, SourceInterface::SOURCE_ID, $sourceId); - if (!$model->getId()) { + if (!$model->getSourceId()) { NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId); } diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php new file mode 100644 index 000000000000..f2b0d29d9146 --- /dev/null +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -0,0 +1,195 @@ +resource = $this->getMock( + \Magento\Inventory\Model\Resource\Source::class, + [], + [], + '', + false + ); + + $this->sourceFactory = $this->getMock( + \Magento\Inventory\Model\SourceFactory::class, + ['create'], + [], + '', + false + ); + + $this->collectionProcessor = $this->getMockBuilder( + \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class + )->getMockForAbstractClass(); + + $this->collectionFactory = $this->getMock( + \Magento\Inventory\Model\Resource\Source\CollectionFactory::class, + ['create'], + [], + '', + false + ); + + $this->sourceSearchResultsFactory = $this->getMock( + \Magento\Inventory\Model\SourceSearchResultsFactory::class, + ['create'], + [], + '', + false + ); + + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->sourceRepository = $objectManager->getObject( + \Magento\Inventory\Model\SourceRepository::class, + [ + 'resource' => $this->resource, + 'sourceFactory' => $this->sourceFactory, + 'collectionProcessor' => $this->collectionProcessor, + 'collectionFactory' => $this->collectionFactory, + 'sourceSearchResultsFactory' => $this->sourceSearchResultsFactory, + ] + ); + } + + public function testSaveSuccessful() + { + /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ + $sourceModel = $this->getMockForAbstractClass( + \Magento\Inventory\Model\Source::class, + [], + '', + false + ); + + $result = $this->sourceRepository->save($sourceModel); + + $this->assertSame($sourceModel, $result); + } + + public function testSaveErrorExpectsException() + { + /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ + $sourceModel = $this->getMockForAbstractClass( + \Magento\Inventory\Model\Source::class, + [], + '', + false + ); + + $this->setExpectedException(\Magento\Framework\Exception\CouldNotSaveException::class); + + $this->resource->expects($this->atLeastOnce()) + ->method('save') + ->will($this->throwException(new \Exception('Some unit test Exception'))); + + $this->sourceRepository->save($sourceModel); + } + + public function testGetSuccessfull() + { + $sourceId = 345; + + /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ + $sourceModel = $this->getMockForAbstractClass( + \Magento\Inventory\Model\Source::class, + ['getSourceId'], + '', + false + ); + + $sourceModel->expects($this->atLeastOnce()) + ->method('getSourceId') + ->will($this->returnValue($sourceId)); + + $this->sourceFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($sourceModel)); + + $this->resource->expects($this->once()) + ->method('load') + ->with( + $sourceModel, + SourceInterface::SOURCE_ID, + $sourceId + ); + + $result = $this->sourceRepository->get($sourceId); + + $this->assertSame($sourceModel, $result); + } + + public function testGetErrorExpectsException() + { + $sourceId = 345; + + /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ + $sourceModel = $this->getMockForAbstractClass( + \Magento\Inventory\Model\Source::class, + ['getSourceId'], + '', + false + ); + + $sourceModel->expects($this->atLeastOnce()) + ->method('getSourceId') + ->will($this->returnValue(null)); + + $this->sourceFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($sourceModel)); + + $this->resource->expects($this->once()) + ->method('load') + ->with( + $sourceModel, + SourceInterface::SOURCE_ID, + $sourceId + ); + + $this->setExpectedException(\Magento\Framework\Exception\NoSuchEntityException::class); + + $this->sourceRepository->get($sourceId); + } +} From b7072f7fc6b6c99978e6ccb159aaf5dae1f278c2 Mon Sep 17 00:00:00 2001 From: Thomas Kreidenhuber Date: Sat, 20 May 2017 18:38:15 +0200 Subject: [PATCH 26/66] magento-engcom/magento2#25 added unit tests for source and sourcecarrierlink models --- .../Test/Unit/Model/SourceCarrierLinkTest.php | 48 +++++++ .../Inventory/Test/Unit/Model/SourceTest.php | 132 ++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php create mode 100644 app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php new file mode 100644 index 000000000000..9b41f88d6089 --- /dev/null +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php @@ -0,0 +1,48 @@ +objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->sourceCarrierLink = $this->objectManager->getObject(SourceCarrierLink::class); + } + + + public function testCarrierCode() + { + $this->sourceCarrierLink->setCarrierCode(SourceCarrierLinkTest::TEST_STRING); + $this->assertEquals($this->source->getCarrierCode(), SourceCarrierLinkTest::TEST_STRING); + } + + public function testPosition() + { + $this->sourceCarrierLink->setPosition(SourceCarrierLinkTest::TEST_POSITION); + $this->assertEquals($this->source->getName(), SourceCarrierLinkTest::TEST_POSITION); + } +} \ No newline at end of file diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php new file mode 100644 index 000000000000..cf85437186a3 --- /dev/null +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php @@ -0,0 +1,132 @@ +objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->source = $this->objectManager->getObject(Source::class); + } + + + public function testSourceId() + { + $this->source->setSourceId(SourceTest::TEST_ID); + $this->assertEquals($this->source->getSourceId(), SourceTest::TEST_ID); + } + + public function testName() + { + $this->source->setName(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getName(), SourceTest::TEST_STRING); + } + + public function testEmail() + { + $this->source->setEmail(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getEmail(), SourceTest::TEST_STRING); + } + + public function testContactName() + { + $this->source->setContactName(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getContactName(), SourceTest::TEST_STRING); + } + + public function testIsActive() + { + $this->source->setIsActive(SourceTest::TEST_IS_ACTIVE); + $this->assertEquals($this->source->getIsActive(), SourceTest::TEST_IS_ACTIVE); + } + + public function testDescription() + { + $this->source->setDescription(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getDescription(), SourceTest::TEST_IS_ACTIVE); + } + + public function testLatitude() + { + $this->source->setLatitude(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getLatitude(), SourceTest::TEST_IS_ACTIVE); + } + + public function testCountryId() + { + $this->source->setCountryId(SourceTest::TEST_ID); + $this->assertEquals($this->source->getCountryId(), SourceTest::TEST_ID); + } + + public function testRegion() + { + $this->source->setRegion(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getRegion(), SourceTest::TEST_ID); + } + + public function testStreet() + { + $this->source->setStreet(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getStreet(), SourceTest::TEST_ID); + } + + public function testPhone() + { + $this->source->setPhone(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getPhone(), SourceTest::TEST_ID); + } + + public function testFax() + { + $this->source->setFax(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getFax(), SourceTest::TEST_ID); + } + + public function testPriority() + { + $this->source->setPriority(SourceTest::TEST_STRING); + $this->assertEquals($this->source->setPriority(), SourceTest::TEST_ID); + } + + public function testCarrierLinkds() + { + $carrierLink1 = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) + ->disableOriginalConstructor() + ->getMock(); + + $carrierLink2 = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) + ->disableOriginalConstructor() + ->getMock(); + + $carrierLinks = [$carrierLink1, $carrierLink2]; + + $this->source->setCarrierLinks($carrierLinks); + $this->assertEquals($this->source->getCarrierLinks(), $carrierLinks); + } + +} \ No newline at end of file From 34eb6a23e95c3fa7f4ea5482b81cb91608c1797c Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Sat, 20 May 2017 18:40:39 +0200 Subject: [PATCH 27/66] magento-engcom/magento2#25: Source API Implementation - Created stub for api-functional test for SourceRepository --- .../Magento/InventoryApi/Api/SourceRepositoryTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index 60c76d462f3e..ee6f0893ea03 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -19,6 +19,7 @@ class SourceRepositoryTest extends WebapiAbstract public function testCreateSource() { //TODO: Implement testCreateSource + $this->fail(__METHOD__ . " is not implemented yet."); } /** @@ -27,6 +28,7 @@ public function testCreateSource() public function testGetSource() { //TODO: Implement testGetSource + $this->fail(__METHOD__ . " is not implemented yet."); } /** @@ -35,6 +37,7 @@ public function testGetSource() public function testGetSourcesList() { //TODO: Implement testGetSourcesList + $this->fail(__METHOD__ . " is not implemented yet."); } /** @@ -43,6 +46,7 @@ public function testGetSourcesList() public function testUpdateSource() { //TODO: Implement testUpdateSource + $this->fail(__METHOD__ . " is not implemented yet."); } /** @@ -51,5 +55,6 @@ public function testUpdateSource() public function testUpdateSourceWithoutCarriers() { //TODO: Implement testUpdateSourceWithoutCarriers + $this->fail(__METHOD__ . " is not implemented yet."); } } From 1fc9560034289945b956037a19ccdacd38f55b71 Mon Sep 17 00:00:00 2001 From: Thomas Kreidenhuber Date: Sat, 20 May 2017 18:50:12 +0200 Subject: [PATCH 28/66] magento-engcom/magento2#25 added fixed typo in test and added di configuration --- app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php | 2 +- app/code/Magento/Inventory/etc/di.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php index cf85437186a3..872bde0a4d7c 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php @@ -113,7 +113,7 @@ public function testPriority() $this->assertEquals($this->source->setPriority(), SourceTest::TEST_ID); } - public function testCarrierLinkds() + public function testCarrierLinks() { $carrierLink1 = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) ->disableOriginalConstructor() diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml index a4a5bf0b172f..f5685c7eb759 100644 --- a/app/code/Magento/Inventory/etc/di.xml +++ b/app/code/Magento/Inventory/etc/di.xml @@ -8,5 +8,6 @@ + From 0b46fdbb9719fbd5776e47cfd8ccaf5653af6966 Mon Sep 17 00:00:00 2001 From: Thomas Kreidenhuber Date: Sat, 20 May 2017 18:58:28 +0200 Subject: [PATCH 29/66] magento-engcom/magento2#25 fixed unit tests for source and sourcecarrierlink --- .../Test/Unit/Model/SourceCarrierLinkTest.php | 4 ++-- .../Inventory/Test/Unit/Model/SourceTest.php | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php index 9b41f88d6089..73afe482fd85 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php @@ -37,12 +37,12 @@ protected function setUp() public function testCarrierCode() { $this->sourceCarrierLink->setCarrierCode(SourceCarrierLinkTest::TEST_STRING); - $this->assertEquals($this->source->getCarrierCode(), SourceCarrierLinkTest::TEST_STRING); + $this->assertEquals($this->sourceCarrierLink->getCarrierCode(), SourceCarrierLinkTest::TEST_STRING); } public function testPosition() { $this->sourceCarrierLink->setPosition(SourceCarrierLinkTest::TEST_POSITION); - $this->assertEquals($this->source->getName(), SourceCarrierLinkTest::TEST_POSITION); + $this->assertEquals($this->sourceCarrierLink->getPosition(), SourceCarrierLinkTest::TEST_POSITION); } } \ No newline at end of file diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php index 872bde0a4d7c..c003252645c0 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php @@ -68,13 +68,13 @@ public function testIsActive() public function testDescription() { $this->source->setDescription(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getDescription(), SourceTest::TEST_IS_ACTIVE); + $this->assertEquals($this->source->getDescription(), SourceTest::TEST_STRING); } public function testLatitude() { $this->source->setLatitude(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getLatitude(), SourceTest::TEST_IS_ACTIVE); + $this->assertEquals($this->source->getLatitude(), SourceTest::TEST_STRING); } public function testCountryId() @@ -86,40 +86,40 @@ public function testCountryId() public function testRegion() { $this->source->setRegion(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getRegion(), SourceTest::TEST_ID); + $this->assertEquals($this->source->getRegion(), SourceTest::TEST_STRING); } public function testStreet() { $this->source->setStreet(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getStreet(), SourceTest::TEST_ID); + $this->assertEquals($this->source->getStreet(), SourceTest::TEST_STRING); } public function testPhone() { $this->source->setPhone(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getPhone(), SourceTest::TEST_ID); + $this->assertEquals($this->source->getPhone(), SourceTest::TEST_STRING); } public function testFax() { $this->source->setFax(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getFax(), SourceTest::TEST_ID); + $this->assertEquals($this->source->getFax(), SourceTest::TEST_STRING); } public function testPriority() { $this->source->setPriority(SourceTest::TEST_STRING); - $this->assertEquals($this->source->setPriority(), SourceTest::TEST_ID); + $this->assertEquals($this->source->getPriority(), SourceTest::TEST_STRING); } public function testCarrierLinks() { - $carrierLink1 = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) + $carrierLink1 = $this->getMock(\Magento\Customer\Model\Customer::class) ->disableOriginalConstructor() ->getMock(); - $carrierLink2 = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) + $carrierLink2 = $this->getMock(\Magento\Customer\Model\Customer::class) ->disableOriginalConstructor() ->getMock(); From 79130595f10112b8fc88c441d4ccae7f4342ec17 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 19:25:08 +0200 Subject: [PATCH 30/66] magento-engcom/magento2#25: Implement rests for SourceRepository --- .../Inventory/Model/SourceRepository.php | 4 +- .../Test/Unit/Model/SourceRepositoryTest.php | 86 +++++++++++++++++-- .../Inventory/Test/Unit/Model/SourceTest.php | 22 +++-- 3 files changed, 97 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index b790530cf22a..ad6fb0a3b0e8 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -95,7 +95,7 @@ public function get($sourceId) $this->resource->load($model, SourceInterface::SOURCE_ID, $sourceId); if (!$model->getSourceId()) { - NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId); + throw NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId); } return $model; @@ -114,7 +114,7 @@ public function getList(SearchCriteriaInterface $searchCriteria = null) $sources = []; /** @var SourceInterface $source */ foreach ($collection->getItems() as $source) { - $addresses[] = $source; + $sources[] = $source; } /** @var SourceSearchResultsInterface $searchResults */ diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index f2b0d29d9146..72e2fcf1c5ad 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -96,9 +96,10 @@ protected function setUp() public function testSaveSuccessful() { /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMockForAbstractClass( + $sourceModel = $this->getMock( \Magento\Inventory\Model\Source::class, [], + [], '', false ); @@ -111,9 +112,10 @@ public function testSaveSuccessful() public function testSaveErrorExpectsException() { /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMockForAbstractClass( + $sourceModel = $this->getMock( \Magento\Inventory\Model\Source::class, [], + [], '', false ); @@ -132,9 +134,10 @@ public function testGetSuccessfull() $sourceId = 345; /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMockForAbstractClass( + $sourceModel = $this->getMock( \Magento\Inventory\Model\Source::class, - ['getSourceId'], + [], + [], '', false ); @@ -165,9 +168,10 @@ public function testGetErrorExpectsException() $sourceId = 345; /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMockForAbstractClass( + $sourceModel = $this->getMock( \Magento\Inventory\Model\Source::class, - ['getSourceId'], + [], + [], '', false ); @@ -192,4 +196,74 @@ public function testGetErrorExpectsException() $this->sourceRepository->get($sourceId); } + + public function testGetList() + { + /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel1 */ + $sourceModel1 = $this->getMock( + \Magento\Inventory\Model\Source::class, + [], + [], + '', + false + ); + + /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel2 */ + $sourceModel2 = $this->getMock( + \Magento\Inventory\Model\Source::class, + [], + [], + '', + false + ); + + $searchCriteria = $this->getMock( + \Magento\Framework\Api\SearchCriteriaInterface::class, + [], + [], + '', + false + ); + + $collection = $this->getMock( + \Magento\Inventory\Model\Resource\Source\Collection::class, + [], + [], + '', + false + ); + + $this->collectionFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($collection)); + + $sources = [ + $sourceModel1, + $sourceModel2 + ]; + + $collection->expects($this->atLeastOnce()) + ->method('getItems') + ->will($this->returnValue($sources)); + + $searchResults = $this->getMock( + \Magento\Inventory\Model\SourceSearchResults::class, + [], + [], + '', + false + ); + + $this->sourceSearchResultsFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($searchResults)); + + $searchResults->expects($this->once()) + ->method('setItems') + ->with($sources); + + $result = $this->sourceRepository->getList($searchCriteria); + + $this->assertSame($searchResults, $result); + } } diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php index c003252645c0..4d8dbbcec760 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php @@ -115,13 +115,21 @@ public function testPriority() public function testCarrierLinks() { - $carrierLink1 = $this->getMock(\Magento\Customer\Model\Customer::class) - ->disableOriginalConstructor() - ->getMock(); - - $carrierLink2 = $this->getMock(\Magento\Customer\Model\Customer::class) - ->disableOriginalConstructor() - ->getMock(); + $carrierLink1 = $this->getMock( + \Magento\Inventory\Model\SourceCarrierLink::class, + [], + [], + '', + false + ); + + $carrierLink2 = $this->getMock( + \Magento\Inventory\Model\SourceCarrierLink::class, + [], + [], + '', + false + ); $carrierLinks = [$carrierLink1, $carrierLink2]; From 2443c2bcec24a615ea7637e3b4006238567d65d6 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 19:29:18 +0200 Subject: [PATCH 31/66] magento-engcom/magento2#25: Fix unit tests --- app/code/Magento/Inventory/Model/Source.php | 2 +- app/code/Magento/Inventory/Model/SourceCarrierLink.php | 4 ++-- .../Inventory/Test/Unit/Model/SourceCarrierLinkTest.php | 1 - app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index 8ed5f0f2caf6..bc507b56a82a 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -322,7 +322,7 @@ public function setPriority($priority) */ public function getCarrierLinks() { - return $this->getData(SourceInterface::PRIORITY); + return $this->getData(SourceInterface::CARRIER_LINKS); } /** diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/SourceCarrierLink.php index f0284bb02148..eabd31651a97 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLink.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLink.php @@ -37,7 +37,7 @@ protected function _construct() */ public function getCarrierCode() { - $this->getData(SourceCarrierLinkInterface::CARRIER_CODE); + return $this->getData(SourceCarrierLinkInterface::CARRIER_CODE); } /** @@ -54,7 +54,7 @@ public function setCarrierCode($carrierCode) */ public function getPosition() { - $this->getData(SourceCarrierLinkInterface::POSITION); + return $this->getData(SourceCarrierLinkInterface::POSITION); } /** diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php index 73afe482fd85..352ca93113a3 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php @@ -33,7 +33,6 @@ protected function setUp() $this->sourceCarrierLink = $this->objectManager->getObject(SourceCarrierLink::class); } - public function testCarrierCode() { $this->sourceCarrierLink->setCarrierCode(SourceCarrierLinkTest::TEST_STRING); diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php index 4d8dbbcec760..f9631c32f082 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php @@ -134,7 +134,7 @@ public function testCarrierLinks() $carrierLinks = [$carrierLink1, $carrierLink2]; $this->source->setCarrierLinks($carrierLinks); - $this->assertEquals($this->source->getCarrierLinks(), $carrierLinks); + $this->assertEquals($carrierLinks, $this->source->getCarrierLinks()); } } \ No newline at end of file From b4a7aedfe503288dae4d7bc4f3f62d36ecdb7b27 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sat, 20 May 2017 19:34:09 +0200 Subject: [PATCH 32/66] magento-engcom/magento2#25: Code styles --- .../Api/SearchCriteria/CollectionProcessorInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Api/SearchCriteria/CollectionProcessorInterface.php b/lib/internal/Magento/Framework/Api/SearchCriteria/CollectionProcessorInterface.php index b32a036eb820..28fe58f6390d 100644 --- a/lib/internal/Magento/Framework/Api/SearchCriteria/CollectionProcessorInterface.php +++ b/lib/internal/Magento/Framework/Api/SearchCriteria/CollectionProcessorInterface.php @@ -21,5 +21,5 @@ interface CollectionProcessorInterface * @throws \InvalidArgumentException * @return void */ - public function process(SearchCriteriaInterface $searchCriteria, AbstractDb $collection); + public function process(SearchCriteriaInterface $searchCriteria, AbstractDb $collection); } From c2af5e57a61801cb22929d2bd5c78826c8b2634c Mon Sep 17 00:00:00 2001 From: Oleksii Korshenko Date: Sat, 20 May 2017 20:41:54 +0200 Subject: [PATCH 33/66] magento-engcom/magento2#25: Source API Implementation - code style fixes --- .../Inventory/Model/Resource/Source/Collection.php | 6 +----- .../Inventory/Model/Resource/SourceCarrierLink.php | 6 +----- .../Model/Resource/SourceCarrierLink/Collection.php | 7 ++----- app/code/Magento/Inventory/Model/Source.php | 6 +++--- .../Magento/Inventory/Model/SourceCarrierLink.php | 12 +++++------- .../Magento/Inventory/Model/SourceRepository.php | 9 +-------- .../Magento/Inventory/Model/SourceSearchResults.php | 1 + .../Test/Unit/Model/SourceCarrierLinkTest.php | 3 +-- .../Test/Unit/Model/SourceRepositoryTest.php | 7 ++++++- .../Magento/Inventory/Test/Unit/Model/SourceTest.php | 3 +-- .../Api/Data/SourceCarrierLinkInterface.php | 4 +--- .../InventoryApi/Api/Data/SourceInterface.php | 6 +++--- app/code/Magento/InventoryApi/etc/acl.xml | 4 ++-- app/code/Magento/InventoryApi/etc/webapi.xml | 8 ++++---- 14 files changed, 32 insertions(+), 50 deletions(-) diff --git a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php index 0b4ca170dae1..4c9069289549 100644 --- a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php +++ b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php @@ -10,10 +10,6 @@ use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Inventory\Model\Source as SourceModel; -/** - * Class Collection - * @package Magento\Inventory\Model\Resource\Source - */ class Collection extends AbstractCollection { /** @@ -31,4 +27,4 @@ public function getIdFieldName() { return SourceInterface::SOURCE_ID; } -} \ No newline at end of file +} diff --git a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php index b0f81b2a9721..5c927aa985b0 100644 --- a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php +++ b/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php @@ -8,7 +8,6 @@ use Magento\Framework\Model\ResourceModel\Db\AbstractDb; use Magento\Inventory\Setup\InstallSchema; -use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; class SourceCarrierLink extends AbstractDb { @@ -16,12 +15,9 @@ class SourceCarrierLink extends AbstractDb * Initialize resource model * * @return void - * - * @codingStandardsIgnore - * @codeCoverageIgnore */ protected function _construct() { $this->_init(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK, 'source_carrier_link_id'); } -} \ No newline at end of file +} diff --git a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php b/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php index 504845bd0012..aec2ab9577af 100644 --- a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php +++ b/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php @@ -3,10 +3,10 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Inventory\Model\Resource\SourceCarrierLink; use Magento\Inventory\Model\Resource\SourceCarrierLink as ResourceSourceCarrierLink; -use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Inventory\Model\SourceCarrierLink as SourceCarrierLinkModel; @@ -15,9 +15,6 @@ class Collection extends AbstractCollection /** * Initialize resource model * @return void - * - * @codingStandardsIgnore - * @codeCoverageIgnore */ protected function _construct() { @@ -33,4 +30,4 @@ public function getIdFieldName() { return 'source_carrier_link_id'; } -} \ No newline at end of file +} diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index bc507b56a82a..c7226302e786 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -6,14 +6,14 @@ namespace Magento\Inventory\Model; -use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\AbstractExtensibleModel; use \Magento\InventoryApi\Api\Data\SourceInterface; /** * Class Source * @package Magento\Inventory\Model */ -class Source extends AbstractModel implements SourceInterface +class Source extends AbstractExtensibleModel implements SourceInterface { /** * @inheritdoc @@ -350,4 +350,4 @@ public function setExtensionAttributes( ) { return $this->_setExtensionAttributes($extensionAttributes); } -} \ No newline at end of file +} diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/SourceCarrierLink.php index eabd31651a97..5a7606340f25 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLink.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLink.php @@ -6,19 +6,18 @@ namespace Magento\Inventory\Model; -use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\AbstractExtensibleModel; use \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; -class SourceCarrierLink extends AbstractModel implements SourceCarrierLinkInterface +class SourceCarrierLink extends AbstractExtensibleModel implements SourceCarrierLinkInterface { - /** * Name of the resource collection model * * @codingStandardsIgnore * @var string */ - protected $_collectionName = 'Magento\Inventory\Model\Resource\SourceCarrierLink\Collection'; + protected $_collectionName = \Magento\Inventory\Model\Resource\SourceCarrierLink\Collection::class; /** * Initialize resource model @@ -28,9 +27,8 @@ class SourceCarrierLink extends AbstractModel implements SourceCarrierLinkInterf */ protected function _construct() { - $this->_init('Magento\Inventory\Model\Resource\SourceCarrierLink'); + $this->_init(\Magento\Inventory\Model\Resource\SourceCarrierLink::class); } - /** * @inheritDoc @@ -82,4 +80,4 @@ public function setExtensionAttributes( ) { return $this->_setExtensionAttributes($extensionAttributes); } -} \ No newline at end of file +} diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index ad6fb0a3b0e8..607b202d4c29 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -110,16 +110,9 @@ public function getList(SearchCriteriaInterface $searchCriteria = null) $collection = $this->collectionFactory->create(); $this->collectionProcessor->process($searchCriteria, $collection); - /** @var SourceInterface[] $sources */ - $sources = []; - /** @var SourceInterface $source */ - foreach ($collection->getItems() as $source) { - $sources[] = $source; - } - /** @var SourceSearchResultsInterface $searchResults */ $searchResults = $this->sourceSearchResultsFactory->create(); - $searchResults->setItems($sources); + $searchResults->setItems($collection->getItems()); $searchResults->setSearchCriteria($searchCriteria); $searchResults->setTotalCount($collection->getSize()); return $searchResults; diff --git a/app/code/Magento/Inventory/Model/SourceSearchResults.php b/app/code/Magento/Inventory/Model/SourceSearchResults.php index f8fec226556f..685ed663b25c 100644 --- a/app/code/Magento/Inventory/Model/SourceSearchResults.php +++ b/app/code/Magento/Inventory/Model/SourceSearchResults.php @@ -14,4 +14,5 @@ */ class SourceSearchResults extends SearchResults implements SourceSearchResultsInterface { + } diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php index 352ca93113a3..fe6ff139cbc1 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php @@ -6,7 +6,6 @@ namespace Magento\Inventory\Test\Unit\Model; -use \Magento\Inventory\Model\Source; use \Magento\Inventory\Model\SourceCarrierLink; class SourceCarrierLinkTest extends \PHPUnit_Framework_TestCase @@ -44,4 +43,4 @@ public function testPosition() $this->sourceCarrierLink->setPosition(SourceCarrierLinkTest::TEST_POSITION); $this->assertEquals($this->sourceCarrierLink->getPosition(), SourceCarrierLinkTest::TEST_POSITION); } -} \ No newline at end of file +} diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 72e2fcf1c5ad..3e06272ef728 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -3,7 +3,9 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Inventory\Test\Unit\Model; + use Magento\InventoryApi\Api\Data\SourceInterface; /** @@ -120,6 +122,9 @@ public function testSaveErrorExpectsException() false ); + $this->resource->expects($this->atLeastOnce()) + ->method('save'); + $this->setExpectedException(\Magento\Framework\Exception\CouldNotSaveException::class); $this->resource->expects($this->atLeastOnce()) @@ -129,7 +134,7 @@ public function testSaveErrorExpectsException() $this->sourceRepository->save($sourceModel); } - public function testGetSuccessfull() + public function testGetSuccessful() { $sourceId = 345; diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php index f9631c32f082..a9c7fcd2d651 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php @@ -7,7 +7,6 @@ namespace Magento\Inventory\Test\Unit\Model; use \Magento\Inventory\Model\Source; -use \Magento\Inventory\Model\SourceCarrierLink; class SourceTest extends \PHPUnit_Framework_TestCase { @@ -137,4 +136,4 @@ public function testCarrierLinks() $this->assertEquals($carrierLinks, $this->source->getCarrierLinks()); } -} \ No newline at end of file +} diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 4a976ee33eb9..ad84cda34323 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -9,7 +9,6 @@ interface SourceCarrierLinkInterface extends ExtensibleDataInterface { - /**#@+ * Constants for keys of data array. Identical to the name of the getter in snake case */ @@ -17,7 +16,6 @@ interface SourceCarrierLinkInterface extends ExtensibleDataInterface const POSITION = 'position'; /**#@-*/ - /** * Get carrier code. * @@ -64,4 +62,4 @@ public function getExtensionAttributes(); public function setExtensionAttributes( \Magento\InventoryApi\Api\Data\SourceCarrierLinkExtensionInterface $extensionAttributes ); -} \ No newline at end of file +} diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index acc63d213b42..70cef91a7dd0 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -143,14 +143,14 @@ public function setLatitude($latitude); /** * Get source longitude. * - * @return int + * @return float */ public function getLongitude(); /** * Set source longitude. * - * @param int $longitude + * @param float $longitude * @return $this */ public function setLongitude($longitude); @@ -317,4 +317,4 @@ public function getExtensionAttributes(); public function setExtensionAttributes( \Magento\InventoryApi\Api\Data\SourceExtensionInterface $extensionAttributes ); -} \ No newline at end of file +} diff --git a/app/code/Magento/InventoryApi/etc/acl.xml b/app/code/Magento/InventoryApi/etc/acl.xml index 6ee353447968..b353c2a55244 100644 --- a/app/code/Magento/InventoryApi/etc/acl.xml +++ b/app/code/Magento/InventoryApi/etc/acl.xml @@ -9,8 +9,8 @@ - - + + diff --git a/app/code/Magento/InventoryApi/etc/webapi.xml b/app/code/Magento/InventoryApi/etc/webapi.xml index 746582646932..6c413af4829c 100644 --- a/app/code/Magento/InventoryApi/etc/webapi.xml +++ b/app/code/Magento/InventoryApi/etc/webapi.xml @@ -10,25 +10,25 @@ - + - + - + - + From df90ef39753e4f409a9479fc532d4c7c864cf59f Mon Sep 17 00:00:00 2001 From: Thomas Kreidenhuber Date: Sun, 21 May 2017 09:49:11 +0200 Subject: [PATCH 34/66] magento-engcom/magento2#25 added missing unit tests in sourcetest --- .../Inventory/Test/Unit/Model/SourceTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php index c003252645c0..2e069b2f112b 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php @@ -77,6 +77,12 @@ public function testLatitude() $this->assertEquals($this->source->getLatitude(), SourceTest::TEST_STRING); } + public function testLongitude() + { + $this->source->setLongitude(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getLongitude(), SourceTest::TEST_STRING); + } + public function testCountryId() { $this->source->setCountryId(SourceTest::TEST_ID); @@ -89,6 +95,12 @@ public function testRegion() $this->assertEquals($this->source->getRegion(), SourceTest::TEST_STRING); } + public function testCity() + { + $this->source->setCity(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getCity(), SourceTest::TEST_STRING); + } + public function testStreet() { $this->source->setStreet(SourceTest::TEST_STRING); @@ -101,6 +113,12 @@ public function testPhone() $this->assertEquals($this->source->getPhone(), SourceTest::TEST_STRING); } + public function testPostcode() + { + $this->source->setPostcode(SourceTest::TEST_STRING); + $this->assertEquals($this->source->getPostcode(), SourceTest::TEST_STRING); + } + public function testFax() { $this->source->setFax(SourceTest::TEST_STRING); From fc4dcba456b8df4d2dd289b84ac75151d8515d0e Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 21 May 2017 10:34:57 +0200 Subject: [PATCH 35/66] Remove obsolete DocBloc --- app/code/Magento/Inventory/Model/SourceSearchResults.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Inventory/Model/SourceSearchResults.php b/app/code/Magento/Inventory/Model/SourceSearchResults.php index 685ed663b25c..ed3ebe129d32 100644 --- a/app/code/Magento/Inventory/Model/SourceSearchResults.php +++ b/app/code/Magento/Inventory/Model/SourceSearchResults.php @@ -10,7 +10,6 @@ /** * Class SourceSearchResults - * @package Magento\Inventory\Model */ class SourceSearchResults extends SearchResults implements SourceSearchResultsInterface { From d2bc7b7f336f2e9e4454287c066bf6fa4919f7d8 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sun, 21 May 2017 11:14:28 +0200 Subject: [PATCH 36/66] magento-engcom/magento2#25: WIP api-functional tests --- .../InventoryApi/Api/SourceRepositoryTest.php | 117 +++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index ee6f0893ea03..5d93f34f9ee7 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -5,7 +5,11 @@ */ namespace Magento\InventoryApi\Api; +use Magento\Directory\Api\CountryInformationAcquirerInterface; +use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\TestCase\WebapiAbstract; +use Magento\TestFramework\Helper\Bootstrap; class SourceRepositoryTest extends WebapiAbstract { @@ -13,13 +17,122 @@ class SourceRepositoryTest extends WebapiAbstract const SERVICE_NAME = 'inventoryApiSourceRepositoryV1'; const RESOURCE_PATH = '/V1/inventory/source/'; + /** + * @var \Magento\InventoryApi\Api\Data\SourceInterfaceFactory + */ + private $sourceFactory; + + /** + * @var CountryInformationAcquirerInterface + */ + private $countryInformationAcquirer; + + /** + * @var \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterfaceFactory + */ + private $sourceCarrierLinkFactory; + + /** + * Execute per test initialization. + */ + public function setUp() + { + $this->sourceFactory = Bootstrap::getObjectManager() + ->create(\Magento\InventoryApi\Api\Data\SourceInterfaceFactory::class); + $this->countryInformationAcquirer = Bootstrap::getObjectManager() + ->create(CountryInformationAcquirerInterface::class); + $this->sourceCarrierLinkFactory = Bootstrap::getObjectManager() + ->create(\Magento\InventoryApi\Api\Data\SourceCarrierLinkInterfaceFactory::class); + } + /** * Create new Inventory Source using Web API and verify it's integrity. */ public function testCreateSource() { - //TODO: Implement testCreateSource - $this->fail(__METHOD__ . " is not implemented yet."); + $country = $this->countryInformationAcquirer->getCountryInfo('DE'); + + $name = 'Source name'; + $description = 'Some description for source'; + $city = 'Exampletown'; + $street = 'Some Street 455'; + $postcode = 54321; + $contactName = 'Contact Name'; + $email = 'example.guy@test.com'; + $fax = '0120002020033'; + $phone = '0120002020044'; + $latitude = 51.343479; + $longitude = 12.387772; + $isActive = true; + $priority = 40; + + $carrierCode1 = 'CAR-1'; + $carrierCode2 = 'CAR-2'; + + /** @var SourceCarrierLinkInterface $carrierLink1 */ + $carrierLink1 = $this->sourceCarrierLinkFactory->create(); + $carrierLink1->setPosition(1) + ->setCarrierCode($carrierCode1); + + /** @var SourceCarrierLinkInterface $carrierLink2*/ + $carrierLink2 = $this->sourceCarrierLinkFactory->create(); + $carrierLink2->setPosition(2) + ->setCarrierCode($carrierCode2); + + /** @var \Magento\InventoryApi\Api\Data\SourceInterface $sourceDataObject */ + $sourceDataObject = $this->sourceFactory->create(); + $sourceDataObject->setName($name) + ->setDescription($description) + ->setCity($city) + ->setPostcode($postcode) + ->setContactName($contactName) + ->setCountryId($country->getId()) + ->setEmail($email) + ->setFax($fax) + ->setPhone($phone) + ->setLatitude($latitude) + ->setLongitude($longitude) + ->setIsActive($isActive) + ->setPriority($priority) + ->setStreet($street) + ->setCarrierLinks([ + $carrierLink1, + $carrierLink2 + ]); + + $regions = $country->getAvailableRegions(); + if ($regions) { + $region = $regions[0]; + $sourceDataObject->setRegion($region->getName()); + $sourceDataObject->setRegionId($region->getId()); + } + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Save', + ], + ]; + + + $requestData = [ + 'source' => [ + SourceInterface::CITY => $sourceDataObject->getCity(), + SourceInterface::CONTACT_NAME => $sourceDataObject->getContactName(), + SourceInterface::COUNTRY_ID => $sourceDataObject->getCountryId(), + SourceInterface::DESCRIPTION => $sourceDataObject->getDescription(), + SourceInterface::NAME => $sourceDataObject->getName(), + SourceInterface::EMAIL => $sourceDataObject->getEmail(), + ], + ]; + + $result = $this->_webApiCall($serviceInfo, $requestData); + var_dump($result); } /** From d9aefacf083b28733a6f19efa6242211fd44c675 Mon Sep 17 00:00:00 2001 From: Thomas Kreidenhuber Date: Sun, 21 May 2017 12:55:59 +0200 Subject: [PATCH 37/66] magento-engcom/magento2#25 made changes from codereview in pull request --- .../Model/Resource/Source/Collection.php | 8 - app/code/Magento/Inventory/Model/Source.php | 11 +- .../Inventory/Model/SourceCarrierLink.php | 8 - .../Inventory/Model/SourceRepository.php | 41 +- .../Inventory/Model/SourceSearchResults.php | 4 - .../Magento/Inventory/Setup/InstallSchema.php | 365 ++++++++++-------- .../Test/Unit/Model/SourceCarrierLinkTest.php | 7 +- .../Test/Unit/Model/SourceRepositoryTest.php | 1 - .../Inventory/Test/Unit/Model/SourceTest.php | 7 +- .../InventoryApi/Api/Data/SourceInterface.php | 2 +- .../Api/SourceRepositoryInterface.php | 2 +- 11 files changed, 255 insertions(+), 201 deletions(-) diff --git a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php index 4c9069289549..d149d175115e 100644 --- a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php +++ b/app/code/Magento/Inventory/Model/Resource/Source/Collection.php @@ -19,12 +19,4 @@ protected function _construct() { $this->_init(SourceModel::class, ResourceSource::class); } - - /** - * @inheritdoc - */ - public function getIdFieldName() - { - return SourceInterface::SOURCE_ID; - } } diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index c7226302e786..b027936da91c 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -10,16 +10,13 @@ use \Magento\InventoryApi\Api\Data\SourceInterface; /** - * Class Source - * @package Magento\Inventory\Model + * Class Source, + * provides implementation of the SourceInterface which adds the possibilty + * for a Merchant to map existing physical sources to some particular sales channels + * this model holds the information like name and description of this physical sources */ class Source extends AbstractExtensibleModel implements SourceInterface { - /** - * @inheritdoc - */ - protected $_collectionName = \Magento\Inventory\Model\Resource\Source\Collection::class; - /** * @inheritdoc */ diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/SourceCarrierLink.php index 5a7606340f25..2b5473103521 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLink.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLink.php @@ -11,14 +11,6 @@ class SourceCarrierLink extends AbstractExtensibleModel implements SourceCarrierLinkInterface { - /** - * Name of the resource collection model - * - * @codingStandardsIgnore - * @var string - */ - protected $_collectionName = \Magento\Inventory\Model\Resource\SourceCarrierLink\Collection::class; - /** * Initialize resource model * diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 607b202d4c29..27bef7ff5584 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -17,11 +17,14 @@ use Magento\Inventory\Model\SourceSearchResultsFactory; use Magento\Inventory\Model\Resource\Source as ResourceSource; use Magento\Inventory\Model\Resource\Source\CollectionFactory; -use Magento\Inventory\Model\SourceFactory; +use Magento\Inventory\Model\SourceFactoryInterface; +use \Psr\Log\LoggerInterface; /** * Class SourceRepository - * @package Magento\Inventory\Model + * + * Provides implementation of CQRS for sourcemodel + * */ class SourceRepository implements SourceRepositoryInterface { @@ -31,7 +34,7 @@ class SourceRepository implements SourceRepositoryInterface private $resource; /** - * @var SourceFactory + * @var SourceFactoryInterface */ private $sourceFactory; @@ -50,26 +53,34 @@ class SourceRepository implements SourceRepositoryInterface */ private $sourceSearchResultsFactory; + /** + * @var LoggerInterface + */ + private $logger; + /** * SourceRepository constructor. * @param ResourceSource $resource - * @param SourceFactory $sourceFactory + * @param SourceFactoryInterface $sourceFactory * @param CollectionProcessorInterface $collectionProcessor * @param CollectionFactory $collectionFactory * @param SourceSearchResultsFactory $sourceSearchResultsFactory + * @param LoggerInterface $logger */ public function __construct( ResourceSource $resource, - SourceFactory $sourceFactory, + SourceFactoryInterface $sourceFactory, CollectionProcessorInterface $collectionProcessor, CollectionFactory $collectionFactory, - SourceSearchResultsFactory $sourceSearchResultsFactory + SourceSearchResultsFactory $sourceSearchResultsFactory, + LoggerInterface $logger ) { $this->resource = $resource; $this->sourceFactory = $sourceFactory; $this->collectionProcessor = $collectionProcessor; $this->collectionFactory = $collectionFactory; $this->sourceSearchResultsFactory = $sourceSearchResultsFactory; + $this->logger = $logger; } /** @@ -80,9 +91,9 @@ public function save(SourceInterface $source) try { $this->resource->save($source); } catch (\Exception $exception) { - throw new CouldNotSaveException(__($exception->getMessage())); + $this->logger->error($exception->getMessage()); + throw new CouldNotSaveException(__('Could not save source')); } - return $source; } /** @@ -91,14 +102,14 @@ public function save(SourceInterface $source) public function get($sourceId) { /** @var SourceInterface|AbstractModel $model */ - $model = $this->sourceFactory->create(); - $this->resource->load($model, SourceInterface::SOURCE_ID, $sourceId); + $source = $this->sourceFactory->create(); + $this->resource->load($source, SourceInterface::SOURCE_ID, $sourceId); - if (!$model->getSourceId()) { + if (!$source->getSourceId()) { throw NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId); } - return $model; + return $source; } /** @@ -108,7 +119,11 @@ public function getList(SearchCriteriaInterface $searchCriteria = null) { /** @var \Magento\Inventory\Model\Resource\Source\Collection $collection */ $collection = $this->collectionFactory->create(); - $this->collectionProcessor->process($searchCriteria, $collection); + + // if there is a searchCriteria defined, use it to add its creterias to the collection + if (!is_null($searchCriteria)) { + $this->collectionProcessor->process($searchCriteria, $collection); + } /** @var SourceSearchResultsInterface $searchResults */ $searchResults = $this->sourceSearchResultsFactory->create(); diff --git a/app/code/Magento/Inventory/Model/SourceSearchResults.php b/app/code/Magento/Inventory/Model/SourceSearchResults.php index 685ed663b25c..e41ad207c8e4 100644 --- a/app/code/Magento/Inventory/Model/SourceSearchResults.php +++ b/app/code/Magento/Inventory/Model/SourceSearchResults.php @@ -8,10 +8,6 @@ use Magento\Framework\Api\SearchResults; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; -/** - * Class SourceSearchResults - * @package Magento\Inventory\Model - */ class SourceSearchResults extends SearchResults implements SourceSearchResultsInterface { diff --git a/app/code/Magento/Inventory/Setup/InstallSchema.php b/app/code/Magento/Inventory/Setup/InstallSchema.php index 18636d89597f..ae8a3c878d28 100644 --- a/app/code/Magento/Inventory/Setup/InstallSchema.php +++ b/app/code/Magento/Inventory/Setup/InstallSchema.php @@ -7,20 +7,25 @@ use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; -/** - * Class InstallSchema - * @package Magento\Inventory\Setup - */ class InstallSchema implements InstallSchemaInterface { /** - * + * Constant for table names of the model \Magento\Inventory\Model\Source */ const TABLE_NAME_SOURCE = 'inventory_source'; + + /** + * Constant for table name of \Magento\Inventory\Model\SourceCarrierLink + */ const TABLE_NAME_SOURCE_CARRIER_LINK = 'inventory_source_carrier_link'; + /** + * Constant for decimal precision for latitude and longitude + */ + const DECIMAL_PLACES = 8; /** * Option keys for column options @@ -32,8 +37,12 @@ class InstallSchema implements InstallSchemaInterface const OPTION_DEFAULT = 'default'; const OPTION_TYPE = 'type'; const OPTION_LENGTH = 'length'; + const OPTION_SCALE = 'scale'; + const OPTION_PRECISION = 'precision'; /** + * Generates needed database structure for source and sourcecarrierlink implementation from this module + * * @param SchemaSetupInterface $setup * @param ModuleContextInterface $context */ @@ -44,123 +53,165 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con $tableNameSourceEntity = $installer->getTable(InstallSchema::TABLE_NAME_SOURCE); if (!$installer->getConnection()->isTableExists($tableNameSourceEntity)) { - $table = $installer->getConnection()->newTable($tableNameSourceEntity); - $options = [ - InstallSchema::OPTION_IDENTITY => true, - InstallSchema::OPTION_UNSIGNED => true, - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_PRIMARY => true - ]; - $table->addColumn(SourceInterface::SOURCE_ID, Table::TYPE_INTEGER, null, $options, 'Source ID'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::NAME, Table::TYPE_TEXT, 255, $options, 'Source Name'); - - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::CONTACT_NAME, Table::TYPE_TEXT, 255, $options, 'Contact Name'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::EMAIL, Table::TYPE_TEXT, 255, $options, 'Email'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true, - InstallSchema::OPTION_DEFAULT => 1 - ]; - $table->addColumn(SourceInterface::IS_ACTIVE, - Table::TYPE_SMALLINT, + $table->addColumn( + SourceInterface::SOURCE_ID, + Table::TYPE_INTEGER, null, - $options, - 'Defines Is Source Active'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::DESCRIPTION, Table::TYPE_TEXT, 255, $options, 'Description'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::LATITUDE, Table::TYPE_TEXT, 255, $options, 'Latitude'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::LONGITUDE, Table::TYPE_TEXT, 255, $options, 'Longitude'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true - ]; - - $table->addColumn(SourceInterface::COUNTRY_ID, Table::TYPE_SMALLINT, null, $options, 'Country Id'); - - $options = [ - InstallSchema::OPTION_NULLABLE => true, - InstallSchema::OPTION_UNSIGNED => true - ]; - - $table->addColumn(SourceInterface::REGION_ID, Table::TYPE_SMALLINT, null, $options, 'Region Id'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::REGION, Table::TYPE_TEXT, 255, $options, 'Region'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::CITY, Table::TYPE_TEXT, 255, $options, 'City'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::STREET, Table::TYPE_TEXT, 255, $options, 'Street'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::POSTCODE, Table::TYPE_TEXT, 255, $options, 'Postcode'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::PHONE, Table::TYPE_TEXT, 255, $options, 'Phone'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn(SourceInterface::FAX, Table::TYPE_TEXT, 255, $options, 'Fax'); - - $options = [ - InstallSchema::OPTION_NULLABLE => true, - InstallSchema::OPTION_UNSIGNED => true, - ]; - - $table->addColumn(SourceInterface::PRIORITY, Table::TYPE_SMALLINT, null, $options, 'Priority'); - - + [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_PRIMARY => true + ], + 'Source ID' + ) + ->addColumn( + SourceInterface::NAME, + Table::TYPE_TEXT, + 255, [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Source Name' + ) + ->addColumn( + SourceInterface::CONTACT_NAME, + Table::TYPE_TEXT, + 255, [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Contact Name' + ) + ->addColumn( + SourceInterface::EMAIL, + Table::TYPE_TEXT, + 255, [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Email' + ) + ->addColumn( + SourceInterface::IS_ACTIVE, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_DEFAULT => 1 + ], + 'Defines Is Source Active' + ) + ->addColumn( + SourceInterface::DESCRIPTION, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Description' + ) + ->addColumn( + SourceInterface::LATITUDE, + Table::TYPE_DECIMAL, null, + [ + InstallSchema::OPTION_PRECISION => InstallSchema::DECIMAL_PLACES, + InstallSchema::OPTION_SCALE => InstallSchema::DECIMAL_PLACES, + InstallSchema::OPTION_NULLABLE => true + ], 'Latitude' + ) + ->addColumn( + SourceInterface::LONGITUDE, + Table::TYPE_DECIMAL, null, + [ + InstallSchema::OPTION_PRECISION => InstallSchema::DECIMAL_PLACES, + InstallSchema::OPTION_SCALE => InstallSchema::DECIMAL_PLACES, + InstallSchema::OPTION_NULLABLE => true + ], 'Longitude' + ) + ->addColumn( + SourceInterface::COUNTRY_ID, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true + ], 'Country Id' + )->addColumn( + SourceInterface::REGION_ID, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => true, + InstallSchema::OPTION_UNSIGNED => true + ], 'Region Id' + )->addColumn( + SourceInterface::REGION, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], 'Region' + ) + ->addColumn( + SourceInterface::CITY, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], 'City' + ) + ->addColumn( + SourceInterface::STREET, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], 'Street' + ) + ->addColumn( + SourceInterface::POSTCODE, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], 'Postcode' + ) + ->addColumn( + SourceInterface::PHONE, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], 'Phone' + ) + ->addColumn( + SourceInterface::FAX, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], 'Fax' + ) + ->addColumn( + SourceInterface::PRIORITY, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => true, + InstallSchema::OPTION_UNSIGNED => true, + ], 'Priority' + ); $table->setComment('Inventory Source Entity Table')->setOption('type', 'InnoDB')->setOption('charset', 'utf8'); $installer->getConnection()->createTable($table); @@ -170,38 +221,43 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con if (!$installer->getConnection()->isTableExists($tableNameCarrierLinkEntity)) { $table = $installer->getConnection()->newTable($tableNameCarrierLinkEntity); - - $options = [ - InstallSchema::OPTION_IDENTITY => true, - InstallSchema::OPTION_UNSIGNED => true, - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_PRIMARY => true - ]; - $table->addColumn('source_carrier_link_id', - Table::TYPE_INTEGER, - null, - $options, - 'Source Carrier Link ID' - ); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true, - ]; - $table->addColumn(SourceInterface::SOURCE_ID, Table::TYPE_INTEGER, null, $options, 'Source ID'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ]; - $table->addColumn('carrier_code', Table::TYPE_TEXT, 255, $options, 'Carrier Code'); - - $options = [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true, - ]; - - $table->addColumn('position', Table::TYPE_SMALLINT, null, $options, 'Position'); + $table->addColumn( + 'source_carrier_link_id', + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_PRIMARY => true + ], + 'Source Carrier Link ID' + ) + ->addColumn( + SourceInterface::SOURCE_ID, + Table::TYPE_INTEGER, null, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + ], 'Source ID' + ) + ->addColumn( + SourceCarrierLinkInterface::CARRIER_CODE, + Table::TYPE_TEXT, 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], 'Carrier Code' + ) + ->addColumn( + 'position', Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + ], + 'Position' + ); // Add foreign key for Pipeline ID field $foreignKeyName = $installer->getConnection()->getForeignKeyName( @@ -218,11 +274,12 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con Table::ACTION_CASCADE ); - $table->setComment('Inventory Source Carrier Link Entity Table')->setOption('type', 'InnoDB')->setOption('charset', - 'utf8'); + $table->setComment('Inventory Source Carrier Link Entity Table')->setOption('type', 'InnoDB')->setOption( + 'charset', + 'utf8' + ); $installer->getConnection()->createTable($table); } - $setup->endSetup(); } } diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php index fe6ff139cbc1..259eee69c31a 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php @@ -8,6 +8,9 @@ use \Magento\Inventory\Model\SourceCarrierLink; +/** + * Class SourceCarrierLinkTest + */ class SourceCarrierLinkTest extends \PHPUnit_Framework_TestCase { /** @@ -19,12 +22,12 @@ class SourceCarrierLinkTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ - protected $objectManager; + private $objectManager; /** * @var SourceCarrierLink */ - protected $sourceCarrierLink; + private $sourceCarrierLink; protected function setUp() { diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 3e06272ef728..0caa923e7b88 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -10,7 +10,6 @@ /** * Class SourceRepositoryTest - * @package Magento\Inventory\Test\Unit\Model */ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase { diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php index 252cb6c309d0..f78c2e66d934 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php @@ -8,6 +8,9 @@ use \Magento\Inventory\Model\Source; +/** + * Class SourceTest + */ class SourceTest extends \PHPUnit_Framework_TestCase { /** @@ -20,12 +23,12 @@ class SourceTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ - protected $objectManager; + private $objectManager; /** * @var Source */ - protected $source; + private $source; protected function setUp() { diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index 70cef91a7dd0..75ac289b5f24 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -165,7 +165,7 @@ public function getCountryId(); /** * Set source country id. * - * @param string $countryId + * @param int $countryId * @return $this */ public function setCountryId($countryId); diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index 7859e32297fb..ffd97d5837a1 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -20,7 +20,7 @@ interface SourceRepositoryInterface * Save Source data. * * @param SourceInterface $source - * @return SourceInterface + * @return void * * @throws CouldNotSaveException */ From f0d8ee85c33ca4c1d999fa72b7ecb82708a32b0e Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sun, 21 May 2017 13:09:55 +0200 Subject: [PATCH 38/66] magento-engcom/magento2#25: Implement first api functional test for creating sources --- .../Inventory/Model/SourceRepository.php | 18 +-- .../Api/SourceRepositoryInterface.php | 11 +- .../InventoryApi/Api/SourceRepositoryTest.php | 120 +++++++++++++----- 3 files changed, 102 insertions(+), 47 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 607b202d4c29..1ae30036c51d 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -12,12 +12,12 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Model\AbstractModel; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; +use Magento\InventoryApi\Api\Data\SourceSearchResultsInterfaceFactory; use Magento\InventoryApi\Api\SourceRepositoryInterface; -use Magento\Inventory\Model\SourceSearchResultsFactory; use Magento\Inventory\Model\Resource\Source as ResourceSource; use Magento\Inventory\Model\Resource\Source\CollectionFactory; -use Magento\Inventory\Model\SourceFactory; /** * Class SourceRepository @@ -31,7 +31,7 @@ class SourceRepository implements SourceRepositoryInterface private $resource; /** - * @var SourceFactory + * @var SourceInterfaceFactory */ private $sourceFactory; @@ -46,24 +46,24 @@ class SourceRepository implements SourceRepositoryInterface private $collectionFactory; /** - * @var SourceSearchResultsFactory + * @var SourceSearchResultsInterfaceFactory */ private $sourceSearchResultsFactory; /** * SourceRepository constructor. * @param ResourceSource $resource - * @param SourceFactory $sourceFactory + * @param SourceInterfaceFactory $sourceFactory * @param CollectionProcessorInterface $collectionProcessor * @param CollectionFactory $collectionFactory - * @param SourceSearchResultsFactory $sourceSearchResultsFactory + * @param SourceSearchResultsInterfaceFactory $sourceSearchResultsFactory */ public function __construct( ResourceSource $resource, - SourceFactory $sourceFactory, + SourceInterfaceFactory $sourceFactory, CollectionProcessorInterface $collectionProcessor, CollectionFactory $collectionFactory, - SourceSearchResultsFactory $sourceSearchResultsFactory + SourceSearchResultsInterfaceFactory $sourceSearchResultsFactory ) { $this->resource = $resource; $this->sourceFactory = $sourceFactory; @@ -92,7 +92,7 @@ public function get($sourceId) { /** @var SourceInterface|AbstractModel $model */ $model = $this->sourceFactory->create(); - $this->resource->load($model, SourceInterface::SOURCE_ID, $sourceId); + $this->resource->load($model, $sourceId, SourceInterface::SOURCE_ID); if (!$model->getSourceId()) { throw NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId); diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index 7859e32297fb..2048dd215db1 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -9,7 +9,6 @@ use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\InventoryApi\Api\Data\SourceInterface; -use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; /** * @api @@ -19,8 +18,8 @@ interface SourceRepositoryInterface /** * Save Source data. * - * @param SourceInterface $source - * @return SourceInterface + * @param \Magento\InventoryApi\Api\Data\SourceInterface $source + * @return \Magento\InventoryApi\Api\Data\SourceInterface * * @throws CouldNotSaveException */ @@ -30,7 +29,7 @@ public function save(SourceInterface $source); * Load Source data by given sourceId. * * @param int $sourceId - * @return SourceInterface + * @return \Magento\InventoryApi\Api\Data\SourceInterface * @throws NoSuchEntityException */ public function get($sourceId); @@ -38,8 +37,8 @@ public function get($sourceId); /** * Load Source data collection by given search criteria * - * @param SearchCriteriaInterface $searchCriteria - * @return SourceSearchResultsInterface + * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria + * @return \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface */ public function getList(SearchCriteriaInterface $searchCriteria = null); } diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index 5d93f34f9ee7..8a4f3a46b582 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -7,7 +7,9 @@ use Magento\Directory\Api\CountryInformationAcquirerInterface; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; +use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterfaceFactory; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; use Magento\TestFramework\TestCase\WebapiAbstract; use Magento\TestFramework\Helper\Bootstrap; @@ -18,7 +20,7 @@ class SourceRepositoryTest extends WebapiAbstract const RESOURCE_PATH = '/V1/inventory/source/'; /** - * @var \Magento\InventoryApi\Api\Data\SourceInterfaceFactory + * @var SourceInterfaceFactory */ private $sourceFactory; @@ -28,21 +30,31 @@ class SourceRepositoryTest extends WebapiAbstract private $countryInformationAcquirer; /** - * @var \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterfaceFactory + * @var SourceCarrierLinkInterfaceFactory */ private $sourceCarrierLinkFactory; + /** + * @var SourceRepositoryInterface + */ + private $sourceRepository; + /** * Execute per test initialization. */ public function setUp() { $this->sourceFactory = Bootstrap::getObjectManager() - ->create(\Magento\InventoryApi\Api\Data\SourceInterfaceFactory::class); + ->create(SourceInterfaceFactory::class); + $this->countryInformationAcquirer = Bootstrap::getObjectManager() ->create(CountryInformationAcquirerInterface::class); + $this->sourceCarrierLinkFactory = Bootstrap::getObjectManager() - ->create(\Magento\InventoryApi\Api\Data\SourceCarrierLinkInterfaceFactory::class); + ->create(SourceCarrierLinkInterfaceFactory::class); + + $this->sourceRepository = Bootstrap::getObjectManager() + ->create(SourceRepositoryInterface::class); } /** @@ -51,6 +63,8 @@ public function setUp() public function testCreateSource() { $country = $this->countryInformationAcquirer->getCountryInfo('DE'); + $regions = $country->getAvailableRegions(); + $region = $regions[0]; $name = 'Source name'; $description = 'Some description for source'; @@ -69,44 +83,39 @@ public function testCreateSource() $carrierCode1 = 'CAR-1'; $carrierCode2 = 'CAR-2'; - /** @var SourceCarrierLinkInterface $carrierLink1 */ - $carrierLink1 = $this->sourceCarrierLinkFactory->create(); - $carrierLink1->setPosition(1) + /** @var SourceCarrierLinkInterface $expectedCarrierLink1 */ + $expectedCarrierLink1 = $this->sourceCarrierLinkFactory->create(); + $expectedCarrierLink1->setPosition(1) ->setCarrierCode($carrierCode1); - /** @var SourceCarrierLinkInterface $carrierLink2*/ - $carrierLink2 = $this->sourceCarrierLinkFactory->create(); - $carrierLink2->setPosition(2) + /** @var SourceCarrierLinkInterface $expectedCarrierLink2 */ + $expectedCarrierLink2 = $this->sourceCarrierLinkFactory->create(); + $expectedCarrierLink2->setPosition(2) ->setCarrierCode($carrierCode2); - /** @var \Magento\InventoryApi\Api\Data\SourceInterface $sourceDataObject */ - $sourceDataObject = $this->sourceFactory->create(); - $sourceDataObject->setName($name) - ->setDescription($description) + /** @var \Magento\InventoryApi\Api\Data\SourceInterface $expectedSource */ + $expectedSource = $this->sourceFactory->create(); + $expectedSource->setName($name) ->setCity($city) ->setPostcode($postcode) ->setContactName($contactName) ->setCountryId($country->getId()) + ->setDescription($description) ->setEmail($email) + ->setStreet($street) ->setFax($fax) ->setPhone($phone) + ->setRegion($region->getName()) + ->setRegionId($region->getId()) ->setLatitude($latitude) ->setLongitude($longitude) ->setIsActive($isActive) ->setPriority($priority) - ->setStreet($street) ->setCarrierLinks([ - $carrierLink1, - $carrierLink2 + $expectedCarrierLink1, + $expectedCarrierLink2 ]); - $regions = $country->getAvailableRegions(); - if ($regions) { - $region = $regions[0]; - $sourceDataObject->setRegion($region->getName()); - $sourceDataObject->setRegionId($region->getId()); - } - $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH, @@ -119,20 +128,67 @@ public function testCreateSource() ], ]; - $requestData = [ 'source' => [ - SourceInterface::CITY => $sourceDataObject->getCity(), - SourceInterface::CONTACT_NAME => $sourceDataObject->getContactName(), - SourceInterface::COUNTRY_ID => $sourceDataObject->getCountryId(), - SourceInterface::DESCRIPTION => $sourceDataObject->getDescription(), - SourceInterface::NAME => $sourceDataObject->getName(), - SourceInterface::EMAIL => $sourceDataObject->getEmail(), + SourceInterface::NAME => $expectedSource->getName(), + SourceInterface::CITY => $expectedSource->getCity(), + SourceInterface::POSTCODE => $expectedSource->getPostcode(), + SourceInterface::CONTACT_NAME => $expectedSource->getContactName(), + SourceInterface::COUNTRY_ID => $expectedSource->getCountryId(), + SourceInterface::DESCRIPTION => $expectedSource->getDescription(), + SourceInterface::EMAIL => $expectedSource->getEmail(), + SourceInterface::STREET => $expectedSource->getStreet(), + SourceInterface::FAX => $expectedSource->getFax(), + SourceInterface::PHONE => $expectedSource->getPhone(), + SourceInterface::REGION => $expectedSource->getRegion(), + SourceInterface::REGION_ID => $expectedSource->getRegionId(), + SourceInterface::LATITUDE => $expectedSource->getLatitude(), + SourceInterface::LONGITUDE => $expectedSource->getLongitude(), + SourceInterface::IS_ACTIVE => $expectedSource->getIsActive(), + SourceInterface::PRIORITY => $expectedSource->getPriority(), + SourceInterface::CARRIER_LINKS => [ + [ + SourceCarrierLinkInterface::CARRIER_CODE => $expectedCarrierLink1->getCarrierCode(), + SourceCarrierLinkInterface::POSITION => $expectedCarrierLink1->getPosition(), + ], + [ + SourceCarrierLinkInterface::CARRIER_CODE => $expectedCarrierLink2->getCarrierCode(), + SourceCarrierLinkInterface::POSITION => $expectedCarrierLink2->getPosition(), + ] + ] ], ]; $result = $this->_webApiCall($serviceInfo, $requestData); - var_dump($result); + $this->assertNotNull($result['source_id']); + + $createdSource = $this->sourceRepository->get($result['source_id']); + $this->assertEquals($expectedSource->getName(), $createdSource->getName()); + $this->assertEquals($expectedSource->getCity(), $createdSource->getCity()); + $this->assertEquals($expectedSource->getPostcode(), $createdSource->getPostcode()); + $this->assertEquals($expectedSource->getContactName(), $createdSource->getContactName()); + $this->assertEquals($expectedSource->getCountryId(), $createdSource->getCountryId()); + $this->assertEquals($expectedSource->getDescription(), $createdSource->getDescription()); + $this->assertEquals($expectedSource->getEmail(), $createdSource->getEmail()); + $this->assertEquals($expectedSource->getStreet(), $createdSource->getStreet()); + $this->assertEquals($expectedSource->getFax(), $createdSource->getFax()); + $this->assertEquals($expectedSource->getPhone(), $createdSource->getPhone()); + $this->assertEquals($expectedSource->getRegion(), $createdSource->getRegion()); + $this->assertEquals($expectedSource->getRegionId(), $createdSource->getRegionId()); + $this->assertEquals($expectedSource->getLatitude(), $createdSource->getLatitude()); + $this->assertEquals($expectedSource->getLongitude(), $createdSource->getLongitude()); + $this->assertEquals($expectedSource->getIsActive(), $createdSource->getIsActive()); + $this->assertEquals($expectedSource->getPriority(), $createdSource->getPriority()); + + $createdCarrierLinks = $createdSource->getCarrierLinks(); + + $createdCarrierLink1 = $createdCarrierLinks[0]; + $this->assertEquals($expectedCarrierLink1->getCarrierCode(), $createdCarrierLink1->getCarrierCode()); + $this->assertEquals($expectedCarrierLink1->getPosition(), $createdCarrierLink1->getPosition()); + + $createdCarrierLink2 = $createdCarrierLinks[1]; + $this->assertEquals($expectedCarrierLink2->getCarrierCode(), $createdCarrierLink2->getCarrierCode()); + $this->assertEquals($expectedCarrierLink2->getPosition(), $createdCarrierLink2->getPosition()); } /** From a437a2049d46b6feb4c10d3c3321957a4a4b2039 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sun, 21 May 2017 15:11:40 +0200 Subject: [PATCH 39/66] magento-engcom/magento2#25: WIP api functional tests --- .../Inventory/Model/SourceRepository.php | 1 + .../Magento/Inventory/Setup/InstallSchema.php | 371 +++++++++--------- .../Test/Unit/Model/SourceRepositoryTest.php | 3 +- .../Api/SourceRepositoryInterface.php | 2 +- .../InventoryApi/Api/SourceRepositoryTest.php | 121 +++--- 5 files changed, 253 insertions(+), 245 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index ec9d0133367e..1f771a66dc66 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -89,6 +89,7 @@ public function save(SourceInterface $source) { try { $this->resource->save($source); + return $source->getSourceId(); } catch (\Exception $exception) { $this->logger->error($exception->getMessage()); throw new CouldNotSaveException(__('Could not save source')); diff --git a/app/code/Magento/Inventory/Setup/InstallSchema.php b/app/code/Magento/Inventory/Setup/InstallSchema.php index ae8a3c878d28..9cddd740c29d 100644 --- a/app/code/Magento/Inventory/Setup/InstallSchema.php +++ b/app/code/Magento/Inventory/Setup/InstallSchema.php @@ -25,7 +25,8 @@ class InstallSchema implements InstallSchemaInterface /** * Constant for decimal precision for latitude and longitude */ - const DECIMAL_PLACES = 8; + const LATLON_PRECISION = 10; + const LATLON_SCALE = 6; /** * Option keys for column options @@ -63,157 +64,161 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con InstallSchema::OPTION_IDENTITY => true, InstallSchema::OPTION_UNSIGNED => true, InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_PRIMARY => true + InstallSchema::OPTION_PRIMARY => true ], 'Source ID' - ) - ->addColumn( - SourceInterface::NAME, - Table::TYPE_TEXT, - 255, [ + )->addColumn( + SourceInterface::NAME, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Source Name' + )->addColumn( + SourceInterface::CONTACT_NAME, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Contact Name' + )->addColumn( + SourceInterface::EMAIL, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Email' + )->addColumn( + SourceInterface::IS_ACTIVE, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_DEFAULT => 1 + ], + 'Defines Is Source Active' + )->addColumn( + SourceInterface::DESCRIPTION, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Description' + )->addColumn( + SourceInterface::LATITUDE, + Table::TYPE_DECIMAL, + null, + [ + InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION, + InstallSchema::OPTION_SCALE => InstallSchema::LATLON_SCALE, + InstallSchema::OPTION_NULLABLE => true + ], + 'Latitude' + )->addColumn( + SourceInterface::LONGITUDE, + Table::TYPE_DECIMAL, + null, + [ + InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION, + InstallSchema::OPTION_SCALE => InstallSchema::LATLON_SCALE, + InstallSchema::OPTION_NULLABLE => true + ], + 'Longitude' + )->addColumn( + SourceInterface::COUNTRY_ID, + Table::TYPE_TEXT, + 2, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Country Id' + )->addColumn( + SourceInterface::REGION_ID, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => true, + InstallSchema::OPTION_UNSIGNED => true + ], + 'Region Id' + )->addColumn( + SourceInterface::REGION, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Region' + )->addColumn( + SourceInterface::CITY, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'City' + )->addColumn( + SourceInterface::STREET, + Table::TYPE_TEXT, + 255, + [ InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' + InstallSchema::OPTION_DEFAULT => '' ], - 'Source Name' - ) - ->addColumn( - SourceInterface::CONTACT_NAME, - Table::TYPE_TEXT, - 255, [ + 'Street' + )->addColumn( + SourceInterface::POSTCODE, + Table::TYPE_TEXT, + 255, + [ InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' + InstallSchema::OPTION_DEFAULT => '' ], - 'Contact Name' - ) - ->addColumn( - SourceInterface::EMAIL, - Table::TYPE_TEXT, - 255, [ + 'Postcode' + )->addColumn( + SourceInterface::PHONE, + Table::TYPE_TEXT, + 255, + [ InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' + InstallSchema::OPTION_DEFAULT => '' + ], + 'Phone' + )->addColumn( + SourceInterface::FAX, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Fax' + )->addColumn( + SourceInterface::PRIORITY, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => true, + InstallSchema::OPTION_UNSIGNED => true, ], - 'Email' - ) - ->addColumn( - SourceInterface::IS_ACTIVE, - Table::TYPE_SMALLINT, - null, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true, - InstallSchema::OPTION_DEFAULT => 1 - ], - 'Defines Is Source Active' - ) - ->addColumn( - SourceInterface::DESCRIPTION, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Description' - ) - ->addColumn( - SourceInterface::LATITUDE, - Table::TYPE_DECIMAL, null, - [ - InstallSchema::OPTION_PRECISION => InstallSchema::DECIMAL_PLACES, - InstallSchema::OPTION_SCALE => InstallSchema::DECIMAL_PLACES, - InstallSchema::OPTION_NULLABLE => true - ], 'Latitude' - ) - ->addColumn( - SourceInterface::LONGITUDE, - Table::TYPE_DECIMAL, null, - [ - InstallSchema::OPTION_PRECISION => InstallSchema::DECIMAL_PLACES, - InstallSchema::OPTION_SCALE => InstallSchema::DECIMAL_PLACES, - InstallSchema::OPTION_NULLABLE => true - ], 'Longitude' - ) - ->addColumn( - SourceInterface::COUNTRY_ID, - Table::TYPE_SMALLINT, - null, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true - ], 'Country Id' - )->addColumn( - SourceInterface::REGION_ID, - Table::TYPE_SMALLINT, - null, - [ - InstallSchema::OPTION_NULLABLE => true, - InstallSchema::OPTION_UNSIGNED => true - ], 'Region Id' - )->addColumn( - SourceInterface::REGION, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], 'Region' - ) - ->addColumn( - SourceInterface::CITY, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], 'City' - ) - ->addColumn( - SourceInterface::STREET, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], 'Street' - ) - ->addColumn( - SourceInterface::POSTCODE, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], 'Postcode' - ) - ->addColumn( - SourceInterface::PHONE, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], 'Phone' - ) - ->addColumn( - SourceInterface::FAX, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], 'Fax' - ) - ->addColumn( - SourceInterface::PRIORITY, - Table::TYPE_SMALLINT, - null, - [ - InstallSchema::OPTION_NULLABLE => true, - InstallSchema::OPTION_UNSIGNED => true, - ], 'Priority' - ); - $table->setComment('Inventory Source Entity Table')->setOption('type', 'InnoDB')->setOption('charset', - 'utf8'); + 'Priority' + ); + + $table->setComment('Inventory Source Entity Table') + ->setOption('type', 'InnoDB') + ->setOption('charset', 'utf8'); $installer->getConnection()->createTable($table); } @@ -222,42 +227,41 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con $table = $installer->getConnection()->newTable($tableNameCarrierLinkEntity); $table->addColumn( - 'source_carrier_link_id', - Table::TYPE_INTEGER, - null, - [ - InstallSchema::OPTION_IDENTITY => true, - InstallSchema::OPTION_UNSIGNED => true, - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_PRIMARY => true - ], - 'Source Carrier Link ID' - ) - ->addColumn( - SourceInterface::SOURCE_ID, - Table::TYPE_INTEGER, null, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true, - ], 'Source ID' - ) - ->addColumn( - SourceCarrierLinkInterface::CARRIER_CODE, - Table::TYPE_TEXT, 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], 'Carrier Code' - ) - ->addColumn( - 'position', Table::TYPE_SMALLINT, - null, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true, - ], - 'Position' - ); + 'source_carrier_link_id', + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_PRIMARY => true + ], + 'Source Carrier Link ID' + )->addColumn( + SourceInterface::SOURCE_ID, + Table::TYPE_INTEGER, null, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + ], + 'Source ID' + )->addColumn( + SourceCarrierLinkInterface::CARRIER_CODE, + Table::TYPE_TEXT, 255, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_DEFAULT => '' + ], + 'Carrier Code' + )->addColumn( + 'position', Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + ], + 'Position' + ); // Add foreign key for Pipeline ID field $foreignKeyName = $installer->getConnection()->getForeignKeyName( @@ -274,10 +278,9 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con Table::ACTION_CASCADE ); - $table->setComment('Inventory Source Carrier Link Entity Table')->setOption('type', 'InnoDB')->setOption( - 'charset', - 'utf8' - ); + $table->setComment('Inventory Source Carrier Link Entity Table') + ->setOption('type', 'InnoDB') + ->setOption('charset', 'utf8'); $installer->getConnection()->createTable($table); } $setup->endSetup(); diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 0caa923e7b88..d3bfae4e7c92 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -106,8 +106,7 @@ public function testSaveSuccessful() ); $result = $this->sourceRepository->save($sourceModel); - - $this->assertSame($sourceModel, $result); + $this->assertNotNull($result); } public function testSaveErrorExpectsException() diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index a1307fed80dc..29df169d2cc2 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -19,7 +19,7 @@ interface SourceRepositoryInterface * Save Source data. * * @param \Magento\InventoryApi\Api\Data\SourceInterface $source - * @return void + * @return int * * @throws CouldNotSaveException */ diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index 8a4f3a46b582..b9e43f36baa2 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -6,6 +6,8 @@ namespace Magento\InventoryApi\Api; use Magento\Directory\Api\CountryInformationAcquirerInterface; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\Api\SortOrderBuilder; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterfaceFactory; use Magento\InventoryApi\Api\Data\SourceInterface; @@ -39,6 +41,16 @@ class SourceRepositoryTest extends WebapiAbstract */ private $sourceRepository; + /** + * @var SearchCriteriaBuilder + */ + private $searchCriteriaBuilder; + + /** + * @var SortOrderBuilder + */ + private $sortOrderBuilder; + /** * Execute per test initialization. */ @@ -55,6 +67,12 @@ public function setUp() $this->sourceRepository = Bootstrap::getObjectManager() ->create(SourceRepositoryInterface::class); + + $this->searchCriteriaBuilder = Bootstrap::getObjectManager() + ->create(SearchCriteriaBuilder::class); + + $this->sortOrderBuilder = Bootstrap::getObjectManager() + ->create(SortOrderBuilder::class); } /** @@ -70,7 +88,7 @@ public function testCreateSource() $description = 'Some description for source'; $city = 'Exampletown'; $street = 'Some Street 455'; - $postcode = 54321; + $postcode = '54321'; $contactName = 'Contact Name'; $email = 'example.guy@test.com'; $fax = '0120002020033'; @@ -129,66 +147,53 @@ public function testCreateSource() ]; $requestData = [ - 'source' => [ - SourceInterface::NAME => $expectedSource->getName(), - SourceInterface::CITY => $expectedSource->getCity(), - SourceInterface::POSTCODE => $expectedSource->getPostcode(), - SourceInterface::CONTACT_NAME => $expectedSource->getContactName(), - SourceInterface::COUNTRY_ID => $expectedSource->getCountryId(), - SourceInterface::DESCRIPTION => $expectedSource->getDescription(), - SourceInterface::EMAIL => $expectedSource->getEmail(), - SourceInterface::STREET => $expectedSource->getStreet(), - SourceInterface::FAX => $expectedSource->getFax(), - SourceInterface::PHONE => $expectedSource->getPhone(), - SourceInterface::REGION => $expectedSource->getRegion(), - SourceInterface::REGION_ID => $expectedSource->getRegionId(), - SourceInterface::LATITUDE => $expectedSource->getLatitude(), - SourceInterface::LONGITUDE => $expectedSource->getLongitude(), - SourceInterface::IS_ACTIVE => $expectedSource->getIsActive(), - SourceInterface::PRIORITY => $expectedSource->getPriority(), - SourceInterface::CARRIER_LINKS => [ - [ - SourceCarrierLinkInterface::CARRIER_CODE => $expectedCarrierLink1->getCarrierCode(), - SourceCarrierLinkInterface::POSITION => $expectedCarrierLink1->getPosition(), - ], - [ - SourceCarrierLinkInterface::CARRIER_CODE => $expectedCarrierLink2->getCarrierCode(), - SourceCarrierLinkInterface::POSITION => $expectedCarrierLink2->getPosition(), - ] - ] - ], + 'source' => $this->formSourceToArray($expectedSource) ]; $result = $this->_webApiCall($serviceInfo, $requestData); - $this->assertNotNull($result['source_id']); - - $createdSource = $this->sourceRepository->get($result['source_id']); - $this->assertEquals($expectedSource->getName(), $createdSource->getName()); - $this->assertEquals($expectedSource->getCity(), $createdSource->getCity()); - $this->assertEquals($expectedSource->getPostcode(), $createdSource->getPostcode()); - $this->assertEquals($expectedSource->getContactName(), $createdSource->getContactName()); - $this->assertEquals($expectedSource->getCountryId(), $createdSource->getCountryId()); - $this->assertEquals($expectedSource->getDescription(), $createdSource->getDescription()); - $this->assertEquals($expectedSource->getEmail(), $createdSource->getEmail()); - $this->assertEquals($expectedSource->getStreet(), $createdSource->getStreet()); - $this->assertEquals($expectedSource->getFax(), $createdSource->getFax()); - $this->assertEquals($expectedSource->getPhone(), $createdSource->getPhone()); - $this->assertEquals($expectedSource->getRegion(), $createdSource->getRegion()); - $this->assertEquals($expectedSource->getRegionId(), $createdSource->getRegionId()); - $this->assertEquals($expectedSource->getLatitude(), $createdSource->getLatitude()); - $this->assertEquals($expectedSource->getLongitude(), $createdSource->getLongitude()); - $this->assertEquals($expectedSource->getIsActive(), $createdSource->getIsActive()); - $this->assertEquals($expectedSource->getPriority(), $createdSource->getPriority()); - - $createdCarrierLinks = $createdSource->getCarrierLinks(); - - $createdCarrierLink1 = $createdCarrierLinks[0]; - $this->assertEquals($expectedCarrierLink1->getCarrierCode(), $createdCarrierLink1->getCarrierCode()); - $this->assertEquals($expectedCarrierLink1->getPosition(), $createdCarrierLink1->getPosition()); - - $createdCarrierLink2 = $createdCarrierLinks[1]; - $this->assertEquals($expectedCarrierLink2->getCarrierCode(), $createdCarrierLink2->getCarrierCode()); - $this->assertEquals($expectedCarrierLink2->getPosition(), $createdCarrierLink2->getPosition()); + $this->assertNotNull($result); + + $createdSource = $this->sourceRepository->get($result); + $this->assertSame($this->formSourceToArray($expectedSource), $this->formSourceToArray($createdSource)); + } + + /** + * @param SourceInterface $source + * @return array + */ + private function formSourceToArray(SourceInterface $source) + { + $result = [ + SourceInterface::NAME => $source->getName(), + SourceInterface::CITY => $source->getCity(), + SourceInterface::POSTCODE => $source->getPostcode(), + SourceInterface::CONTACT_NAME => $source->getContactName(), + SourceInterface::COUNTRY_ID => $source->getCountryId(), + SourceInterface::DESCRIPTION => $source->getDescription(), + SourceInterface::EMAIL => $source->getEmail(), + SourceInterface::STREET => $source->getStreet(), + SourceInterface::FAX => $source->getFax(), + SourceInterface::PHONE => $source->getPhone(), + SourceInterface::REGION => $source->getRegion(), + SourceInterface::REGION_ID => $source->getRegionId(), + SourceInterface::LATITUDE => $source->getLatitude(), + SourceInterface::LONGITUDE => $source->getLongitude(), + SourceInterface::IS_ACTIVE => $source->getIsActive(), + SourceInterface::PRIORITY => $source->getPriority(), + SourceInterface::CARRIER_LINKS => [] + ]; + + $carrierLinks = $source->getCarrierLinks(); + if ($carrierLinks) { + foreach ($carrierLinks as $carrierLink) { + $result[SourceInterface::CARRIER_LINKS][] = [ + SourceCarrierLinkInterface::CARRIER_CODE => $carrierLink->getCarrierCode(), + SourceCarrierLinkInterface::POSITION => $carrierLink->getPosition(), + ]; + } + } + + return $result; } /** From 42e3cce6b36866263f499c3cee32d3f976558de6 Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Wed, 24 May 2017 11:47:03 +0200 Subject: [PATCH 40/66] magento-engcom/magento2#25: Source API Implementation - Fixes according to test results --- .../Inventory/Model/SourceRepository.php | 11 +++++--- .../Test/Unit/Model/SourceRepositoryTest.php | 26 ++++++++++++------- .../Api/SourceRepositoryInterface.php | 26 ++++++++----------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 27bef7ff5584..1a66b8965f67 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -12,13 +12,14 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Model\AbstractModel; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; use Magento\InventoryApi\Api\SourceRepositoryInterface; use Magento\Inventory\Model\SourceSearchResultsFactory; use Magento\Inventory\Model\Resource\Source as ResourceSource; use Magento\Inventory\Model\Resource\Source\CollectionFactory; use Magento\Inventory\Model\SourceFactoryInterface; -use \Psr\Log\LoggerInterface; +use Psr\Log\LoggerInterface; /** * Class SourceRepository @@ -34,7 +35,7 @@ class SourceRepository implements SourceRepositoryInterface private $resource; /** - * @var SourceFactoryInterface + * @var SourceInterfaceFactory */ private $sourceFactory; @@ -61,7 +62,7 @@ class SourceRepository implements SourceRepositoryInterface /** * SourceRepository constructor. * @param ResourceSource $resource - * @param SourceFactoryInterface $sourceFactory + * @param SourceInterfaceFactory $sourceFactory * @param CollectionProcessorInterface $collectionProcessor * @param CollectionFactory $collectionFactory * @param SourceSearchResultsFactory $sourceSearchResultsFactory @@ -69,7 +70,7 @@ class SourceRepository implements SourceRepositoryInterface */ public function __construct( ResourceSource $resource, - SourceFactoryInterface $sourceFactory, + SourceInterfaceFactory $sourceFactory, CollectionProcessorInterface $collectionProcessor, CollectionFactory $collectionFactory, SourceSearchResultsFactory $sourceSearchResultsFactory, @@ -94,6 +95,8 @@ public function save(SourceInterface $source) $this->logger->error($exception->getMessage()); throw new CouldNotSaveException(__('Could not save source')); } + + return $source; } /** diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 0caa923e7b88..10a0e967ce52 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -38,6 +38,11 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase */ private $sourceSearchResultsFactory; + /** + * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $loggerMock; + /** * @var \Magento\Inventory\Model\SourceRepository|\PHPUnit_Framework_MockObject_MockObject */ @@ -54,7 +59,7 @@ protected function setUp() ); $this->sourceFactory = $this->getMock( - \Magento\Inventory\Model\SourceFactory::class, + \Magento\InventoryApi\Api\Data\SourceInterfaceFactory::class, ['create'], [], '', @@ -81,6 +86,10 @@ protected function setUp() false ); + $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->sourceRepository = $objectManager->getObject( \Magento\Inventory\Model\SourceRepository::class, @@ -90,6 +99,7 @@ protected function setUp() 'collectionProcessor' => $this->collectionProcessor, 'collectionFactory' => $this->collectionFactory, 'sourceSearchResultsFactory' => $this->sourceSearchResultsFactory, + 'logger' => $this->loggerMock, ] ); } @@ -97,17 +107,13 @@ protected function setUp() public function testSaveSuccessful() { /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMock( - \Magento\Inventory\Model\Source::class, - [], - [], - '', - false - ); + $sourceModelMock = $this->getMockBuilder(\Magento\Inventory\Model\Source::class) + ->disableOriginalConstructor() + ->getMock(); - $result = $this->sourceRepository->save($sourceModel); + $result = $this->sourceRepository->save($sourceModelMock); - $this->assertSame($sourceModel, $result); + $this->assertSame($sourceModelMock, $result); } public function testSaveErrorExpectsException() diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index ffd97d5837a1..3bc8947a4cec 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -5,12 +5,6 @@ */ namespace Magento\InventoryApi\Api; -use Magento\Framework\Api\SearchCriteriaInterface; -use Magento\Framework\Exception\CouldNotSaveException; -use Magento\Framework\Exception\NoSuchEntityException; -use Magento\InventoryApi\Api\Data\SourceInterface; -use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; - /** * @api */ @@ -19,27 +13,29 @@ interface SourceRepositoryInterface /** * Save Source data. * - * @param SourceInterface $source - * @return void + * @param \Magento\InventoryApi\Api\Data\SourceInterface $source + * @return int * - * @throws CouldNotSaveException + * @throws \Magento\Framework\Exception\CouldNotSaveException */ - public function save(SourceInterface $source); + public function save(\Magento\InventoryApi\Api\Data\SourceInterface $source); /** * Load Source data by given sourceId. * * @param int $sourceId - * @return SourceInterface - * @throws NoSuchEntityException + * @return \Magento\InventoryApi\Api\Data\SourceInterface + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function get($sourceId); /** * Load Source data collection by given search criteria * - * @param SearchCriteriaInterface $searchCriteria - * @return SourceSearchResultsInterface + * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria + * @return \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface */ - public function getList(SearchCriteriaInterface $searchCriteria = null); + public function getList( + \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null + ); } From 1e9da30b972f458975a96c19de3ace23168cc8d5 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sun, 28 May 2017 15:32:53 +0200 Subject: [PATCH 41/66] magento-engcom/magento2#25: WIP api-functional tests --- .../Api/Data/SourceCarrierLinkInterface.php | 1 + .../InventoryApi/Api/SourceRepositoryTest.php | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index ad84cda34323..99b91f37a204 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -14,6 +14,7 @@ interface SourceCarrierLinkInterface extends ExtensibleDataInterface */ const CARRIER_CODE = 'carrier_code'; const POSITION = 'position'; + const EXTENSION_ATTRIBUTES = 'extension_attributes'; /**#@-*/ /** diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index b9e43f36baa2..f62295bd4cf2 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -147,21 +147,42 @@ public function testCreateSource() ]; $requestData = [ - 'source' => $this->formSourceToArray($expectedSource) + 'source' => $this->getSourceDataArray($expectedSource) ]; $result = $this->_webApiCall($serviceInfo, $requestData); $this->assertNotNull($result); $createdSource = $this->sourceRepository->get($result); - $this->assertSame($this->formSourceToArray($expectedSource), $this->formSourceToArray($createdSource)); + $this->assertSame( + $this->getExpectedValues($this->getSourceDataArray($expectedSource)), + $this->getSourceDataArray($createdSource) + ); + } + + /** + * @param array $sourceData + * @return array + */ + private function getExpectedValues(array $sourceData) + { + $sourceData[SourceInterface::LATITUDE] = number_format( + $sourceData[SourceInterface::LATITUDE], + 6 + ); + $sourceData[SourceInterface::LONGITUDE] = number_format( + $sourceData[SourceInterface::LONGITUDE], + 6 + ); + + return $sourceData; } /** * @param SourceInterface $source * @return array */ - private function formSourceToArray(SourceInterface $source) + private function getSourceDataArray(SourceInterface $source) { $result = [ SourceInterface::NAME => $source->getName(), @@ -189,6 +210,7 @@ private function formSourceToArray(SourceInterface $source) $result[SourceInterface::CARRIER_LINKS][] = [ SourceCarrierLinkInterface::CARRIER_CODE => $carrierLink->getCarrierCode(), SourceCarrierLinkInterface::POSITION => $carrierLink->getPosition(), + SourceCarrierLinkInterface::EXTENSION_ATTRIBUTES => [], ]; } } From 3712ecf0cf8eb8098806cf0ea14cf5cb5f51fc53 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sun, 28 May 2017 19:15:16 +0200 Subject: [PATCH 42/66] magento-engcom/magento2#25: Finish first api-functional test --- .../Inventory/Model/SourceRepository.php | 81 +++++++++++++++++-- .../Api/Data/SourceCarrierLinkInterface.php | 5 +- .../InventoryApi/Api/SourceRepositoryTest.php | 3 +- 3 files changed, 79 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 9beb1574ad41..0120daf1baaf 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -6,18 +6,22 @@ namespace Magento\Inventory\Model; +use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Model\AbstractModel; +use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterfaceFactory; use Magento\InventoryApi\Api\SourceRepositoryInterface; use Magento\Inventory\Model\Resource\Source as ResourceSource; +use Magento\Inventory\Model\Resource\SourceCarrierLink as ResourceSourceCarrierLink; use Magento\Inventory\Model\Resource\Source\CollectionFactory; +use Magento\Inventory\Model\Resource\SourceCarrierLink\CollectionFactory as CarrierLinkCollectionFactory; use \Psr\Log\LoggerInterface; /** @@ -31,7 +35,12 @@ class SourceRepository implements SourceRepositoryInterface /** * @var ResourceSource */ - private $resource; + private $resourceSource; + + /** + * @var ResourceSourceCarrierLink + */ + private $resourceSourceCarrierLink; /** * @var SourceInterfaceFactory @@ -48,11 +57,21 @@ class SourceRepository implements SourceRepositoryInterface */ private $collectionFactory; + /** + * @var CarrierLinkCollectionFactory + */ + private $carrierLinkCollectionFactory; + /** * @var SourceSearchResultsInterfaceFactory */ private $sourceSearchResultsFactory; + /** + * @var SearchCriteriaBuilder + */ + private $searchCriteriaBuilder; + /** * @var LoggerInterface */ @@ -60,26 +79,35 @@ class SourceRepository implements SourceRepositoryInterface /** * SourceRepository constructor. - * @param ResourceSource $resource + * @param ResourceSource $resourceSource + * @param ResourceSourceCarrierLink $resourceSourceCarrierLink * @param SourceInterfaceFactory $sourceFactory * @param CollectionProcessorInterface $collectionProcessor * @param CollectionFactory $collectionFactory + * @param CarrierLinkCollectionFactory $carrierLinkCollectionFactory * @param SourceSearchResultsInterfaceFactory $sourceSearchResultsFactory + * @param SearchCriteriaBuilder $searchCriteriaBuilder * @param LoggerInterface $logger */ public function __construct( - ResourceSource $resource, + ResourceSource $resourceSource, + ResourceSourceCarrierLink $resourceSourceCarrierLink, SourceInterfaceFactory $sourceFactory, CollectionProcessorInterface $collectionProcessor, CollectionFactory $collectionFactory, + CarrierLinkCollectionFactory $carrierLinkCollectionFactory, SourceSearchResultsInterfaceFactory $sourceSearchResultsFactory, + SearchCriteriaBuilder $searchCriteriaBuilder, LoggerInterface $logger ) { - $this->resource = $resource; + $this->resourceSource = $resourceSource; + $this->resourceSourceCarrierLink = $resourceSourceCarrierLink; $this->sourceFactory = $sourceFactory; $this->collectionProcessor = $collectionProcessor; $this->collectionFactory = $collectionFactory; + $this->carrierLinkCollectionFactory = $carrierLinkCollectionFactory; $this->sourceSearchResultsFactory = $sourceSearchResultsFactory; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->logger = $logger; } @@ -89,7 +117,8 @@ public function __construct( public function save(SourceInterface $source) { try { - $this->resource->save($source); + $this->saveSource($source); + $this->saveSourceCarrierLinks($source); return $source->getSourceId(); } catch (\Exception $exception) { $this->logger->error($exception->getMessage()); @@ -97,14 +126,36 @@ public function save(SourceInterface $source) } } + /** + * @param SourceInterface $source + */ + private function saveSource(SourceInterface $source) + { + /** @var SourceInterface|AbstractModel $source */ + $this->resourceSource->save($source); + } + + /** + * @param SourceInterface $source + */ + private function saveSourceCarrierLinks(SourceInterface $source) + { + /** @var SourceCarrierLinkInterface|AbstractModel $carrierLink */ + foreach ($source->getCarrierLinks() as $carrierLink) { + $carrierLink->setData(SourceInterface::SOURCE_ID, $source->getSourceId()); + $this->resourceSourceCarrierLink->save($carrierLink); + } + } + /** * @inheritdoc */ public function get($sourceId) { - /** @var SourceInterface|AbstractModel $model */ + /** @var SourceInterface|AbstractModel $source */ $source = $this->sourceFactory->create(); - $this->resource->load($source, $sourceId, SourceInterface::SOURCE_ID); + $this->resourceSource->load($source, $sourceId, SourceInterface::SOURCE_ID); + $this->addCarrierLinks($source); if (!$source->getSourceId()) { throw NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId); @@ -113,6 +164,22 @@ public function get($sourceId) return $source; } + /** + * @param SourceInterface $source + */ + private function addCarrierLinks(SourceInterface $source) + { + /** @var ResourceSourceCarrierLink\Collection $collection */ + $collection = $this->carrierLinkCollectionFactory->create(); + + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(SourceInterface::SOURCE_ID, $source->getSourceId()) + ->create(); + + $this->collectionProcessor->process($searchCriteria, $collection); + $source->setCarrierLinks($collection->getItems()); + } + /** * @inheritdoc */ diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 99b91f37a204..44bcb68d6b3e 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -7,6 +7,10 @@ use \Magento\Framework\Api\ExtensibleDataInterface; +/** + * SourceCarrierLink interface + * @api + */ interface SourceCarrierLinkInterface extends ExtensibleDataInterface { /**#@+ @@ -14,7 +18,6 @@ interface SourceCarrierLinkInterface extends ExtensibleDataInterface */ const CARRIER_CODE = 'carrier_code'; const POSITION = 'position'; - const EXTENSION_ATTRIBUTES = 'extension_attributes'; /**#@-*/ /** diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index f62295bd4cf2..047e70c2b3af 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -154,7 +154,7 @@ public function testCreateSource() $this->assertNotNull($result); $createdSource = $this->sourceRepository->get($result); - $this->assertSame( + $this->assertEquals( $this->getExpectedValues($this->getSourceDataArray($expectedSource)), $this->getSourceDataArray($createdSource) ); @@ -210,7 +210,6 @@ private function getSourceDataArray(SourceInterface $source) $result[SourceInterface::CARRIER_LINKS][] = [ SourceCarrierLinkInterface::CARRIER_CODE => $carrierLink->getCarrierCode(), SourceCarrierLinkInterface::POSITION => $carrierLink->getPosition(), - SourceCarrierLinkInterface::EXTENSION_ATTRIBUTES => [], ]; } } From a3599a49b9cfd73178fbf2df5da77193d6803857 Mon Sep 17 00:00:00 2001 From: Vadim Justus Date: Sun, 28 May 2017 20:56:14 +0200 Subject: [PATCH 43/66] magento-engcom/magento2#25: wip: Implement further api-functional tests --- .../Inventory/Model/SourceRepository.php | 7 +- .../Magento/Cms/Api/BlockRepositoryTest.php | 1 + .../InventoryApi/Api/SourceRepositoryTest.php | 284 ++++++++++++------ 3 files changed, 200 insertions(+), 92 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 0120daf1baaf..f16ae071906f 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -188,15 +188,16 @@ public function getList(SearchCriteriaInterface $searchCriteria = null) /** @var \Magento\Inventory\Model\Resource\Source\Collection $collection */ $collection = $this->collectionFactory->create(); + /** @var SourceSearchResultsInterface $searchResults */ + $searchResults = $this->sourceSearchResultsFactory->create(); + // if there is a searchCriteria defined, use it to add its creterias to the collection if (!is_null($searchCriteria)) { $this->collectionProcessor->process($searchCriteria, $collection); + $searchResults->setSearchCriteria($searchCriteria); } - /** @var SourceSearchResultsInterface $searchResults */ - $searchResults = $this->sourceSearchResultsFactory->create(); $searchResults->setItems($collection->getItems()); - $searchResults->setSearchCriteria($searchCriteria); $searchResults->setTotalCount($collection->getSize()); return $searchResults; } diff --git a/dev/tests/api-functional/testsuite/Magento/Cms/Api/BlockRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Cms/Api/BlockRepositoryTest.php index 15ccd5e2586d..3c00fdc1ae86 100644 --- a/dev/tests/api-functional/testsuite/Magento/Cms/Api/BlockRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Cms/Api/BlockRepositoryTest.php @@ -262,6 +262,7 @@ public function testSearch() $searchData = $searchCriteriaBuilder->create()->__toArray(); $requestData = ['searchCriteria' => $searchData]; + $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH . "/search" . '?' . http_build_query($requestData), diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index 047e70c2b3af..d01340e4ecad 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -6,7 +6,9 @@ namespace Magento\InventoryApi\Api; use Magento\Directory\Api\CountryInformationAcquirerInterface; +use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\Api\SortOrder; use Magento\Framework\Api\SortOrderBuilder; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterfaceFactory; @@ -46,6 +48,11 @@ class SourceRepositoryTest extends WebapiAbstract */ private $searchCriteriaBuilder; + /** + * @var FilterBuilder + */ + private $filterBuilder; + /** * @var SortOrderBuilder */ @@ -71,95 +78,13 @@ public function setUp() $this->searchCriteriaBuilder = Bootstrap::getObjectManager() ->create(SearchCriteriaBuilder::class); + $this->filterBuilder = Bootstrap::getObjectManager() + ->create(FilterBuilder::class); + $this->sortOrderBuilder = Bootstrap::getObjectManager() ->create(SortOrderBuilder::class); } - /** - * Create new Inventory Source using Web API and verify it's integrity. - */ - public function testCreateSource() - { - $country = $this->countryInformationAcquirer->getCountryInfo('DE'); - $regions = $country->getAvailableRegions(); - $region = $regions[0]; - - $name = 'Source name'; - $description = 'Some description for source'; - $city = 'Exampletown'; - $street = 'Some Street 455'; - $postcode = '54321'; - $contactName = 'Contact Name'; - $email = 'example.guy@test.com'; - $fax = '0120002020033'; - $phone = '0120002020044'; - $latitude = 51.343479; - $longitude = 12.387772; - $isActive = true; - $priority = 40; - - $carrierCode1 = 'CAR-1'; - $carrierCode2 = 'CAR-2'; - - /** @var SourceCarrierLinkInterface $expectedCarrierLink1 */ - $expectedCarrierLink1 = $this->sourceCarrierLinkFactory->create(); - $expectedCarrierLink1->setPosition(1) - ->setCarrierCode($carrierCode1); - - /** @var SourceCarrierLinkInterface $expectedCarrierLink2 */ - $expectedCarrierLink2 = $this->sourceCarrierLinkFactory->create(); - $expectedCarrierLink2->setPosition(2) - ->setCarrierCode($carrierCode2); - - /** @var \Magento\InventoryApi\Api\Data\SourceInterface $expectedSource */ - $expectedSource = $this->sourceFactory->create(); - $expectedSource->setName($name) - ->setCity($city) - ->setPostcode($postcode) - ->setContactName($contactName) - ->setCountryId($country->getId()) - ->setDescription($description) - ->setEmail($email) - ->setStreet($street) - ->setFax($fax) - ->setPhone($phone) - ->setRegion($region->getName()) - ->setRegionId($region->getId()) - ->setLatitude($latitude) - ->setLongitude($longitude) - ->setIsActive($isActive) - ->setPriority($priority) - ->setCarrierLinks([ - $expectedCarrierLink1, - $expectedCarrierLink2 - ]); - - $serviceInfo = [ - 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH, - 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, - ], - 'soap' => [ - 'service' => self::SERVICE_NAME, - 'serviceVersion' => self::SERVICE_VERSION, - 'operation' => self::SERVICE_NAME . 'Save', - ], - ]; - - $requestData = [ - 'source' => $this->getSourceDataArray($expectedSource) - ]; - - $result = $this->_webApiCall($serviceInfo, $requestData); - $this->assertNotNull($result); - - $createdSource = $this->sourceRepository->get($result); - $this->assertEquals( - $this->getExpectedValues($this->getSourceDataArray($expectedSource)), - $this->getSourceDataArray($createdSource) - ); - } - /** * @param array $sourceData * @return array @@ -217,13 +142,121 @@ private function getSourceDataArray(SourceInterface $source) return $result; } + /** + * @param int $countCarrier + * @param string $postcode + * @return SourceInterface + */ + private function createRandomSource($countCarrier = 2, $postcode = '54321', $isActive = true) + { + $country = $this->countryInformationAcquirer->getCountryInfo('US'); + $regions = $country->getAvailableRegions(); + $region = $regions[rand(0, count($regions)-1)]; + + $name = 'Api Test ' . uniqid(); + $description = 'This is an inventory source created by api-functional tests'; + $city = 'Exampletown'; + $street = 'Some Street 455'; + $contactName = 'Contact Name'; + $email = 'example.guy@test.com'; + $fax = '0120002066033'; + $phone = '01660002020044'; + $latitude = 51.343479; + $longitude = 12.387772; + $priority = rand(1,999); + + $carriers = []; + for ($index = 1; $index <= $countCarrier; $index++) { + $carrierCode = 'CAR-' . $index; + $carrier = $this->sourceCarrierLinkFactory->create(); + $carrier->setPosition($index) + ->setCarrierCode($carrierCode); + $carriers[] = $carrier; + } + + /** @var \Magento\InventoryApi\Api\Data\SourceInterface $source */ + $source = $this->sourceFactory->create(); + $source->setName($name) + ->setCity($city) + ->setPostcode($postcode) + ->setContactName($contactName) + ->setCountryId($country->getId()) + ->setDescription($description) + ->setEmail($email) + ->setStreet($street) + ->setFax($fax) + ->setPhone($phone) + ->setRegion($region->getName()) + ->setRegionId($region->getId()) + ->setLatitude($latitude) + ->setLongitude($longitude) + ->setIsActive($isActive) + ->setPriority($priority) + ->setCarrierLinks($carriers); + + return $source; + } + + /** + * Create new Inventory Source using Web API and verify it's integrity. + */ + public function testCreateSource() + { + $expectedSource = $this->createRandomSource(3); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Save', + ], + ]; + + $requestData = [ + 'source' => $this->getSourceDataArray($expectedSource) + ]; + + $result = $this->_webApiCall($serviceInfo, $requestData); + $this->assertNotNull($result); + + $createdSource = $this->sourceRepository->get($result); + $this->assertEquals( + $this->getExpectedValues($this->getSourceDataArray($expectedSource)), + $this->getSourceDataArray($createdSource) + ); + } + /** * Load already existing Inventory Source using Web API and verify it's integrity. */ public function testGetSource() { - //TODO: Implement testGetSource - $this->fail(__METHOD__ . " is not implemented yet."); + $expectedSource = $this->createRandomSource(5); + $currentSourceId = $this->sourceRepository->save($expectedSource); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $currentSourceId, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + ], + ]; + + $result = $this->_webApiCall($serviceInfo, [SourceInterface::SOURCE_ID => $currentSourceId]); + $this->assertNotNull($result); + + $this->assertEquals($currentSourceId, $result[SourceInterface::SOURCE_ID]); + + unset($result[SourceInterface::SOURCE_ID]); + $this->assertEquals($this->getSourceDataArray($expectedSource), $result); } /** @@ -231,8 +264,81 @@ public function testGetSource() */ public function testGetSourcesList() { - //TODO: Implement testGetSourcesList - $this->fail(__METHOD__ . " is not implemented yet."); + $this->markTestSkipped('WIP: Search seems to ignore filter criterias!'); + + /** @var SearchCriteriaBuilder $searchCriteriaBuilder */ + $searchCriteriaBuilder = Bootstrap::getObjectManager() + ->create(SearchCriteriaBuilder::class); + + $postcode1 = uniqid('APITEST'); + $postcode2 = uniqid('APITEST'); + + $source1 = $this->createRandomSource(2, $postcode1, true); + $source1->setSourceId($this->sourceRepository->save($source1)); + + $source2 = $this->createRandomSource(3, $postcode1, false); + $this->sourceRepository->save($source2); + + $source3 = $this->createRandomSource(1, $postcode2, true); + $this->sourceRepository->save($source3); + + $source4 = $this->createRandomSource(3, $postcode2, true); + $this->sourceRepository->save($source4); + + $filter1 = $this->filterBuilder->setField(SourceInterface::POSTCODE) + ->setValue($postcode1); + + $filter2 = $this->filterBuilder->setField(SourceInterface::POSTCODE) + ->setValue($postcode2); + + $filter3 = $this->filterBuilder->setField(SourceInterface::IS_ACTIVE) + ->setValue(true); + + // where postcode = $postcode1 + // or postcode = $postcode2 + // and is_active = true + $searchCriteriaBuilder->addFilters([$filter1, $filter3]); + $searchCriteriaBuilder->addFilters([$filter2, $filter3]); + + $searchCriteriaBuilder->setPageSize(2); + + /** @var SortOrder $sortOrder */ + $sortOrder = $this->sortOrderBuilder->setField(SourceInterface::SOURCE_ID) + ->setDirection(SortOrder::SORT_ASC) + ->create(); + + $searchCriteriaBuilder->setSortOrders([$sortOrder]); + + $searchData = $searchCriteriaBuilder->create()->__toArray(); + $requestData = ['searchCriteria' => $searchData]; + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'search?' . http_build_query($requestData), + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'GetList', + ], + ]; + + var_dump($serviceInfo); + + $searchResult = $this->_webApiCall($serviceInfo, $requestData); + var_dump($searchResult); + + $this->assertEquals(3, $searchResult['page_size']); + $this->assertEquals(2, count($searchResult['items'])); + $this->assertEquals( + $searchResult['items'][0][SourceInterface::SOURCE_ID], + $source1->getSourceId() + ); + $this->assertEquals( + $searchResult['items'][1][SourceInterface::SOURCE_ID], + $source2->getSourceId() + ); } /** From 2ce2684f49bf7fce371e8c270895fa6bdb1f856b Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Sun, 28 May 2017 22:50:01 +0300 Subject: [PATCH 44/66] magento-engcom/magento2#25: Source Management API Implementation - Added PHP 7 types --- app/code/Magento/Inventory/Model/Source.php | 70 +++++------ .../Inventory/Model/SourceRepository.php | 6 +- .../Magento/Inventory/Setup/InstallSchema.php | 2 +- .../InventoryApi/Api/Data/SourceInterface.php | 110 +++++++++--------- .../Api/SourceRepositoryInterface.php | 7 +- 5 files changed, 98 insertions(+), 97 deletions(-) diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index b027936da91c..4fc3e34a1b25 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -36,7 +36,7 @@ public function getSourceId() /** * @inheritdoc */ - public function setSourceId($sourceId) + public function setSourceId(int $sourceId): SourceInterface { $this->setData(SourceInterface::SOURCE_ID, $sourceId); return $this; @@ -45,7 +45,7 @@ public function setSourceId($sourceId) /** * @inheritdoc */ - public function getName() + public function getName(): string { return $this->getData(SourceInterface::NAME); } @@ -53,7 +53,7 @@ public function getName() /** * @inheritdoc */ - public function setName($name) + public function setName(string $name): SourceInterface { $this->setData(SourceInterface::NAME, $name); return $this; @@ -62,7 +62,7 @@ public function setName($name) /** * @inheritdoc */ - public function getEmail() + public function getEmail(): string { return $this->getData(SourceInterface::EMAIL); } @@ -70,7 +70,7 @@ public function getEmail() /** * @inheritdoc */ - public function setEmail($email) + public function setEmail(string $email): SourceInterface { $this->setData(SourceInterface::EMAIL, $email); return $this; @@ -79,7 +79,7 @@ public function setEmail($email) /** * @inheritdoc */ - public function getContactName() + public function getContactName(): string { return $this->getData(SourceInterface::CONTACT_NAME); } @@ -87,7 +87,7 @@ public function getContactName() /** * @inheritdoc */ - public function setContactName($contactName) + public function setContactName(string $contactName): SourceInterface { $this->setData(SourceInterface::CONTACT_NAME, $contactName); return $this; @@ -96,7 +96,7 @@ public function setContactName($contactName) /** * @inheritdoc */ - public function getIsActive() + public function getIsActive(): bool { return $this->getData(SourceInterface::IS_ACTIVE); } @@ -104,7 +104,7 @@ public function getIsActive() /** * @inheritdoc */ - public function setIsActive($active) + public function setIsActive(bool $active): SourceInterface { $this->setData(SourceInterface::IS_ACTIVE, $active); return $this; @@ -113,7 +113,7 @@ public function setIsActive($active) /** * @inheritdoc */ - public function getDescription() + public function getDescription(): string { return $this->getData(SourceInterface::DESCRIPTION); } @@ -121,7 +121,7 @@ public function getDescription() /** * @inheritdoc */ - public function setDescription($description) + public function setDescription(string $description): SourceInterface { $this->setData(SourceInterface::DESCRIPTION, $description); return $this; @@ -130,7 +130,7 @@ public function setDescription($description) /** * @inheritdoc */ - public function getLatitude() + public function getLatitude(): float { return $this->getData(SourceInterface::LATITUDE); } @@ -138,7 +138,7 @@ public function getLatitude() /** * @inheritdoc */ - public function setLatitude($latitude) + public function setLatitude(float $latitude): SourceInterface { $this->setData(SourceInterface::LATITUDE, $latitude); return $this; @@ -147,7 +147,7 @@ public function setLatitude($latitude) /** * @inheritdoc */ - public function getLongitude() + public function getLongitude(): float { return $this->getData(SourceInterface::LONGITUDE); } @@ -155,7 +155,7 @@ public function getLongitude() /** * @inheritdoc */ - public function setLongitude($longitude) + public function setLongitude(float $longitude): SourceInterface { $this->setData(SourceInterface::LONGITUDE, $longitude); return $this; @@ -164,7 +164,7 @@ public function setLongitude($longitude) /** * @inheritdoc */ - public function getCountryId() + public function getCountryId(): string { return $this->getData(SourceInterface::COUNTRY_ID); } @@ -172,7 +172,7 @@ public function getCountryId() /** * @inheritdoc */ - public function setCountryId($countryId) + public function setCountryId(string $countryId): SourceInterface { $this->setData(SourceInterface::COUNTRY_ID, $countryId); return $this; @@ -181,7 +181,7 @@ public function setCountryId($countryId) /** * @inheritdoc */ - public function getRegionId() + public function getRegionId(): int { return $this->getData(SourceInterface::REGION_ID); } @@ -189,7 +189,7 @@ public function getRegionId() /** * @inheritdoc */ - public function setRegionId($regionId) + public function setRegionId(int $regionId): SourceInterface { $this->setData(SourceInterface::REGION_ID, $regionId); return $this; @@ -198,7 +198,7 @@ public function setRegionId($regionId) /** * @inheritdoc */ - public function getRegion() + public function getRegion(): string { return $this->getData(SourceInterface::REGION); } @@ -206,7 +206,7 @@ public function getRegion() /** * @inheritdoc */ - public function setRegion($region) + public function setRegion(string $region): SourceInterface { $this->setData(SourceInterface::REGION, $region); return $this; @@ -215,7 +215,7 @@ public function setRegion($region) /** * @inheritdoc */ - public function getCity() + public function getCity(): string { return $this->getData(SourceInterface::CITY); } @@ -223,7 +223,7 @@ public function getCity() /** * @inheritdoc */ - public function setCity($city) + public function setCity(string $city): SourceInterface { $this->setData(SourceInterface::CITY, $city); return $this; @@ -232,7 +232,7 @@ public function setCity($city) /** * @inheritdoc */ - public function getStreet() + public function getStreet(): string { return $this->getData(SourceInterface::STREET); } @@ -240,7 +240,7 @@ public function getStreet() /** * @inheritdoc */ - public function setStreet($street) + public function setStreet(string $street): SourceInterface { $this->setData(SourceInterface::STREET, $street); return $this; @@ -249,7 +249,7 @@ public function setStreet($street) /** * @inheritdoc */ - public function getPostcode() + public function getPostcode(): string { return $this->getData(SourceInterface::POSTCODE); } @@ -257,7 +257,7 @@ public function getPostcode() /** * @inheritdoc */ - public function setPostcode($postcode) + public function setPostcode(string $postcode): SourceInterface { $this->setData(SourceInterface::POSTCODE, $postcode); return $this; @@ -266,7 +266,7 @@ public function setPostcode($postcode) /** * @inheritdoc */ - public function getPhone() + public function getPhone(): string { return $this->getData(SourceInterface::PHONE); } @@ -274,7 +274,7 @@ public function getPhone() /** * @inheritdoc */ - public function setPhone($phone) + public function setPhone(string $phone): SourceInterface { $this->setData(SourceInterface::PHONE, $phone); return $this; @@ -283,7 +283,7 @@ public function setPhone($phone) /** * @inheritdoc */ - public function getFax() + public function getFax(): string { return $this->getData(SourceInterface::FAX); } @@ -291,7 +291,7 @@ public function getFax() /** * @inheritdoc */ - public function setFax($fax) + public function setFax(string $fax): SourceInterface { $this->setData(SourceInterface::FAX, $fax); return $this; @@ -300,7 +300,7 @@ public function setFax($fax) /** * @inheritdoc */ - public function getPriority() + public function getPriority(): int { return $this->getData(SourceInterface::PRIORITY); } @@ -308,7 +308,7 @@ public function getPriority() /** * @inheritdoc */ - public function setPriority($priority) + public function setPriority(int $priority): SourceInterface { $this->setData(SourceInterface::PRIORITY, $priority); return $this; @@ -317,7 +317,7 @@ public function setPriority($priority) /** * @inheritdoc */ - public function getCarrierLinks() + public function getCarrierLinks(): array { return $this->getData(SourceInterface::CARRIER_LINKS); } @@ -325,7 +325,7 @@ public function getCarrierLinks() /** * @inheritdoc */ - public function setCarrierLinks($carrierLinks) + public function setCarrierLinks(array $carrierLinks): SourceInterface { $this->setData(SourceInterface::CARRIER_LINKS, $carrierLinks); return $this; diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index f16ae071906f..458dc316d8d2 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -114,7 +114,7 @@ public function __construct( /** * @inheritdoc */ - public function save(SourceInterface $source) + public function save(SourceInterface $source): int { try { $this->saveSource($source); @@ -150,7 +150,7 @@ private function saveSourceCarrierLinks(SourceInterface $source) /** * @inheritdoc */ - public function get($sourceId) + public function get(int $sourceId): SourceInterface { /** @var SourceInterface|AbstractModel $source */ $source = $this->sourceFactory->create(); @@ -183,7 +183,7 @@ private function addCarrierLinks(SourceInterface $source) /** * @inheritdoc */ - public function getList(SearchCriteriaInterface $searchCriteria = null) + public function getList(SearchCriteriaInterface $searchCriteria = null): SourceSearchResultsInterface { /** @var \Magento\Inventory\Model\Resource\Source\Collection $collection */ $collection = $this->collectionFactory->create(); diff --git a/app/code/Magento/Inventory/Setup/InstallSchema.php b/app/code/Magento/Inventory/Setup/InstallSchema.php index 9cddd740c29d..e3fc9360650f 100644 --- a/app/code/Magento/Inventory/Setup/InstallSchema.php +++ b/app/code/Magento/Inventory/Setup/InstallSchema.php @@ -136,7 +136,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con )->addColumn( SourceInterface::COUNTRY_ID, Table::TYPE_TEXT, - 2, + 30, [ InstallSchema::OPTION_NULLABLE => false, InstallSchema::OPTION_DEFAULT => '' diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index 75ac289b5f24..76b7cbd634da 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -5,7 +5,7 @@ */ namespace Magento\InventoryApi\Api\Data; -use \Magento\Framework\Api\ExtensibleDataInterface; +use Magento\Framework\Api\ExtensibleDataInterface; /** * @api @@ -46,260 +46,260 @@ public function getSourceId(); * Set source id. * * @param int $sourceId - * @return $this + * @return SourceInterface */ - public function setSourceId($sourceId); + public function setSourceId(int $sourceId): SourceInterface; /** * Get source name. * * @return string */ - public function getName(); + public function getName(): string; /** * Set source name. * * @param string $name - * @return $this + * @return SourceInterface */ - public function setName($name); + public function setName(string $name): SourceInterface; /** * Get source email * * @return string */ - public function getEmail(); + public function getEmail(): string; /** * Set source email * * @param string $email - * @return $this + * @return SourceInterface */ - public function setEmail($email); + public function setEmail(string $email): SourceInterface; /** * Get source contact name. * * @return string */ - public function getContactName(); + public function getContactName(): string; /** * Set source contact name. * * @param string $contactName - * @return $this + * @return SourceInterface */ - public function setContactName($contactName); + public function setContactName(string $contactName): SourceInterface; /** * Check if source is enabled. * * @return bool */ - public function getIsActive(); + public function getIsActive(): bool; /** * Enable or disable source. * * @param bool $active - * @return $this + * @return SourceInterface */ - public function setIsActive($active); + public function setIsActive(bool $active): SourceInterface; /** * Get source description. * * @return string */ - public function getDescription(); + public function getDescription(): string; /** * Set source description. * * @param string $description - * @return $this + * @return SourceInterface */ - public function setDescription($description); + public function setDescription(string $description): SourceInterface; /** * Get source latitude. * * @return float */ - public function getLatitude(); + public function getLatitude(): float; /** * Set source latitude. * * @param float $latitude - * @return $this + * @return SourceInterface */ - public function setLatitude($latitude); + public function setLatitude(float $latitude): SourceInterface; /** * Get source longitude. * * @return float */ - public function getLongitude(); + public function getLongitude(): float; /** * Set source longitude. * * @param float $longitude - * @return $this + * @return SourceInterface */ - public function setLongitude($longitude); + public function setLongitude(float $longitude): SourceInterface; /** * Get source country id. * * @return string */ - public function getCountryId(); + public function getCountryId(): string; /** * Set source country id. * - * @param int $countryId - * @return $this + * @param string $countryId + * @return SourceInterface */ - public function setCountryId($countryId); + public function setCountryId(string $countryId): SourceInterface; /** * Get region id if source has registered region. * * @return int */ - public function getRegionId(); + public function getRegionId(): int; /** * Set region id if source has registered region. * * @param int $regionId - * @return $this + * @return SourceInterface */ - public function setRegionId($regionId); + public function setRegionId(int $regionId): SourceInterface; /** * Get region title if source has custom region * * @return string */ - public function getRegion(); + public function getRegion(): string; /** * Set source region title. * * @param string $region - * @return $this + * @return SourceInterface */ - public function setRegion($region); + public function setRegion(string $region): SourceInterface; /** * Get source city. * * @return string */ - public function getCity(); + public function getCity(): string; /** * Set source city. * * @param string $city - * @return $this + * @return SourceInterface */ - public function setCity($city); + public function setCity(string $city): SourceInterface; /** * Get source street name. * * @return string */ - public function getStreet(); + public function getStreet(): string; /** * Set source street name. * * @param string $street - * @return $this + * @return SourceInterface */ - public function setStreet($street); + public function setStreet(string $street): SourceInterface; /** * Get source post code. * * @return string */ - public function getPostcode(); + public function getPostcode(): string; /** * Set source post code. * * @param string $postcode - * @return $this + * @return SourceInterface */ - public function setPostcode($postcode); + public function setPostcode(string $postcode): SourceInterface; /** * Get source phone number. * * @return string */ - public function getPhone(); + public function getPhone(): string; /** * Set source phone number. * * @param string $phone - * @return $this + * @return SourceInterface */ - public function setPhone($phone); + public function setPhone(string $phone): SourceInterface; /** * Get source fax. * * @return string */ - public function getFax(); + public function getFax(): string; /** * Set source fax. * * @param string $fax - * @return $this + * @return SourceInterface */ - public function setFax($fax); + public function setFax(string $fax): SourceInterface; /** * Get source priority * * @return int */ - public function getPriority(); + public function getPriority(): int; /** * Set source priority * * @param int $priority - * @return $this + * @return SourceInterface */ - public function setPriority($priority); + public function setPriority(int $priority): SourceInterface; /** * @param \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] $carrierLinks - * @return $this + * @return SourceInterface */ - public function setCarrierLinks($carrierLinks); + public function setCarrierLinks(array $carrierLinks): SourceInterface; /** * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] */ - public function getCarrierLinks(); + public function getCarrierLinks(): array; /** * Retrieve existing extension attributes object or create a new one. diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index 29df169d2cc2..b6c5a4af239b 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -9,6 +9,7 @@ use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; /** * @api @@ -23,7 +24,7 @@ interface SourceRepositoryInterface * * @throws CouldNotSaveException */ - public function save(SourceInterface $source); + public function save(SourceInterface $source): int; /** * Load Source data by given sourceId. @@ -32,7 +33,7 @@ public function save(SourceInterface $source); * @return \Magento\InventoryApi\Api\Data\SourceInterface * @throws NoSuchEntityException */ - public function get($sourceId); + public function get(int $sourceId): SourceInterface; /** * Load Source data collection by given search criteria @@ -40,5 +41,5 @@ public function get($sourceId); * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface */ - public function getList(SearchCriteriaInterface $searchCriteria = null); + public function getList(SearchCriteriaInterface $searchCriteria = null): SourceSearchResultsInterface; } From 385132ac1a2473ee10fef28f1f25d9a9c532ea60 Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Mon, 29 May 2017 12:05:44 +0300 Subject: [PATCH 45/66] magento-engcom/magento2#25: Source Management API Implementation - Removed PHP 7 Types to keep code PHPUnit 4 compatible - Fixed Unit Tests --- app/code/Magento/Inventory/Model/Source.php | 70 ++++++------ .../Inventory/Model/SourceRepository.php | 6 +- .../Test/Unit/Model/SourceRepositoryTest.php | 100 +++++++++++++---- .../InventoryApi/Api/Data/SourceInterface.php | 106 +++++++++--------- .../Api/SourceRepositoryInterface.php | 18 ++- 5 files changed, 176 insertions(+), 124 deletions(-) diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index 4fc3e34a1b25..b027936da91c 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -36,7 +36,7 @@ public function getSourceId() /** * @inheritdoc */ - public function setSourceId(int $sourceId): SourceInterface + public function setSourceId($sourceId) { $this->setData(SourceInterface::SOURCE_ID, $sourceId); return $this; @@ -45,7 +45,7 @@ public function setSourceId(int $sourceId): SourceInterface /** * @inheritdoc */ - public function getName(): string + public function getName() { return $this->getData(SourceInterface::NAME); } @@ -53,7 +53,7 @@ public function getName(): string /** * @inheritdoc */ - public function setName(string $name): SourceInterface + public function setName($name) { $this->setData(SourceInterface::NAME, $name); return $this; @@ -62,7 +62,7 @@ public function setName(string $name): SourceInterface /** * @inheritdoc */ - public function getEmail(): string + public function getEmail() { return $this->getData(SourceInterface::EMAIL); } @@ -70,7 +70,7 @@ public function getEmail(): string /** * @inheritdoc */ - public function setEmail(string $email): SourceInterface + public function setEmail($email) { $this->setData(SourceInterface::EMAIL, $email); return $this; @@ -79,7 +79,7 @@ public function setEmail(string $email): SourceInterface /** * @inheritdoc */ - public function getContactName(): string + public function getContactName() { return $this->getData(SourceInterface::CONTACT_NAME); } @@ -87,7 +87,7 @@ public function getContactName(): string /** * @inheritdoc */ - public function setContactName(string $contactName): SourceInterface + public function setContactName($contactName) { $this->setData(SourceInterface::CONTACT_NAME, $contactName); return $this; @@ -96,7 +96,7 @@ public function setContactName(string $contactName): SourceInterface /** * @inheritdoc */ - public function getIsActive(): bool + public function getIsActive() { return $this->getData(SourceInterface::IS_ACTIVE); } @@ -104,7 +104,7 @@ public function getIsActive(): bool /** * @inheritdoc */ - public function setIsActive(bool $active): SourceInterface + public function setIsActive($active) { $this->setData(SourceInterface::IS_ACTIVE, $active); return $this; @@ -113,7 +113,7 @@ public function setIsActive(bool $active): SourceInterface /** * @inheritdoc */ - public function getDescription(): string + public function getDescription() { return $this->getData(SourceInterface::DESCRIPTION); } @@ -121,7 +121,7 @@ public function getDescription(): string /** * @inheritdoc */ - public function setDescription(string $description): SourceInterface + public function setDescription($description) { $this->setData(SourceInterface::DESCRIPTION, $description); return $this; @@ -130,7 +130,7 @@ public function setDescription(string $description): SourceInterface /** * @inheritdoc */ - public function getLatitude(): float + public function getLatitude() { return $this->getData(SourceInterface::LATITUDE); } @@ -138,7 +138,7 @@ public function getLatitude(): float /** * @inheritdoc */ - public function setLatitude(float $latitude): SourceInterface + public function setLatitude($latitude) { $this->setData(SourceInterface::LATITUDE, $latitude); return $this; @@ -147,7 +147,7 @@ public function setLatitude(float $latitude): SourceInterface /** * @inheritdoc */ - public function getLongitude(): float + public function getLongitude() { return $this->getData(SourceInterface::LONGITUDE); } @@ -155,7 +155,7 @@ public function getLongitude(): float /** * @inheritdoc */ - public function setLongitude(float $longitude): SourceInterface + public function setLongitude($longitude) { $this->setData(SourceInterface::LONGITUDE, $longitude); return $this; @@ -164,7 +164,7 @@ public function setLongitude(float $longitude): SourceInterface /** * @inheritdoc */ - public function getCountryId(): string + public function getCountryId() { return $this->getData(SourceInterface::COUNTRY_ID); } @@ -172,7 +172,7 @@ public function getCountryId(): string /** * @inheritdoc */ - public function setCountryId(string $countryId): SourceInterface + public function setCountryId($countryId) { $this->setData(SourceInterface::COUNTRY_ID, $countryId); return $this; @@ -181,7 +181,7 @@ public function setCountryId(string $countryId): SourceInterface /** * @inheritdoc */ - public function getRegionId(): int + public function getRegionId() { return $this->getData(SourceInterface::REGION_ID); } @@ -189,7 +189,7 @@ public function getRegionId(): int /** * @inheritdoc */ - public function setRegionId(int $regionId): SourceInterface + public function setRegionId($regionId) { $this->setData(SourceInterface::REGION_ID, $regionId); return $this; @@ -198,7 +198,7 @@ public function setRegionId(int $regionId): SourceInterface /** * @inheritdoc */ - public function getRegion(): string + public function getRegion() { return $this->getData(SourceInterface::REGION); } @@ -206,7 +206,7 @@ public function getRegion(): string /** * @inheritdoc */ - public function setRegion(string $region): SourceInterface + public function setRegion($region) { $this->setData(SourceInterface::REGION, $region); return $this; @@ -215,7 +215,7 @@ public function setRegion(string $region): SourceInterface /** * @inheritdoc */ - public function getCity(): string + public function getCity() { return $this->getData(SourceInterface::CITY); } @@ -223,7 +223,7 @@ public function getCity(): string /** * @inheritdoc */ - public function setCity(string $city): SourceInterface + public function setCity($city) { $this->setData(SourceInterface::CITY, $city); return $this; @@ -232,7 +232,7 @@ public function setCity(string $city): SourceInterface /** * @inheritdoc */ - public function getStreet(): string + public function getStreet() { return $this->getData(SourceInterface::STREET); } @@ -240,7 +240,7 @@ public function getStreet(): string /** * @inheritdoc */ - public function setStreet(string $street): SourceInterface + public function setStreet($street) { $this->setData(SourceInterface::STREET, $street); return $this; @@ -249,7 +249,7 @@ public function setStreet(string $street): SourceInterface /** * @inheritdoc */ - public function getPostcode(): string + public function getPostcode() { return $this->getData(SourceInterface::POSTCODE); } @@ -257,7 +257,7 @@ public function getPostcode(): string /** * @inheritdoc */ - public function setPostcode(string $postcode): SourceInterface + public function setPostcode($postcode) { $this->setData(SourceInterface::POSTCODE, $postcode); return $this; @@ -266,7 +266,7 @@ public function setPostcode(string $postcode): SourceInterface /** * @inheritdoc */ - public function getPhone(): string + public function getPhone() { return $this->getData(SourceInterface::PHONE); } @@ -274,7 +274,7 @@ public function getPhone(): string /** * @inheritdoc */ - public function setPhone(string $phone): SourceInterface + public function setPhone($phone) { $this->setData(SourceInterface::PHONE, $phone); return $this; @@ -283,7 +283,7 @@ public function setPhone(string $phone): SourceInterface /** * @inheritdoc */ - public function getFax(): string + public function getFax() { return $this->getData(SourceInterface::FAX); } @@ -291,7 +291,7 @@ public function getFax(): string /** * @inheritdoc */ - public function setFax(string $fax): SourceInterface + public function setFax($fax) { $this->setData(SourceInterface::FAX, $fax); return $this; @@ -300,7 +300,7 @@ public function setFax(string $fax): SourceInterface /** * @inheritdoc */ - public function getPriority(): int + public function getPriority() { return $this->getData(SourceInterface::PRIORITY); } @@ -308,7 +308,7 @@ public function getPriority(): int /** * @inheritdoc */ - public function setPriority(int $priority): SourceInterface + public function setPriority($priority) { $this->setData(SourceInterface::PRIORITY, $priority); return $this; @@ -317,7 +317,7 @@ public function setPriority(int $priority): SourceInterface /** * @inheritdoc */ - public function getCarrierLinks(): array + public function getCarrierLinks() { return $this->getData(SourceInterface::CARRIER_LINKS); } @@ -325,7 +325,7 @@ public function getCarrierLinks(): array /** * @inheritdoc */ - public function setCarrierLinks(array $carrierLinks): SourceInterface + public function setCarrierLinks($carrierLinks) { $this->setData(SourceInterface::CARRIER_LINKS, $carrierLinks); return $this; diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 458dc316d8d2..f16ae071906f 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -114,7 +114,7 @@ public function __construct( /** * @inheritdoc */ - public function save(SourceInterface $source): int + public function save(SourceInterface $source) { try { $this->saveSource($source); @@ -150,7 +150,7 @@ private function saveSourceCarrierLinks(SourceInterface $source) /** * @inheritdoc */ - public function get(int $sourceId): SourceInterface + public function get($sourceId) { /** @var SourceInterface|AbstractModel $source */ $source = $this->sourceFactory->create(); @@ -183,7 +183,7 @@ private function addCarrierLinks(SourceInterface $source) /** * @inheritdoc */ - public function getList(SearchCriteriaInterface $searchCriteria = null): SourceSearchResultsInterface + public function getList(SearchCriteriaInterface $searchCriteria = null) { /** @var \Magento\Inventory\Model\Resource\Source\Collection $collection */ $collection = $this->collectionFactory->create(); diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 9aa62a5f8665..1992154472a7 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -7,6 +7,9 @@ namespace Magento\Inventory\Test\Unit\Model; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\Inventory\Model\Resource\SourceCarrierLink as ResourceSourceCarrierLink; +use Magento\Inventory\Model\Resource\SourceCarrierLink\CollectionFactory as CarrierLinkCollectionFactory; +use Magento\Framework\Api\SearchCriteriaBuilder; /** * Class SourceRepositoryTest @@ -16,7 +19,12 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Inventory\Model\Resource\Source|\PHPUnit_Framework_MockObject_MockObject */ - private $resource; + private $resourceSource; + + /** + * @var ResourceSourceCarrierLink|\PHPUnit_Framework_MockObject_MockObject + */ + private $carrierLinkResource; /** * @var \Magento\Inventory\Model\SourceFactory|\PHPUnit_Framework_MockObject_MockObject @@ -38,6 +46,16 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase */ private $sourceSearchResultsFactory; + /** + * @var CarrierLinkCollectionFactory|\PHPUnit_Framework_MockObject_MockObject + */ + private $carrierLinkCollectionFactory; + + /** + * @var SearchCriteriaBuilder|\PHPUnit_Framework_MockObject_MockObject + */ + private $searchCriteriaBuilder; + /** * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -50,7 +68,7 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->resource = $this->getMock( + $this->resourceSource = $this->getMock( \Magento\Inventory\Model\Resource\Source::class, [], [], @@ -58,6 +76,19 @@ protected function setUp() false ); + $this->carrierLinkResource = $this->getMockBuilder(ResourceSourceCarrierLink::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->carrierLinkCollectionFactory = $this->getMockBuilder(CarrierLinkCollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->searchCriteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $this->sourceFactory = $this->getMock( \Magento\InventoryApi\Api\Data\SourceInterfaceFactory::class, ['create'], @@ -79,7 +110,7 @@ protected function setUp() ); $this->sourceSearchResultsFactory = $this->getMock( - \Magento\Inventory\Model\SourceSearchResultsFactory::class, + \Magento\InventoryApi\Api\Data\SourceSearchResultsInterfaceFactory::class, ['create'], [], '', @@ -94,11 +125,14 @@ protected function setUp() $this->sourceRepository = $objectManager->getObject( \Magento\Inventory\Model\SourceRepository::class, [ - 'resource' => $this->resource, + 'resourceSource' => $this->resourceSource, + 'resourceSourceCarrierLink' => $this->carrierLinkResource, 'sourceFactory' => $this->sourceFactory, 'collectionProcessor' => $this->collectionProcessor, 'collectionFactory' => $this->collectionFactory, + 'carrierLinkCollectionFactory' => $this->carrierLinkCollectionFactory, 'sourceSearchResultsFactory' => $this->sourceSearchResultsFactory, + 'searchCriteriaBuilder' => $this->searchCriteriaBuilder, 'logger' => $this->loggerMock, ] ); @@ -106,17 +140,17 @@ protected function setUp() public function testSaveSuccessful() { - /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMock( - \Magento\Inventory\Model\Source::class, - [], - [], - '', - false - ); + $sourceId = 42; + /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceMock */ + $sourceMock = $this->getMockBuilder(\Magento\Inventory\Model\Source::class) + ->disableOriginalConstructor() + ->getMock(); + + $sourceMock->expects($this->atLeastOnce())->method('getSourceId')->willReturn($sourceId); + $sourceMock->expects($this->atLeastOnce())->method('getCarrierLinks')->willReturn([]); + $this->resourceSource->expects($this->once())->method('save')->with($sourceMock); - $result = $this->sourceRepository->save($sourceModel); - $this->assertNotNull($result); + $this->assertEquals($sourceId, $this->sourceRepository->save($sourceMock)); } public function testSaveErrorExpectsException() @@ -130,12 +164,12 @@ public function testSaveErrorExpectsException() false ); - $this->resource->expects($this->atLeastOnce()) + $this->resourceSource->expects($this->atLeastOnce()) ->method('save'); $this->setExpectedException(\Magento\Framework\Exception\CouldNotSaveException::class); - $this->resource->expects($this->atLeastOnce()) + $this->resourceSource->expects($this->atLeastOnce()) ->method('save') ->will($this->throwException(new \Exception('Some unit test Exception'))); @@ -154,6 +188,17 @@ public function testGetSuccessful() '', false ); + $searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteria::class) + ->disableOriginalConstructor() + ->getMock(); + $carrierLinkCollectionMock = $this->getMockBuilder( + \Magento\Inventory\Model\Resource\SourceCarrierLink\Collection::class + )->disableOriginalConstructor()->getMock(); + + $this->carrierLinkCollectionFactory->expects($this->atLeastOnce())->method('create') + ->willReturn($carrierLinkCollectionMock); + $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('addFilter')->willReturnSelf(); + $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('create')->willReturn($searchCriteriaMock); $sourceModel->expects($this->atLeastOnce()) ->method('getSourceId') @@ -163,12 +208,12 @@ public function testGetSuccessful() ->method('create') ->will($this->returnValue($sourceModel)); - $this->resource->expects($this->once()) + $this->resourceSource->expects($this->once()) ->method('load') ->with( $sourceModel, - SourceInterface::SOURCE_ID, - $sourceId + $sourceId, + SourceInterface::SOURCE_ID ); $result = $this->sourceRepository->get($sourceId); @@ -188,6 +233,17 @@ public function testGetErrorExpectsException() '', false ); + $searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteria::class) + ->disableOriginalConstructor() + ->getMock(); + $carrierLinkCollectionMock = $this->getMockBuilder( + \Magento\Inventory\Model\Resource\SourceCarrierLink\Collection::class + )->disableOriginalConstructor()->getMock(); + + $this->carrierLinkCollectionFactory->expects($this->atLeastOnce())->method('create') + ->willReturn($carrierLinkCollectionMock); + $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('addFilter')->willReturnSelf(); + $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('create')->willReturn($searchCriteriaMock); $sourceModel->expects($this->atLeastOnce()) ->method('getSourceId') @@ -197,12 +253,12 @@ public function testGetErrorExpectsException() ->method('create') ->will($this->returnValue($sourceModel)); - $this->resource->expects($this->once()) + $this->resourceSource->expects($this->once()) ->method('load') ->with( $sourceModel, - SourceInterface::SOURCE_ID, - $sourceId + $sourceId, + SourceInterface::SOURCE_ID ); $this->setExpectedException(\Magento\Framework\Exception\NoSuchEntityException::class); diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index 76b7cbd634da..0d544391f86a 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -46,260 +46,260 @@ public function getSourceId(); * Set source id. * * @param int $sourceId - * @return SourceInterface + * @return $this */ - public function setSourceId(int $sourceId): SourceInterface; + public function setSourceId($sourceId); /** * Get source name. * * @return string */ - public function getName(): string; + public function getName(); /** * Set source name. * * @param string $name - * @return SourceInterface + * @return $this */ - public function setName(string $name): SourceInterface; + public function setName($name); /** * Get source email * * @return string */ - public function getEmail(): string; + public function getEmail(); /** * Set source email * * @param string $email - * @return SourceInterface + * @return $this */ - public function setEmail(string $email): SourceInterface; + public function setEmail($email); /** * Get source contact name. * * @return string */ - public function getContactName(): string; + public function getContactName(); /** * Set source contact name. * * @param string $contactName - * @return SourceInterface + * @return $this */ - public function setContactName(string $contactName): SourceInterface; + public function setContactName($contactName); /** * Check if source is enabled. * * @return bool */ - public function getIsActive(): bool; + public function getIsActive(); /** * Enable or disable source. * * @param bool $active - * @return SourceInterface + * @return $this */ - public function setIsActive(bool $active): SourceInterface; + public function setIsActive($active); /** * Get source description. * * @return string */ - public function getDescription(): string; + public function getDescription(); /** * Set source description. * * @param string $description - * @return SourceInterface + * @return $this */ - public function setDescription(string $description): SourceInterface; + public function setDescription($description); /** * Get source latitude. * * @return float */ - public function getLatitude(): float; + public function getLatitude(); /** * Set source latitude. * * @param float $latitude - * @return SourceInterface + * @return $this */ - public function setLatitude(float $latitude): SourceInterface; + public function setLatitude($latitude); /** * Get source longitude. * * @return float */ - public function getLongitude(): float; + public function getLongitude(); /** * Set source longitude. * * @param float $longitude - * @return SourceInterface + * @return $this */ - public function setLongitude(float $longitude): SourceInterface; + public function setLongitude($longitude); /** * Get source country id. * * @return string */ - public function getCountryId(): string; + public function getCountryId(); /** * Set source country id. * * @param string $countryId - * @return SourceInterface + * @return $this */ - public function setCountryId(string $countryId): SourceInterface; + public function setCountryId($countryId); /** * Get region id if source has registered region. * * @return int */ - public function getRegionId(): int; + public function getRegionId(); /** * Set region id if source has registered region. * * @param int $regionId - * @return SourceInterface + * @return $this */ - public function setRegionId(int $regionId): SourceInterface; + public function setRegionId($regionId); /** * Get region title if source has custom region * * @return string */ - public function getRegion(): string; + public function getRegion(); /** * Set source region title. * * @param string $region - * @return SourceInterface + * @return $this */ - public function setRegion(string $region): SourceInterface; + public function setRegion($region); /** * Get source city. * * @return string */ - public function getCity(): string; + public function getCity(); /** * Set source city. * * @param string $city - * @return SourceInterface + * @return $this */ - public function setCity(string $city): SourceInterface; + public function setCity($city); /** * Get source street name. * * @return string */ - public function getStreet(): string; + public function getStreet(); /** * Set source street name. * * @param string $street - * @return SourceInterface + * @return $this */ - public function setStreet(string $street): SourceInterface; + public function setStreet($street); /** * Get source post code. * * @return string */ - public function getPostcode(): string; + public function getPostcode(); /** * Set source post code. * * @param string $postcode - * @return SourceInterface + * @return $this */ - public function setPostcode(string $postcode): SourceInterface; + public function setPostcode($postcode); /** * Get source phone number. * * @return string */ - public function getPhone(): string; + public function getPhone(); /** * Set source phone number. * * @param string $phone - * @return SourceInterface + * @return $this */ - public function setPhone(string $phone): SourceInterface; + public function setPhone($phone); /** * Get source fax. * * @return string */ - public function getFax(): string; + public function getFax(); /** * Set source fax. * * @param string $fax - * @return SourceInterface + * @return $this */ - public function setFax(string $fax): SourceInterface; + public function setFax($fax); /** * Get source priority * * @return int */ - public function getPriority(): int; + public function getPriority(); /** * Set source priority * * @param int $priority - * @return SourceInterface + * @return $this */ - public function setPriority(int $priority): SourceInterface; + public function setPriority($priority); /** * @param \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] $carrierLinks - * @return SourceInterface + * @return $this */ - public function setCarrierLinks(array $carrierLinks): SourceInterface; + public function setCarrierLinks($carrierLinks); /** * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] */ - public function getCarrierLinks(): array; + public function getCarrierLinks(); /** * Retrieve existing extension attributes object or create a new one. diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index b6c5a4af239b..3bc8947a4cec 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -5,12 +5,6 @@ */ namespace Magento\InventoryApi\Api; -use Magento\Framework\Api\SearchCriteriaInterface; -use Magento\Framework\Exception\CouldNotSaveException; -use Magento\Framework\Exception\NoSuchEntityException; -use Magento\InventoryApi\Api\Data\SourceInterface; -use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; - /** * @api */ @@ -22,18 +16,18 @@ interface SourceRepositoryInterface * @param \Magento\InventoryApi\Api\Data\SourceInterface $source * @return int * - * @throws CouldNotSaveException + * @throws \Magento\Framework\Exception\CouldNotSaveException */ - public function save(SourceInterface $source): int; + public function save(\Magento\InventoryApi\Api\Data\SourceInterface $source); /** * Load Source data by given sourceId. * * @param int $sourceId * @return \Magento\InventoryApi\Api\Data\SourceInterface - * @throws NoSuchEntityException + * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function get(int $sourceId): SourceInterface; + public function get($sourceId); /** * Load Source data collection by given search criteria @@ -41,5 +35,7 @@ public function get(int $sourceId): SourceInterface; * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface */ - public function getList(SearchCriteriaInterface $searchCriteria = null): SourceSearchResultsInterface; + public function getList( + \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null + ); } From 8c094fddf6011e26a4d06a81e5592c9f55d8e57d Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Mon, 29 May 2017 12:58:48 +0300 Subject: [PATCH 46/66] magento-engcom/magento2#25: Source Management API Implementation - Unit Tests Updated --- app/code/Magento/Inventory/Model/Source.php | 6 +- .../Inventory/Model/SourceCarrierLink.php | 4 +- .../Test/Unit/Model/SourceCarrierLinkTest.php | 49 ---- .../Test/Unit/Model/SourceRepositoryTest.php | 253 ++++++------------ .../Inventory/Test/Unit/Model/SourceTest.php | 160 ----------- 5 files changed, 92 insertions(+), 380 deletions(-) delete mode 100644 app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php delete mode 100644 app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index b027936da91c..f07dda86daf6 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -11,9 +11,11 @@ /** * Class Source, - * provides implementation of the SourceInterface which adds the possibilty + * provides implementation of the SourceInterface which adds the possibility * for a Merchant to map existing physical sources to some particular sales channels - * this model holds the information like name and description of this physical sources + * this model holds the information like name and description of this physical sources. + * + * @codeCoverageIgnore */ class Source extends AbstractExtensibleModel implements SourceInterface { diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/SourceCarrierLink.php index 2b5473103521..d79fcbaed25b 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLink.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLink.php @@ -9,12 +9,14 @@ use Magento\Framework\Model\AbstractExtensibleModel; use \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; +/** + * @codeCoverageIgnore + */ class SourceCarrierLink extends AbstractExtensibleModel implements SourceCarrierLinkInterface { /** * Initialize resource model * - * @codingStandardsIgnore * @return void */ protected function _construct() diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php deleted file mode 100644 index 259eee69c31a..000000000000 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceCarrierLinkTest.php +++ /dev/null @@ -1,49 +0,0 @@ -objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->sourceCarrierLink = $this->objectManager->getObject(SourceCarrierLink::class); - } - - public function testCarrierCode() - { - $this->sourceCarrierLink->setCarrierCode(SourceCarrierLinkTest::TEST_STRING); - $this->assertEquals($this->sourceCarrierLink->getCarrierCode(), SourceCarrierLinkTest::TEST_STRING); - } - - public function testPosition() - { - $this->sourceCarrierLink->setPosition(SourceCarrierLinkTest::TEST_POSITION); - $this->assertEquals($this->sourceCarrierLink->getPosition(), SourceCarrierLinkTest::TEST_POSITION); - } -} diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 1992154472a7..d93181bc5767 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -7,8 +7,17 @@ namespace Magento\Inventory\Test\Unit\Model; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; +use Magento\InventoryApi\Api\Data\SourceSearchResultsInterfaceFactory; +use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; +use Magento\Inventory\Model\Source; +use Magento\Inventory\Model\Resource\Source as SourceResource; +use Magento\Inventory\Model\Resource\Source\CollectionFactory as SourceCollectionFactory; +use Magento\Inventory\Model\Resource\Source\Collection as SourceCollection; +use Magento\Inventory\Model\SourceCarrierLink; use Magento\Inventory\Model\Resource\SourceCarrierLink as ResourceSourceCarrierLink; use Magento\Inventory\Model\Resource\SourceCarrierLink\CollectionFactory as CarrierLinkCollectionFactory; +use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Api\SearchCriteriaBuilder; /** @@ -17,9 +26,9 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Inventory\Model\Resource\Source|\PHPUnit_Framework_MockObject_MockObject + * @var SourceResource|\PHPUnit_Framework_MockObject_MockObject */ - private $resourceSource; + private $sourceResource; /** * @var ResourceSourceCarrierLink|\PHPUnit_Framework_MockObject_MockObject @@ -27,22 +36,22 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase private $carrierLinkResource; /** - * @var \Magento\Inventory\Model\SourceFactory|\PHPUnit_Framework_MockObject_MockObject + * @var SourceInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ private $sourceFactory; /** - * @var \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface|\PHPUnit_Framework_MockObject_MockObject + * @var CollectionProcessorInterface|\PHPUnit_Framework_MockObject_MockObject */ private $collectionProcessor; /** - * @var \Magento\Inventory\Model\Resource\Source\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject + * @var SourceCollectionFactory|\PHPUnit_Framework_MockObject_MockObject */ private $collectionFactory; /** - * @var \Magento\Inventory\Model\SourceSearchResultsFactory|\PHPUnit_Framework_MockObject_MockObject + * @var SourceSearchResultsInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ private $sourceSearchResultsFactory; @@ -62,70 +71,48 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase private $loggerMock; /** - * @var \Magento\Inventory\Model\SourceRepository|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Inventory\Model\SourceRepository */ - private $sourceRepository; + private $model; protected function setUp() { - $this->resourceSource = $this->getMock( - \Magento\Inventory\Model\Resource\Source::class, - [], - [], - '', - false - ); - + $this->sourceResource = $this->getMockBuilder(SourceResource::class)->disableOriginalConstructor()->getMock(); $this->carrierLinkResource = $this->getMockBuilder(ResourceSourceCarrierLink::class) ->disableOriginalConstructor() ->getMock(); - $this->carrierLinkCollectionFactory = $this->getMockBuilder(CarrierLinkCollectionFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $this->searchCriteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class) ->disableOriginalConstructor() ->getMock(); - - $this->sourceFactory = $this->getMock( - \Magento\InventoryApi\Api\Data\SourceInterfaceFactory::class, - ['create'], - [], - '', - false - ); - - $this->collectionProcessor = $this->getMockBuilder( - \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class - )->getMockForAbstractClass(); - - $this->collectionFactory = $this->getMock( - \Magento\Inventory\Model\Resource\Source\CollectionFactory::class, - ['create'], - [], - '', - false - ); - - $this->sourceSearchResultsFactory = $this->getMock( - \Magento\InventoryApi\Api\Data\SourceSearchResultsInterfaceFactory::class, - ['create'], - [], - '', - false - ); - + $this->sourceFactory = $this->getMockBuilder(SourceInterfaceFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->collectionProcessor = $this->getMockBuilder(CollectionProcessorInterface::class) + ->disableOriginalConstructor() + ->setMethods(['process']) + ->getMock(); + $this->collectionFactory = $this->getMockBuilder(SourceCollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->sourceSearchResultsFactory = $this->getMockBuilder(SourceSearchResultsInterfaceFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->sourceRepository = $objectManager->getObject( + $this->model = $objectManager->getObject( \Magento\Inventory\Model\SourceRepository::class, [ - 'resourceSource' => $this->resourceSource, + 'resourceSource' => $this->sourceResource, 'resourceSourceCarrierLink' => $this->carrierLinkResource, 'sourceFactory' => $this->sourceFactory, 'collectionProcessor' => $this->collectionProcessor, @@ -145,49 +132,40 @@ public function testSaveSuccessful() $sourceMock = $this->getMockBuilder(\Magento\Inventory\Model\Source::class) ->disableOriginalConstructor() ->getMock(); + $carrierLinkMock = $this->getMockBuilder(SourceCarrierLink::class) + ->disableOriginalConstructor() + ->getMock(); $sourceMock->expects($this->atLeastOnce())->method('getSourceId')->willReturn($sourceId); - $sourceMock->expects($this->atLeastOnce())->method('getCarrierLinks')->willReturn([]); - $this->resourceSource->expects($this->once())->method('save')->with($sourceMock); + $sourceMock->expects($this->atLeastOnce())->method('getCarrierLinks')->willReturn([$carrierLinkMock]); + + $this->sourceResource->expects($this->once())->method('save')->with($sourceMock); + $this->carrierLinkResource->expects($this->once())->method('save')->with($carrierLinkMock); - $this->assertEquals($sourceId, $this->sourceRepository->save($sourceMock)); + $this->assertEquals($sourceId, $this->model->save($sourceMock)); } + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + */ public function testSaveErrorExpectsException() { - /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMock( - \Magento\Inventory\Model\Source::class, - [], - [], - '', - false - ); - - $this->resourceSource->expects($this->atLeastOnce()) - ->method('save'); - - $this->setExpectedException(\Magento\Framework\Exception\CouldNotSaveException::class); - - $this->resourceSource->expects($this->atLeastOnce()) + /** @var Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ + $sourceModel = $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(); + $this->sourceResource->expects($this->atLeastOnce())->method('save'); + $this->sourceResource->expects($this->atLeastOnce()) ->method('save') ->will($this->throwException(new \Exception('Some unit test Exception'))); - $this->sourceRepository->save($sourceModel); + $this->model->save($sourceModel); } public function testGetSuccessful() { $sourceId = 345; - /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMock( - \Magento\Inventory\Model\Source::class, - [], - [], - '', - false - ); + /** @var Source|\PHPUnit_Framework_MockObject_MockObject $sourceMock */ + $sourceMock = $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(); $searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteria::class) ->disableOriginalConstructor() ->getMock(); @@ -200,39 +178,34 @@ public function testGetSuccessful() $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('addFilter')->willReturnSelf(); $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('create')->willReturn($searchCriteriaMock); - $sourceModel->expects($this->atLeastOnce()) + $carrierLinkCollectionMock->expects($this->atLeastOnce())->method('getItems')->willReturn([]); + $sourceMock->expects($this->atLeastOnce())->method('setCarrierLinks')->with([]); + + $sourceMock->expects($this->atLeastOnce()) ->method('getSourceId') ->will($this->returnValue($sourceId)); - - $this->sourceFactory->expects($this->once()) - ->method('create') - ->will($this->returnValue($sourceModel)); - - $this->resourceSource->expects($this->once()) + $this->sourceFactory->expects($this->once())->method('create')->willReturn($sourceMock); + $this->sourceResource->expects($this->once()) ->method('load') ->with( - $sourceModel, + $sourceMock, $sourceId, SourceInterface::SOURCE_ID ); - $result = $this->sourceRepository->get($sourceId); - $this->assertSame($sourceModel, $result); + $this->assertSame($sourceMock, $this->model->get($sourceId)); } + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + */ public function testGetErrorExpectsException() { $sourceId = 345; - /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMock( - \Magento\Inventory\Model\Source::class, - [], - [], - '', - false - ); + /** @var Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ + $sourceModel = $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(); $searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteria::class) ->disableOriginalConstructor() ->getMock(); @@ -245,15 +218,9 @@ public function testGetErrorExpectsException() $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('addFilter')->willReturnSelf(); $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('create')->willReturn($searchCriteriaMock); - $sourceModel->expects($this->atLeastOnce()) - ->method('getSourceId') - ->will($this->returnValue(null)); - - $this->sourceFactory->expects($this->once()) - ->method('create') - ->will($this->returnValue($sourceModel)); - - $this->resourceSource->expects($this->once()) + $sourceModel->expects($this->atLeastOnce())->method('getSourceId')->willReturn(null); + $this->sourceFactory->expects($this->once())->method('create')->willReturn($sourceModel); + $this->sourceResource->expects($this->once()) ->method('load') ->with( $sourceModel, @@ -261,78 +228,28 @@ public function testGetErrorExpectsException() SourceInterface::SOURCE_ID ); - $this->setExpectedException(\Magento\Framework\Exception\NoSuchEntityException::class); - - $this->sourceRepository->get($sourceId); + $this->model->get($sourceId); } public function testGetList() { - /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel1 */ - $sourceModel1 = $this->getMock( - \Magento\Inventory\Model\Source::class, - [], - [], - '', - false - ); - - /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel2 */ - $sourceModel2 = $this->getMock( - \Magento\Inventory\Model\Source::class, - [], - [], - '', - false - ); - - $searchCriteria = $this->getMock( - \Magento\Framework\Api\SearchCriteriaInterface::class, - [], - [], - '', - false - ); - - $collection = $this->getMock( - \Magento\Inventory\Model\Resource\Source\Collection::class, - [], - [], - '', - false - ); - - $this->collectionFactory->expects($this->once()) - ->method('create') - ->will($this->returnValue($collection)); - + $sourceCollection = $this->getMockBuilder(SourceCollection::class)->disableOriginalConstructor()->getMock(); + $searchResults = $this->getMockBuilder(SourceSearchResultsInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $searchCriteria = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteriaInterface::class) + ->disableOriginalConstructor() + ->getMock(); $sources = [ - $sourceModel1, - $sourceModel2 + $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(), + $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock() ]; - $collection->expects($this->atLeastOnce()) - ->method('getItems') - ->will($this->returnValue($sources)); - - $searchResults = $this->getMock( - \Magento\Inventory\Model\SourceSearchResults::class, - [], - [], - '', - false - ); - - $this->sourceSearchResultsFactory->expects($this->once()) - ->method('create') - ->will($this->returnValue($searchResults)); - - $searchResults->expects($this->once()) - ->method('setItems') - ->with($sources); - - $result = $this->sourceRepository->getList($searchCriteria); + $this->collectionFactory->expects($this->once())->method('create')->willReturn($sourceCollection); + $sourceCollection->expects($this->atLeastOnce())->method('getItems')->willReturn($sources); + $this->sourceSearchResultsFactory->expects($this->once())->method('create')->willReturn($searchResults); + $searchResults->expects($this->once())->method('setItems')->with($sources); - $this->assertSame($searchResults, $result); + $this->assertSame($searchResults, $this->model->getList($searchCriteria)); } } diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php deleted file mode 100644 index f78c2e66d934..000000000000 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceTest.php +++ /dev/null @@ -1,160 +0,0 @@ -objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->source = $this->objectManager->getObject(Source::class); - } - - - public function testSourceId() - { - $this->source->setSourceId(SourceTest::TEST_ID); - $this->assertEquals($this->source->getSourceId(), SourceTest::TEST_ID); - } - - public function testName() - { - $this->source->setName(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getName(), SourceTest::TEST_STRING); - } - - public function testEmail() - { - $this->source->setEmail(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getEmail(), SourceTest::TEST_STRING); - } - - public function testContactName() - { - $this->source->setContactName(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getContactName(), SourceTest::TEST_STRING); - } - - public function testIsActive() - { - $this->source->setIsActive(SourceTest::TEST_IS_ACTIVE); - $this->assertEquals($this->source->getIsActive(), SourceTest::TEST_IS_ACTIVE); - } - - public function testDescription() - { - $this->source->setDescription(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getDescription(), SourceTest::TEST_STRING); - } - - public function testLatitude() - { - $this->source->setLatitude(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getLatitude(), SourceTest::TEST_STRING); - } - - public function testLongitude() - { - $this->source->setLongitude(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getLongitude(), SourceTest::TEST_STRING); - } - - public function testCountryId() - { - $this->source->setCountryId(SourceTest::TEST_ID); - $this->assertEquals($this->source->getCountryId(), SourceTest::TEST_ID); - } - - public function testRegion() - { - $this->source->setRegion(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getRegion(), SourceTest::TEST_STRING); - } - - public function testCity() - { - $this->source->setCity(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getCity(), SourceTest::TEST_STRING); - } - - public function testStreet() - { - $this->source->setStreet(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getStreet(), SourceTest::TEST_STRING); - } - - public function testPhone() - { - $this->source->setPhone(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getPhone(), SourceTest::TEST_STRING); - } - - public function testPostcode() - { - $this->source->setPostcode(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getPostcode(), SourceTest::TEST_STRING); - } - - public function testFax() - { - $this->source->setFax(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getFax(), SourceTest::TEST_STRING); - } - - public function testPriority() - { - $this->source->setPriority(SourceTest::TEST_STRING); - $this->assertEquals($this->source->getPriority(), SourceTest::TEST_STRING); - } - - public function testCarrierLinks() - { - $carrierLink1 = $this->getMock( - \Magento\Inventory\Model\SourceCarrierLink::class, - [], - [], - '', - false - ); - - $carrierLink2 = $this->getMock( - \Magento\Inventory\Model\SourceCarrierLink::class, - [], - [], - '', - false - ); - - $carrierLinks = [$carrierLink1, $carrierLink2]; - - $this->source->setCarrierLinks($carrierLinks); - $this->assertEquals($carrierLinks, $this->source->getCarrierLinks()); - } - -} From 31f49a62a39e600a70999204153dc53e72b81a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20R=C3=B6ttig?= Date: Mon, 5 Jun 2017 13:39:52 +0200 Subject: [PATCH 47/66] Review Fixes --- .../Inventory/Model/SourceRepository.php | 32 ++++++------------- .../Api/SourceRepositoryInterface.php | 2 ++ .../InventoryApi/Api/SourceRepositoryTest.php | 6 ++-- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index f16ae071906f..994fee729e2a 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -117,8 +117,15 @@ public function __construct( public function save(SourceInterface $source) { try { - $this->saveSource($source); - $this->saveSourceCarrierLinks($source); + /** @var SourceInterface|AbstractModel $source */ + $this->resourceSource->save($source); + + /** @var SourceCarrierLinkInterface|AbstractModel $carrierLink */ + foreach ($source->getCarrierLinks() as $carrierLink) { + $carrierLink->setData(SourceInterface::SOURCE_ID, $source->getSourceId()); + $this->resourceSourceCarrierLink->save($carrierLink); + } + return $source->getSourceId(); } catch (\Exception $exception) { $this->logger->error($exception->getMessage()); @@ -126,27 +133,6 @@ public function save(SourceInterface $source) } } - /** - * @param SourceInterface $source - */ - private function saveSource(SourceInterface $source) - { - /** @var SourceInterface|AbstractModel $source */ - $this->resourceSource->save($source); - } - - /** - * @param SourceInterface $source - */ - private function saveSourceCarrierLinks(SourceInterface $source) - { - /** @var SourceCarrierLinkInterface|AbstractModel $carrierLink */ - foreach ($source->getCarrierLinks() as $carrierLink) { - $carrierLink->setData(SourceInterface::SOURCE_ID, $source->getSourceId()); - $this->resourceSourceCarrierLink->save($carrierLink); - } - } - /** * @inheritdoc */ diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index 3bc8947a4cec..5df65d06cb46 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -16,6 +16,8 @@ interface SourceRepositoryInterface * @param \Magento\InventoryApi\Api\Data\SourceInterface $source * @return int * + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\StateException * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function save(\Magento\InventoryApi\Api\Data\SourceInterface $source); diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index d01340e4ecad..109ed0dd2c1d 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -14,8 +14,8 @@ use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterfaceFactory; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; -use Magento\TestFramework\TestCase\WebapiAbstract; use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\TestCase\WebapiAbstract; class SourceRepositoryTest extends WebapiAbstract { @@ -151,7 +151,7 @@ private function createRandomSource($countCarrier = 2, $postcode = '54321', $isA { $country = $this->countryInformationAcquirer->getCountryInfo('US'); $regions = $country->getAvailableRegions(); - $region = $regions[rand(0, count($regions)-1)]; + $region = $regions[mt_rand(0, count($regions)-1)]; $name = 'Api Test ' . uniqid(); $description = 'This is an inventory source created by api-functional tests'; @@ -163,7 +163,7 @@ private function createRandomSource($countCarrier = 2, $postcode = '54321', $isA $phone = '01660002020044'; $latitude = 51.343479; $longitude = 12.387772; - $priority = rand(1,999); + $priority = mt_rand(1,999); $carriers = []; for ($index = 1; $index <= $countCarrier; $index++) { From fe5ced8fd2d4fc4f0625f815efe0ddd0e198f42c Mon Sep 17 00:00:00 2001 From: larsroettig Date: Mon, 5 Jun 2017 15:03:56 +0200 Subject: [PATCH 48/66] magento-engcom/magento2#25 Add Bugfix for testGetSourcesList test and complete this test case --- .../InventoryApi/Api/SourceRepositoryTest.php | 39 ++++--------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index 109ed0dd2c1d..0a6b09d7ac2d 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -264,7 +264,7 @@ public function testGetSource() */ public function testGetSourcesList() { - $this->markTestSkipped('WIP: Search seems to ignore filter criterias!'); + //$this->markTestSkipped('WIP: Search seems to ignore filter criterias!'); /** @var SearchCriteriaBuilder $searchCriteriaBuilder */ $searchCriteriaBuilder = Bootstrap::getObjectManager() @@ -274,7 +274,7 @@ public function testGetSourcesList() $postcode2 = uniqid('APITEST'); $source1 = $this->createRandomSource(2, $postcode1, true); - $source1->setSourceId($this->sourceRepository->save($source1)); + $this->sourceRepository->save($source1); $source2 = $this->createRandomSource(3, $postcode1, false); $this->sourceRepository->save($source2); @@ -285,29 +285,10 @@ public function testGetSourcesList() $source4 = $this->createRandomSource(3, $postcode2, true); $this->sourceRepository->save($source4); - $filter1 = $this->filterBuilder->setField(SourceInterface::POSTCODE) - ->setValue($postcode1); - - $filter2 = $this->filterBuilder->setField(SourceInterface::POSTCODE) - ->setValue($postcode2); - - $filter3 = $this->filterBuilder->setField(SourceInterface::IS_ACTIVE) - ->setValue(true); - - // where postcode = $postcode1 - // or postcode = $postcode2 - // and is_active = true - $searchCriteriaBuilder->addFilters([$filter1, $filter3]); - $searchCriteriaBuilder->addFilters([$filter2, $filter3]); - - $searchCriteriaBuilder->setPageSize(2); - - /** @var SortOrder $sortOrder */ - $sortOrder = $this->sortOrderBuilder->setField(SourceInterface::SOURCE_ID) - ->setDirection(SortOrder::SORT_ASC) - ->create(); - - $searchCriteriaBuilder->setSortOrders([$sortOrder]); + // add filters to find all active items with created postcode + $postcodeFilter = implode(',', [$postcode1, $postcode2]); + $searchCriteriaBuilder->addFilter('postcode', $postcodeFilter, 'in'); + $searchCriteriaBuilder->addFilter('is_active', 1, 'eq'); $searchData = $searchCriteriaBuilder->create()->__toArray(); $requestData = ['searchCriteria' => $searchData]; @@ -324,20 +305,16 @@ public function testGetSourcesList() ], ]; - var_dump($serviceInfo); - $searchResult = $this->_webApiCall($serviceInfo, $requestData); - var_dump($searchResult); - $this->assertEquals(3, $searchResult['page_size']); - $this->assertEquals(2, count($searchResult['items'])); + $this->assertEquals(3, count($searchResult['items'])); $this->assertEquals( $searchResult['items'][0][SourceInterface::SOURCE_ID], $source1->getSourceId() ); $this->assertEquals( $searchResult['items'][1][SourceInterface::SOURCE_ID], - $source2->getSourceId() + $source3->getSourceId() ); } From 385541a3f9ccdc2f8acbfb8c9df5e540a417f79c Mon Sep 17 00:00:00 2001 From: larsroettig Date: Mon, 5 Jun 2017 18:10:51 +0200 Subject: [PATCH 49/66] magento-engcom/magento2#25 Add new testcases and bugfix for SourceRepository save method --- .../Model/Resource/SourceCarrierLink.php | 22 +++++ .../Inventory/Model/SourceRepository.php | 31 +++++-- .../InventoryApi/Api/SourceRepositoryTest.php | 93 +++++++++++++++++-- 3 files changed, 127 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php index 5c927aa985b0..d3a071265e99 100644 --- a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php +++ b/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php @@ -6,6 +6,7 @@ namespace Magento\Inventory\Model\Resource; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; use Magento\Inventory\Setup\InstallSchema; @@ -20,4 +21,25 @@ protected function _construct() { $this->_init(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK, 'source_carrier_link_id'); } + + /** + * Delete all source carrier links by sourceId. + * + * @param SourceInterface $sourceId + * + * @throws \Exception + * + * @return $this + */ + public function deleteBySource(SourceInterface $source) + { + $connection = $this->getConnection(); + + $connection->delete( + $connection->getTableName(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK), + $connection->quoteInto('source_id = ?', $source->getId()) + ); + + return $this; + } } diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 994fee729e2a..26b7144a09ea 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -6,23 +6,23 @@ namespace Magento\Inventory\Model; +use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Framework\Exception\CouldNotSaveException; -use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Model\AbstractModel; +use Magento\Inventory\Model\Resource\Source as ResourceSource; +use Magento\Inventory\Model\Resource\Source\CollectionFactory; +use Magento\Inventory\Model\Resource\SourceCarrierLink as ResourceSourceCarrierLink; +use Magento\Inventory\Model\Resource\SourceCarrierLink\CollectionFactory as CarrierLinkCollectionFactory; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterfaceFactory; use Magento\InventoryApi\Api\SourceRepositoryInterface; -use Magento\Inventory\Model\Resource\Source as ResourceSource; -use Magento\Inventory\Model\Resource\SourceCarrierLink as ResourceSourceCarrierLink; -use Magento\Inventory\Model\Resource\Source\CollectionFactory; -use Magento\Inventory\Model\Resource\SourceCarrierLink\CollectionFactory as CarrierLinkCollectionFactory; -use \Psr\Log\LoggerInterface; +use Psr\Log\LoggerInterface; /** * Class SourceRepository @@ -120,6 +120,13 @@ public function save(SourceInterface $source) /** @var SourceInterface|AbstractModel $source */ $this->resourceSource->save($source); + if ($source->getCarrierLinks() === null) { + return $source->getSourceId(); + } + + // clean up for the old carrier links + $this->resourceSourceCarrierLink->deleteBySource($source); + /** @var SourceCarrierLinkInterface|AbstractModel $carrierLink */ foreach ($source->getCarrierLinks() as $carrierLink) { $carrierLink->setData(SourceInterface::SOURCE_ID, $source->getSourceId()); @@ -141,7 +148,9 @@ public function get($sourceId) /** @var SourceInterface|AbstractModel $source */ $source = $this->sourceFactory->create(); $this->resourceSource->load($source, $sourceId, SourceInterface::SOURCE_ID); - $this->addCarrierLinks($source); + + $carrierLinks = $this->loadCarrierLinksBySource($source); + $source->setCarrierLinks($carrierLinks); if (!$source->getSourceId()) { throw NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId); @@ -151,9 +160,13 @@ public function get($sourceId) } /** + * Loads the carrier links by given source. + * * @param SourceInterface $source + * + * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] */ - private function addCarrierLinks(SourceInterface $source) + private function loadCarrierLinksBySource(SourceInterface $source) { /** @var ResourceSourceCarrierLink\Collection $collection */ $collection = $this->carrierLinkCollectionFactory->create(); @@ -163,7 +176,7 @@ private function addCarrierLinks(SourceInterface $source) ->create(); $this->collectionProcessor->process($searchCriteria, $collection); - $source->setCarrierLinks($collection->getItems()); + return $collection->getItems(); } /** diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index 0a6b09d7ac2d..a0dcc2b69291 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -8,7 +8,6 @@ use Magento\Directory\Api\CountryInformationAcquirerInterface; use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\SearchCriteriaBuilder; -use Magento\Framework\Api\SortOrder; use Magento\Framework\Api\SortOrderBuilder; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterfaceFactory; @@ -22,6 +21,7 @@ class SourceRepositoryTest extends WebapiAbstract const SERVICE_VERSION = 'V1'; const SERVICE_NAME = 'inventoryApiSourceRepositoryV1'; const RESOURCE_PATH = '/V1/inventory/source/'; + const TEST_PREFIX = 'SOURCE_APITEST_'; /** * @var SourceInterfaceFactory @@ -153,7 +153,7 @@ private function createRandomSource($countCarrier = 2, $postcode = '54321', $isA $regions = $country->getAvailableRegions(); $region = $regions[mt_rand(0, count($regions)-1)]; - $name = 'Api Test ' . uniqid(); + $name = uniqid(self::TEST_PREFIX, false); $description = 'This is an inventory source created by api-functional tests'; $city = 'Exampletown'; $street = 'Some Street 455'; @@ -197,6 +197,35 @@ private function createRandomSource($countCarrier = 2, $postcode = '54321', $isA return $source; } + /** + * Update the given source in magento + * + * @param SourceInterface $expectedSource + * + * @return int + */ + private function updateSource($expectedSource) + { + $requestData = [ + 'source' => $this->getSourceDataArray($expectedSource) + ]; + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $expectedSource->getSourceId(), + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Save', + ], + ]; + + // call the webservice to update the source + return $this->_webApiCall($serviceInfo, $requestData); + } + /** * Create new Inventory Source using Web API and verify it's integrity. */ @@ -270,8 +299,8 @@ public function testGetSourcesList() $searchCriteriaBuilder = Bootstrap::getObjectManager() ->create(SearchCriteriaBuilder::class); - $postcode1 = uniqid('APITEST'); - $postcode2 = uniqid('APITEST'); + $postcode1 = uniqid(self::TEST_PREFIX, false); + $postcode2 = uniqid(self::TEST_PREFIX, false); $source1 = $this->createRandomSource(2, $postcode1, true); $this->sourceRepository->save($source1); @@ -308,8 +337,7 @@ public function testGetSourcesList() $searchResult = $this->_webApiCall($serviceInfo, $requestData); $this->assertEquals(3, count($searchResult['items'])); - $this->assertEquals( - $searchResult['items'][0][SourceInterface::SOURCE_ID], + $this->assertEquals($searchResult['items'][0][SourceInterface::SOURCE_ID], $source1->getSourceId() ); $this->assertEquals( @@ -323,8 +351,33 @@ public function testGetSourcesList() */ public function testUpdateSource() { - //TODO: Implement testUpdateSource - $this->fail(__METHOD__ . " is not implemented yet."); + // create a new source + $expectedSource = $this->createRandomSource(2); + $this->sourceRepository->save($expectedSource); + + // set name and city property's in the source to update them + $expectedName = uniqid('UpdatedName_', false); + $expectedCity = uniqid('UpdatedCity_', false); + $expectedSource->setName($expectedName); + $expectedSource->setCity($expectedCity); + $updateSourceId = $this->updateSource($expectedSource); + + // verify it's integrity + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $updateSourceId, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + ], + ]; + + $result = $this->_webApiCall($serviceInfo, [SourceInterface::SOURCE_ID => $updateSourceId]); + $this->assertEquals($expectedName, $result[SourceInterface::NAME]); + $this->assertEquals($expectedCity, $result[SourceInterface::CITY]); } /** @@ -332,7 +385,27 @@ public function testUpdateSource() */ public function testUpdateSourceWithoutCarriers() { - //TODO: Implement testUpdateSourceWithoutCarriers - $this->fail(__METHOD__ . " is not implemented yet."); + $expectedSource = $this->createRandomSource(2); + $this->sourceRepository->save($expectedSource); + + $carriers = []; + $expectedSource->setCarrierLinks($carriers); + $updateSourceId = $this->updateSource($expectedSource); + + // verify it's integrity + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $updateSourceId, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + ], + ]; + + $result = $this->_webApiCall($serviceInfo, [SourceInterface::SOURCE_ID => $updateSourceId]); + $this->assertEquals($carriers, $result[SourceInterface::CARRIER_LINKS]); } } From 9aae5e1859e53f41f6917c46395abad112ca6ea2 Mon Sep 17 00:00:00 2001 From: larsroettig Date: Mon, 5 Jun 2017 18:51:03 +0200 Subject: [PATCH 50/66] magento-engcom/magento2#25 Add testcase for GetSourcesList with CarrierLinks --- app/code/Magento/Inventory/Model/SourceRepository.php | 8 +++++++- .../Magento/InventoryApi/Api/SourceRepositoryTest.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 26b7144a09ea..56ffd3c0cbfd 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -196,7 +196,13 @@ public function getList(SearchCriteriaInterface $searchCriteria = null) $searchResults->setSearchCriteria($searchCriteria); } - $searchResults->setItems($collection->getItems()); + /** @var \Magento\InventoryApi\Api\Data\SourceInterface[] $sourceItems */ + $sourceItems = $collection->getItems(); + foreach ($sourceItems as $sourceItem) { + $sourceItem->setCarrierLinks($this->loadCarrierLinksBySource($sourceItem)); + } + + $searchResults->setItems($sourceItems); $searchResults->setTotalCount($collection->getSize()); return $searchResults; } diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index a0dcc2b69291..c3b308928117 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -344,6 +344,16 @@ public function testGetSourcesList() $searchResult['items'][1][SourceInterface::SOURCE_ID], $source3->getSourceId() ); + + /** @var SourceCarrierLinkInterface[] $carrierLinks */ + $resultCarrierLink = $searchResult['items'][0][SourceInterface::CARRIER_LINKS]; + + $counter = 0; + foreach ($source1->getCarrierLinks() as $carrierLink) { + $carrierCode = $resultCarrierLink[$counter][SourceCarrierLinkInterface::CARRIER_CODE]; + $this->assertEquals($carrierLink->getCarrierCode(), $carrierCode); + $counter++; + } } /** From 73d64422050c0d0ad3ba23a6cd89dece9746fbbc Mon Sep 17 00:00:00 2001 From: larsroettig Date: Mon, 5 Jun 2017 20:19:06 +0200 Subject: [PATCH 51/66] magento-engcom/magento2#25 Add Fixes for Review Coments --- app/code/Magento/Inventory/Model/SourceRepository.php | 4 ++-- app/code/Magento/Inventory/Setup/InstallSchema.php | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 56ffd3c0cbfd..4783834d24e7 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -117,7 +117,7 @@ public function __construct( public function save(SourceInterface $source) { try { - /** @var SourceInterface|AbstractModel $source */ + /** @var SourceInterface $source */ $this->resourceSource->save($source); if ($source->getCarrierLinks() === null) { @@ -127,7 +127,7 @@ public function save(SourceInterface $source) // clean up for the old carrier links $this->resourceSourceCarrierLink->deleteBySource($source); - /** @var SourceCarrierLinkInterface|AbstractModel $carrierLink */ + /** @var SourceCarrierLinkInterface $carrierLink */ foreach ($source->getCarrierLinks() as $carrierLink) { $carrierLink->setData(SourceInterface::SOURCE_ID, $source->getSourceId()); $this->resourceSourceCarrierLink->save($carrierLink); diff --git a/app/code/Magento/Inventory/Setup/InstallSchema.php b/app/code/Magento/Inventory/Setup/InstallSchema.php index e3fc9360650f..d8b754886158 100644 --- a/app/code/Magento/Inventory/Setup/InstallSchema.php +++ b/app/code/Magento/Inventory/Setup/InstallSchema.php @@ -25,7 +25,8 @@ class InstallSchema implements InstallSchemaInterface /** * Constant for decimal precision for latitude and longitude */ - const LATLON_PRECISION = 10; + const LATLON_PRECISION_LAT = 8; + const LATLON_PRECISION_LON = 9; const LATLON_SCALE = 6; /** @@ -118,8 +119,9 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con Table::TYPE_DECIMAL, null, [ - InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION, + InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION_LAT, InstallSchema::OPTION_SCALE => InstallSchema::LATLON_SCALE, + InstallSchema::OPTION_UNSIGNED => false, InstallSchema::OPTION_NULLABLE => true ], 'Latitude' @@ -128,8 +130,9 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con Table::TYPE_DECIMAL, null, [ - InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION, + InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION_LON, InstallSchema::OPTION_SCALE => InstallSchema::LATLON_SCALE, + InstallSchema::OPTION_UNSIGNED => false, InstallSchema::OPTION_NULLABLE => true ], 'Longitude' From 203320bd760ff7111d2fac39456130faf5421182 Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Tue, 6 Jun 2017 11:02:09 +0300 Subject: [PATCH 52/66] magento-engcom/magento2#25: Source API implementation - Unit tests fixed --- .../Inventory/Test/Unit/Model/SourceRepositoryTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index d93181bc5767..6632636d6cb1 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -19,6 +19,7 @@ use Magento\Inventory\Model\Resource\SourceCarrierLink\CollectionFactory as CarrierLinkCollectionFactory; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Inventory\Model\Resource\SourceCarrierLink\Collection as CarrierLinkCollection; /** * Class SourceRepositoryTest @@ -244,12 +245,20 @@ public function testGetList() $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(), $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock() ]; + $carrierLinkCollectionMock = $this->getMockBuilder(CarrierLinkCollection::class) + ->disableOriginalConstructor() + ->getMock(); $this->collectionFactory->expects($this->once())->method('create')->willReturn($sourceCollection); $sourceCollection->expects($this->atLeastOnce())->method('getItems')->willReturn($sources); $this->sourceSearchResultsFactory->expects($this->once())->method('create')->willReturn($searchResults); $searchResults->expects($this->once())->method('setItems')->with($sources); + $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('addFilter')->willReturnSelf(); + $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('create')->willReturn($searchCriteria); + $this->carrierLinkCollectionFactory->expects($this->atLeastOnce())->method('create') + ->willReturn($carrierLinkCollectionMock); + $this->assertSame($searchResults, $this->model->getList($searchCriteria)); } } From bceb81bf32c7619f5015412dd0a2e0e688d66716 Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Tue, 6 Jun 2017 12:02:00 +0300 Subject: [PATCH 53/66] magento-engcom/magento2#25: Source API implementation --- composer.json | 2 ++ composer.lock | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 083a4918a5c7..b7e1f146445c 100644 --- a/composer.json +++ b/composer.json @@ -137,6 +137,8 @@ "magento/module-import-export": "100.2.0-dev", "magento/module-indexer": "100.2.0-dev", "magento/module-integration": "100.2.0-dev", + "magento/module-inventory": "100.0.0-dev", + "magento/module-inventory-api": "100.0.0-dev", "magento/module-layered-navigation": "100.2.0-dev", "magento/module-media-storage": "100.2.0-dev", "magento/module-msrp": "100.2.0-dev", diff --git a/composer.lock b/composer.lock index 119ad0b8059c..0c57f183a30f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "468277cb85ede262e3dd3155da88a15a", - "content-hash": "83b07861c465af490d6cf0c75adc78fd", + "hash": "75007f16bc2cd0f07bcadac88243d2ad", + "content-hash": "934bfcd14838f5b573dde3d8c9bd564a", "packages": [ { "name": "braintree/braintree_php", From 9abf23dab44479c7640271b5b8185c571f725180 Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Tue, 6 Jun 2017 12:48:55 +0300 Subject: [PATCH 54/66] magento-engcom/magento2#25: Source API implementation --- .../Model/{Resource => ResourceModel}/Source.php | 2 +- .../Source/Collection.php | 4 ++-- .../SourceCarrierLink.php | 2 +- .../SourceCarrierLink/Collection.php | 4 ++-- app/code/Magento/Inventory/Model/Source.php | 2 +- .../Inventory/Model/SourceCarrierLink.php | 2 +- .../Magento/Inventory/Model/SourceRepository.php | 10 +++++----- .../Magento/Inventory/Setup/InstallSchema.php | 15 ++++++++++----- .../Test/Unit/Model/SourceRepositoryTest.php | 16 ++++++++-------- 9 files changed, 31 insertions(+), 26 deletions(-) rename app/code/Magento/Inventory/Model/{Resource => ResourceModel}/Source.php (90%) rename app/code/Magento/Inventory/Model/{Resource => ResourceModel}/Source/Collection.php (79%) rename app/code/Magento/Inventory/Model/{Resource => ResourceModel}/SourceCarrierLink.php (95%) rename app/code/Magento/Inventory/Model/{Resource => ResourceModel}/SourceCarrierLink/Collection.php (81%) diff --git a/app/code/Magento/Inventory/Model/Resource/Source.php b/app/code/Magento/Inventory/Model/ResourceModel/Source.php similarity index 90% rename from app/code/Magento/Inventory/Model/Resource/Source.php rename to app/code/Magento/Inventory/Model/ResourceModel/Source.php index 2859a5935dd9..44a65dc7fe21 100644 --- a/app/code/Magento/Inventory/Model/Resource/Source.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\Inventory\Model\Resource; +namespace Magento\Inventory\Model\ResourceModel; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; use Magento\Inventory\Setup\InstallSchema; diff --git a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php b/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php similarity index 79% rename from app/code/Magento/Inventory/Model/Resource/Source/Collection.php rename to app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php index d149d175115e..a38a23889531 100644 --- a/app/code/Magento/Inventory/Model/Resource/Source/Collection.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php @@ -3,9 +3,9 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Inventory\Model\Resource\Source; +namespace Magento\Inventory\Model\ResourceModel\Source; -use Magento\Inventory\Model\Resource\Source as ResourceSource; +use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Inventory\Model\Source as SourceModel; diff --git a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/ResourceModel/SourceCarrierLink.php similarity index 95% rename from app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php rename to app/code/Magento/Inventory/Model/ResourceModel/SourceCarrierLink.php index d3a071265e99..f63943605395 100644 --- a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/SourceCarrierLink.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\Inventory\Model\Resource; +namespace Magento\Inventory\Model\ResourceModel; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; diff --git a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php b/app/code/Magento/Inventory/Model/ResourceModel/SourceCarrierLink/Collection.php similarity index 81% rename from app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php rename to app/code/Magento/Inventory/Model/ResourceModel/SourceCarrierLink/Collection.php index aec2ab9577af..cb5ecd67a171 100644 --- a/app/code/Magento/Inventory/Model/Resource/SourceCarrierLink/Collection.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/SourceCarrierLink/Collection.php @@ -4,9 +4,9 @@ * See COPYING.txt for license details. */ -namespace Magento\Inventory\Model\Resource\SourceCarrierLink; +namespace Magento\Inventory\Model\ResourceModel\SourceCarrierLink; -use Magento\Inventory\Model\Resource\SourceCarrierLink as ResourceSourceCarrierLink; +use Magento\Inventory\Model\ResourceModel\SourceCarrierLink as ResourceSourceCarrierLink; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Inventory\Model\SourceCarrierLink as SourceCarrierLinkModel; diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index f07dda86daf6..7dab07822b39 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -24,7 +24,7 @@ class Source extends AbstractExtensibleModel implements SourceInterface */ protected function _construct() { - $this->_init(\Magento\Inventory\Model\Resource\Source::class); + $this->_init(\Magento\Inventory\Model\ResourceModel\Source::class); } /** diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/SourceCarrierLink.php index d79fcbaed25b..e538e5a74ead 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLink.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLink.php @@ -21,7 +21,7 @@ class SourceCarrierLink extends AbstractExtensibleModel implements SourceCarrier */ protected function _construct() { - $this->_init(\Magento\Inventory\Model\Resource\SourceCarrierLink::class); + $this->_init(\Magento\Inventory\Model\ResourceModel\SourceCarrierLink::class); } /** diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 4783834d24e7..657e0857f70c 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -12,10 +12,10 @@ use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Model\AbstractModel; -use Magento\Inventory\Model\Resource\Source as ResourceSource; -use Magento\Inventory\Model\Resource\Source\CollectionFactory; -use Magento\Inventory\Model\Resource\SourceCarrierLink as ResourceSourceCarrierLink; -use Magento\Inventory\Model\Resource\SourceCarrierLink\CollectionFactory as CarrierLinkCollectionFactory; +use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; +use Magento\Inventory\Model\ResourceModel\Source\CollectionFactory; +use Magento\Inventory\Model\ResourceModel\SourceCarrierLink as ResourceSourceCarrierLink; +use Magento\Inventory\Model\ResourceModel\SourceCarrierLink\CollectionFactory as CarrierLinkCollectionFactory; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; @@ -184,7 +184,7 @@ private function loadCarrierLinksBySource(SourceInterface $source) */ public function getList(SearchCriteriaInterface $searchCriteria = null) { - /** @var \Magento\Inventory\Model\Resource\Source\Collection $collection */ + /** @var \Magento\Inventory\Model\ResourceModel\Source\Collection $collection */ $collection = $this->collectionFactory->create(); /** @var SourceSearchResultsInterface $searchResults */ diff --git a/app/code/Magento/Inventory/Setup/InstallSchema.php b/app/code/Magento/Inventory/Setup/InstallSchema.php index d8b754886158..05138043575d 100644 --- a/app/code/Magento/Inventory/Setup/InstallSchema.php +++ b/app/code/Magento/Inventory/Setup/InstallSchema.php @@ -1,5 +1,8 @@ disableOriginalConstructor() ->getMock(); $carrierLinkCollectionMock = $this->getMockBuilder( - \Magento\Inventory\Model\Resource\SourceCarrierLink\Collection::class + \Magento\Inventory\Model\ResourceModel\SourceCarrierLink\Collection::class )->disableOriginalConstructor()->getMock(); $this->carrierLinkCollectionFactory->expects($this->atLeastOnce())->method('create') @@ -211,7 +211,7 @@ public function testGetErrorExpectsException() ->disableOriginalConstructor() ->getMock(); $carrierLinkCollectionMock = $this->getMockBuilder( - \Magento\Inventory\Model\Resource\SourceCarrierLink\Collection::class + \Magento\Inventory\Model\ResourceModel\SourceCarrierLink\Collection::class )->disableOriginalConstructor()->getMock(); $this->carrierLinkCollectionFactory->expects($this->atLeastOnce())->method('create') From 705c758bb0eb98177a2276a31d439880419b60e7 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 6 Jun 2017 15:44:37 +0300 Subject: [PATCH 55/66] magento-engcom/magento2#25: Source API Implementation -- global refactoring --- .../Model/ResourceModel/Source/Collection.php | 1 - app/code/Magento/Inventory/Model/Source.php | 33 +- .../Inventory/Model/SourceCarrierLink.php | 12 +- .../Inventory/Model/SourceSearchResults.php | 17 - .../Magento/Inventory/Setup/InstallSchema.php | 460 +++++++++--------- app/code/Magento/Inventory/etc/di.xml | 2 +- .../Api/Data/SourceCarrierLinkInterface.php | 8 +- .../InventoryApi/Api/Data/SourceInterface.php | 100 ++-- .../Api/Data/SourceSearchResultsInterface.php | 2 +- .../InventoryApi/Api/SourceRepositoryTest.php | 44 +- 10 files changed, 321 insertions(+), 358 deletions(-) delete mode 100644 app/code/Magento/Inventory/Model/SourceSearchResults.php diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php b/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php index a38a23889531..f36c5e5618bd 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php @@ -6,7 +6,6 @@ namespace Magento\Inventory\Model\ResourceModel\Source; use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; -use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Inventory\Model\Source as SourceModel; diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index 7dab07822b39..90ac93212c65 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -41,7 +41,6 @@ public function getSourceId() public function setSourceId($sourceId) { $this->setData(SourceInterface::SOURCE_ID, $sourceId); - return $this; } /** @@ -58,7 +57,6 @@ public function getName() public function setName($name) { $this->setData(SourceInterface::NAME, $name); - return $this; } /** @@ -75,7 +73,6 @@ public function getEmail() public function setEmail($email) { $this->setData(SourceInterface::EMAIL, $email); - return $this; } /** @@ -92,24 +89,22 @@ public function getContactName() public function setContactName($contactName) { $this->setData(SourceInterface::CONTACT_NAME, $contactName); - return $this; } /** * @inheritdoc */ - public function getIsActive() + public function isEnabled() { - return $this->getData(SourceInterface::IS_ACTIVE); + return $this->getData(SourceInterface::ENABLED); } /** * @inheritdoc */ - public function setIsActive($active) + public function setEnabled($enabled) { - $this->setData(SourceInterface::IS_ACTIVE, $active); - return $this; + $this->setData(SourceInterface::ENABLED, $enabled); } /** @@ -126,7 +121,6 @@ public function getDescription() public function setDescription($description) { $this->setData(SourceInterface::DESCRIPTION, $description); - return $this; } /** @@ -143,7 +137,6 @@ public function getLatitude() public function setLatitude($latitude) { $this->setData(SourceInterface::LATITUDE, $latitude); - return $this; } /** @@ -160,7 +153,6 @@ public function getLongitude() public function setLongitude($longitude) { $this->setData(SourceInterface::LONGITUDE, $longitude); - return $this; } /** @@ -177,7 +169,6 @@ public function getCountryId() public function setCountryId($countryId) { $this->setData(SourceInterface::COUNTRY_ID, $countryId); - return $this; } /** @@ -194,7 +185,6 @@ public function getRegionId() public function setRegionId($regionId) { $this->setData(SourceInterface::REGION_ID, $regionId); - return $this; } /** @@ -211,7 +201,6 @@ public function getRegion() public function setRegion($region) { $this->setData(SourceInterface::REGION, $region); - return $this; } /** @@ -228,7 +217,6 @@ public function getCity() public function setCity($city) { $this->setData(SourceInterface::CITY, $city); - return $this; } /** @@ -245,7 +233,6 @@ public function getStreet() public function setStreet($street) { $this->setData(SourceInterface::STREET, $street); - return $this; } /** @@ -262,7 +249,6 @@ public function getPostcode() public function setPostcode($postcode) { $this->setData(SourceInterface::POSTCODE, $postcode); - return $this; } /** @@ -279,7 +265,6 @@ public function getPhone() public function setPhone($phone) { $this->setData(SourceInterface::PHONE, $phone); - return $this; } /** @@ -296,7 +281,6 @@ public function getFax() public function setFax($fax) { $this->setData(SourceInterface::FAX, $fax); - return $this; } /** @@ -313,7 +297,6 @@ public function getPriority() public function setPriority($priority) { $this->setData(SourceInterface::PRIORITY, $priority); - return $this; } /** @@ -330,7 +313,6 @@ public function getCarrierLinks() public function setCarrierLinks($carrierLinks) { $this->setData(SourceInterface::CARRIER_LINKS, $carrierLinks); - return $this; } /** @@ -338,7 +320,12 @@ public function setCarrierLinks($carrierLinks) */ public function getExtensionAttributes() { - return $this->_getExtensionAttributes(); + $extensionAttributes = $this->_getExtensionAttributes(); + if (null === $extensionAttributes) { + $extensionAttributes = $this->extensionAttributesFactory->create(SourceInterface::class); + $this->setExtensionAttributes($extensionAttributes); + } + return $extensionAttributes; } /** diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLink.php b/app/code/Magento/Inventory/Model/SourceCarrierLink.php index e538e5a74ead..a1f3043a5357 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLink.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLink.php @@ -3,11 +3,10 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Inventory\Model; use Magento\Framework\Model\AbstractExtensibleModel; -use \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; +use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; /** * @codeCoverageIgnore @@ -38,7 +37,6 @@ public function getCarrierCode() public function setCarrierCode($carrierCode) { $this->setData(SourceCarrierLinkInterface::CARRIER_CODE, $carrierCode); - return $this; } /** @@ -55,7 +53,6 @@ public function getPosition() public function setPosition($position) { $this->setData(SourceCarrierLinkInterface::POSITION, $position); - return $this; } /** @@ -63,7 +60,12 @@ public function setPosition($position) */ public function getExtensionAttributes() { - return $this->_getExtensionAttributes(); + $extensionAttributes = $this->_getExtensionAttributes(); + if (null === $extensionAttributes) { + $extensionAttributes = $this->extensionAttributesFactory->create(SourceCarrierLinkInterface::class); + $this->setExtensionAttributes($extensionAttributes); + } + return $extensionAttributes; } /** diff --git a/app/code/Magento/Inventory/Model/SourceSearchResults.php b/app/code/Magento/Inventory/Model/SourceSearchResults.php deleted file mode 100644 index ed3ebe129d32..000000000000 --- a/app/code/Magento/Inventory/Model/SourceSearchResults.php +++ /dev/null @@ -1,17 +0,0 @@ -startSetup(); - - $tableNameSourceEntity = $installer->getTable(InstallSchema::TABLE_NAME_SOURCE); - if (!$installer->getConnection()->isTableExists($tableNameSourceEntity)) { - $table = $installer->getConnection()->newTable($tableNameSourceEntity); - - $table->addColumn( - SourceInterface::SOURCE_ID, - Table::TYPE_INTEGER, - null, - [ - InstallSchema::OPTION_IDENTITY => true, - InstallSchema::OPTION_UNSIGNED => true, - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_PRIMARY => true - ], - 'Source ID' - )->addColumn( - SourceInterface::NAME, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Source Name' - )->addColumn( - SourceInterface::CONTACT_NAME, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Contact Name' - )->addColumn( - SourceInterface::EMAIL, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Email' - )->addColumn( - SourceInterface::IS_ACTIVE, - Table::TYPE_SMALLINT, - null, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true, - InstallSchema::OPTION_DEFAULT => 1 - ], - 'Defines Is Source Active' - )->addColumn( - SourceInterface::DESCRIPTION, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Description' - )->addColumn( - SourceInterface::LATITUDE, - Table::TYPE_DECIMAL, - null, - [ - InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION_LAT, - InstallSchema::OPTION_SCALE => InstallSchema::LATLON_SCALE, - InstallSchema::OPTION_UNSIGNED => false, - InstallSchema::OPTION_NULLABLE => true - ], - 'Latitude' - )->addColumn( - SourceInterface::LONGITUDE, - Table::TYPE_DECIMAL, - null, - [ - InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION_LON, - InstallSchema::OPTION_SCALE => InstallSchema::LATLON_SCALE, - InstallSchema::OPTION_UNSIGNED => false, - InstallSchema::OPTION_NULLABLE => true - ], - 'Longitude' - )->addColumn( - SourceInterface::COUNTRY_ID, - Table::TYPE_TEXT, - 30, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Country Id' - )->addColumn( - SourceInterface::REGION_ID, - Table::TYPE_SMALLINT, - null, - [ - InstallSchema::OPTION_NULLABLE => true, - InstallSchema::OPTION_UNSIGNED => true - ], - 'Region Id' - )->addColumn( - SourceInterface::REGION, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Region' - )->addColumn( - SourceInterface::CITY, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'City' - )->addColumn( - SourceInterface::STREET, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Street' - )->addColumn( - SourceInterface::POSTCODE, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Postcode' - )->addColumn( - SourceInterface::PHONE, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Phone' - )->addColumn( - SourceInterface::FAX, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Fax' - )->addColumn( - SourceInterface::PRIORITY, - Table::TYPE_SMALLINT, - null, - [ - InstallSchema::OPTION_NULLABLE => true, - InstallSchema::OPTION_UNSIGNED => true, - ], - 'Priority' - ); + $setup->startSetup(); + $setup->getConnection()->createTable($this->createSourceTable($setup)); + $setup->getConnection()->createTable($this->createSourceCarrierLinkTable($setup)); + $setup->endSetup(); + } - $table->setComment('Inventory Source Entity Table') - ->setOption('type', 'InnoDB') - ->setOption('charset', 'utf8'); - $installer->getConnection()->createTable($table); - } + /** + * @param SchemaSetupInterface $setup + * @return Table + */ + private function createSourceTable(SchemaSetupInterface $setup) + { + $sourceTable = $setup->getTable(InstallSchema::TABLE_NAME_SOURCE); - $tableNameCarrierLinkEntity = $installer->getTable(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK); - if (!$installer->getConnection()->isTableExists($tableNameCarrierLinkEntity)) { + return $setup->getConnection()->newTable( + $sourceTable + )->setComment( + 'Inventory Source Table' + )->addColumn( + SourceInterface::SOURCE_ID, + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_PRIMARY => true, + ], + 'Source ID' + )->addColumn( + SourceInterface::NAME, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + ], + 'Source Name' + )->addColumn( + SourceInterface::CONTACT_NAME, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => true, + ], + 'Contact Name' + )->addColumn( + SourceInterface::EMAIL, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => true, + ], + 'Email' + )->addColumn( + SourceInterface::ENABLED, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_DEFAULT => 1, + ], + 'Defines Is Source Enabled' + )->addColumn( + SourceInterface::DESCRIPTION, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => true, + ], + 'Description' + )->addColumn( + SourceInterface::LATITUDE, + Table::TYPE_DECIMAL, + null, + [ + InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION_LAT, + InstallSchema::OPTION_SCALE => InstallSchema::LATLON_SCALE, + InstallSchema::OPTION_UNSIGNED => false, + InstallSchema::OPTION_NULLABLE => true, + ], + 'Latitude' + )->addColumn( + SourceInterface::LONGITUDE, + Table::TYPE_DECIMAL, + null, + [ + InstallSchema::OPTION_PRECISION => InstallSchema::LATLON_PRECISION_LON, + InstallSchema::OPTION_SCALE => InstallSchema::LATLON_SCALE, + InstallSchema::OPTION_UNSIGNED => false, + InstallSchema::OPTION_NULLABLE => true, + ], + 'Longitude' + )->addColumn( + SourceInterface::COUNTRY_ID, + Table::TYPE_TEXT, + 2, + [ + InstallSchema::OPTION_NULLABLE => false, + ], + 'Country Id' + )->addColumn( + SourceInterface::REGION_ID, + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_NULLABLE => true, + InstallSchema::OPTION_UNSIGNED => true, + ], + 'Region Id' + )->addColumn( + SourceInterface::REGION, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => true, + ], + 'Region' + )->addColumn( + SourceInterface::CITY, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => true, + ], + 'City' + )->addColumn( + SourceInterface::STREET, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => true, + ], + 'Street' + )->addColumn( + SourceInterface::POSTCODE, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + ], + 'Postcode' + )->addColumn( + SourceInterface::PHONE, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => true, + ], + 'Phone' + )->addColumn( + SourceInterface::FAX, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => true, + ], + 'Fax' + )->addColumn( + SourceInterface::PRIORITY, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => true, + InstallSchema::OPTION_UNSIGNED => true, + ], + 'Priority' + ); + } - $table = $installer->getConnection()->newTable($tableNameCarrierLinkEntity); - $table->addColumn( - 'source_carrier_link_id', - Table::TYPE_INTEGER, - null, - [ - InstallSchema::OPTION_IDENTITY => true, - InstallSchema::OPTION_UNSIGNED => true, - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_PRIMARY => true - ], - 'Source Carrier Link ID' - )->addColumn( - SourceInterface::SOURCE_ID, - Table::TYPE_INTEGER, null, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true, - ], - 'Source ID' - )->addColumn( - SourceCarrierLinkInterface::CARRIER_CODE, - Table::TYPE_TEXT, 255, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_DEFAULT => '' - ], - 'Carrier Code' - )->addColumn( - 'position', Table::TYPE_SMALLINT, - null, - [ - InstallSchema::OPTION_NULLABLE => false, - InstallSchema::OPTION_UNSIGNED => true, - ], - 'Position' - ); + /** + * @param SchemaSetupInterface $setup + * @return Table + */ + private function createSourceCarrierLinkTable(SchemaSetupInterface $setup) + { + $sourceCarrierLinkTable = $setup->getTable(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK); + $sourceTable = $setup->getTable(InstallSchema::TABLE_NAME_SOURCE); - // Add foreign key for Pipeline ID field - $foreignKeyName = $installer->getConnection()->getForeignKeyName( - $tableNameCarrierLinkEntity, + return $setup->getConnection()->newTable( + $sourceCarrierLinkTable + )->setComment( + 'Inventory Source Carrier Link Table' + )->addColumn( + 'source_carrier_link_id', + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_PRIMARY => true, + ], + 'Source Carrier Link ID' + )->addColumn( + SourceInterface::SOURCE_ID, + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_UNSIGNED => true, + ], + 'Source ID' + )->addColumn( + SourceCarrierLinkInterface::CARRIER_CODE, + Table::TYPE_TEXT, 255, + [ + InstallSchema::OPTION_NULLABLE => false, + ], + 'Carrier Code' + )->addColumn( + 'position', + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => true, + InstallSchema::OPTION_UNSIGNED => true, + ], + 'Position' + )->addForeignKey( + $setup->getFkName( + $sourceCarrierLinkTable, SourceInterface::SOURCE_ID, - $tableNameCarrierLinkEntity, + $sourceTable, SourceInterface::SOURCE_ID - ); - $table->addForeignKey( - $foreignKeyName, - SourceInterface::SOURCE_ID, - $tableNameSourceEntity, - SourceInterface::SOURCE_ID, - Table::ACTION_CASCADE - ); - - $table->setComment('Inventory Source Carrier Link Entity Table') - ->setOption('type', 'InnoDB') - ->setOption('charset', 'utf8'); - $installer->getConnection()->createTable($table); - } - $setup->endSetup(); + ), + SourceInterface::SOURCE_ID, + $sourceTable, + SourceInterface::SOURCE_ID, + AdapterInterface::FK_ACTION_CASCADE + ); } } diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml index f5685c7eb759..83f969554a86 100644 --- a/app/code/Magento/Inventory/etc/di.xml +++ b/app/code/Magento/Inventory/etc/di.xml @@ -9,5 +9,5 @@ - + diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 44bcb68d6b3e..63c8308411e0 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -5,7 +5,7 @@ */ namespace Magento\InventoryApi\Api\Data; -use \Magento\Framework\Api\ExtensibleDataInterface; +use Magento\Framework\Api\ExtensibleDataInterface; /** * SourceCarrierLink interface @@ -31,7 +31,7 @@ public function getCarrierCode(); * Set carrier code. * * @param string $carrierCode - * @return $this + * @return void */ public function setCarrierCode($carrierCode); @@ -46,14 +46,14 @@ public function getPosition(); * Set position. * * @param int|null $position - * @return $this + * @return void */ public function setPosition($position); /** * Retrieve existing extension attributes object or create a new one. * - * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkExtensionInterface|null + * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkExtensionInterface */ public function getExtensionAttributes(); diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index 0d544391f86a..e39f2808dbd1 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -19,7 +19,7 @@ interface SourceInterface extends ExtensibleDataInterface const NAME = 'name'; const CONTACT_NAME = 'contact_name'; const EMAIL = 'email'; - const IS_ACTIVE = 'is_active'; + const ENABLED = 'enabled'; const DESCRIPTION = 'description'; const LATITUDE = 'latitude'; const LONGITUDE = 'longitude'; @@ -46,7 +46,7 @@ public function getSourceId(); * Set source id. * * @param int $sourceId - * @return $this + * @return void */ public function setSourceId($sourceId); @@ -61,37 +61,37 @@ public function getName(); * Set source name. * * @param string $name - * @return $this + * @return void */ public function setName($name); /** * Get source email * - * @return string + * @return string|null */ public function getEmail(); /** * Set source email * - * @param string $email - * @return $this + * @param string|null $email + * @return void */ public function setEmail($email); /** * Get source contact name. * - * @return string + * @return string|null */ public function getContactName(); /** * Set source contact name. * - * @param string $contactName - * @return $this + * @param string|null $contactName + * @return void */ public function setContactName($contactName); @@ -100,58 +100,58 @@ public function setContactName($contactName); * * @return bool */ - public function getIsActive(); + public function isEnabled(); /** * Enable or disable source. * - * @param bool $active - * @return $this + * @param bool $enabled + * @return void */ - public function setIsActive($active); + public function setEnabled($enabled); /** * Get source description. * - * @return string + * @return string|null */ public function getDescription(); /** * Set source description. * - * @param string $description - * @return $this + * @param string|null $description + * @return void */ public function setDescription($description); /** * Get source latitude. * - * @return float + * @return float|null */ public function getLatitude(); /** * Set source latitude. * - * @param float $latitude - * @return $this + * @param float|null $latitude + * @return void */ public function setLatitude($latitude); /** * Get source longitude. * - * @return float + * @return float|null */ public function getLongitude(); /** * Set source longitude. * - * @param float $longitude - * @return $this + * @param float|null $longitude + * @return void */ public function setLongitude($longitude); @@ -166,67 +166,67 @@ public function getCountryId(); * Set source country id. * * @param string $countryId - * @return $this + * @return void */ public function setCountryId($countryId); /** * Get region id if source has registered region. * - * @return int + * @return int|null */ public function getRegionId(); /** * Set region id if source has registered region. * - * @param int $regionId - * @return $this + * @param int|null $regionId + * @return void */ public function setRegionId($regionId); /** * Get region title if source has custom region * - * @return string + * @return string|null */ public function getRegion(); /** * Set source region title. * - * @param string $region - * @return $this + * @param string|null $region + * @return void */ public function setRegion($region); /** * Get source city. * - * @return string + * @return string|null */ public function getCity(); /** * Set source city. * - * @param string $city - * @return $this + * @param string|null $city + * @return void */ public function setCity($city); /** * Get source street name. * - * @return string + * @return string|null */ public function getStreet(); /** * Set source street name. * - * @param string $street - * @return $this + * @param string|null $street + * @return void */ public function setStreet($street); @@ -241,29 +241,29 @@ public function getPostcode(); * Set source post code. * * @param string $postcode - * @return $this + * @return void */ public function setPostcode($postcode); /** * Get source phone number. * - * @return string + * @return string|null */ public function getPhone(); /** * Set source phone number. * - * @param string $phone - * @return $this + * @param string|null $phone + * @return void */ public function setPhone($phone); /** * Get source fax. * - * @return string + * @return string|null */ public function getFax(); @@ -271,7 +271,7 @@ public function getFax(); * Set source fax. * * @param string $fax - * @return $this + * @return void|null */ public function setFax($fax); @@ -286,25 +286,25 @@ public function getPriority(); * Set source priority * * @param int $priority - * @return $this + * @return void */ public function setPriority($priority); /** - * @param \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] $carrierLinks - * @return $this + * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] */ - public function setCarrierLinks($carrierLinks); + public function getCarrierLinks(); /** - * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] + * @param \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] $carrierLinks + * @return void */ - public function getCarrierLinks(); + public function setCarrierLinks($carrierLinks); /** - * Retrieve existing extension attributes object or create a new one. + * Retrieve existing extension attributes object. * - * @return \Magento\InventoryApi\Api\Data\SourceExtensionInterface|null + * @return \Magento\InventoryApi\Api\Data\SourceExtensionInterface */ public function getExtensionAttributes(); @@ -312,7 +312,7 @@ public function getExtensionAttributes(); * Set an extension attributes object. * * @param \Magento\InventoryApi\Api\Data\SourceExtensionInterface $extensionAttributes - * @return $this + * @return void */ public function setExtensionAttributes( \Magento\InventoryApi\Api\Data\SourceExtensionInterface $extensionAttributes diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php index 2a24ead8fe56..28d9e0956944 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php @@ -23,7 +23,7 @@ public function getItems(); * Set sources list. * * @param \Magento\InventoryApi\Api\Data\SourceInterface[] $items - * @return $this + * @return void */ public function setItems(array $items); } diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index c3b308928117..0d9f91771228 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -124,7 +124,7 @@ private function getSourceDataArray(SourceInterface $source) SourceInterface::REGION_ID => $source->getRegionId(), SourceInterface::LATITUDE => $source->getLatitude(), SourceInterface::LONGITUDE => $source->getLongitude(), - SourceInterface::IS_ACTIVE => $source->getIsActive(), + SourceInterface::ENABLED => $source->isEnabled(), SourceInterface::PRIORITY => $source->getPriority(), SourceInterface::CARRIER_LINKS => [] ]; @@ -147,7 +147,7 @@ private function getSourceDataArray(SourceInterface $source) * @param string $postcode * @return SourceInterface */ - private function createRandomSource($countCarrier = 2, $postcode = '54321', $isActive = true) + private function createRandomSource($countCarrier = 2, $postcode = '54321', $enabled = true) { $country = $this->countryInformationAcquirer->getCountryInfo('US'); $regions = $country->getAvailableRegions(); @@ -169,30 +169,30 @@ private function createRandomSource($countCarrier = 2, $postcode = '54321', $isA for ($index = 1; $index <= $countCarrier; $index++) { $carrierCode = 'CAR-' . $index; $carrier = $this->sourceCarrierLinkFactory->create(); - $carrier->setPosition($index) - ->setCarrierCode($carrierCode); + $carrier->setPosition($index); + $carrier->setCarrierCode($carrierCode); $carriers[] = $carrier; } /** @var \Magento\InventoryApi\Api\Data\SourceInterface $source */ $source = $this->sourceFactory->create(); - $source->setName($name) - ->setCity($city) - ->setPostcode($postcode) - ->setContactName($contactName) - ->setCountryId($country->getId()) - ->setDescription($description) - ->setEmail($email) - ->setStreet($street) - ->setFax($fax) - ->setPhone($phone) - ->setRegion($region->getName()) - ->setRegionId($region->getId()) - ->setLatitude($latitude) - ->setLongitude($longitude) - ->setIsActive($isActive) - ->setPriority($priority) - ->setCarrierLinks($carriers); + $source->setName($name); + $source->setCity($city); + $source->setPostcode($postcode); + $source->setContactName($contactName); + $source->setCountryId($country->getId()); + $source->setDescription($description); + $source->setEmail($email); + $source->setStreet($street); + $source->setFax($fax); + $source->setPhone($phone); + $source->setRegion($region->getName()); + $source->setRegionId($region->getId()); + $source->setLatitude($latitude); + $source->setLongitude($longitude); + $source->setEnabled($enabled); + $source->setPriority($priority); + $source->setCarrierLinks($carriers); return $source; } @@ -317,7 +317,7 @@ public function testGetSourcesList() // add filters to find all active items with created postcode $postcodeFilter = implode(',', [$postcode1, $postcode2]); $searchCriteriaBuilder->addFilter('postcode', $postcodeFilter, 'in'); - $searchCriteriaBuilder->addFilter('is_active', 1, 'eq'); + $searchCriteriaBuilder->addFilter('enabled', 1, 'eq'); $searchData = $searchCriteriaBuilder->create()->__toArray(); $requestData = ['searchCriteria' => $searchData]; From f3849ccbcd1c18776d7f035e499749492799676e Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 6 Jun 2017 17:54:32 +0300 Subject: [PATCH 56/66] magento-engcom/magento2#25: Source API Implementation -- global refactoring --- .../Inventory/Model/ResourceModel/Source.php | 55 ++++++++- .../Model/ResourceModel/Source/Collection.php | 46 ++++++++ .../Model/SourceCarrierLinkManagement.php | 107 ++++++++++++++++++ .../SourceCarrierLinkManagementInterface.php | 34 ++++++ .../Inventory/Model/SourceRepository.php | 105 ++++------------- app/code/Magento/Inventory/etc/di.xml | 1 + .../InventoryApi/Api/Data/SourceInterface.php | 2 +- .../Api/SourceRepositoryInterface.php | 7 +- 8 files changed, 267 insertions(+), 90 deletions(-) create mode 100644 app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php create mode 100644 app/code/Magento/Inventory/Model/SourceCarrierLinkManagementInterface.php diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Source.php b/app/code/Magento/Inventory/Model/ResourceModel/Source.php index 44a65dc7fe21..abcfdd180a66 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source.php @@ -3,15 +3,38 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Inventory\Model\ResourceModel; +use Magento\Framework\Model\AbstractModel; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Model\ResourceModel\Db\Context; +use Magento\Inventory\Model\SourceCarrierLinkManagementInterface; use Magento\Inventory\Setup\InstallSchema; use Magento\InventoryApi\Api\Data\SourceInterface; class Source extends AbstractDb { + /** + * @var SourceCarrierLinkManagementInterface + */ + private $sourceCarrierLinkManagement; + + /** + * Source constructor + * + * @param Context $context + * @param SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement + * @param null $connectionName + */ + public function __construct( + Context $context, + SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement, + $connectionName = null + ) { + parent::__construct($context, $connectionName); + $this->sourceCarrierLinkManagement = $sourceCarrierLinkManagement; + } + /** * @inheritdoc */ @@ -19,4 +42,34 @@ protected function _construct() { $this->_init(InstallSchema::TABLE_NAME_SOURCE, SourceInterface::SOURCE_ID); } + + /** + * @inheritdoc + */ + public function load(AbstractModel $object, $value, $field = null) + { + parent::load($object, $value, $field); + /** @var SourceInterface $object */ + $this->sourceCarrierLinkManagement->loadCarrierLinksBySource($object); + return $this; + } + + /** + * @inheritdoc + */ + public function save(AbstractModel $object) + { + $connection = $this->getConnection(); + $connection->beginTransaction(); + try { + parent::save($object); + /** @var SourceInterface $object */ + $this->sourceCarrierLinkManagement->saveCarrierLinksBySource($object); + $connection->commit(); + } catch (\Exception $e) { + $connection->rollBack(); + throw $e; + } + return $this; + } } diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php b/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php index f36c5e5618bd..7e78a2d12cb8 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php @@ -8,9 +8,41 @@ use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Inventory\Model\Source as SourceModel; +use Magento\Inventory\Model\SourceCarrierLinkManagementInterface; +use Magento\InventoryApi\Api\Data\SourceInterface; class Collection extends AbstractCollection { + /** + * @var SourceCarrierLinkManagementInterface + */ + private $sourceCarrierLinkManagement; + + /** + * Collection constructor + * + * @param SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement + */ + public function __construct( + \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, + \Psr\Log\LoggerInterface $logger, + \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, + \Magento\Framework\Event\ManagerInterface $eventManager, + SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement, + \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, + \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null + ) { + parent::__construct( + $entityFactory, + $logger, + $fetchStrategy, + $eventManager, + $connection, + $resource + ); + $this->sourceCarrierLinkManagement = $sourceCarrierLinkManagement; + } + /** * @inheritdoc */ @@ -18,4 +50,18 @@ protected function _construct() { $this->_init(SourceModel::class, ResourceSource::class); } + + /** + * @inheritdoc + */ + public function load($printQuery = false, $logQuery = false) + { + parent::load($printQuery, $logQuery); + + foreach ($this->_items as $item) { + /** @var SourceInterface $item */ + $this->sourceCarrierLinkManagement->loadCarrierLinksBySource($item); + } + return $this; + } } diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php new file mode 100644 index 000000000000..a8970720cc3f --- /dev/null +++ b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php @@ -0,0 +1,107 @@ +connection = $connection; + $this->resourceSourceCarrierLink = $resourceSourceCarrierLink; + $this->collectionProcessor = $collectionProcessor; + $this->carrierLinkCollectionFactory = $carrierLinkCollectionFactory; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * @inheritdoc + */ + public function saveCarrierLinksBySource(SourceInterface $source) + { + if ($source->getCarrierLinks() !== null) { + $connection = $this->connection->getConnection(); + $connection->delete( + $connection->getTableName(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK), + $connection->quoteInto('source_id = ?', $source->getSourceId()) + ); + + /** @var SourceCarrierLinkInterface|AbstractModel $carrierLink */ + foreach ($source->getCarrierLinks() as $carrierLink) { + $carrierLink->setData(SourceInterface::SOURCE_ID, $source->getSourceId()); + $this->resourceSourceCarrierLink->save($carrierLink); + } + } + } + + /** + * @inheritdoc + */ + public function loadCarrierLinksBySource(SourceInterface $source) + { + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(SourceInterface::SOURCE_ID, $source->getSourceId()) + ->create(); + + /** @var ResourceSourceCarrierLink\Collection $collection */ + $collection = $this->carrierLinkCollectionFactory->create(); + $this->collectionProcessor->process($searchCriteria, $collection); + + $source->setCarrierLinks($collection->getItems()); + } +} diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagementInterface.php b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagementInterface.php new file mode 100644 index 000000000000..9fbcd8dfa0a8 --- /dev/null +++ b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagementInterface.php @@ -0,0 +1,34 @@ +resourceSource = $resourceSource; - $this->resourceSourceCarrierLink = $resourceSourceCarrierLink; $this->sourceFactory = $sourceFactory; $this->collectionProcessor = $collectionProcessor; - $this->collectionFactory = $collectionFactory; - $this->carrierLinkCollectionFactory = $carrierLinkCollectionFactory; + $this->sourceCollectionFactory = $sourceCollectionFactory; $this->sourceSearchResultsFactory = $sourceSearchResultsFactory; $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->logger = $logger; @@ -117,26 +96,12 @@ public function __construct( public function save(SourceInterface $source) { try { - /** @var SourceInterface $source */ + /** @var SourceInterface|AbstractModel $source */ $this->resourceSource->save($source); - - if ($source->getCarrierLinks() === null) { - return $source->getSourceId(); - } - - // clean up for the old carrier links - $this->resourceSourceCarrierLink->deleteBySource($source); - - /** @var SourceCarrierLinkInterface $carrierLink */ - foreach ($source->getCarrierLinks() as $carrierLink) { - $carrierLink->setData(SourceInterface::SOURCE_ID, $source->getSourceId()); - $this->resourceSourceCarrierLink->save($carrierLink); - } - return $source->getSourceId(); } catch (\Exception $exception) { $this->logger->error($exception->getMessage()); - throw new CouldNotSaveException(__('Could not save source')); + throw new CouldNotSaveException(__('Could not save source'), $exception); } } @@ -149,61 +114,31 @@ public function get($sourceId) $source = $this->sourceFactory->create(); $this->resourceSource->load($source, $sourceId, SourceInterface::SOURCE_ID); - $carrierLinks = $this->loadCarrierLinksBySource($source); - $source->setCarrierLinks($carrierLinks); - if (!$source->getSourceId()) { throw NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId); } - return $source; } - /** - * Loads the carrier links by given source. - * - * @param SourceInterface $source - * - * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface[] - */ - private function loadCarrierLinksBySource(SourceInterface $source) - { - /** @var ResourceSourceCarrierLink\Collection $collection */ - $collection = $this->carrierLinkCollectionFactory->create(); - - $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(SourceInterface::SOURCE_ID, $source->getSourceId()) - ->create(); - - $this->collectionProcessor->process($searchCriteria, $collection); - return $collection->getItems(); - } - /** * @inheritdoc */ public function getList(SearchCriteriaInterface $searchCriteria = null) { - /** @var \Magento\Inventory\Model\ResourceModel\Source\Collection $collection */ - $collection = $this->collectionFactory->create(); + /** @var SourceCollection $collection */ + $collection = $this->sourceCollectionFactory->create(); - /** @var SourceSearchResultsInterface $searchResults */ - $searchResults = $this->sourceSearchResultsFactory->create(); - - // if there is a searchCriteria defined, use it to add its creterias to the collection - if (!is_null($searchCriteria)) { + if (null === $searchCriteria) { + $searchCriteria = $this->searchCriteriaBuilder->create(); + } else { $this->collectionProcessor->process($searchCriteria, $collection); - $searchResults->setSearchCriteria($searchCriteria); - } - - /** @var \Magento\InventoryApi\Api\Data\SourceInterface[] $sourceItems */ - $sourceItems = $collection->getItems(); - foreach ($sourceItems as $sourceItem) { - $sourceItem->setCarrierLinks($this->loadCarrierLinksBySource($sourceItem)); } - $searchResults->setItems($sourceItems); - $searchResults->setTotalCount($collection->getSize()); - return $searchResults; + /** @var SourceSearchResultsInterface $searchResult */ + $searchResult = $this->sourceSearchResultsFactory->create(); + $searchResult->setItems($collection->getItems()); + $searchResult->setTotalCount($collection->getSize()); + $searchResult->setSearchCriteria($searchCriteria); + return $searchResult; } } diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml index 83f969554a86..3c6091ff5561 100644 --- a/app/code/Magento/Inventory/etc/di.xml +++ b/app/code/Magento/Inventory/etc/di.xml @@ -10,4 +10,5 @@ + diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index e39f2808dbd1..a391977d0fe7 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -304,7 +304,7 @@ public function setCarrierLinks($carrierLinks); /** * Retrieve existing extension attributes object. * - * @return \Magento\InventoryApi\Api\Data\SourceExtensionInterface + * @return \Magento\InventoryApi\Api\Data\SourceExtensionInterface|null */ public function getExtensionAttributes(); diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index 5df65d06cb46..3c065576730e 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -11,7 +11,8 @@ interface SourceRepositoryInterface { /** - * Save Source data. + * Save Source data. If you want to create plugin on get method, also you need to create separate plugin + * on getList method, because entity loading way is different for these methods * * @param \Magento\InventoryApi\Api\Data\SourceInterface $source * @return int @@ -23,7 +24,7 @@ interface SourceRepositoryInterface public function save(\Magento\InventoryApi\Api\Data\SourceInterface $source); /** - * Load Source data by given sourceId. + * Get Source data by given sourceId. * * @param int $sourceId * @return \Magento\InventoryApi\Api\Data\SourceInterface @@ -32,7 +33,7 @@ public function save(\Magento\InventoryApi\Api\Data\SourceInterface $source); public function get($sourceId); /** - * Load Source data collection by given search criteria + * Load Source data collection by given search criteria. * * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface From ee0201ae3b939d046b7e7fbbbc59fe4da0e329ea Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 6 Jun 2017 19:17:41 +0300 Subject: [PATCH 57/66] magento-engcom/magento2#25: Source API Implementation -- global refactoring -- fix unit tests --- .../Test/Unit/Model/SourceRepositoryTest.php | 266 +++++++++++------- 1 file changed, 157 insertions(+), 109 deletions(-) diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 58e294cb78d8..6dd646ca9327 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -3,9 +3,9 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Inventory\Test\Unit\Model; +use Magento\Framework\Api\SearchCriteriaInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterfaceFactory; @@ -14,12 +14,8 @@ use Magento\Inventory\Model\ResourceModel\Source as SourceResource; use Magento\Inventory\Model\ResourceModel\Source\CollectionFactory as SourceCollectionFactory; use Magento\Inventory\Model\ResourceModel\Source\Collection as SourceCollection; -use Magento\Inventory\Model\SourceCarrierLink; -use Magento\Inventory\Model\ResourceModel\SourceCarrierLink as ResourceSourceCarrierLink; -use Magento\Inventory\Model\ResourceModel\SourceCarrierLink\CollectionFactory as CarrierLinkCollectionFactory; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Api\SearchCriteriaBuilder; -use Magento\Inventory\Model\ResourceModel\SourceCarrierLink\Collection as CarrierLinkCollection; /** * Class SourceRepositoryTest @@ -29,12 +25,7 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase /** * @var SourceResource|\PHPUnit_Framework_MockObject_MockObject */ - private $sourceResource; - - /** - * @var ResourceSourceCarrierLink|\PHPUnit_Framework_MockObject_MockObject - */ - private $carrierLinkResource; + private $resourceSource; /** * @var SourceInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject @@ -49,18 +40,13 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase /** * @var SourceCollectionFactory|\PHPUnit_Framework_MockObject_MockObject */ - private $collectionFactory; + private $sourceCollectionFactory; /** * @var SourceSearchResultsInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ private $sourceSearchResultsFactory; - /** - * @var CarrierLinkCollectionFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $carrierLinkCollectionFactory; - /** * @var SearchCriteriaBuilder|\PHPUnit_Framework_MockObject_MockObject */ @@ -71,6 +57,11 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase */ private $loggerMock; + /** + * @var Source|\PHPUnit_Framework_MockObject_MockObject + */ + private $source; + /** * @var \Magento\Inventory\Model\SourceRepository */ @@ -78,14 +69,7 @@ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->sourceResource = $this->getMockBuilder(SourceResource::class)->disableOriginalConstructor()->getMock(); - $this->carrierLinkResource = $this->getMockBuilder(ResourceSourceCarrierLink::class) - ->disableOriginalConstructor() - ->getMock(); - $this->carrierLinkCollectionFactory = $this->getMockBuilder(CarrierLinkCollectionFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); + $this->resourceSource = $this->getMockBuilder(SourceResource::class)->disableOriginalConstructor()->getMock(); $this->searchCriteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class) ->disableOriginalConstructor() ->getMock(); @@ -97,7 +81,7 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods(['process']) ->getMock(); - $this->collectionFactory = $this->getMockBuilder(SourceCollectionFactory::class) + $this->sourceCollectionFactory = $this->getMockBuilder(SourceCollectionFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); @@ -108,17 +92,18 @@ protected function setUp() $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); + $this->source = $this->getMockBuilder(Source::class) + ->disableOriginalConstructor() + ->getMock(); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject( \Magento\Inventory\Model\SourceRepository::class, [ - 'resourceSource' => $this->sourceResource, - 'resourceSourceCarrierLink' => $this->carrierLinkResource, + 'resourceSource' => $this->resourceSource, 'sourceFactory' => $this->sourceFactory, 'collectionProcessor' => $this->collectionProcessor, - 'collectionFactory' => $this->collectionFactory, - 'carrierLinkCollectionFactory' => $this->carrierLinkCollectionFactory, + 'sourceCollectionFactory' => $this->sourceCollectionFactory, 'sourceSearchResultsFactory' => $this->sourceSearchResultsFactory, 'searchCriteriaBuilder' => $this->searchCriteriaBuilder, 'logger' => $this->loggerMock, @@ -126,24 +111,20 @@ protected function setUp() ); } - public function testSaveSuccessful() + public function testSave() { $sourceId = 42; - /** @var \Magento\Inventory\Model\Source|\PHPUnit_Framework_MockObject_MockObject $sourceMock */ - $sourceMock = $this->getMockBuilder(\Magento\Inventory\Model\Source::class) - ->disableOriginalConstructor() - ->getMock(); - $carrierLinkMock = $this->getMockBuilder(SourceCarrierLink::class) - ->disableOriginalConstructor() - ->getMock(); - $sourceMock->expects($this->atLeastOnce())->method('getSourceId')->willReturn($sourceId); - $sourceMock->expects($this->atLeastOnce())->method('getCarrierLinks')->willReturn([$carrierLinkMock]); - - $this->sourceResource->expects($this->once())->method('save')->with($sourceMock); - $this->carrierLinkResource->expects($this->once())->method('save')->with($carrierLinkMock); + $this->source + ->expects($this->once()) + ->method('getSourceId') + ->willReturn($sourceId); + $this->resourceSource + ->expects($this->once()) + ->method('save') + ->with($this->source); - $this->assertEquals($sourceId, $this->model->save($sourceMock)); + self::assertEquals($sourceId, $this->model->save($this->source)); } /** @@ -151,51 +132,42 @@ public function testSaveSuccessful() */ public function testSaveErrorExpectsException() { - /** @var Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(); - $this->sourceResource->expects($this->atLeastOnce())->method('save'); - $this->sourceResource->expects($this->atLeastOnce()) + $message = 'some message'; + + $this->resourceSource + ->expects($this->once()) ->method('save') - ->will($this->throwException(new \Exception('Some unit test Exception'))); + ->willThrowException(new \Exception($message)); + + $this->loggerMock + ->expects($this->once()) + ->method('error') + ->with($message); - $this->model->save($sourceModel); + $this->model->save($this->source); } - public function testGetSuccessful() + public function testGet() { $sourceId = 345; - /** @var Source|\PHPUnit_Framework_MockObject_MockObject $sourceMock */ - $sourceMock = $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(); - $searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteria::class) - ->disableOriginalConstructor() - ->getMock(); - $carrierLinkCollectionMock = $this->getMockBuilder( - \Magento\Inventory\Model\ResourceModel\SourceCarrierLink\Collection::class - )->disableOriginalConstructor()->getMock(); - - $this->carrierLinkCollectionFactory->expects($this->atLeastOnce())->method('create') - ->willReturn($carrierLinkCollectionMock); - $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('addFilter')->willReturnSelf(); - $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('create')->willReturn($searchCriteriaMock); - - $carrierLinkCollectionMock->expects($this->atLeastOnce())->method('getItems')->willReturn([]); - $sourceMock->expects($this->atLeastOnce())->method('setCarrierLinks')->with([]); - - $sourceMock->expects($this->atLeastOnce()) + $this->source + ->expects($this->once()) ->method('getSourceId') - ->will($this->returnValue($sourceId)); - $this->sourceFactory->expects($this->once())->method('create')->willReturn($sourceMock); - $this->sourceResource->expects($this->once()) + ->willReturn($sourceId); + $this->sourceFactory + ->expects($this->once()) + ->method('create') + ->willReturn($this->source); + $this->resourceSource->expects($this->once()) ->method('load') ->with( - $sourceMock, + $this->source, $sourceId, SourceInterface::SOURCE_ID ); - - $this->assertSame($sourceMock, $this->model->get($sourceId)); + self::assertSame($this->source, $this->model->get($sourceId)); } /** @@ -205,26 +177,18 @@ public function testGetErrorExpectsException() { $sourceId = 345; - /** @var Source|\PHPUnit_Framework_MockObject_MockObject $sourceModel */ - $sourceModel = $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(); - $searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteria::class) - ->disableOriginalConstructor() - ->getMock(); - $carrierLinkCollectionMock = $this->getMockBuilder( - \Magento\Inventory\Model\ResourceModel\SourceCarrierLink\Collection::class - )->disableOriginalConstructor()->getMock(); - - $this->carrierLinkCollectionFactory->expects($this->atLeastOnce())->method('create') - ->willReturn($carrierLinkCollectionMock); - $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('addFilter')->willReturnSelf(); - $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('create')->willReturn($searchCriteriaMock); - - $sourceModel->expects($this->atLeastOnce())->method('getSourceId')->willReturn(null); - $this->sourceFactory->expects($this->once())->method('create')->willReturn($sourceModel); - $this->sourceResource->expects($this->once()) + $this->source + ->expects($this->once()) + ->method('getSourceId') + ->willReturn(null); + $this->sourceFactory + ->expects($this->once()) + ->method('create') + ->willReturn($this->source); + $this->resourceSource->expects($this->once()) ->method('load') ->with( - $sourceModel, + $this->source, $sourceId, SourceInterface::SOURCE_ID ); @@ -232,33 +196,117 @@ public function testGetErrorExpectsException() $this->model->get($sourceId); } - public function testGetList() + public function testGetListWithSearchCriteria() { - $sourceCollection = $this->getMockBuilder(SourceCollection::class)->disableOriginalConstructor()->getMock(); - $searchResults = $this->getMockBuilder(SourceSearchResultsInterface::class) + $items = [ + $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(), + $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock() + ]; + $totalCount = 2; + $searchCriteria = $this->getMockBuilder(SearchCriteriaInterface::class) ->disableOriginalConstructor() ->getMock(); - $searchCriteria = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteriaInterface::class) + + $sourceCollection = $this->getMockBuilder(SourceCollection::class) ->disableOriginalConstructor() ->getMock(); - $sources = [ + $sourceCollection + ->expects($this->once()) + ->method('getItems') + ->willReturn($items); + $sourceCollection + ->expects($this->once()) + ->method('getSize') + ->willReturn($totalCount); + $this->sourceCollectionFactory + ->expects($this->once()) + ->method('create') + ->willReturn($sourceCollection); + + $searchResults = $this->getMockBuilder(SourceSearchResultsInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $searchResults + ->expects($this->once()) + ->method('setItems') + ->with($items); + $searchResults + ->expects($this->once()) + ->method('setTotalCount') + ->with($totalCount); + $searchResults + ->expects($this->once()) + ->method('setSearchCriteria') + ->with($searchCriteria); + $this->sourceSearchResultsFactory + ->expects($this->once()) + ->method('create') + ->willReturn($searchResults); + + $this->collectionProcessor + ->expects($this->once()) + ->method('process') + ->with($searchCriteria, $sourceCollection); + + self::assertSame($searchResults, $this->model->getList($searchCriteria)); + } + + public function testGetListWithoutSearchCriteria() + { + $items = [ $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock(), $this->getMockBuilder(Source::class)->disableOriginalConstructor()->getMock() ]; - $carrierLinkCollectionMock = $this->getMockBuilder(CarrierLinkCollection::class) + $totalCount = 2; + + $searchCriteria = $this->getMockBuilder(SearchCriteriaInterface::class) ->disableOriginalConstructor() ->getMock(); + $this->searchCriteriaBuilder + ->expects($this->once()) + ->method('create') + ->willReturn($searchCriteria); - $this->collectionFactory->expects($this->once())->method('create')->willReturn($sourceCollection); - $sourceCollection->expects($this->atLeastOnce())->method('getItems')->willReturn($sources); - $this->sourceSearchResultsFactory->expects($this->once())->method('create')->willReturn($searchResults); - $searchResults->expects($this->once())->method('setItems')->with($sources); - - $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('addFilter')->willReturnSelf(); - $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('create')->willReturn($searchCriteria); - $this->carrierLinkCollectionFactory->expects($this->atLeastOnce())->method('create') - ->willReturn($carrierLinkCollectionMock); + $sourceCollection = $this->getMockBuilder(SourceCollection::class) + ->disableOriginalConstructor() + ->getMock(); + $sourceCollection + ->expects($this->once()) + ->method('getItems') + ->willReturn($items); + $sourceCollection + ->expects($this->once()) + ->method('getSize') + ->willReturn($totalCount); + $this->sourceCollectionFactory + ->expects($this->once()) + ->method('create') + ->willReturn($sourceCollection); - $this->assertSame($searchResults, $this->model->getList($searchCriteria)); + $searchResults = $this->getMockBuilder(SourceSearchResultsInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $searchResults + ->expects($this->once()) + ->method('setItems') + ->with($items); + $searchResults + ->expects($this->once()) + ->method('setTotalCount') + ->with($totalCount); + $searchResults + ->expects($this->once()) + ->method('setSearchCriteria') + ->with($searchCriteria); + $this->sourceSearchResultsFactory + ->expects($this->once()) + ->method('create') + ->willReturn($searchResults); + + $this->collectionProcessor + ->expects($this->never()) + ->method('process'); + + self::assertSame($searchResults, $this->model->getList()); } } From 8a9de28483c2288b5a3c4b182fb3ddc5be7ab496 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 7 Jun 2017 11:16:50 +0300 Subject: [PATCH 58/66] magento-engcom/magento2#25: Source API Implementation -- fix static tests --- .../Model/ResourceModel/Source/Collection.php | 21 +++-- .../Magento/Inventory/Setup/InstallSchema.php | 77 ++++++++++++------- 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php b/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php index 7e78a2d12cb8..533b6fe7647c 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source/Collection.php @@ -5,11 +5,16 @@ */ namespace Magento\Inventory\Model\ResourceModel\Source; +use Magento\Framework\Data\Collection\EntityFactoryInterface; +use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Inventory\Model\Source as SourceModel; use Magento\Inventory\Model\SourceCarrierLinkManagementInterface; use Magento\InventoryApi\Api\Data\SourceInterface; +use Psr\Log\LoggerInterface; class Collection extends AbstractCollection { @@ -21,16 +26,22 @@ class Collection extends AbstractCollection /** * Collection constructor * + * @param EntityFactoryInterface $entityFactory + * @param LoggerInterface $logger + * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy + * @param ManagerInterface $eventManager * @param SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement + * @param AdapterInterface $connection + * @param AbstractDb $resource */ public function __construct( - \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, - \Psr\Log\LoggerInterface $logger, + EntityFactoryInterface $entityFactory, + LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, - \Magento\Framework\Event\ManagerInterface $eventManager, + ManagerInterface $eventManager, SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement, - \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, - \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null + AdapterInterface $connection = null, + AbstractDb $resource = null ) { parent::__construct( $entityFactory, diff --git a/app/code/Magento/Inventory/Setup/InstallSchema.php b/app/code/Magento/Inventory/Setup/InstallSchema.php index 644632b9e7b0..0f1859715ccf 100644 --- a/app/code/Magento/Inventory/Setup/InstallSchema.php +++ b/app/code/Magento/Inventory/Setup/InstallSchema.php @@ -54,7 +54,12 @@ class InstallSchema implements InstallSchemaInterface public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); - $setup->getConnection()->createTable($this->createSourceTable($setup)); + + $sourceTable = $this->createSourceTable($setup); + $sourceTable = $this->addAddressFields($sourceTable); + $sourceTable = $this->addContactInfoFields($sourceTable); + $setup->getConnection()->createTable($sourceTable); + $setup->getConnection()->createTable($this->createSourceCarrierLinkTable($setup)); $setup->endSetup(); } @@ -90,22 +95,6 @@ private function createSourceTable(SchemaSetupInterface $setup) InstallSchema::OPTION_NULLABLE => false, ], 'Source Name' - )->addColumn( - SourceInterface::CONTACT_NAME, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => true, - ], - 'Contact Name' - )->addColumn( - SourceInterface::EMAIL, - Table::TYPE_TEXT, - 255, - [ - InstallSchema::OPTION_NULLABLE => true, - ], - 'Email' )->addColumn( SourceInterface::ENABLED, Table::TYPE_SMALLINT, @@ -147,6 +136,24 @@ private function createSourceTable(SchemaSetupInterface $setup) ], 'Longitude' )->addColumn( + SourceInterface::PRIORITY, + Table::TYPE_SMALLINT, + null, + [ + InstallSchema::OPTION_NULLABLE => true, + InstallSchema::OPTION_UNSIGNED => true, + ], + 'Priority' + ); + } + + /** + * @param Table $sourceTable + * @return Table + */ + private function addAddressFields(Table $sourceTable) + { + $sourceTable->addColumn( SourceInterface::COUNTRY_ID, Table::TYPE_TEXT, 2, @@ -195,32 +202,50 @@ private function createSourceTable(SchemaSetupInterface $setup) InstallSchema::OPTION_NULLABLE => false, ], 'Postcode' + ); + return $sourceTable; + } + + /** + * @param Table $sourceTable + * @return Table + */ + private function addContactInfoFields(Table $sourceTable) + { + $sourceTable->addColumn( + SourceInterface::CONTACT_NAME, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => true, + ], + 'Contact Name' )->addColumn( - SourceInterface::PHONE, + SourceInterface::EMAIL, Table::TYPE_TEXT, 255, [ InstallSchema::OPTION_NULLABLE => true, ], - 'Phone' + 'Email' )->addColumn( - SourceInterface::FAX, + SourceInterface::PHONE, Table::TYPE_TEXT, 255, [ InstallSchema::OPTION_NULLABLE => true, ], - 'Fax' + 'Phone' )->addColumn( - SourceInterface::PRIORITY, - Table::TYPE_SMALLINT, - null, + SourceInterface::FAX, + Table::TYPE_TEXT, + 255, [ InstallSchema::OPTION_NULLABLE => true, - InstallSchema::OPTION_UNSIGNED => true, ], - 'Priority' + 'Fax' ); + return $sourceTable; } /** From 73877d2ef9a5f357145570d49fc5a0f67b8174f5 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 7 Jun 2017 11:17:47 +0300 Subject: [PATCH 59/66] magento-engcom/magento2#25: Source API Implementation -- fix static tests -- fix soap tests --- .../InventoryApi/Api/Data/SourceCarrierLinkInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 63c8308411e0..9d0fb91a8d9d 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -53,7 +53,7 @@ public function setPosition($position); /** * Retrieve existing extension attributes object or create a new one. * - * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkExtensionInterface + * @return \Magento\InventoryApi\Api\Data\SourceCarrierLinkExtensionInterface|null */ public function getExtensionAttributes(); From a0df2b980715a37547ec96116911d336736742f2 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 7 Jun 2017 11:39:00 +0300 Subject: [PATCH 60/66] magento-engcom/magento2#25: Source API Implementation -- fix static tests --- app/code/Magento/Inventory/Setup/InstallSchema.php | 3 ++- .../Test/Unit/Model/SourceRepositoryTest.php | 11 ++++------- .../Magento/InventoryApi/Api/SourceRepositoryTest.php | 9 ++++----- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Inventory/Setup/InstallSchema.php b/app/code/Magento/Inventory/Setup/InstallSchema.php index 0f1859715ccf..fbe20664a851 100644 --- a/app/code/Magento/Inventory/Setup/InstallSchema.php +++ b/app/code/Magento/Inventory/Setup/InstallSchema.php @@ -283,7 +283,8 @@ private function createSourceCarrierLinkTable(SchemaSetupInterface $setup) 'Source ID' )->addColumn( SourceCarrierLinkInterface::CARRIER_CODE, - Table::TYPE_TEXT, 255, + Table::TYPE_TEXT, + 255, [ InstallSchema::OPTION_NULLABLE => false, ], diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 6dd646ca9327..291b7ca2e607 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -18,7 +18,7 @@ use Magento\Framework\Api\SearchCriteriaBuilder; /** - * Class SourceRepositoryTest + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class SourceRepositoryTest extends \PHPUnit_Framework_TestCase { @@ -159,13 +159,10 @@ public function testGet() ->expects($this->once()) ->method('create') ->willReturn($this->source); - $this->resourceSource->expects($this->once()) + $this->resourceSource + ->expects($this->once()) ->method('load') - ->with( - $this->source, - $sourceId, - SourceInterface::SOURCE_ID - ); + ->with($this->source, $sourceId, SourceInterface::SOURCE_ID); self::assertSame($this->source, $this->model->get($sourceId)); } diff --git a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php index 0d9f91771228..7da8904c3091 100644 --- a/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/InventoryApi/Api/SourceRepositoryTest.php @@ -151,7 +151,7 @@ private function createRandomSource($countCarrier = 2, $postcode = '54321', $ena { $country = $this->countryInformationAcquirer->getCountryInfo('US'); $regions = $country->getAvailableRegions(); - $region = $regions[mt_rand(0, count($regions)-1)]; + $region = $regions[mt_rand(0, count($regions) - 1)]; $name = uniqid(self::TEST_PREFIX, false); $description = 'This is an inventory source created by api-functional tests'; @@ -163,7 +163,7 @@ private function createRandomSource($countCarrier = 2, $postcode = '54321', $ena $phone = '01660002020044'; $latitude = 51.343479; $longitude = 12.387772; - $priority = mt_rand(1,999); + $priority = mt_rand(1, 999); $carriers = []; for ($index = 1; $index <= $countCarrier; $index++) { @@ -293,8 +293,6 @@ public function testGetSource() */ public function testGetSourcesList() { - //$this->markTestSkipped('WIP: Search seems to ignore filter criterias!'); - /** @var SearchCriteriaBuilder $searchCriteriaBuilder */ $searchCriteriaBuilder = Bootstrap::getObjectManager() ->create(SearchCriteriaBuilder::class); @@ -337,7 +335,8 @@ public function testGetSourcesList() $searchResult = $this->_webApiCall($serviceInfo, $requestData); $this->assertEquals(3, count($searchResult['items'])); - $this->assertEquals($searchResult['items'][0][SourceInterface::SOURCE_ID], + $this->assertEquals( + $searchResult['items'][0][SourceInterface::SOURCE_ID], $source1->getSourceId() ); $this->assertEquals( From 2eb0a778eff4870eabb09e03cd5656e04d053485 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 7 Jun 2017 12:50:02 +0300 Subject: [PATCH 61/66] magento-engcom/magento2#25: Source API Implementation -- global refactoring --- .../Model/SourceCarrierLinkManagement.php | 56 +++++++++++++++---- .../SourceCarrierLinkManagementInterface.php | 2 + .../Inventory/Model/SourceRepository.php | 10 +++- .../Api/SourceRepositoryInterface.php | 1 - 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php index a8970720cc3f..5635df07340c 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php @@ -8,6 +8,7 @@ use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\App\ResourceConnection; +use Magento\Framework\Exception\StateException; use Magento\Framework\Model\AbstractModel; use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; use Magento\Inventory\Model\ResourceModel\SourceCarrierLink as ResourceSourceCarrierLink; @@ -74,21 +75,54 @@ public function __construct( */ public function saveCarrierLinksBySource(SourceInterface $source) { - if ($source->getCarrierLinks() !== null) { - $connection = $this->connection->getConnection(); - $connection->delete( - $connection->getTableName(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK), - $connection->quoteInto('source_id = ?', $source->getSourceId()) - ); - - /** @var SourceCarrierLinkInterface|AbstractModel $carrierLink */ - foreach ($source->getCarrierLinks() as $carrierLink) { - $carrierLink->setData(SourceInterface::SOURCE_ID, $source->getSourceId()); - $this->resourceSourceCarrierLink->save($carrierLink); + if (is_array($source->getCarrierLinks())) { + try { + $this->deleteCurrentCarrierLinks($source); + if (!empty($source->getCarrierLinks())) { + $this->saveNewCarrierLinks($source); + } + } catch (\Exception $e) { + throw new StateException(__('Could not update Carrier Links'), $e); } } } + /** + * @param SourceInterface $source + * @return void + */ + private function deleteCurrentCarrierLinks(SourceInterface $source) + { + $connection = $this->connection->getConnection(); + $connection->delete( + $connection->getTableName(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK), + $connection->quoteInto('source_id = ?', $source->getSourceId()) + ); + } + + /** + * @param SourceInterface $source + * @return void + */ + private function saveNewCarrierLinks(SourceInterface $source) + { + $carrierLinkData = []; + /** @var SourceCarrierLinkInterface|AbstractModel $carrierLink */ + foreach ($source->getCarrierLinks() as $carrierLink) { + $carrierLinkData[] = [ + 'source_id' => $source->getSourceId(), + SourceCarrierLinkInterface::CARRIER_CODE => $carrierLink->getCarrierCode(), + SourceCarrierLinkInterface::POSITION => $carrierLink->getPosition(), + ]; + } + + $connection = $this->connection->getConnection(); + $connection->insertMultiple( + $connection->getTableName(InstallSchema::TABLE_NAME_SOURCE_CARRIER_LINK), + $carrierLinkData + ); + } + /** * @inheritdoc */ diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagementInterface.php b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagementInterface.php index 9fbcd8dfa0a8..3f5ae25d3d68 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagementInterface.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagementInterface.php @@ -5,6 +5,7 @@ */ namespace Magento\Inventory\Model; +use Magento\Framework\Exception\StateException; use Magento\InventoryApi\Api\Data\SourceInterface; /** @@ -21,6 +22,7 @@ interface SourceCarrierLinkManagementInterface * * @param SourceInterface $source * @return void + * @throws StateException */ public function saveCarrierLinksBySource(SourceInterface $source); diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 014baca7ed04..da4aa5feafc9 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -10,6 +10,7 @@ use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Exception\StateException; use Magento\Framework\Model\AbstractModel; use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; use Magento\Inventory\Model\ResourceModel\Source\Collection as SourceCollection; @@ -99,9 +100,12 @@ public function save(SourceInterface $source) /** @var SourceInterface|AbstractModel $source */ $this->resourceSource->save($source); return $source->getSourceId(); - } catch (\Exception $exception) { - $this->logger->error($exception->getMessage()); - throw new CouldNotSaveException(__('Could not save source'), $exception); + } catch (StateException $e) { + $this->logger->error($e->getPrevious()->getMessage()); + throw $e; + } catch (\Exception $e) { + $this->logger->error($e->getMessage()); + throw new CouldNotSaveException(__('Could not save source'), $e); } } diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index 3c065576730e..dc11198fec78 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -17,7 +17,6 @@ interface SourceRepositoryInterface * @param \Magento\InventoryApi\Api\Data\SourceInterface $source * @return int * - * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\StateException * @throws \Magento\Framework\Exception\CouldNotSaveException */ From 2e2f443726a13307015bfaebd6fe524b18a645b6 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 7 Jun 2017 13:29:20 +0300 Subject: [PATCH 62/66] magento-engcom/magento2#25: Source API Implementation -- global refactoring --- app/code/Magento/Inventory/Model/SourceRepository.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index da4aa5feafc9..26c1276431a2 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -13,7 +13,6 @@ use Magento\Framework\Exception\StateException; use Magento\Framework\Model\AbstractModel; use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; -use Magento\Inventory\Model\ResourceModel\Source\Collection as SourceCollection; use Magento\Inventory\Model\ResourceModel\Source\CollectionFactory; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; @@ -129,7 +128,6 @@ public function get($sourceId) */ public function getList(SearchCriteriaInterface $searchCriteria = null) { - /** @var SourceCollection $collection */ $collection = $this->sourceCollectionFactory->create(); if (null === $searchCriteria) { From 7860aed0249ae482e0d10464c0278d2c23906ffe Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 7 Jun 2017 13:30:23 +0300 Subject: [PATCH 63/66] magento-engcom/magento2#25: Source API Implementation -- global refactoring --- app/code/Magento/Inventory/Model/SourceRepository.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 26c1276431a2..da4aa5feafc9 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -13,6 +13,7 @@ use Magento\Framework\Exception\StateException; use Magento\Framework\Model\AbstractModel; use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; +use Magento\Inventory\Model\ResourceModel\Source\Collection as SourceCollection; use Magento\Inventory\Model\ResourceModel\Source\CollectionFactory; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; @@ -128,6 +129,7 @@ public function get($sourceId) */ public function getList(SearchCriteriaInterface $searchCriteria = null) { + /** @var SourceCollection $collection */ $collection = $this->sourceCollectionFactory->create(); if (null === $searchCriteria) { From 82ce7efaf913168739139076ef8416f827fc503a Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 7 Jun 2017 15:30:43 +0300 Subject: [PATCH 64/66] magento-engcom/magento2#25: Source API Implementation -- fix static tests --- app/code/Magento/Inventory/Model/SourceRepository.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index da4aa5feafc9..b435b07019bb 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -11,7 +11,6 @@ use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\StateException; -use Magento\Framework\Model\AbstractModel; use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; use Magento\Inventory\Model\ResourceModel\Source\Collection as SourceCollection; use Magento\Inventory\Model\ResourceModel\Source\CollectionFactory; @@ -97,7 +96,7 @@ public function __construct( public function save(SourceInterface $source) { try { - /** @var SourceInterface|AbstractModel $source */ + /** @var SourceInterface $source */ $this->resourceSource->save($source); return $source->getSourceId(); } catch (StateException $e) { @@ -114,7 +113,7 @@ public function save(SourceInterface $source) */ public function get($sourceId) { - /** @var SourceInterface|AbstractModel $source */ + /** @var SourceInterface $source */ $source = $this->sourceFactory->create(); $this->resourceSource->load($source, $sourceId, SourceInterface::SOURCE_ID); From 759c935d82109392b91da409a1a316e5ae1ca0ea Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 7 Jun 2017 15:40:54 +0300 Subject: [PATCH 65/66] magento-engcom/magento2#25: Source API Implementation -- fix static tests --- app/code/Magento/Inventory/Model/SourceRepository.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index b435b07019bb..da4aa5feafc9 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -11,6 +11,7 @@ use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\StateException; +use Magento\Framework\Model\AbstractModel; use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; use Magento\Inventory\Model\ResourceModel\Source\Collection as SourceCollection; use Magento\Inventory\Model\ResourceModel\Source\CollectionFactory; @@ -96,7 +97,7 @@ public function __construct( public function save(SourceInterface $source) { try { - /** @var SourceInterface $source */ + /** @var SourceInterface|AbstractModel $source */ $this->resourceSource->save($source); return $source->getSourceId(); } catch (StateException $e) { @@ -113,7 +114,7 @@ public function save(SourceInterface $source) */ public function get($sourceId) { - /** @var SourceInterface $source */ + /** @var SourceInterface|AbstractModel $source */ $source = $this->sourceFactory->create(); $this->resourceSource->load($source, $sourceId, SourceInterface::SOURCE_ID); From 9eb37ab6e4293eabfd15604b9def73f2c21461fb Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Thu, 8 Jun 2017 13:44:24 +0300 Subject: [PATCH 66/66] magento-engcom/magento2#25: Source API Implementation -- fix static tests --- app/code/Magento/Inventory/Model/SourceRepository.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index da4aa5feafc9..6a2316c388fa 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -11,13 +11,10 @@ use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\StateException; -use Magento\Framework\Model\AbstractModel; use Magento\Inventory\Model\ResourceModel\Source as ResourceSource; -use Magento\Inventory\Model\ResourceModel\Source\Collection as SourceCollection; use Magento\Inventory\Model\ResourceModel\Source\CollectionFactory; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; -use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; use Magento\InventoryApi\Api\Data\SourceSearchResultsInterfaceFactory; use Magento\InventoryApi\Api\SourceRepositoryInterface; use Psr\Log\LoggerInterface; @@ -97,7 +94,6 @@ public function __construct( public function save(SourceInterface $source) { try { - /** @var SourceInterface|AbstractModel $source */ $this->resourceSource->save($source); return $source->getSourceId(); } catch (StateException $e) { @@ -114,7 +110,6 @@ public function save(SourceInterface $source) */ public function get($sourceId) { - /** @var SourceInterface|AbstractModel $source */ $source = $this->sourceFactory->create(); $this->resourceSource->load($source, $sourceId, SourceInterface::SOURCE_ID); @@ -129,7 +124,6 @@ public function get($sourceId) */ public function getList(SearchCriteriaInterface $searchCriteria = null) { - /** @var SourceCollection $collection */ $collection = $this->sourceCollectionFactory->create(); if (null === $searchCriteria) { @@ -138,7 +132,6 @@ public function getList(SearchCriteriaInterface $searchCriteria = null) $this->collectionProcessor->process($searchCriteria, $collection); } - /** @var SourceSearchResultsInterface $searchResult */ $searchResult = $this->sourceSearchResultsFactory->create(); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize());