public function testLeadSourceIndex()
 {
     // Given
     $mockNumberList = Mockery::mock();
     $mockNumber = Mockery::mock();
     $mockNumber->friendly_name = '(555) 444 444';
     $mockNumber->region = 'Some region';
     $mockNumber->phone_number = '+1555444444';
     $mockNumbers = [$mockNumber];
     $mockNumberList->available_phone_numbers = $mockNumbers;
     $mockTwilio = Mockery::mock('Services_Twilio');
     $mockTwilio->account = Mockery::mock();
     $mockTwilio->account->available_phone_numbers = Mockery::mock();
     $mockTwilio->account->available_phone_numbers->shouldReceive('getList')->with('US', 'Local', ['AreaCode' => null])->andReturn($mockNumberList);
     App::instance('Twilio', $mockTwilio);
     $newLeadSource = new LeadSource(['number' => '+136428733', 'description' => 'Some billboard somewhere', 'forwarding_number' => '+13947283']);
     $newLeadSource->save();
     // When
     $newResponse = $this->call('GET', route('dashboard'));
     // Then
     $newLeadSources = $newResponse->getOriginalContent()['leadSources'];
     $this->assertCount(1, $newLeadSources);
     $this->assertEquals($newLeadSources[0]['number'], '+136428733');
     $this->assertEquals($newLeadSources[0]['description'], 'Some billboard somewhere');
     $this->assertEquals($newLeadSources[0]['forwarding_number'], '+13947283');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->except("_token");
     $data['user']['id'] = 1;
     App::instance(SmsCourierInterface::class, new Mitake_SMS($this->apiKey));
     event(new SendSMSEvent($data));
     $user = User::find($data['user']['id']);
     echo "<pre>";
     return json_encode($user->sms()->get(), JSON_PRETTY_PRINT);
 }
 public function testIndex()
 {
     // Given
     $mockNumber = Mockery::mock();
     $mockNumber->friendlyName = '(555) 444 444';
     $mockNumber->region = 'Some region';
     $mockNumber->phoneNumber = '+1555444444';
     $mockNumbers = [$mockNumber];
     $mockTwilioClient = Mockery::mock(Client::class);
     $mockUsPhones = Mockery::mock();
     $mockTwilioClient->shouldReceive("availablePhoneNumbers")->withAnyArgs("US")->andReturn($mockUsPhones);
     $mockUsPhones->local = Mockery::mock();
     $mockUsPhones->local->shouldReceive('stream')->andReturn($mockNumbers);
     App::instance(Client::class, $mockTwilioClient);
     //Then
     $this->visit(route('available_number.index'))->assertViewHas("numbers", $mockNumbers);
 }
 public function testDestroy()
 {
     // Given
     Session::start();
     $this->assertCount(0, LeadSource::all());
     $newLeadSource = new LeadSource(['number' => '+136428733', 'description' => 'Some billboard somewhere', 'forwarding_number' => '+13947283']);
     $newLeadSource->save();
     $this->assertCount(1, LeadSource::all());
     $mockNumber = Mockery::mock();
     $mockNumber->sid = 'sup3runiq3s1d';
     $mockTwilioClient = Mockery::mock(Client::class);
     $mockPhoneToDelete = Mockery::mock(IncomingPhoneNumberInstance::class);
     $mockPhoneToDelete->shouldReceive("delete")->once();
     $mockTwilioClient->incomingPhoneNumbers = Mockery::mock(IncomingPhoneNumberList::class);
     $mockTwilioClient->incomingPhoneNumbers->shouldReceive('read')->withAnyArgs()->once()->andReturn([0 => $mockPhoneToDelete]);
     App::instance(Client::class, $mockTwilioClient);
     // When
     $response = $this->call('DELETE', route('lead_source.destroy', [$newLeadSource]), ['_token' => Session::token()]);
     // Then
     $this->assertCount(0, LeadSource::all());
 }
 /**
  * @test
  **/
 public function it_show_IfCanBeBoughtByTheCurrentUser()
 {
     $authenticator = m::mock('StdClass')->shouldReceive("check")->once()->andReturn(true)->shouldReceive('hasGroup')->andReturn(true)->getMock();
     App::instance('authenticator', $authenticator);
     $presenter = new PresenterProducts([]);
     $can_buy = $presenter->canBeBought();
     $this->assertTrue($can_buy);
 }
 private function mockGetTokenWithError()
 {
     $mock_auth = m::mock('StdClass')->shouldReceive('getToken')->once()->andThrow(new UserNotFoundException())->getMock();
     App::instance('authenticator', $mock_auth);
 }
 /**
  * Prepares / Disables route middlewares.
  *
  * @param  bool $disable
  *
  * @return  void
  */
 public function prepareMiddleware($disable = true)
 {
     App::instance('middleware.disable', true);
 }