What are the Slack Archives?
Itβs a history of our time together in the Slack Community! Thereβs a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.
Because this space is not active, you wonβt be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..
Hi Please let me know how can I write unit test cases of the function having redis dependency. In fu
Hi
Please let me know how can I write unit test cases of the function having redis dependency.
In function I am getting the value from redis after passing key.
public function getGlobalConfigValueByKey(string $configKey) { $configValueData = $this->getFactory()->getStorageClient()->get(GlobalConfigConfig::REDIS_GLOBAL_CONFIG_KEY . ':' . strtolower($configKey)); unset($configValueData['_timestamp']); return json_encode($configValueData); }
Comments
-
Mock the factory and the storage client to return a JSON you define in your test.
0 -
I am trying to use
$storageClient = $this->getStorageClientMock();
But it is giving error
I have tried to add following helper in codeception.yml\SprykerTest\Client\Storage\Helper\StorageHelper
But still error is there
0 -
Please give reference to implement same.
0 -
Did you called
docker/sdk cli vendor/bin/codecept
?
Normally you don't get the methods of the test helpers in the parent class but on the tester, try$this->tester->getStorageClientMock()
0 -
no error is still there
0 -
Can you show the codeception.yml from this module?
0 -
namespace: PyzTest\Zed\GlobalConfig paths: tests: . data: _data support: _support log: _output coverage: enabled: true remote: false whitelist: { include: ['../../../../src/*'] } suites: Business: path: Business class_name: GlobalConfigBusinessTester modules: enabled: - Asserts - \SprykerTest\Shared\Testify\Helper\Environment - \SprykerTest\Shared\Testify\Helper\ConfigHelper - \SprykerTest\Shared\Testify\Helper\DependencyHelper - \SprykerTest\Shared\Propel\Helper\TransactionHelper - \SprykerTest\Zed\Sales\Helper\BusinessHelper - \SprykerTest\Shared\Testify\Helper\LocatorHelper: projectNamespaces: ['Pyz']
0 -
Your codeception.yml for this module is missing the
\SprykerTest\Client\Storage\Helper\StorageHelper
afterwards build the tests again and it should be fine.0 -
I have tried same but it is giving error in other test cases
0 -
after adding this helper
0 -
these are resolved after adding following helper lines:
- \SprykerTest\Client\Testify\Helper\ClientHelper - \SprykerTest\Client\Testify\Helper\DependencyProviderHelper
0 -
But this error still exists:
0 -
I have tried the following:
$arr = [ "default" => "<https://selectandconfig-widget.schneider-electric.com/>", "zh_CN" => "<https://selectandconfig-widget.schneider-electric.cn/>", "_timestamp" => 1667978400.8121 ]; $storageClient = $this->getMockBuilder(StorageClient::class) ->onlyMethods(['get']) ->getMock(); $storageClient ->method('get') ->willReturn($arr); $configStorageFactoryMock = $this->getMockBuilder(GlobalConfigPersistenceFactory::class) ->onlyMethods(['getStorageClient']) ->getMock(); $configStorageFactoryMock ->method('getStorageClient') ->willReturn($storageClient); $configValue = $this->tester->createFacade()->getGlobalConfigValueByKey("scwidgetUrl"); dd($configValue);
0 -
Here config value is coming null
0 -
This is the function I am testing:
public function getGlobalConfigValueByKey(string $configKey) { $configValueData = $this->getFactory()->getStorageClient()->get(GlobalConfigConfig::REDIS_GLOBAL_CONFIG_KEY . ':' . strtolower($configKey)); unset($configValueData['_timestamp']); return json_encode($configValueData); }
0 -
Can you please check where I went wrong
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 78 Spryker News
- 936 Developer Corner
- 793 Spryker Development
- 90 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 27 Job Opportunities
- 3.2K π Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 33 Product & Business Questions
- 69 Spryker Safari Questions
- 50 Random