How to get base url in Unit Test?Tools for Unit Testing in MagentoUnit Test for overwrite collection class in magento2Magento Unit Test ErrorUnit test case for custom module REST APIUnit test Issue on getting valueWhat we can achieve by unit test in Magento 2 ? How it is useful?unit test with phpunitUnit test in magento 2 Error: Call to a member function getAllVisibleItems() on nullHow to post form data from Unit Test controller to custom controller | Magento 2Class 'MagentoTestFrameworkTestCaseAbstractController' not found when running unit test for custom module
How can I review my manager, who is fine?
Why am I getting unevenly-spread results when using $RANDOM?
force:lightningQuickAction . Will implementing this open the component as modalpop up directly?
What does "spinning upon the shoals" mean?
How to have a filled pattern
In layman's terms, does the Luckstone just give a passive +1 to all d20 rolls and saves except for death saves?
What is the meaning of "prairie-dog" in this sentence?
How many Jimmys can fit?
Sorting a list according to some pre-specified rules
As a supervisor, what feedback would you expect from a PhD who quits?
Array or vector? Two dimensional array or matrix?
Quotients of a ring of integers
How to reclaim personal item I've lent to the office without burning bridges?
How should I ask for a "pint" in countries that use metric?
NOLOCK or Read Uncommitted locking / latching behaviours
Why do Martians have to wear space helmets?
This LM317 diagram doesn't make any sense to me
What purpose does mercury dichloride have in fireworks?
Jimmy needs your help!
Computer name naming convention for security
How to understand flavors and when to use combination of them?
Sense of humor in your sci-fi stories
Four ships at the ocean with the same distance
Can one block with a protection from color creature?
How to get base url in Unit Test?
Tools for Unit Testing in MagentoUnit Test for overwrite collection class in magento2Magento Unit Test ErrorUnit test case for custom module REST APIUnit test Issue on getting valueWhat we can achieve by unit test in Magento 2 ? How it is useful?unit test with phpunitUnit test in magento 2 Error: Call to a member function getAllVisibleItems() on nullHow to post form data from Unit Test controller to custom controller | Magento 2Class 'MagentoTestFrameworkTestCaseAbstractController' not found when running unit test for custom module
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
This is my unit test in my custom module:
namespace StarTrekTestUnitModel;
class BeyondTest extends PHPUnitFrameworkTestCase
how can i get my magento 2 base url in there?
magento2 base-url unit-tests
This question has an open bounty worth +100
reputation from mileven ending ending at 2019-07-08 02:02:17Z">in 2 days.
The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.
add a comment |
This is my unit test in my custom module:
namespace StarTrekTestUnitModel;
class BeyondTest extends PHPUnitFrameworkTestCase
how can i get my magento 2 base url in there?
magento2 base-url unit-tests
This question has an open bounty worth +100
reputation from mileven ending ending at 2019-07-08 02:02:17Z">in 2 days.
The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.
Sounds like you need an integration test, not a unit test.
– Shawn Abramson
Jul 1 at 3:35
add a comment |
This is my unit test in my custom module:
namespace StarTrekTestUnitModel;
class BeyondTest extends PHPUnitFrameworkTestCase
how can i get my magento 2 base url in there?
magento2 base-url unit-tests
This is my unit test in my custom module:
namespace StarTrekTestUnitModel;
class BeyondTest extends PHPUnitFrameworkTestCase
how can i get my magento 2 base url in there?
magento2 base-url unit-tests
magento2 base-url unit-tests
asked Jun 28 at 10:07
milevenmileven
898 bronze badges
898 bronze badges
This question has an open bounty worth +100
reputation from mileven ending ending at 2019-07-08 02:02:17Z">in 2 days.
The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.
This question has an open bounty worth +100
reputation from mileven ending ending at 2019-07-08 02:02:17Z">in 2 days.
The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.
Sounds like you need an integration test, not a unit test.
– Shawn Abramson
Jul 1 at 3:35
add a comment |
Sounds like you need an integration test, not a unit test.
– Shawn Abramson
Jul 1 at 3:35
Sounds like you need an integration test, not a unit test.
– Shawn Abramson
Jul 1 at 3:35
Sounds like you need an integration test, not a unit test.
– Shawn Abramson
Jul 1 at 3:35
add a comment |
2 Answers
2
active
oldest
votes
namespace StarTrekTestUnitModel;
class BeyondTest extends PHPUnitFrameworkTestCase
protected $_storeManager;
public function __construct(
MagentoStoreModelStoreManagerInterface $storeManager,
)
$this->_storeManager = $storeManager;
/**
* Prining URLs using StoreManagerInterface
*/
public function getStoreManagerData()
echo $this->_storeManager->getStore()->getBaseUrl() . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_DIRECT_LINK) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_STATIC) . '<br />';
add a comment |
I think you have to look into the core Magento unit test code how they use and get base URL.
I am not sure about this is what I shared is exactly you want, but I think it will help you.
Look into the Magento core test module.
vendor/magento/module-cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php
Find the function public function testGetBaseUrl()
inside this function they get base URL $this->imagesHelper->getBaseUrl();
using imageHelper they are use protected variable protected $imagesHelper;
by class MagentoCmsHelperWysiwygImages
UPDATE:
There is one anoter example of to get base URL using storeRepository look into the core module.
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/UrlRewrite/Model/StoreSwitcher/RewriteUrlTest.php
See the public function testSwitchToNonExistingPage()
they are get store using object manager using $storeRepository = $this->objectManager->create(MagentoStoreApiStoreRepositoryInterface::class);
pass the storecode using $toStore = $storeRepository->get($toStoreCode);
if you wan to get URL store specific.and finally get URL using $toStore->getBaseUrl();
I think it will help to solve out your issue.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f280055%2fhow-to-get-base-url-in-unit-test%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
namespace StarTrekTestUnitModel;
class BeyondTest extends PHPUnitFrameworkTestCase
protected $_storeManager;
public function __construct(
MagentoStoreModelStoreManagerInterface $storeManager,
)
$this->_storeManager = $storeManager;
/**
* Prining URLs using StoreManagerInterface
*/
public function getStoreManagerData()
echo $this->_storeManager->getStore()->getBaseUrl() . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_DIRECT_LINK) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_STATIC) . '<br />';
add a comment |
namespace StarTrekTestUnitModel;
class BeyondTest extends PHPUnitFrameworkTestCase
protected $_storeManager;
public function __construct(
MagentoStoreModelStoreManagerInterface $storeManager,
)
$this->_storeManager = $storeManager;
/**
* Prining URLs using StoreManagerInterface
*/
public function getStoreManagerData()
echo $this->_storeManager->getStore()->getBaseUrl() . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_DIRECT_LINK) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_STATIC) . '<br />';
add a comment |
namespace StarTrekTestUnitModel;
class BeyondTest extends PHPUnitFrameworkTestCase
protected $_storeManager;
public function __construct(
MagentoStoreModelStoreManagerInterface $storeManager,
)
$this->_storeManager = $storeManager;
/**
* Prining URLs using StoreManagerInterface
*/
public function getStoreManagerData()
echo $this->_storeManager->getStore()->getBaseUrl() . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_DIRECT_LINK) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_STATIC) . '<br />';
namespace StarTrekTestUnitModel;
class BeyondTest extends PHPUnitFrameworkTestCase
protected $_storeManager;
public function __construct(
MagentoStoreModelStoreManagerInterface $storeManager,
)
$this->_storeManager = $storeManager;
/**
* Prining URLs using StoreManagerInterface
*/
public function getStoreManagerData()
echo $this->_storeManager->getStore()->getBaseUrl() . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_DIRECT_LINK) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . '<br />';
echo $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_STATIC) . '<br />';
answered Jul 1 at 4:28
Ketan BoradaKetan Borada
90511 silver badges40 bronze badges
90511 silver badges40 bronze badges
add a comment |
add a comment |
I think you have to look into the core Magento unit test code how they use and get base URL.
I am not sure about this is what I shared is exactly you want, but I think it will help you.
Look into the Magento core test module.
vendor/magento/module-cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php
Find the function public function testGetBaseUrl()
inside this function they get base URL $this->imagesHelper->getBaseUrl();
using imageHelper they are use protected variable protected $imagesHelper;
by class MagentoCmsHelperWysiwygImages
UPDATE:
There is one anoter example of to get base URL using storeRepository look into the core module.
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/UrlRewrite/Model/StoreSwitcher/RewriteUrlTest.php
See the public function testSwitchToNonExistingPage()
they are get store using object manager using $storeRepository = $this->objectManager->create(MagentoStoreApiStoreRepositoryInterface::class);
pass the storecode using $toStore = $storeRepository->get($toStoreCode);
if you wan to get URL store specific.and finally get URL using $toStore->getBaseUrl();
I think it will help to solve out your issue.
add a comment |
I think you have to look into the core Magento unit test code how they use and get base URL.
I am not sure about this is what I shared is exactly you want, but I think it will help you.
Look into the Magento core test module.
vendor/magento/module-cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php
Find the function public function testGetBaseUrl()
inside this function they get base URL $this->imagesHelper->getBaseUrl();
using imageHelper they are use protected variable protected $imagesHelper;
by class MagentoCmsHelperWysiwygImages
UPDATE:
There is one anoter example of to get base URL using storeRepository look into the core module.
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/UrlRewrite/Model/StoreSwitcher/RewriteUrlTest.php
See the public function testSwitchToNonExistingPage()
they are get store using object manager using $storeRepository = $this->objectManager->create(MagentoStoreApiStoreRepositoryInterface::class);
pass the storecode using $toStore = $storeRepository->get($toStoreCode);
if you wan to get URL store specific.and finally get URL using $toStore->getBaseUrl();
I think it will help to solve out your issue.
add a comment |
I think you have to look into the core Magento unit test code how they use and get base URL.
I am not sure about this is what I shared is exactly you want, but I think it will help you.
Look into the Magento core test module.
vendor/magento/module-cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php
Find the function public function testGetBaseUrl()
inside this function they get base URL $this->imagesHelper->getBaseUrl();
using imageHelper they are use protected variable protected $imagesHelper;
by class MagentoCmsHelperWysiwygImages
UPDATE:
There is one anoter example of to get base URL using storeRepository look into the core module.
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/UrlRewrite/Model/StoreSwitcher/RewriteUrlTest.php
See the public function testSwitchToNonExistingPage()
they are get store using object manager using $storeRepository = $this->objectManager->create(MagentoStoreApiStoreRepositoryInterface::class);
pass the storecode using $toStore = $storeRepository->get($toStoreCode);
if you wan to get URL store specific.and finally get URL using $toStore->getBaseUrl();
I think it will help to solve out your issue.
I think you have to look into the core Magento unit test code how they use and get base URL.
I am not sure about this is what I shared is exactly you want, but I think it will help you.
Look into the Magento core test module.
vendor/magento/module-cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php
Find the function public function testGetBaseUrl()
inside this function they get base URL $this->imagesHelper->getBaseUrl();
using imageHelper they are use protected variable protected $imagesHelper;
by class MagentoCmsHelperWysiwygImages
UPDATE:
There is one anoter example of to get base URL using storeRepository look into the core module.
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/UrlRewrite/Model/StoreSwitcher/RewriteUrlTest.php
See the public function testSwitchToNonExistingPage()
they are get store using object manager using $storeRepository = $this->objectManager->create(MagentoStoreApiStoreRepositoryInterface::class);
pass the storecode using $toStore = $storeRepository->get($toStoreCode);
if you wan to get URL store specific.and finally get URL using $toStore->getBaseUrl();
I think it will help to solve out your issue.
edited Jul 1 at 5:32
answered Jul 1 at 5:14
Chirag PatelChirag Patel
3,6796 silver badges28 bronze badges
3,6796 silver badges28 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f280055%2fhow-to-get-base-url-in-unit-test%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Sounds like you need an integration test, not a unit test.
– Shawn Abramson
Jul 1 at 3:35