/**
  * @param $json
  * @return Day[]
  */
 private function toDays($json)
 {
     $days = [];
     foreach ($json as $date => $movies) {
         $days[] = new Day($date, $movies, Type::show(), $this->getClientId(), $this->getToken());
     }
     return $days;
 }
Example #2
0
 /**
  * @param $items
  */
 private function setReleases($items)
 {
     foreach ($items as $item) {
         if ($this->type == Type::movie()) {
             $this->releases[] = new Movie($item, $this->id, $this->token, $this->client);
         }
         if ($this->type == Type::show()) {
             $this->releases[] = new Show($item, $this->id, $this->token, $this->client);
         }
     }
 }
 public function testThatItWorks()
 {
     $client = Mockery::mock(stdClass::class . ", " . ClientInterface::class);
     $request = Mockery::mock(stdClass::class . ", " . RequestInterface::class);
     $response = Mockery::mock(stdClass::class . ", " . ResponseInterface::class);
     $client->shouldReceive("createRequest")->once()->andReturn($request);
     $response->shouldReceive("getStatusCode")->once()->andReturn(200);
     $response->shouldReceive("json")->once()->andReturn([]);
     $client->shouldReceive("send")->andReturn($response);
     $clientId = getenv("CLIENT_ID");
     $response = (new History('rolle', Type::movies(), get_token()))->make($clientId, $client);
     $this->assertInternalType("object", $response);
 }
    public function testSearchMovieWithToken()
    {
        $client = mock_client(200, '[
  {
    "type": "movie",
    "score": 26.019499,
    "movie": {
      "title": "Batman Begins",
      "overview": "Driven by tragedy, billionaire Bruce Wayne dedicates his life to uncovering and defeating the corruption that plagues his home, Gotham City.  Unable to work within the system, he instead creates a new identity, a symbol of fear for the criminal underworld - The Batman.",
      "year": 2005,
      "images": {
        "poster": {
          "full": "https://walter.trakt.us/images/movies/000/000/001/posters/original/9634ffd477.jpg?1406080393",
          "medium": "https://walter.trakt.us/images/movies/000/000/001/posters/medium/9634ffd477.jpg?1406080393",
          "thumb": "https://walter.trakt.us/images/movies/000/000/001/posters/thumb/9634ffd477.jpg?1406080393"
        },
        "fanart": {
          "full": "https://walter.trakt.us/images/movies/000/000/001/fanarts/original/7da8cfbe9e.jpg?1406080393",
          "medium": "https://walter.trakt.us/images/movies/000/000/001/fanarts/medium/7da8cfbe9e.jpg?1406080393",
          "thumb": "https://walter.trakt.us/images/movies/000/000/001/fanarts/thumb/7da8cfbe9e.jpg?1406080393"
        }
      },
      "ids": {
        "trakt": 1,
        "slug": "batman-begins-2005",
        "imdb": "tt0372784",
        "tmdb": 272
      }
    }
  }
]');
        $auth = mock_auth();
        $trakt = new Trakt($auth, $client);
        $search = $trakt->search->byText("Batman", Type::movie(), 2011, get_token());
        $this->assertInstanceOf(Collection::class, $search);
        $this->assertInstanceOf(Movie::class, $search->first());
    }
Example #5
0
 /**
  * @param $json
  */
 private function getMedia($json)
 {
     if (property_exists($json, "type")) {
         if ($this instanceof Movie) {
             $this->type = Type::movie();
             return $json->movie;
         }
         if ($this instanceof Show) {
             $this->type = Type::show();
             return $json->show;
         }
         if ($this instanceof Person) {
             $this->type = Type::person();
             return $json->person;
         }
     }
     return $this->json;
 }
 /**
  * @param ResponseInterface $response
  * @param ClientInterface $client
  * @return Calendar
  */
 public function handle(ResponseInterface $response, ClientInterface $client)
 {
     $json = $this->getJson($response);
     return new Calendar($json, Type::movie(), $this->getClientId(), $this->getToken(), $client);
 }
 public function testRequestWithoutToken()
 {
     $response = (new History('megawubs', Type::movies()))->make(get_client_id(), TraktHttpClient::make());
     $this->assertInternalType("object", $response);
 }
 private function isEpisode($item)
 {
     return $item->type == Type::episode();
 }
    public function testCanHandleResponseWithShows()
    {
        $json = '{
  "2014-07-14": [
    {
      "airs_at": "2014-07-14T01:00:00.000Z",
      "episode": {
        "season": 7,
        "number": 4,
        "title": "Death is Not the End",
        "ids": {
          "trakt": 443,
          "tvdb": 4851180,
          "imdb": "tt3500614",
          "tmdb": 988123,
          "tvrage": null
        }
      },
      "show": {
        "title": "True Blood",
        "year": 2008,
        "ids": {
          "trakt": 5,
          "slug": "true-blood",
          "tvdb": 82283,
          "imdb": "tt0844441",
          "tmdb": 10545,
          "tvrage": 12662
        }
      }
    },
    {
      "airs_at": "2014-07-14T02:00:00.000Z",
      "episode": {
        "season": 1,
        "number": 3,
        "title": "Two Boats and a Helicopter",
        "ids": {
          "trakt": 499,
          "tvdb": 4854797,
          "imdb": "tt3631218",
          "tmdb": 988346,
          "tvrage": null
        }
      },
      "show": {
        "title": "The Leftovers",
        "year": 2014,
        "ids": {
          "trakt": 7,
          "slug": "the-leftovers",
          "tvdb": 269689,
          "imdb": "tt2699128",
          "tmdb": 54344,
          "tvrage": null
        }
      }
    }
  ],
  "2014-07-21": [
    {
      "airs_at": "2014-07-21T01:00:00.000Z",
      "episode": {
        "season": 7,
        "number": 5,
        "title": "Return to Oz",
        "ids": {
          "trakt": 444,
          "tvdb": 4851181,
          "imdb": "tt3500616",
          "tmdb": 988124,
          "tvrage": null
        }
      },
      "show": {
        "title": "True Blood",
        "year": 2008,
        "ids": {
          "trakt": 5,
          "slug": "true-blood",
          "tvdb": 82283,
          "imdb": "tt0844441",
          "tmdb": 10545,
          "tvrage": 12662
        }
      }
    },
    {
      "airs_at": "2014-07-21T02:00:00.000Z",
      "episode": {
        "season": 1,
        "number": 4,
        "title": "B.J. and the A.C.",
        "ids": {
          "trakt": 500,
          "tvdb": 4854798,
          "imdb": "tt3594942",
          "tmdb": 988347,
          "tvrage": null
        }
      },
      "show": {
        "title": "The Leftovers",
        "year": 2014,
        "ids": {
          "trakt": 7,
          "slug": "the-leftovers",
          "tvdb": 269689,
          "imdb": "tt2699128",
          "tmdb": 54344,
          "tvrage": null
        }
      }
    }
  ]
}';
        $mockResponse = new TestResponse($json);
        $json = $mockResponse->json(['object' => true]);
        $days = [];
        $client = Mockery::mock(stdClass::class . ", " . ClientInterface::class);
        foreach ($json as $date => $shows) {
            $days[] = new Day($date, $shows, Type::show(), get_client_id(), get_token(), $client);
        }
        $this->assertInstanceOf(Show::class, $days[0]->releases[0]);
        $this->assertCount(2, $days);
    }
 public function testSearchMovie()
 {
     $request = new ByText("guardians of the galaxy", Type::movie(), "2014");
     $this->assertEquals(RequestType::GET, $request->getRequestType());
     $this->assertEquals("search", $request->getUrl());
 }