nothingworksinc / ticketbeast

Back to the lesson videos:
https://course.testdrivenlaravel.com/lessons
552 stars 11 forks source link

Stuck in concerts_with_a_published_at_date_are_published test because of PHP error #81

Open bigweld86 opened 6 years ago

bigweld86 commented 6 years ago

Hi. I started my tests as recomended in the videos, using Laravel 5.3. When working on the test concerts_with_a_published_at_date_are_published I'm getting an issue, according to what I have found online, it is related to PHP7.2.

Here's the issue:


F...E                                                              6 / 6 (100%)

Time: 480 ms, Memory: 18.00MB

There was 1 error:

1) ConcertTest::concerts_with_a_published_at_date_are_published
ErrorException: count(): Parameter must be an array or an object that implements Countable

/Users/bigweld/Sites/ticketbeast/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1231
/Users/bigweld/Sites/ticketbeast/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1466
/Users/bigweld/Sites/ticketbeast/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3561
/Users/bigweld/Sites/ticketbeast/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3573
/Users/bigweld/Sites/ticketbeast/tests/unit/ConcertTest.php:68

--

There were 2 failures:

1) ViewConcertListingTest::test_user_can_view_a_published_concert_listing
A request to [http://localhost/concerts/1] failed. Received status code [500].

/Users/bigweld/Sites/ticketbeast/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:222
/Users/bigweld/Sites/ticketbeast/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:92
/Users/bigweld/Sites/ticketbeast/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:61
/Users/bigweld/Sites/ticketbeast/tests/features/ViewConcertListingTest.php:34

Caused by
ErrorException: count(): Parameter must be an array or an object that implements Countable in /Users/bigweld/Sites/ticketbeast/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1231

Is there a way to solve this without modifying the PHP version? I tried updating to Laravel 5.4 and followed the steps related to using BrowserKitTest but that didn't work either.

Thanks, Sebastian

drbyte commented 6 years ago

Which lesson/commit are you working with? I tried going through the github repo to figure out how you could be triggering that error on line 68 of ConcertTest.php, and gave up after several dozen times seeing things off by 10+ lines.

bigweld86 commented 6 years ago

@drbyte I'm in the lesson named Testing Query Scopes

bigweld86 commented 6 years ago

Everything up to this lesson was fine. This is the part that's failing:

$publishedConcerts = Concert::published()->get();

Here's the scope in the Model:

public function scopePublished($query)
    {
        return $query->whereNotNull('published_at');
    }

And here's the call in the controller:

$concert = Concert::published()->findOrFail($id);

I've checked multiple times and the code is exactly the one from the lecture.

Thanks.

drbyte commented 6 years ago

I think yours is a PHP 7.2 limitation, which requires a Laravel version that's been updated for compatibility.

https://github.com/laravel/framework/blame/5.3/src/Illuminate/Database/Eloquent/Builder.php#L1231 https://github.com/laravel/framework/blame/5.4/src/Illuminate/Database/Eloquent/Builder.php#L936 https://github.com/laravel/framework/pull/20258/files

I realize that bumping up to Laravel 5.5 is a bigger leap until you get through several more lessons to the one where Adam does a big refactor for that.

Consuming the rest of this course will be easier if you can downgrade to PHP 7.1.

bigweld86 commented 6 years ago

@drbyte I just downgrade to PHP 7.1 and it worked fine! Thanks a lot (y)!!!

adamwathan commented 5 years ago

Just in case anyone else is following along using 5.3 and runs into this issue, the easiest way to get around it is to use the latest unreleased version of Laravel 5.3.

Run this in your terminal:

composer require laravel/framework:5.3.x-dev

...or change your laravel/framework dependency in your composer.json file to 5.3.x-dev.

madsem commented 5 years ago

@adamwathan this note for php7.2 users should really be included in the beginning of the course, where you include the composer command to install Laravel 5.3... :)

Just ran into the same issue, luckily I just installed Valet a couple days ago so it was only a valet use php7.1

Thanks for this course btw, it rocks, super happy and already learned a bunch of cool things.