•  
      request #42633 Disallow usage of self::once() in tests
    Infos
    #42633
    Kevin Traini (ktraini)
    2025-04-16 15:42
    2025-04-16 11:39
    44308
    Details
    Disallow usage of self::once() in tests

    When using a PHPUnit mock, you can do this:

    $mock = $this->createMock(MyClass::class);
    $mock->expects(self::once())->method('myMethod');
    

    But method once is not static, you should use $this->once(). Same for other invocation count checker (never, exactly, atLeastOnce, ...)

    Add a PHPCS sniffer to check and fix

    Empty
    Empty
    Empty
    • [ ] enhancement
    • [ ] internal improvement
    Empty
    Stage
    Kevin Traini (ktraini)
    Closed
    2025-04-16
    Attachments
    Empty
    References
    Referencing request #42633

    Follow-ups