Skip to content

Commit 0a0ba2d

Browse files
committed
Renamed the method validateSubmission() to verifySubmission()
The validation happens before the form is submitted. Because of that, `validateSubmission` is the wrong name. We renamed the method but kept the old method as an alias method in the client.
1 parent 075d019 commit 0a0ba2d

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

src/Client.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(string $host, string $publicKey, string $privateKey,
5959
/**
6060
* Validates the given form data with the configured mosparo
6161
* instance. Returns a VerificationResult object which contains
62-
* all needed informations.
62+
* all needed information.
6363
*
6464
* @param array $formData
6565
* @param string $submitToken
@@ -69,7 +69,7 @@ public function __construct(string $host, string $publicKey, string $privateKey,
6969
* @throws \Mosparo\ApiClient\Exception Submit or validation token not available.
7070
* @throws \Mosparo\ApiClient\Exception An error occurred while sending the request to mosparo.
7171
*/
72-
public function validateSubmission(array $formData, string $submitToken = null, string $validationToken = null): VerificationResult
72+
public function verifySubmission(array $formData, string $submitToken = null, string $validationToken = null): VerificationResult
7373
{
7474
$requestHelper = new RequestHelper($this->publicKey, $this->privateKey);
7575

@@ -129,6 +129,28 @@ public function validateSubmission(array $formData, string $submitToken = null,
129129
);
130130
}
131131

132+
/**
133+
* DEPRECATED: Use Client::verifySubmission() instead.
134+
*
135+
* Validates the given form data with the configured mosparo
136+
* instance. Returns a VerificationResult object which contains
137+
* all needed information.
138+
*
139+
* @deprecated 1.0.2 This method has the wrong method name. Please use Client::verifySubmission() instead.
140+
*
141+
* @param array $formData
142+
* @param string $submitToken
143+
* @param string $validationToken
144+
* @return \Mosparo\ApiClient\VerificationResult
145+
*
146+
* @throws \Mosparo\ApiClient\Exception Submit or validation token not available.
147+
* @throws \Mosparo\ApiClient\Exception An error occurred while sending the request to mosparo.
148+
*/
149+
public function validateSubmission(array $formData, string $submitToken = null, string $validationToken = null): VerificationResult
150+
{
151+
return $this->verifySubmission($formData, $submitToken, $validationToken);
152+
}
153+
132154
/**
133155
* Retrieves the statistics data from mosparo for the given time range,
134156
* counted by date.

tests/ClientTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,58 @@ public function setUp(): void
2828
$this->handlerStack->push($historyMiddleware);
2929
}
3030

31-
public function testValidateSubmissionWithoutTokens()
31+
public function testVerifySubmissionWithoutTokens()
3232
{
3333
$this->expectException(Exception::class);
3434
$this->expectExceptionMessage('Submit or validation token not available.');
3535

3636
$apiClient = new Client('http://test.local', 'testPublicKey', 'testPrivateKey', ['handler' => $this->handlerStack]);
37-
$result = $apiClient->validateSubmission(['name' => 'John Example']);
37+
$result = $apiClient->verifySubmission(['name' => 'John Example']);
3838
}
3939

40-
public function testValidateSubmissionWithoutValidationTokens()
40+
public function testVerifySubmissionWithoutValidationTokens()
4141
{
4242
$this->expectException(Exception::class);
4343
$this->expectExceptionMessage('Submit or validation token not available.');
4444

4545
$apiClient = new Client('http://test.local', 'testPublicKey', 'testPrivateKey', ['handler' => $this->handlerStack]);
46-
$result = $apiClient->validateSubmission(['name' => 'John Example', '_mosparo_submitToken' => 'submitToken']);
46+
$result = $apiClient->verifySubmission(['name' => 'John Example', '_mosparo_submitToken' => 'submitToken']);
4747
}
4848

49-
public function testValidateSubmissionFormTokensEmptyResponse()
49+
public function testVerifySubmissionFormTokensEmptyResponse()
5050
{
5151
$this->handler->append(new Response(200, ['Content-Type' => 'application/json'], json_encode([])));
5252

5353
$this->expectException(Exception::class);
5454
$this->expectExceptionMessage('Response from API invalid.');
5555

5656
$apiClient = new Client('http://test.local', 'testPublicKey', 'testPrivateKey', ['handler' => $this->handlerStack]);
57-
$result = $apiClient->validateSubmission(['name' => 'John Example', '_mosparo_submitToken' => 'submitToken', '_mosparo_validationToken' => 'validationToken']);
57+
$result = $apiClient->verifySubmission(['name' => 'John Example', '_mosparo_submitToken' => 'submitToken', '_mosparo_validationToken' => 'validationToken']);
5858
}
5959

60-
public function testValidateSubmissionTokensAsArgumentEmptyResponse()
60+
public function testVerifySubmissionTokensAsArgumentEmptyResponse()
6161
{
6262
$this->handler->append(new Response(200, ['Content-Type' => 'application/json'], json_encode([])));
6363

6464
$this->expectException(Exception::class);
6565
$this->expectExceptionMessage('Response from API invalid.');
6666

6767
$apiClient = new Client('http://test.local', 'testPublicKey', 'testPrivateKey', ['handler' => $this->handlerStack]);
68-
$result = $apiClient->validateSubmission(['name' => 'John Example'], 'submitToken', 'validationToken');
68+
$result = $apiClient->verifySubmission(['name' => 'John Example'], 'submitToken', 'validationToken');
6969
}
7070

71-
public function testValidateSubmissionConnectionError()
71+
public function testVerifySubmissionConnectionError()
7272
{
7373
$this->handler->append(new RequestException('Error Communicating with Server', new Request('GET', 'test')));
7474

7575
$this->expectException(Exception::class);
7676
$this->expectExceptionMessage('An error occurred while sending the request to mosparo.');
7777

7878
$apiClient = new Client('http://test.local', 'testPublicKey', 'testPrivateKey', ['handler' => $this->handlerStack]);
79-
$result = $apiClient->validateSubmission(['name' => 'John Example'], 'submitToken', 'validationToken');
79+
$result = $apiClient->verifySubmission(['name' => 'John Example'], 'submitToken', 'validationToken');
8080
}
8181

82-
public function testValidateSubmissionIsValid()
82+
public function testVerifySubmissionIsValid()
8383
{
8484
$publicKey = 'testPublicKey';
8585
$privateKey = 'testPrivateKey';
@@ -107,7 +107,7 @@ public function testValidateSubmissionIsValid()
107107
// Start the test
108108
$apiClient = new Client('http://test.local', $publicKey, $privateKey, ['handler' => $this->handlerStack]);
109109

110-
$result = $apiClient->validateSubmission($formData, $submitToken, $validationToken);
110+
$result = $apiClient->verifySubmission($formData, $submitToken, $validationToken);
111111

112112
// Check the result
113113
$this->assertInstanceOf(VerificationResult::class, $result);
@@ -125,7 +125,7 @@ public function testValidateSubmissionIsValid()
125125
$this->assertEquals($requestData['formSignature'], $formSignature);
126126
}
127127

128-
public function testValidateSubmissionIsNotValid()
128+
public function testVerifySubmissionIsNotValid()
129129
{
130130
$publicKey = 'testPublicKey';
131131
$privateKey = 'testPrivateKey';
@@ -147,7 +147,7 @@ public function testValidateSubmissionIsNotValid()
147147
// Start the test
148148
$apiClient = new Client('http://test.local', 'testPublicKey', $privateKey, ['handler' => $this->handlerStack]);
149149

150-
$result = $apiClient->validateSubmission($formData, $submitToken, $validationToken);
150+
$result = $apiClient->verifySubmission($formData, $submitToken, $validationToken);
151151

152152
// Check the result
153153
$this->assertInstanceOf(VerificationResult::class, $result);

0 commit comments

Comments
 (0)