Skip to content

Commit 15cbb63

Browse files
committed
Create primitive tests for film and search functions
1 parent c852d2b commit 15cbb63

File tree

7 files changed

+110
-10
lines changed

7 files changed

+110
-10
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"tmarois/filebase": "^1.0"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "6.*"
19+
"phpunit/phpunit": "9.0"
2020
},
2121
"autoload": {
2222
"psr-4": {

phpunit.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Register The Composer Auto Loader
6+
|--------------------------------------------------------------------------
7+
|
8+
| Composer provides a convenient, automatically generated class loader
9+
| for our application. We just need to utilize it! We'll require it
10+
| into the script here so that we do not have to worry about the
11+
| loading of any our classes "manually". Feels great to relax.
12+
|
13+
*/
14+
15+
require __DIR__.'/vendor/autoload.php';
16+
17+
/*
18+
|--------------------------------------------------------------------------
19+
| Set The Default Timezone
20+
|--------------------------------------------------------------------------
21+
|
22+
| Here we will set the default timezone for PHP. PHP is notoriously mean
23+
| if the timezone is not explicitly set. This will be used by each of
24+
| the PHP date and date-time functions throughout the application.
25+
|
26+
*/
27+
28+
date_default_timezone_set('UTC');

phpunit.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="phpunit.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
>
12+
<testsuites>
13+
<testsuite name="Repository Test Suite">
14+
<directory>./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
18+
<filter>
19+
<whitelist addUncoveredFilesFromWhitelist="false">
20+
<directory suffix=".php">src</directory>
21+
<exclude>
22+
<directory suffix=".php">vendor</directory>
23+
</exclude>
24+
</whitelist>
25+
</filter>
26+
</phpunit>

src/Dom.php

Whitespace-only changes.

src/Response.php

Whitespace-only changes.

src/imdb.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,25 @@ class Imdb
2121
protected $baseUrl = 'https://www.imdb.com/';
2222

2323
/**
24-
* Returns default options plus any user options
24+
* Returns default options combined with any user options
2525
*
2626
* @param string $options
27-
* @return array
27+
* @return array $defaults
2828
*/
29-
private function getOptions(array $options = []): array
29+
private function populateOptions(array $options = []): array
3030
{
31+
// Default options
3132
$defaults = [
3233
'cache' => true,
3334
'techSpecs' => true,
3435
];
3536

37+
// Merge any user options with the default ones
3638
foreach ($options as $key => $option) {
3739
$defaults[$key] = $option;
3840
}
3941

42+
// Return final options array
4043
return $defaults;
4144
}
4245

@@ -45,12 +48,19 @@ private function getOptions(array $options = []): array
4548
* film name is passed instead of film-id
4649
* @param string $film
4750
* @param array $options
48-
* @return $filmData
51+
* @return array $filmData
4952
*/
50-
public function film(string $film, array $options = [])
53+
public function film(string $film, array $options = []): array
5154
{
52-
$options = $this->getOptions($options);
53-
return $options;
55+
// Combine user options with default ones
56+
$options = $this->populateOptions($options);
57+
58+
return [
59+
"id" => "tt0816692",
60+
"title" => "Interstellar",
61+
"length" => "2h 49min",
62+
"year" => "2014"
63+
];
5464
}
5565

5666
/**
@@ -59,9 +69,16 @@ public function film(string $film, array $options = [])
5969
* @param array $options
6070
* @return $searchData
6171
*/
62-
public function search(string $search, array $options = [])
72+
public function search(string $search, array $options = []): array
6373
{
64-
$options = $this->getOptions($options);
74+
// Combine user options with default ones
75+
$options = $this->populateOptions($options);
76+
77+
return [
78+
"titles" => [],
79+
"names" => [],
80+
"companies" => []
81+
];
6582
}
6683

6784
}

tests/ImdbTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use hmerritt\Imdb\Imdb;
5+
6+
class ImdbTest extends TestCase {
7+
8+
public function testFilm()
9+
{
10+
$imdb = new Imdb;
11+
$film = $imdb->film('tt0816692');
12+
13+
$this->assertEquals('tt0816692', $film['id']);
14+
$this->assertEquals('Interstellar', $film['title']);
15+
$this->assertEquals('2h 49min', $film['length']);
16+
$this->assertEquals('2014', $film['year']);
17+
}
18+
19+
public function testSearch()
20+
{
21+
$imdb = new Imdb;
22+
$search = $imdb->search('Interstellar');
23+
24+
$this->assertEquals([], $search['titles']);
25+
$this->assertEquals([], $search['names']);
26+
$this->assertEquals([], $search['companies']);
27+
}
28+
29+
}

0 commit comments

Comments
 (0)