Example #1
0
 /**
  * Registers services on the given container.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Container $pimple A container instance
  */
 public function register(Container $pimple)
 {
     $pimple['js'] = function ($pimple) {
         $js = new Js($pimple['access_token']);
         $js->setCache($pimple['cache']);
         return $js;
     };
 }
 private function registerJs()
 {
     $this->app->singleton('wechat.js', function () {
         $js = new Js(app('wechat.accesstoken'));
         $js->setCache(app('wechat.cache'));
         return $js;
     });
 }
Example #3
0
 /**
  * Test ticket().
  */
 public function testTicket()
 {
     $http = $this->getMockHttp();
     $cache = $this->getMockCache();
     $cache->shouldReceive('fetch')->andReturn('foo');
     $accessToken = $this->getMockAccessToken();
     $js = new Js($accessToken);
     $js->setCache($cache);
     $js->setHttp($http);
     $js->setUrl('http://easywechat.org');
     $this->assertEquals('foo', $js->ticket());
     $http = $this->getMockHttp();
     $cache = $this->getMockCache();
     $cache->shouldReceive('fetch')->andReturnUsing(function ($key) {
         return 'overtrue.ticket';
     });
     $cache->shouldReceive('set')->andReturnUsing(function ($key, $ticket, $expires) {
         return $ticket;
     });
     $http->shouldReceive('get')->andReturn(['ticket' => 'overtrue.ticket', 'expires_in' => 7200]);
     $accessToken = $this->getMockAccessToken();
     $js = new Js($accessToken);
     $js->setCache($cache);
     $js->setHttp($http);
     $this->assertEquals('overtrue.ticket', $js->ticket());
 }