Skip to content

Commit eab0d8f

Browse files
committed
Fixed unit test
1 parent bc8c34e commit eab0d8f

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

codegens/php-guzzle/test/unit/convert.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ describe('convert function', function () {
1010
it('should convert a simple get request', function (done) {
1111
const collection = new sdk.Collection(JSON.parse(
1212
fs.readFileSync(path.resolve(__dirname, './fixtures/sample_collection.json').toString())));
13-
convert(collection.items.members[31].request, {asyncType: 'sync'}, function (err, snippet) {
14-
if (err) {
15-
console.error(err);
16-
}
17-
expect(snippet).to.not.be.empty;
18-
fs.writeFileSync(path.resolve(__dirname, './fixtures/snippet.php'), snippet);
13+
collection.items.members.forEach((item) => {
14+
convert(item.request, { asyncType: 'sync' }, function (err, snippet) {
15+
if (err) {
16+
console.error(err);
17+
}
18+
expect(snippet).to.not.be.empty;
19+
});
1920
});
2021
done();
2122
});

codegens/php-guzzle/test/unit/phpGuzzle.test.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ describe('convert function', function () {
2626
console.error(err);
2727
}
2828
expect(snippet).to.not.be.empty;
29-
fs.writeFileSync(path.resolve(__dirname, collectionsPath, './snippet.php'), snippet);
3029
});
3130
done();
3231
});
@@ -181,37 +180,27 @@ describe('getSnippetClient function', function () {
181180

182181
describe('getSnippetFooter function', function () {
183182
it('should return the async version without options', function () {
184-
const expectedString = '$promise = $client->sendAsync($request);\n$promise->then' +
185-
'(\n function (ResponseInterface $res) {\n echo $res->getBody();\n },\n ' +
186-
' function (RequestException $e) {\n echo $e->getMessage();\n echo $e->getRequest()->getMethod();\n }\n);\n';
183+
const expectedString = '$res = $client->sendAsync($request)->wait();\necho $res->getBody();\n';
187184
expect(getSnippetFooter()).to.equal(expectedString);
188185
});
189186

190187
it('should return the async version with request options', function () {
191-
const expectedString = '$promise = $client->sendAsync($request, $options);\n$promise->then' +
192-
'(\n function (ResponseInterface $res) {\n echo $res->getBody();\n },\n ' +
193-
' function (RequestException $e) {\n echo $e->getMessage();\n echo $e->getRequest()->getMethod();\n }\n);\n';
188+
const expectedString = '$res = $client->sendAsync($request, $options)->wait();\necho $res->getBody();\n';
194189
expect(getSnippetFooter({}, true)).to.equal(expectedString);
195190
});
196191

197192
it('should return the async version with empty options', function () {
198-
const expectedString = '$promise = $client->sendAsync($request);\n$promise->then' +
199-
'(\n function (ResponseInterface $res) {\n echo $res->getBody();\n },\n ' +
200-
' function (RequestException $e) {\n echo $e->getMessage();\n echo $e->getRequest()->getMethod();\n }\n);\n';
193+
const expectedString = '$res = $client->sendAsync($request)->wait();\necho $res->getBody();\n';
201194
expect(getSnippetFooter({})).to.equal(expectedString);
202195
});
203196

204197
it('should return the async version with options as async', function () {
205-
const expectedString = '$promise = $client->sendAsync($request);\n$promise->then' +
206-
'(\n function (ResponseInterface $res) {\n echo $res->getBody();\n },\n ' +
207-
' function (RequestException $e) {\n echo $e->getMessage();\n echo $e->getRequest()->getMethod();\n }\n);\n';
198+
const expectedString = '$res = $client->sendAsync($request)->wait();\necho $res->getBody();\n';
208199
expect(getSnippetFooter({asyncType: 'async'})).to.equal(expectedString);
209200
});
210201

211202
it('should return the async version with options as other string', function () {
212-
const expectedString = '$promise = $client->sendAsync($request);\n$promise->then' +
213-
'(\n function (ResponseInterface $res) {\n echo $res->getBody();\n },\n ' +
214-
' function (RequestException $e) {\n echo $e->getMessage();\n echo $e->getRequest()->getMethod();\n }\n);\n';
203+
const expectedString = '$res = $client->sendAsync($request)->wait();\necho $res->getBody();\n';
215204
expect(getSnippetFooter({asyncType: 'other'})).to.equal(expectedString);
216205
});
217206

0 commit comments

Comments
 (0)