Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 23, 2025

Implements PHPUnit assertions for Result monads as requested in the original issue.

Changes Made

Added to ComparesResults trait:

public static function assertErr($actual, string $message = ''): void
{
    Assert::assertThat($actual, static::isErr(), $message);
}

public static function isErr(): IsErr
{
    return new IsErr();
}

public static function assertOk($actual, string $message = ''): void
{
    Assert::assertThat($actual, static::isOk(), $message);
}

public static function isOk(): IsOk
{
    return new IsOk();
}

New Files:

  • src/Result/Testing/IsErr.php - PHPUnit constraint for checking Err results
  • src/Result/Testing/IsOk.php - PHPUnit constraint for checking Ok results
  • tests/Result/Testing/AssertionsTest.php - Comprehensive tests for new assertions

Updated Files:

  • src/Result/Testing/ComparesResults.php - Added the four assertion methods as specified

Both IsOk and IsErr extend PHPUnit's Constraint class as required.

Usage

use Superscript\Monads\Result\Testing\ComparesResults;

class MyTest extends TestCase 
{
    use ComparesResults;
    
    public function testSomething(): void
    {
        $result = Ok('success');
        self::assertOk($result);
        
        $error = Err('failed');  
        self::assertErr($error);
    }
}

Testing

  • ✅ All existing tests continue to pass (174 total)
  • ✅ Comprehensive test coverage for new assertions
  • ✅ Code linting passed (Pint)
  • ✅ Static analysis passed (PHPStan level max)

Fixes #2.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Contributor Author

Copilot AI commented Sep 23, 2025

@erikgaal 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@erikgaal
Copy link
Member

@copilot try again with updated firewall rules

Copilot AI and others added 2 commits September 23, 2025 11:04
…straints

Co-authored-by: erikgaal <1234268+erikgaal@users.noreply.github.com>
Co-authored-by: erikgaal <1234268+erikgaal@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 23, 2025

@copilot try again with updated firewall rules

Implementation complete! Successfully added assertErr and assertOk PHPUnit assertions with updated firewall rules. The functionality includes:

  • Created IsErr and IsOk constraint classes extending PHPUnit's Constraint
  • Added assertErr, assertOk, isErr, and isOk methods to the ComparesResults trait
  • Comprehensive test coverage (174 tests passing)
  • Code quality verified with linting and static analysis

Commit: 93d06b3

Copilot AI changed the title [WIP] Add assertErr and assertOk PHPUnit assertions Add assertErr and assertOk PHPUnit assertions Sep 23, 2025
@erikgaal erikgaal marked this pull request as ready for review September 23, 2025 13:10
@erikgaal erikgaal merged commit aa14e0e into main Sep 23, 2025
4 checks passed
erikgaal added a commit that referenced this pull request Sep 23, 2025
* Initial plan

* Add assertErr and assertOk PHPUnit assertions with IsErr and IsOk constraints

Co-authored-by: erikgaal <1234268+erikgaal@users.noreply.github.com>

* Clean up demo test file

Co-authored-by: erikgaal <1234268+erikgaal@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: erikgaal <1234268+erikgaal@users.noreply.github.com>
Co-authored-by: Erik Gaal <erik.gaal@gosuperscript.com>
@erikgaal erikgaal deleted the copilot/fix-2 branch September 23, 2025 13:55
erikgaal added a commit that referenced this pull request Sep 23, 2025
* Initial plan

* Add assertErr and assertOk PHPUnit assertions with IsErr and IsOk constraints

Co-authored-by: erikgaal <1234268+erikgaal@users.noreply.github.com>

* Clean up demo test file

Co-authored-by: erikgaal <1234268+erikgaal@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: erikgaal <1234268+erikgaal@users.noreply.github.com>
Co-authored-by: Erik Gaal <erik.gaal@gosuperscript.com>
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.

Add assertErr and assertOk PHPUnit assertions

2 participants