Skip to content

Commit

Permalink
Merge pull request #5 from hmerritt/v1.0.3
Browse files Browse the repository at this point in the history
v1.0.3
- Encode search string to be URL compatible
- Add search test to cover URL encoding
  • Loading branch information
hmerritt committed Dec 7, 2020
2 parents f3f715b + a94f483 commit 89494aa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ php:
- 7.3

install:
- composer self-update
- composer install --dev --no-interaction
- composer self-update 1.9.3
- composer install --no-interaction

script:
- mkdir -p build/logs
- php vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- composer test

after_script:
- travis_retry php vendor/bin/php-coveralls -v
- travis_retry php vendor/bin/php-coveralls -v
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
bootstrap="phpunit.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
processIsolation="false"
stopOnFailure="false"
>
Expand Down
6 changes: 5 additions & 1 deletion src/Imdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ public function search(string $search, array $options = []): array
// -> handles finding specific content from the dom
$htmlPieces = new HtmlPieces;

// Encode search string as a standard URL string
// -> ' ' => '%20'
$search_url = urlencode(urldecode($search));

// Load imdb search page and parse the dom
$page = $dom->fetch("https://www.imdb.com/find?q=$search&s=".$options["category"], $options);
$page = $dom->fetch("https://www.imdb.com/find?q=$search_url&s=".$options["category"], $options);

// Add all search data to response $store
$response->add("titles", $htmlPieces->get($page, "titles"));
Expand Down
5 changes: 5 additions & 0 deletions tests/ImdbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public function testSearch()

$this->assertEquals('Interstellar', $search['titles'][0]['title']);
$this->assertEquals('tt0816692', $search['titles'][0]['id']);

$search_2 = $imdb->search('The Life and Death of Colonel Blimp');

$this->assertEquals('The Life and Death of Colonel Blimp', $search_2['titles'][0]['title']);
$this->assertEquals('tt0036112', $search_2['titles'][0]['id']);
}

public function test404Page()
Expand Down

0 comments on commit 89494aa

Please sign in to comment.