[PR #121] [MERGED] Made all exceptions inherit from a base exception #626

Closed
opened 2026-03-14 12:16:50 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/antonioribeiro/google2fa/pull/121
Author: @poisa
Created: 6/22/2019
Status: Merged
Merged: 6/24/2019
Merged by: @antonioribeiro

Base: masterHead: new-base-exception


📝 Commits (2)

  • e3e0d42 Made all exceptions inherit from a base exception
  • 513060b Made exceptions implement an interface instead of inheriting from a base exception

📊 Changes

5 files changed (+35 additions, -31 deletions)

View changed files

src/Exceptions/Google2FAExceptionInterface.php (+8 -0)
📝 src/Exceptions/IncompatibleWithGoogleAuthenticatorException.php (+1 -1)
📝 src/Exceptions/InvalidCharactersException.php (+1 -1)
📝 src/Exceptions/SecretKeyTooShortException.php (+1 -1)
📝 tests/Google2FATest.php (+24 -28)

📄 Description

Implements changes proposed in #115.

Currently you have to catch every single exception this package throws. If you make a generic exception, say Google2FAException and have all other exceptions extend this one it is much easier for consumers of this package to catch anything thrown by it. Sometimes you don't care exactly what exception was thrown but you'd like to identify the general area (or package) of the problem.

Changes in tests:

Unit tests used the @expectedException to test for exceptions. There is nothing wrong with this approach except that we now want to test two things:

  1. That the exception is a subclass of Google2FAException
  2. That the exception is an instance of each particular exception.

In order to achieve both, I wrapped the test calls in a try/catch block which catches with the generalized exception, and then checks for the specific exception.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/antonioribeiro/google2fa/pull/121 **Author:** [@poisa](https://github.com/poisa) **Created:** 6/22/2019 **Status:** ✅ Merged **Merged:** 6/24/2019 **Merged by:** [@antonioribeiro](https://github.com/antonioribeiro) **Base:** `master` ← **Head:** `new-base-exception` --- ### 📝 Commits (2) - [`e3e0d42`](https://github.com/antonioribeiro/google2fa/commit/e3e0d4270fe6d87d3092d057cde6d738aa5625d0) Made all exceptions inherit from a base exception - [`513060b`](https://github.com/antonioribeiro/google2fa/commit/513060b67d13584b3430b71999fd67ea4888f09c) Made exceptions implement an interface instead of inheriting from a base exception ### 📊 Changes **5 files changed** (+35 additions, -31 deletions) <details> <summary>View changed files</summary> ➕ `src/Exceptions/Google2FAExceptionInterface.php` (+8 -0) 📝 `src/Exceptions/IncompatibleWithGoogleAuthenticatorException.php` (+1 -1) 📝 `src/Exceptions/InvalidCharactersException.php` (+1 -1) 📝 `src/Exceptions/SecretKeyTooShortException.php` (+1 -1) 📝 `tests/Google2FATest.php` (+24 -28) </details> ### 📄 Description Implements changes proposed in #115. > Currently you have to catch every single exception this package throws. If you make a generic exception, say `Google2FAException` and have all other exceptions extend this one it is much easier for consumers of this package to catch anything thrown by it. Sometimes you don't care exactly what exception was thrown but you'd like to identify the general area (or package) of the problem. ### Changes in tests: Unit tests used the `@expectedException` to test for exceptions. There is nothing wrong with this approach except that we now want to test two things: 1) That the exception is a subclass of `Google2FAException` 2) That the exception is an instance of each particular exception. In order to achieve both, I wrapped the test calls in a try/catch block which catches with the generalized exception, and then checks for the specific exception. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-14 12:16:50 +03:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/google2fa#626
No description provided.