Skip to content

Commit 89494aa

Browse files
committed
Merge pull request #5 from hmerritt/v1.0.3
v1.0.3 - Encode search string to be URL compatible - Add search test to cover URL encoding
2 parents f3f715b + a94f483 commit 89494aa

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ php:
44
- 7.3
55

66
install:
7-
- composer self-update
8-
- composer install --dev --no-interaction
7+
- composer self-update 1.9.3
8+
- composer install --no-interaction
99

1010
script:
1111
- mkdir -p build/logs
12-
- php vendor/bin/phpunit --coverage-clover build/logs/clover.xml
12+
- composer test
1313

1414
after_script:
15-
- travis_retry php vendor/bin/php-coveralls -v
15+
- travis_retry php vendor/bin/php-coveralls -v

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
bootstrap="phpunit.php"
55
colors="true"
66
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
7+
convertNoticesToExceptions="false"
8+
convertWarningsToExceptions="false"
99
processIsolation="false"
1010
stopOnFailure="false"
1111
>

src/Imdb.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ public function search(string $search, array $options = []): array
147147
// -> handles finding specific content from the dom
148148
$htmlPieces = new HtmlPieces;
149149

150+
// Encode search string as a standard URL string
151+
// -> ' ' => '%20'
152+
$search_url = urlencode(urldecode($search));
153+
150154
// Load imdb search page and parse the dom
151-
$page = $dom->fetch("https://www.imdb.com/find?q=$search&s=".$options["category"], $options);
155+
$page = $dom->fetch("https://www.imdb.com/find?q=$search_url&s=".$options["category"], $options);
152156

153157
// Add all search data to response $store
154158
$response->add("titles", $htmlPieces->get($page, "titles"));

tests/ImdbTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function testSearch()
7272

7373
$this->assertEquals('Interstellar', $search['titles'][0]['title']);
7474
$this->assertEquals('tt0816692', $search['titles'][0]['id']);
75+
76+
$search_2 = $imdb->search('The Life and Death of Colonel Blimp');
77+
78+
$this->assertEquals('The Life and Death of Colonel Blimp', $search_2['titles'][0]['title']);
79+
$this->assertEquals('tt0036112', $search_2['titles'][0]['id']);
7580
}
7681

7782
public function test404Page()

0 commit comments

Comments
 (0)