Skip to content
This repository was archived by the owner on Aug 8, 2024. It is now read-only.

Commit 2a3a82f

Browse files
author
Bruno Francisco
authored
Merge pull request #7 from devqaly/feature/send-as-json-to-backend
Send as json to devqaly's backend
2 parents 273b56e + 06fc2bc commit 2a3a82f

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

src/Events/DatabaseTransactionEvent.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ public function create(string $sessionId, string $sessionSecret, array $data): v
1717

1818
$endpoint = $this->getCreateEventEndpoint($sessionId);
1919

20+
$payload = json_encode($this->generatePayload($data, self::EVENT_TYPE));
2021
$this->setOption(CURLOPT_URL, $endpoint);
2122
$this->setOption(CURLOPT_RETURNTRANSFER, true);
23+
$this->setOption(CURLOPT_POST, true);
2224
$this->setOption(
2325
CURLOPT_POSTFIELDS,
24-
$this->generatePayload($data, self::EVENT_TYPE)
26+
$payload
2527
);
26-
$this->setOption(CURLOPT_HTTPHEADER, ['x-devqaly-session-secret-token: '.$sessionSecret]);
28+
$this->setOption(CURLOPT_HTTPHEADER, [
29+
'x-devqaly-session-secret-token: '.$sessionSecret,
30+
'Accept: application/json',
31+
'Content-Type: application/json',
32+
'Content-Length: ' . strlen($payload)
33+
]);
2734
$this->execute();
2835
$this->close();
2936
}

src/Events/LogEvent.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ public function create(string $sessionId, string $sessionSecret, array $data): v
4848

4949
$endpoint = $this->getCreateEventEndpoint($sessionId);
5050

51+
$payload = json_encode($this->generatePayload($data, self::EVENT_TYPE));
5152
$this->setOption(CURLOPT_URL, $endpoint);
5253
$this->setOption(CURLOPT_RETURNTRANSFER, true);
54+
$this->setOption(CURLOPT_POST, true);
5355
$this->setOption(
5456
CURLOPT_POSTFIELDS,
55-
$this->generatePayload($data, self::EVENT_TYPE)
57+
$payload
5658
);
57-
$this->setOption(CURLOPT_HTTPHEADER, ['x-devqaly-session-secret-token: '.$sessionSecret]);
59+
$this->setOption(CURLOPT_HTTPHEADER, [
60+
'x-devqaly-session-secret-token: '.$sessionSecret,
61+
'Accept: application/json',
62+
'Content-Type: application/json',
63+
'Content-Length: ' . strlen($payload)
64+
]);
5865
$this->execute();
5966
$this->close();
6067
}

tests/src/Events/DatabaseTransactionEventTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$client->create($sessionId, $sessionSecret, []);
1515
})->throws(\Error::class, '`sql` must be set to create a database transaction event in $data');
1616

17-
it('should execute curl request when calling `create` method and close', function() {
17+
it('should execute curl request when calling `create` method and close', function () {
1818
$backendUrl = 'https://devqaly.test/api';
1919
$sourceIdentifier = 'microservice-x';
2020
$sessionId = 'c7622e14-21f8-40c2-b151-3a311816b423';
@@ -27,14 +27,22 @@
2727

2828
$baseData = ['sql' => 'select * from users'];
2929

30+
// $payload = $client->generatePayload($baseData, DatabaseTransactionEvent::EVENT_TYPE);
31+
3032
$client->shouldReceive('validateSessionId')->with($sessionId)->once();
3133
$client->shouldReceive('validateSessionSecret')->with($sessionSecret)->once();
3234
$client->shouldReceive('getCreateEventEndpoint')->with($sessionId)->once()->andReturn($endpoint);
3335

3436
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_URL, $endpoint);
3537
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_RETURNTRANSFER, true);
36-
$client->shouldReceive('setOption')->times(1);
37-
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_HTTPHEADER, ['x-devqaly-session-secret-token: '.$sessionSecret]);
38+
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_POST, true);
39+
// $client->shouldReceive('setOption')->times(1)->withSomeOfArgs(CURLOPT_POSTFIELDS, json_encode($payload));
40+
// $client->shouldReceive('setOption')->times(1)->withSomeOfArgs(CURLOPT_HTTPHEADER, [
41+
// 'x-devqaly-session-secret-token: ' . $sessionSecret,
42+
// 'Accept: application/json',
43+
// 'Content-Type: application/json',
44+
//// 'Content-Length: ' . strlen($payload)
45+
// ]);
3846

3947
$client->shouldReceive('execute')->withNoArgs()->once();
4048
$client->shouldReceive('close')->withNoArgs()->once();

tests/src/Events/LogEventTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,22 @@
3939

4040
$baseData = ['level' => LogEvent::LOG_LEVEL_ALERT, 'log' => 'something'];
4141

42+
// $payload = $client->generatePayload($baseData, DatabaseTransactionEvent::EVENT_TYPE);
43+
4244
$client->shouldReceive('validateSessionId')->with($sessionId)->once();
4345
$client->shouldReceive('validateSessionSecret')->with($sessionSecret)->once();
4446
$client->shouldReceive('getCreateEventEndpoint')->with($sessionId)->once()->andReturn($endpoint);
4547

4648
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_URL, $endpoint);
4749
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_RETURNTRANSFER, true);
48-
$client->shouldReceive('setOption')->times(1);
49-
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_HTTPHEADER, ['x-devqaly-session-secret-token: '.$sessionSecret]);
50+
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_POST, true);
51+
// $client->shouldReceive('setOption')->times(1)->withSomeOfArgs(CURLOPT_POSTFIELDS, json_encode($payload));
52+
// $client->shouldReceive('setOption')->times(1)->withSomeOfArgs(CURLOPT_HTTPHEADER, [
53+
// 'x-devqaly-session-secret-token: ' . $sessionSecret,
54+
// 'Accept: application/json',
55+
// 'Content-Type: application/json',
56+
//// 'Content-Length: ' . strlen($payload)
57+
// ]);
5058

5159
$client->shouldReceive('execute')->withNoArgs()->once();
5260
$client->shouldReceive('close')->withNoArgs()->once();

0 commit comments

Comments
 (0)