Maybe show us the bit of code that is causing the problem?
Unit Testing and Redis: enemies of fun
I'm testing a json api, and the methods for creating the test couldn't be easier, however, I'm running into a snag:
Part of the function that I'm testing calls another controller that stashes some data into a redis database, (it's part of a pestering campaign (like a drip campaign, but pushy)). When I use the app normally, everything is gravy, testing in Postman, still gravy.
However, when I start to test, I get some errors about Connection Refused.
Test code:
$faker = Faker::create();
$this->post('/create-user', [
'email' => $faker->email,
'password' => $faker->md5
])->seeJson(['uuid']);
And the response:
1) UserTest::testCreate
Unable to find JSON fragment [["uuid"]] within [{"error":{"fields":null,"general":"Connection refused [tcp:\/\/127.0.0.1:6379]"}}].
Failed asserting that false is true.
/if5/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:261
/if5/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:220
/if5/tests/UserTest.php:22
The method I'm testing:
$uuid = substr(sha1(microtime()), 0, 12);
$user = new User;
$user->email = Input::get('email');
$user->password = Input::get('password');
$user->uuid = $uuid;
$user->confirmation_token = md5(microtime());
if (!$user->save()) {
return Response::error('Could not create new user.', $user->getErrors(), 400);
}
$bitfields = BitfieldController::createBitfield($uuid);
The last line is where I get Redis into the mix. How should I proceed with making this test?
Thanks!!
Yeah, that's what it was, needed to run inside homestead. Closing this and hanging my head in shame....
Please or to participate in this conversation.