function testCreate() { // Given $this->startSession(); $userData = ['name' => 'Captain Kirk', 'email' => '*****@*****.**', 'password' => 'strongpassword', 'country_code' => '1', 'phone_number' => '5558180101']; $newUser = new User($userData); $newUser->save(); $this->be($newUser); $propertyData = ['description' => 'Some description', 'image_url' => 'http://www.someimage.com']; $newProperty = new VacationProperty($propertyData); $newUser->properties()->save($newProperty); $this->assertCount(0, Reservation::all()); $mockTwilioClient = Mockery::mock(Client::class)->makePartial(); $mockTwilioMessages = Mockery::mock(); $mockTwilioClient->messages = $mockTwilioMessages; $twilioNumber = config('services.twilio')['number']; $mockTwilioMessages->shouldReceive('create')->with($newUser->fullNumber(), ['from' => $twilioNumber, 'body' => 'Some reservation message - Reply \'yes\' or \'accept\' to confirm the reservation, or anything else to reject it.'])->once(); $this->app->instance(Client::class, $mockTwilioClient); // When $response = $this->call('POST', route('reservation-create', ['id' => $newProperty->id]), ['message' => 'Some reservation message', '_token' => csrf_token()]); // Then $this->assertCount(1, Reservation::all()); $reservation = Reservation::first(); $this->assertEquals($reservation->message, 'Some reservation message'); $this->assertRedirectedToRoute('property-show', ['id' => $newProperty->id]); $this->assertSessionHas('status'); $flashreservation = $this->app['session']->get('status'); $this->assertEquals($flashreservation, "Sending your reservation request now."); }