JeffreyWay / Laravel-Testing-Decoded

This project is exclusively for reporting typos and errors in the book, "Laravel Testing Decoded."
34 stars 10 forks source link

Array is treated as string in Chapter 5, pp.57-58 (PDF version) #83

Open tolgamorf opened 11 years ago

tolgamorf commented 11 years ago

In Chapter 5: Unit Testing 101, Section: Making the Test Pass, pages: 57 and 58 (PDF version):

The signature of the function link_to() causes $parameters variable to be treated as a string and PHPUnit gives the following error:

- INFO - PHPUnit 3.7.22 by Sebastian Bergmann.
> [#] 
> [#] Configuration read from /Users/tolga/Sites/lesson/phpunit.xml
> [#] 
> [#] {"error":{"type":"ErrorException","message":"Invalid argument supplied for foreach()","file":"\/Users\/tolga\/Sites\/lesson\/app\/helpers.php","line":8}}

Signature of the function

function link_to($url, $body, $parameters = null)

line where error occurs

foreach($parameters as $attribute => $value)

I am not sure if this error occurs due to a configuration flag in my PHP installation (using 5.5.1), but it can be fixed by either using $parameters = array() or $parameters = [] for the last argument.