ohffs's avatar
Level 50

Basic http test of file download route?

In the olden days I used to be able to do things like :

$response = $this->get(route('user.whatever', $user->id));
$this->assertEquals(true, $response->getFile()->whatever());

But now if I try with the newer tests I get an UnexpectedValueException: The Response content must be a string or object implementing __toString(), "boolean" given. back from phpunit.

$response = $this->get(route('user.whatever', $user->id));

I can't see any way around it in the docs or in the framework code - there doesn't seem to be a way of testing for file downloads without running them through Dusk - or am I missing something?

0 likes
10 replies
ohffs's avatar
Level 50

@SaeedPrez yeah - I'm trying to avoid relying on browserkit as it feels like it's 'deprecated' (certainly doesn't get any mention in the docs outside of the upgrade guide).

Just tried writing the same thing in Dusk and discovered there doesn't seem to be any built-in way of checking file downloads with it either.

Super....

At this rate I'm going to end up doing a file_get_contents() and testing against that :-/

SaeedPrez's avatar

Hm, should write to Adam Wathan on Twitter/email, he should know..

I was building my 5.3 project the TDD way, then I upgraded it to 5.4 mid way and I haven't touched the tests since,..

Have to fix all tests before release..

ohffs's avatar
Level 50

@SaeedPrez yeah - I might prod him on the GitHub page for the TDD course. I feel a bit guilty randomly prodding folk on twitter sometimes - I imagine it can be a bit over-loaded if you're well-known.

The migration to 5.4 went fine for me until the testing stuff - I've been at this for days now and I still feel like I'm 'doing it wrong'. I'm going to end up with lots of duplicated tests just because doing the 'interacting with the app' parts in dusk is so slow to run so I have plain http post/get + assertions covering the much the same things.

Hey ho :'-/

SaeedPrez's avatar

@ohffs good idea, he did say we (customers of TDD course) should contact him if we have any questions..

All this test talk got my brain thinking about tests, I'll try Dusk today, see if I can update all my tests..

ohffs's avatar
Level 50

@SaeedPrez dusk is fine (if slow) for a lot of stuff. If my apps were more JS-heavy I think I'd be over the moon with it. This app that I decided to migrate to 5.4 has zero JS in it - so all I really get from Dusk is a 10x slowdown :-/

SaeedPrez's avatar

The documentation looks awesome, what Dusk can do.. but for simple uses, I can see the benefits of BrowserKit, especially if there is 10x speed difference..

1 like

Please or to participate in this conversation.