{"id":9427,"date":"2021-01-14T11:23:32","date_gmt":"2021-01-14T16:23:32","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=9427"},"modified":"2021-01-14T11:23:32","modified_gmt":"2021-01-14T16:23:32","slug":"laravel-8-22-release-with-new-event-fake-assertion","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/laravel-8-22-release-with-new-event-fake-assertion\/","title":{"rendered":"Laravel 8.22 Release With new Event Fake Assertion Announced"},"content":{"rendered":"\n
Laravel 8.22 release with a new event fake assertion, a collection method to reduce associative arrays to a single value has been announced.<\/p>\n\n\n\n
This new release also comes with several fixes and improvements.<\/p>\n\n\n\n
Laravel 8.22 comes with a new assertion assertNothingDispatched()<\/strong> to Event::fake()<\/strong> mock. Currently, all the assertion for Events require a specific event to be provided, this will catch “any” event. See example:<\/p>\n\n\n [php] foo(false); \/\/ Function that should NOT dispatch any event<\/p>\n Event::assertNothingDispatched(); <\/p>\n\n\n\n Add reduce with keys to collections and lazy collections features adds the method reduceWithKeys <\/strong><\/em>to Collections and LazyCollections<\/strong><\/em>.<\/p>\n\n\n\n Similar to map and mapWithKeys<\/strong><\/em>, this augments reduce to pass associative arrays’ keys to its callback. We can’t do that currently because PHP<\/a>‘s array_reduce doesn’t pass array keys to its callback. See example:<\/p>\n\n\n [php] return $data->reduceWithKeys(function($carry, $value, $key) { Fixes in this release include a fixed error from missing null check on PHP 8 in Illuminate\\Validation\\Concerns\\ValidatesAttributes::validateJson()<\/strong>. A bug with RetryCommand can happen if retryUntil <\/strong><\/em>doesn’t return a DateTimeInterface object but rather an integer timestamp or null.<\/p>\n\n\n\n Issues in Illuminate\\Testing\\PendingCommand::expectsTable()<\/strong> have been fixed as is the same with morphTo()<\/strong> attempting to map an empty string morph type to an instance.<\/p>\n\n\n\n For these and more about Laravel 8.22 release please visit the changelog here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" Laravel 8.22 release with a new event fake assertion, a collection method to reduce associative arrays to a single value has been announced. This new release also comes with several…<\/p>\n","protected":false},"author":1,"featured_media":9428,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,13,27,16],"tags":[252,344,350,424,452],"yoast_head":"\n
\nEvent::fake();<\/p>\n
\n[\/php]<\/p>\n\n\n\n
\n$data = collect([
\n ‘name’ => ‘Mo Khosh’,
\n ‘username’ => ‘mokhosh’,
\n]);<\/p>\n
\n return $carry . $key . ‘: ‘ . $value . PHP_EOL;
\n});
\n[\/php]<\/p>\n\n\n\n