/**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('urlshortener.factory', Drivers\Factory::class);
     $this->app->singleton('urlshortener', function ($app) {
         $shortener = new UrlShortener($app['urlshortener.factory']);
         $shortener->setDriver($app['config']->get('urlshortener.driver'));
         return $shortener;
     });
 }
Example #2
0
 /**
  *  @test
  *  @expectedException \Waavi\UrlShortener\Exceptions\InvalidResponseException
  */
 public function it_throws_invalid_response_exception_on_invalid_api_response()
 {
     $factory = Mockery::mock(Factory::class);
     $driver = Mockery::mock(BaseDriver::class);
     $shortener = new UrlShortener($factory);
     $factory->shouldReceive('make')->with('driverName')->andReturn($driver);
     $shortener->setDriver('driverName');
     $driver->shouldReceive('expand')->with('http://google.com')->andThrow(new \Mremi\UrlShortener\Exception\InvalidApiResponseException());
     $shortener->expand('http://google.com');
 }
Example #3
0
 /**
  *  Creates a new URL Shortener instance with the given driver name.
  *  Useful for chained calls using the facade when a different driver is to be used for just one request.
  *
  *  @param  string $driverName
  *  @return UrlShortener
  */
 public function driver($driverName)
 {
     $shortener = new UrlShortener($this->driverFactory);
     $shortener->setDriver($driverName);
     return $shortener;
 }