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

Http mock fails with new symfony/http-foundation - 4x #46

Open
kordos opened this issue Apr 24, 2018 · 0 comments
Open

Http mock fails with new symfony/http-foundation - 4x #46

kordos opened this issue Apr 24, 2018 · 0 comments

Comments

@kordos
Copy link

kordos commented Apr 24, 2018

It fails with new http foundation. In my case it is 4.0.8
From yesterday my API tests started to failing after updating dependencies from silex 2.2.4 to 2.3.0
which installed new symfony components in 4.x version
Update info:

Package operations: 0 installs, 5 updates, 1 removal

  • Removing symfony/polyfill-php70 (v1.7.0)
  • Updating symfony/routing (v3.4.8 => v4.0.8): Loading from cache
  • Updating symfony/http-foundation (v3.4.8 => v4.0.8): Loading from cache
  • Updating symfony/event-dispatcher (v3.4.8 => v4.0.8): Loading from cache
  • Updating symfony/http-kernel (v3.4.8 => v4.0.8): Loading from cache
  • Updating silex/silex (v2.2.4 => v2.3.0): Loading from cache

In tests I get error:

Client error: GET http://localhost:8082/v1/countries/de.json resulted in a 404 Not Found
with content which I set in body: { name: Proxy-Germany, code: de }

Test code:


$I->getHttpMock()->mock
	->when()
		->methodIs('GET')
		->pathIs('/v1/countries/de.json')
	->then()
		->header('content-type', 'application/json')
		->body('{ "name": "Proxy-Germany", "code": "de" }')
	->end();
$I->getHttpMock()->setUp();

$countryCode = "de";

$I->sendGET('/v1/countries/'. $countryCode . '-proxy.json');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['code' => $countryCode, 'name' => 'Proxy-Germany']);  

After many hours of investigation I noticed that I can fix it by replacing body method with callback:

$I->getHttpMock()->mock
	->when()
		->methodIs('GET')
		->pathIs('/v1/countries/de.json')
	->then()
		->header('content-type', 'application/json')
		->callback(
			function (Response $response) {
				$response->setContent('{ "name": "Proxy-Germany", "code": "de" }')
					->setStatusCode(200);
			}
		)
	->end();
$I->getHttpMock()->setUp();

$countryCode = "de";

$I->sendGET('/v1/countries/'. $countryCode . '-proxy.json');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['code' => $countryCode, 'name' => 'Proxy-Germany']);

I guessing that http mock library uses some old code that isn't present in 4.x versions.

Please fix issue.
Regards,
Pawel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant