Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ConvertTime Class with Time Conversion Functionality and Unit Tests #177

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

arafat-web
Copy link

Description:
This pull request introduces the ConvertTime class, providing a robust time conversion function alongside a complete suite of unit tests to ensure accurate and reliable operation.

Key Features:

  • convertTime Function: Converts a specified value between various time units (e.g., seconds, minutes, hours, days, weeks, months, and years) using predefined conversion factors.
  • Exception Handling: Throws clear exceptions for invalid input units, enhancing user feedback and preventing errors.
  • PSR-12 Compliance: The code adheres to PSR-12 standards, ensuring readability and maintainability.

Unit Tests:

The ConvertTimeTest class covers the following:

  • Basic Conversion Tests: Verifies correct conversions between time units.
  • Edge Case Handling: Tests zero-value conversions for non-negative results.
  • Invalid Unit Handling: Tests exception handling for invalid from and to units with descriptive error messages.

This addition enhances functionality by enabling easy and accurate time conversions while ensuring reliability through comprehensive testing.

@arafat-web arafat-web changed the title Add ConvertTime Class with Comprehensive Time Conversion Functionality and Unit Tests Add ConvertTime Class with Time Conversion Functionality and Unit Tests Oct 30, 2024
Comment on lines +85 to +91
// Example usage
try {
$timeResult = convertTime(120, 'minutes', 'seconds');
echo "120 minutes = $timeResult seconds\n";
} catch (InvalidArgumentException $e) {
echo "Error: " . $e->getMessage() . "\n";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep examples like this in the test code, with assertions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants