Codeception / Codeception/Stub

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

Open
#30 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
PHP
Stars
301
Forks
19
PR merge metrics
No merged PRs in 30d

Description

#### 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

```php
$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:

```yml
# paste suite config here
```
Addittional info
RN I do this
```php
$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
methods = $methods;
}

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

return call_user_func_array($method, $args);
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.