You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for Lazy assertions / assertions chains #169
I'd love to see this for this package, but i'm not sure how to go about that without a BC break. If you can create a PR that would allow this functionality, or allow for an easy upgrade path then id like it.
I'd like to see this in this package too. I actually have an implementation for this. I'll see if it can be easily integrated and make a merge request.
Reacted by Michael Zangerle, Andrii Dembitskyi and Stéphane FEREY
Chainability could be introduced without breaking any existing code with a new class that serves as a proxy to Assert's static functions. The value under assertion would be passed through a constructor either directly or through a helper on Assert (Assert::that($variable), Assert::chain($variable)). It would then leverage the magic __call method to pass the arguments onto Assert.
generate.php could call a new script to add @method declarations to this new AssertionChain classes to make sure that intellisense works. This would keep the documentation and the AssertionChain dependent on Assert.php and would not require upkeep since it is generated off of the main class
/**
* @method void integer(string $message = '') // Generated by script in bin/
*/
class AssertionChain
{
public function __construct($value)
{
$this->value;
}
public function getValue()
{
return $this->value;
}
public function __call($method, array $arguments)
{
array_unshift($this->value, $arguments);
Assert::$method($arguments);
return $this;
}
}
class Assert
{
public static function chain($value)
{
return new AssertionChain($value);
}
}
Activity
BackEndTea commentedon Mar 14, 2020
I'd love to see this for this package, but i'm not sure how to go about that without a BC break. If you can create a PR that would allow this functionality, or allow for an easy upgrade path then id like it.
arjanfrans commentedon Mar 29, 2022
I'd like to see this in this package too. I actually have an implementation for this. I'll see if it can be easily integrated and make a merge request.
mindofmicah commentedon Oct 4, 2023
Chainability could be introduced without breaking any existing code with a new class that serves as a proxy to Assert's static functions. The value under assertion would be passed through a constructor either directly or through a helper on Assert (Assert::that($variable), Assert::chain($variable)). It would then leverage the magic __call method to pass the arguments onto Assert.
generate.php could call a new script to add @method declarations to this new AssertionChain classes to make sure that intellisense works. This would keep the documentation and the AssertionChain dependent on Assert.php and would not require upkeep since it is generated off of the main class
shadowhand commentedon Oct 21, 2025
I think this becomes much easier with PHP 8.5 pipe operator if we implement #280