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 team Can you please give some referece how mocking works in spryker test cases?

U03TXRYL7U7
U03TXRYL7U7 Posts: 64 🧑🏻‍🚀 - Cadet

Hi team
Can you please give some referece how mocking works in spryker test cases?

Comments

  • Alberto Reyer
    Alberto Reyer Posts: 690 🪐 - Explorer

    Depends what you want to mock?
    Unittests? $this->tester->createMockBuilder('<class>'); and all other things you can do with PHPUnit.
    Just instead of $this-><phpunit method>() you need to call $this->tester-><phpunit method>() as long as the base test class you extend is using the unit extension of codeception.

    Beside that you can mock factories, configs and faceds for every module using the provided test helpers from spryker: https://docs.spryker.com/docs/scos/dev/guidelines/testing-guidelines/available-test-helpers.html#testify-helpers

    There are plenty of documentation parts available on testing and mocking in Spryker: https://docs.spryker.com/docs/scos/dev/guidelines/testing-guidelines/testing-concepts.html

  • U03TXRYL7U7
    U03TXRYL7U7 Posts: 64 🧑🏻‍🚀 - Cadet

    yes I am trying to mock unit tests
    I have written following code in tester class:

    public function createUtility()
    {
    return new ImageUrlTemplatingUtility($this->mockGlobalConfigFacade());
    }
    In code, in above class, ImageUrlTemplatingUtility have dependency injection of another module facade, I want to mock that.

    I am trying to do by

    public function mockGlobalConfigFacade()
    {
    return Stub::make('GlobalConfigFacade', ['getGlobalCOnfigValueByKey' => '/files?p_Doc_Ref=#pictureRef#&p_File_Type=rendition_369_jpg']);
    }

    in tester class

    but it is giving error that
    Stubbed class GlobalConfigFacade doesn't exist.

  • U03TXRYL7U7
    U03TXRYL7U7 Posts: 64 🧑🏻‍🚀 - Cadet

    It is done by making following change in code:
    public function mockGlobalConfigFacade()
    {
    return Stub::make(GlobalConfigFacade::class, ['getGlobalCOnfigValueByKey' => '/files?p_Doc_Ref=#pictureRef#&p_File_Type=rendition_369_jpg']);
    }
    insead of

    public function mockGlobalConfigFacade()
    {
    return Stub::make('GlobalConfigFacade', ['getGlobalCOnfigValueByKey' => '/files?p_Doc_Ref=#pictureRef#&p_File_Type=rendition_369_jpg']);
    }

    Please confirm whether it is correct way to do same.