Skip to content

Commit 2999c93

Browse files
Make error classes' props private and expose public methods
1 parent 724bef3 commit 2999c93

13 files changed

+34
-33
lines changed

src/Exceptions/SeamActionAttemptError.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66

77
class SeamActionAttemptError extends \Exception
88
{
9-
public ActionAttempt $actionAttempt;
9+
private ActionAttempt $actionAttempt;
1010

1111
public function __construct(string $message, ActionAttempt $actionAttempt)
1212
{
1313
parent::__construct($message);
1414
$this->name = get_class($this);
1515
$this->actionAttempt = $actionAttempt;
1616
}
17+
18+
public function getActionAttempt(): ActionAttempt
19+
{
20+
return $this->actionAttempt;
21+
}
1722
}

src/Exceptions/SeamActionAttemptFailedError.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66

77
class SeamActionAttemptFailedError extends SeamActionAttemptError
88
{
9-
public string $errorCode;
9+
private string $errorCode;
1010

1111
public function __construct(ActionAttempt $actionAttempt)
1212
{
1313
parent::__construct($actionAttempt->error->message, $actionAttempt);
1414
$this->name = get_class($this);
1515
$this->errorCode = $actionAttempt->error->type;
1616
}
17+
18+
public function getErrorCode(): string
19+
{
20+
return $this->errorCode;
21+
}
1722
}

src/Exceptions/SeamHttpApiError.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
class SeamHttpApiError extends \Exception
66
{
7-
public string $errorCode;
8-
public int $statusCode;
9-
public string $requestId;
10-
public ?object $data;
7+
private string $errorCode;
8+
private int $statusCode;
9+
private string $requestId;
10+
private ?object $data = null;
1111

1212
public function __construct(object $error, int $statusCode, string $requestId)
1313
{

tests/AccessCodesTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Tests\Fixture;
7-
use GuzzleHttp\Client;
8-
use GuzzleHttp\Exception\ClientErrorResponseException as ClientErrorResponseException;
9-
use GuzzleHttp\Promise\Is;
107

118
final class AccessCodesTest extends TestCase
129
{
@@ -62,7 +59,7 @@ public function testAccessCodes(): void
6259
$seam->access_codes->get(access_code_id: $access_code_id);
6360

6461
$this->fail("Expected the code to be deleted");
65-
} catch (Exception $exception) {
62+
} catch (\Seam\SeamHttpApiError $exception) {
6663
$this->assertTrue(
6764
str_contains($exception->getMessage(), "Access Code Not Found")
6865
);

tests/ActionAttemptsTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testFailedActionAttempt(): void
5151
"status" => "error",
5252
"error" => [
5353
"message" => "Failed",
54-
"type" => "foo"
54+
"type" => "failed_attempt"
5555
]
5656
]
5757
);
@@ -60,9 +60,9 @@ public function testFailedActionAttempt(): void
6060
$seam->action_attempts->poll_until_ready($action_attempt->action_attempt_id);
6161
$this->fail("Expected SeamActionAttemptFailedError");
6262
} catch (\Seam\SeamActionAttemptFailedError $e) {
63-
$this->assertEquals($action_attempt->action_attempt_id, $e->actionAttempt->action_attempt_id);
64-
$this->assertEquals("error", $e->actionAttempt->status);
65-
$this->assertEquals("foo", $e->errorCode);
63+
$this->assertEquals($action_attempt->action_attempt_id, $e->getActionAttempt()->action_attempt_id);
64+
$this->assertEquals("error", $e->getActionAttempt()->status);
65+
$this->assertEquals("failed_attempt", $e->getErrorCode());
6666
$this->assertEquals("Failed", $e->getMessage());
6767
}
6868
}
@@ -92,8 +92,8 @@ public function testTimeoutActionAttempt(): void
9292
$seam->action_attempts->poll_until_ready($action_attempt->action_attempt_id, 0.1);
9393
$this->fail("Expected TimeoutError");
9494
} catch (\Seam\SeamActionAttemptTimeoutError $e) {
95-
$this->assertEquals($action_attempt->action_attempt_id, $e->actionAttempt->action_attempt_id);
96-
$this->assertEquals("pending", $e->actionAttempt->status);
95+
$this->assertEquals($action_attempt->action_attempt_id, $e->getActionAttempt()->action_attempt_id);
96+
$this->assertEquals("pending", $e->getActionAttempt()->status);
9797
$this->assertEquals("Timed out waiting for action attempt after 0.1s", $e->getMessage());
9898
}
9999
}

tests/ClientSessionsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Tests\Fixture;
7-
use GuzzleHttp\Client;
87

98
final class ClientSessionsTest extends TestCase
109
{

tests/ConnectWebviewsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Tests\Fixture;
7-
use GuzzleHttp\Client;
87

98
final class ConnectWebviewsTest extends TestCase
109
{

tests/ConnectedAccountsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testDeleteConnectedAccount(): void
4848
} catch (\Seam\SeamHttpApiError $exception) {
4949
$this->assertTrue(
5050
str_contains(
51-
$exception->errorCode,
51+
$exception->getErrorCode(),
5252
"connected_account_not_found"
5353
)
5454
);

tests/DevicesTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Tests\Fixture;
7-
use GuzzleHttp\Client;
87

98
final class DevicesTest extends TestCase
109
{
@@ -47,9 +46,9 @@ public function testGetAndListDevices(): void
4746
$seam->devices->get(device_id: $device_id);
4847

4948
$this->fail("Expected the device to be deleted");
50-
} catch (Exception $exception) {
49+
} catch (\Seam\SeamHttpApiError $exception) {
5150
$this->assertTrue(
52-
str_contains($exception->errorCode, "device_not_found")
51+
str_contains($exception->getErrorCode(), "device_not_found")
5352
);
5453
}
5554

tests/EventsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Tests\Fixture;
7-
use GuzzleHttp\Client;
87

98
final class EventsTest extends TestCase
109
{
@@ -38,7 +37,7 @@ public function testListEventsError(): void
3837
$seam = Fixture::getTestServer();
3938
try {
4039
$seam->events->list(since: "invalid_date");
41-
} catch (Exception $e) {
40+
} catch (\Seam\SeamHttpInvalidInputError $e) {
4241
$this->assertTrue(
4342
str_contains($e->getMessage(), "Must be parsable date string")
4443
);

0 commit comments

Comments
 (0)