diff --git a/tests/Assert/Tests/ContextAwareLazyAssertion.php b/tests/Assert/Tests/ContextAwareLazyAssertionTest.php similarity index 91% rename from tests/Assert/Tests/ContextAwareLazyAssertion.php rename to tests/Assert/Tests/ContextAwareLazyAssertionTest.php index 570db2d7..3cde9fd2 100644 --- a/tests/Assert/Tests/ContextAwareLazyAssertion.php +++ b/tests/Assert/Tests/ContextAwareLazyAssertionTest.php @@ -20,7 +20,7 @@ use Assert\Tests\Fixtures\ContextAware\LazyAssertion; use PHPUnit\Framework\TestCase; -class ContextAwareLazyAssertion extends TestCase +class ContextAwareLazyAssertionTest extends TestCase { public function testContextIsPassedThroughToExceptions() { @@ -28,7 +28,8 @@ public function testContextIsPassedThroughToExceptions() /** @var LazyAssertion $assertion */ $assertion = Assert::lazy(); $assertion->tryAll() - ->that(true, '', null, $context) + ->that(true, '', null) + ->withContext($context) ->false() ->null(); diff --git a/tests/Assert/Tests/Fixtures/ContextAware/Assert.php b/tests/Assert/Tests/Fixtures/ContextAware/Assert.php index b61a4950..2b84f0ee 100644 --- a/tests/Assert/Tests/Fixtures/ContextAware/Assert.php +++ b/tests/Assert/Tests/Fixtures/ContextAware/Assert.php @@ -15,6 +15,8 @@ namespace Assert\Tests\Fixtures\ContextAware; use Assert\Assert as BaseAssert; +use Assert\AssertionChain as BaseAssertionChain; + class Assert extends BaseAssert { @@ -24,9 +26,9 @@ class Assert extends BaseAssert /** @var string */ protected static $lazyAssertionClass = LazyAssertion::class; - public static function that($value, $defaultMessage = null, $defaultPropertyPath = null, array $context = []) + public static function that($value, $defaultMessage = null, string $defaultPropertyPath = null): BaseAssertionChain { - $assertionChain = new AssertionChain($value, $defaultMessage, $defaultPropertyPath, $context); + $assertionChain = new AssertionChain($value, $defaultMessage, $defaultPropertyPath); return $assertionChain->setAssertionClassName(static::$assertionClass); } diff --git a/tests/Assert/Tests/Fixtures/ContextAware/AssertionChain.php b/tests/Assert/Tests/Fixtures/ContextAware/AssertionChain.php index 2b274bc7..e21facf7 100644 --- a/tests/Assert/Tests/Fixtures/ContextAware/AssertionChain.php +++ b/tests/Assert/Tests/Fixtures/ContextAware/AssertionChain.php @@ -21,9 +21,8 @@ class AssertionChain extends BaseAssertionChain /** @var array */ private $context; - public function __construct($value, $defaultMessage = null, $defaultPropertyPath = null, array $context = []) + public function setContext(array $context) { - parent::__construct($value, $defaultMessage, $defaultPropertyPath); $this->context = $context; } diff --git a/tests/Assert/Tests/Fixtures/ContextAware/LazyAssertion.php b/tests/Assert/Tests/Fixtures/ContextAware/LazyAssertion.php index 048001bd..3a5dcf89 100644 --- a/tests/Assert/Tests/Fixtures/ContextAware/LazyAssertion.php +++ b/tests/Assert/Tests/Fixtures/ContextAware/LazyAssertion.php @@ -18,17 +18,14 @@ class LazyAssertion extends BaseLazyAssertion { - /** @var string The class to use as AssertionChain factory */ - protected $assertClass = Assert::class; - /** @var AssertionChain */ - protected $currentChain; + public function __construct() + { + $this->assertClass = Assert::class; + } - public function that($value, $propertyPath, $defaultMessage = null, array $context = []) + public function withContext(array $context) { - $this->currentChainFailed = false; - $this->thisChainTryAll = false; - $assertClass = $this->assertClass; - $this->currentChain = $assertClass::that($value, $defaultMessage, $propertyPath, $context); + $this->currentChain->setContext($context); return $this; }