Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected::exactly should have ability to change callback method per times called #30

Open
mikk150 opened this issue Jun 9, 2020 · 0 comments

Comments

@mikk150
Copy link

mikk150 commented Jun 9, 2020

What are you trying to achieve?

Http client send method is called 2 times on a test
I would like to make different response objects for each of them
on one of them I would also like to have asserts

What do you get instead?

RN it is impossible to have different callbacks for consecutive calls

Provide console output if related. Use -vvv mode for more details.

Provide test source code if related

$oauth2Provider->setHttpClient($this->construct(Client::class, [], [
    'send' => Expected::exactly(2,
        function (RequestInterface $request) {
            return new Response(200, [
                'content-type' => 'application/json'
            ], '{"access_token": "access", "expires_in": 3600, "refresh_token": "refresh"}');
        },
        function (RequestInterface $request) {
            //assertions go here

            return new Response(200, [
            ], 'response body goes here');
        }
    ]))
]));

Details

  • Codeception version:
  • PHP Version: 7.4.6
  • Operating System: Ubuntu
  • Installation type: Composer
  • List of installed packages (composer show)
  • Suite configuration:
# paste suite config here

Addittional info
RN I do this

$oauth2Provider->setHttpClient($this->construct(Client::class, [], [
    'send' => Expected::exactly(2, Closure::fromCallable(new MultiCallable([
        function (RequestInterface $request) {
            return new Response(200, [
                'content-type' => 'application/json'
            ], '{"access_token": "access", "expires_in": 3600, "refresh_token": "refresh"}');
        },
        function (RequestInterface $request) {
            //asserts go here

            return new Response(200, [
            ], 'response body goes here');
        }
    ])))
]));
<?php

class MultiCallable
{
    private $methods;

    public function __construct($methods)
    {
        $this->methods = $methods;
    }

    public function __invoke(...$args)
    {
        $method = array_shift($this->methods);

        return call_user_func_array($method, $args);
    }
}
@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant