From 3ceb5f0254b5b278835f18793c03031686699c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Tue, 20 Aug 2019 13:02:20 +0200 Subject: [PATCH] #409 README: Add with assert description + example --- readme.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 223a4d04..8480c135 100644 --- a/readme.md +++ b/readme.md @@ -111,6 +111,7 @@ This table shows all assertions (class `Assert` means `Tester\Assert`): - `Assert::match($pattern, $value)` - Compares result using regular expression or mask. - `Assert::matchFile($file, $value)` - Compares result using regular expression or mask sorted in file. - `Assert::count($count, $value)` - Reports an error if number of items in $value is not $count. +- `Assert::with($objectOrClass, $closure)` - Executes function that can access private and protected members of given object via $this. Testing exceptions: @@ -123,7 +124,6 @@ Assert::exception(function () { Testing PHP errors, warnings or notices: - ```php Assert::error(function () { $h = new Greeting; @@ -131,6 +131,16 @@ Assert::error(function () { }, E_NOTICE, 'Undefined property: Greeting::$abc'); ``` +Testing private access methods: + +```php +$h = new Greeting; +Assert::with($h, function () { + // normalize() is internal private method. + Assert::same('Hello David', $this->normalize('Hello david')); // $this is Greeting +}); +``` + Tips and features -----------------