Exemplo n.º 1
0
 /**
  * @expectedException LeagueWrap\Exception\CacheNotFoundException
  */
 public function testRememberSummonerCacheOnlyNoHit()
 {
     $bakasan = file_get_contents('tests/Json/summoner.bakasan.json');
     $this->cache->shouldReceive('has')->once()->with('9bd8e5b11e0ac9c0a52d5711c9057dd2')->andReturn(false);
     $this->client->shouldReceive('baseUrl')->once();
     $api = new LeagueWrap\Api('key', $this->client);
     $api->remember(null, $this->cache)->setCacheOnly();
     $summoner = $api->summoner()->info('bakasan');
 }
Exemplo n.º 2
0
 public function testCaching5xxError()
 {
     $response = new LeagueWrap\Response('', 500);
     $exception = new LeagueWrap\Response\Http500('', 500);
     $this->cache->shouldReceive('set')->once()->with('9bd8e5b11e0ac9c0a52d5711c9057dd2', m::any(), 10)->andReturn(true);
     $this->cache->shouldReceive('has')->twice()->with('9bd8e5b11e0ac9c0a52d5711c9057dd2')->andReturn(false, true);
     $this->cache->shouldReceive('get')->once()->with('9bd8e5b11e0ac9c0a52d5711c9057dd2')->andReturn($exception);
     $this->client->shouldReceive('baseUrl')->twice();
     $this->client->shouldReceive('request')->with('na/v1.4/summoner/by-name/bakasan', ['api_key' => 'key'])->once()->andReturn($response);
     LeagueWrap\StaticApi::mount();
     $api = new LeagueWrap\Api('key', $this->client);
     $api->remember(10, $this->cache);
     $api->setServerErrorCaching();
     $summoner = $api->summoner();
     try {
         $summoner->info('bakasan');
     } catch (LeagueWrap\Response\Http500 $e) {
     }
     try {
         $summoner->info('bakasan');
     } catch (LeagueWrap\Response\Http500 $e) {
     }
     $this->assertEquals(1, $summoner->getRequestCount());
 }
Exemplo n.º 3
0
 public function testAllRegionsLimit()
 {
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'br')->andReturn(true);
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'eune')->andReturn(true);
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'euw')->andReturn(true);
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'kr')->andReturn(true);
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'lan')->andReturn(true);
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'las')->andReturn(true);
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'na')->andReturn(true);
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'oce')->andReturn(true);
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'ru')->andReturn(true);
     $this->limit1->shouldReceive('setRate')->once()->with(10, 5, 'tr')->andReturn(true);
     $this->limit1->shouldReceive('hit')->once()->with(1)->andReturn(true);
     $this->limit1->shouldReceive('isValid')->once()->andReturn(true);
     $this->limit1->shouldReceive('getRegion')->times(10)->andReturn('br', 'eune', 'euw', 'kr', 'lan', 'las', 'na', 'oce', 'ru', 'tr');
     $this->limit1->shouldReceive('newInstance')->times(10)->andReturn($this->limit1);
     $this->client->shouldReceive('baseUrl')->once();
     $this->client->shouldReceive('request')->with('v1.2/champion', ['freeToPlay' => 'true', 'api_key' => 'key'])->once()->andReturn(file_get_contents('tests/Json/champion.free.json'));
     $api = new LeagueWrap\Api('key', $this->client);
     $api->limit(10, 5, 'all', $this->limit1);
     $champion = $api->champion();
     $info = $champion->free();
     $this->assertTrue(is_array($info->champions));
 }