From 2c4b8b3cb620297c99570e821087f01f9190712d Mon Sep 17 00:00:00 2001 From: Michal Stefanak Date: Tue, 20 Jul 2021 14:44:59 +0200 Subject: [PATCH] added tests --- README.md | 86 +-- composer.json | 3 +- src/Deepr.php | 62 +- src/components/Collection.php | 11 - src/components/ILoadable.php | 2 +- tests/DeeprTest.php | 97 +++ tests/classes/Database.php | 73 +++ tests/classes/Movie.php | 54 ++ tests/classes/Movies.php | 70 +++ tests/classes/Person.php | 22 + tests/classes/Root.php | 38 ++ tests/classes/data/actors.json | 1074 ++++++++++++++++++++++++++++++++ tests/classes/data/movies.json | 230 +++++++ tests/jsons/01-input.json | 5 + tests/jsons/01-output.json | 5 + tests/jsons/02-input.json | 10 + tests/jsons/02-output.json | 12 + tests/jsons/03-input.json | 12 + tests/jsons/03-output.json | 18 + tests/jsons/04-input.json | 11 + tests/jsons/04-output.json | 11 + tests/jsons/05-input.json | 11 + tests/jsons/05-output.json | 8 + tests/jsons/06-input.json | 20 + tests/jsons/06-output.json | 10 + tests/jsons/07-input.json | 12 + tests/jsons/07-output.json | 19 + tests/jsons/08-input.json | 10 + tests/jsons/08-output.json | 10 + tests/jsons/09-input.json | 5 + tests/jsons/09-output.json | 3 + tests/jsons/10-input.json | 8 + tests/jsons/10-output.json | 5 + 33 files changed, 1898 insertions(+), 129 deletions(-) create mode 100644 tests/DeeprTest.php create mode 100644 tests/classes/Database.php create mode 100644 tests/classes/Movie.php create mode 100644 tests/classes/Movies.php create mode 100644 tests/classes/Person.php create mode 100644 tests/classes/Root.php create mode 100644 tests/classes/data/actors.json create mode 100644 tests/classes/data/movies.json create mode 100644 tests/jsons/01-input.json create mode 100644 tests/jsons/01-output.json create mode 100644 tests/jsons/02-input.json create mode 100644 tests/jsons/02-output.json create mode 100644 tests/jsons/03-input.json create mode 100644 tests/jsons/03-output.json create mode 100644 tests/jsons/04-input.json create mode 100644 tests/jsons/04-output.json create mode 100644 tests/jsons/05-input.json create mode 100644 tests/jsons/05-output.json create mode 100644 tests/jsons/06-input.json create mode 100644 tests/jsons/06-output.json create mode 100644 tests/jsons/07-input.json create mode 100644 tests/jsons/07-output.json create mode 100644 tests/jsons/08-input.json create mode 100644 tests/jsons/08-output.json create mode 100644 tests/jsons/09-input.json create mode 100644 tests/jsons/09-output.json create mode 100644 tests/jsons/10-input.json create mode 100644 tests/jsons/10-output.json diff --git a/README.md b/README.md index 34cda50..563c09a 100644 --- a/README.md +++ b/README.md @@ -1,87 +1,7 @@ # deepr-php -PHP API library following Deepr specification +PHP API library following [Deepr specification](https://github.com/deeprjs/deepr). -https://github.com/deeprjs/deepr +![](https://img.shields.io/badge/phpunit-passed-success) ![](https://img.shields.io/badge/coverage-98%25-green) ![](https://img.shields.io/github/stars/stefanak-michal/deepr-php) ![](https://img.shields.io/packagist/dt/stefanak-michal/deepr-php) ![](https://img.shields.io/github/v/release/stefanak-michal/deepr-php) ![](https://img.shields.io/github/commits-since/stefanak-michal/deepr-php/latest) - -### Example - -```php - -function applyColumns(IComponent $object, array $row) -{ - foreach ($row as $column => $value) { - if (property_exists($object, $column)) - $object->$column = $value; - } -} - -class Movies extends Collection implements ILoadable -{ - public $count; - - public function __construct() - { - $this->count = DB::getMoviesCount(); - } - - public function load(): array - { - $items = []; - foreach (DB::getMovies() as $row) { - $movie = new Movie(); - applyColumns($movie, $row); - $items[] = $movie; - } - return $items; - } - - public function getByTitle(string $title): Collection - { - $collection = new self(); - - $movie = new Movie(); - $row = DB::getMovieByTitle($title); - applyColumns($movie, $row); - $collection->add($movie); - - return $collection; - } -} - -class Movie extends Collection -{ - public $_id; - public $title; - public $released; - public $tagline; -} - -class Root extends Collection -{ - public $movies = Movies::class; -} - -$deepr = new Deepr(); -$json = '{"movies": {"count": true, "[]": [0, 2],"title": true, "released": true}}'; -$collection = new Root(); -$deepr->invokeQuery($collection, json_decode($j, true)); -echo '
' . json_encode($collection->execute(), JSON_PRETTY_PRINT) . '
' . PHP_EOL; - -/* -{ - "movies": { - "count": 38, - "0": { - "title": "The Matrix", - "released": 1999 - }, - "1": { - "title": "The Matrix Reloaded", - "released": 2003 - } - } -} -*/ -``` +Check wiki for more informations about how to use this library. \ No newline at end of file diff --git a/composer.json b/composer.json index d5105cf..637336e 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "php": ">=7.1.0" }, "require-dev": { - "phpunit/phpunit": ">=7.5.0" + "phpunit/phpunit": ">=7.5.0", + "ext-json": "*" }, "support": { "issues": "https://github.com/stefanak-michal/deepr-php/issues", diff --git a/src/Deepr.php b/src/Deepr.php index 1118c34..799d571 100644 --- a/src/Deepr.php +++ b/src/Deepr.php @@ -86,27 +86,26 @@ private function recursion(IComponent $root, string $action, array $values) } elseif ($k === '[]' && !empty($action)) { if (self::$debug) var_dump($action . ' []'); - if (!($root instanceof ILoadable)) - throw new Exception('You are trying access collection on not loadable object'); - - $offset = 0; - $length = null; - if (is_int($v)) { - $offset = $v; - $length = 1; - } elseif (is_array($v)) { - $offset = $v[0] ?? 0; - $length = $v[1] ?? null; - } + if ($root instanceof ILoadable) { + $offset = 0; + $length = null; + if (is_int($v)) { + $offset = $v; + $length = 1; + } elseif (is_array($v)) { + $offset = $v[0] ?? 0; + $length = $v[1] ?? null; + } - $items = $root->load(); - $tmpValues = $values; - unset($tmpValues['[]']); - foreach (array_slice($items, $offset, $length) as $item) { - $this->recursion($item, $action, $tmpValues); - $root->add($item); + $tmpValues = $values; + unset($tmpValues['[]']); + foreach ($root->load($offset, $length) as $item) { + $this->recursion($item, $action, $tmpValues); + $root->add($item); + } + } else { + throw new Exception('To access collection of class it has to implement ILoadable interface'); } - return; } elseif ($k === '()') { continue; @@ -115,18 +114,19 @@ private function recursion(IComponent $root, string $action, array $values) var_dump($key . ' ()'); $data = $root->{$key}(...$v['()']); - if (!($data instanceof Collection)) - throw new Exception('Method response has to be Collection'); + if ($data instanceof Collection) { + $nest = $this->isNest($k); + foreach ($data->getChildren() as $child) { + $this->recursion($child, $key, $v); + if (!$nest) + $root->add($child); + } - $nest = $this->isNest($k); - foreach ($data->getChildren() as $child) { - $this->recursion($child, $key, $v); - if (!$nest) - $root->add($child); + if ($nest) + $root->add($data, $this->getKey($k)); + } else { + throw new Exception('Method response has to be Collection'); } - - if ($nest) - $root->add($data, $this->getKey($k)); } elseif ($v === true) { if (self::$debug) var_dump($action . ' ' . $k . ' true'); @@ -147,10 +147,6 @@ private function recursion(IComponent $root, string $action, array $values) if (self::$debug) var_dump($action . ' array unnest'); $this->recursion($root, $this->getKey($k, false), $v); - } else { - if (self::$debug) - var_dump($action . ' array iterate'); - $this->recursion($root, $k, $v); } } } diff --git a/src/components/Collection.php b/src/components/Collection.php index 54f69e8..be930a4 100644 --- a/src/components/Collection.php +++ b/src/components/Collection.php @@ -28,17 +28,6 @@ public function add(IComponent $component, string $name = '') $this->children[] = $component; } - /** - * Remove child from collection - * @param IComponent $component - */ - public function remove(IComponent $component) - { - $key = array_search($component, $this->children); - if ($key !== false) - unset($this->children[$key]); - } - /** * Get list of children * @return IComponent[] diff --git a/src/components/ILoadable.php b/src/components/ILoadable.php index 3ed7d72..daaa373 100644 --- a/src/components/ILoadable.php +++ b/src/components/ILoadable.php @@ -10,5 +10,5 @@ */ interface ILoadable { - public function load(): array; + public function load(int $offset, ?int $length): array; } diff --git a/tests/DeeprTest.php b/tests/DeeprTest.php new file mode 100644 index 0000000..3109cee --- /dev/null +++ b/tests/DeeprTest.php @@ -0,0 +1,97 @@ +assertInstanceOf(Deepr::class, $deepr); + return $deepr; + } + + /** + * @depends testDeepr + * @dataProvider jsonProvider + * @param string $input + * @param string $output + * @param Deepr $deepr + */ + public function testInvokeQueries(string $input, string $output, Deepr $deepr) + { + try { + $root = new Root(); + $deepr->invokeQuery($root, json_decode($input, true)); + $result = $root->execute(); + $result = json_encode($result); + $this->assertJsonStringEqualsJsonString($output, $result); + } catch (Exception $e) { + $this->markTestIncomplete($e->getMessage()); + } + } + + /** + * @depends testDeepr + * @param Deepr $deepr + */ + public function testParallel(Deepr $deepr) + { + $root = new Root(); + $this->expectException(Exception::class); + $deepr->invokeQuery($root, json_decode('{"||":[]}', true)); + } + + /** + * @depends testDeepr + * @param Deepr $deepr + */ + public function testMissingException(Deepr $deepr) + { + $root = new Root(); + $this->expectException(Exception::class); + $deepr->invokeQuery($root, json_decode('{ "missingFunction": { "()": [] } }', true)); + } + + /** + * Use json files in jsons directory as sample data for requests + * @return array + */ + public function jsonProvider() + { + $data = []; + $dir = __DIR__ . DIRECTORY_SEPARATOR . 'jsons' . DIRECTORY_SEPARATOR; + if (file_exists($dir)) { + foreach (glob($dir . '*.json') as $file) { + list($i, $type) = explode('-', pathinfo($file, PATHINFO_FILENAME), 2); + $i = intval($i); + $type = $type == 'input' ? 0 : 1; + + $json = file_get_contents($file); + if ($json === false) + continue; + $json = json_decode($json, true); + if (json_last_error() != JSON_ERROR_NONE) + continue; + $data[$i][$type] = json_encode($json); + } + } + + return $data; + } +} diff --git a/tests/classes/Database.php b/tests/classes/Database.php new file mode 100644 index 0000000..44b797c --- /dev/null +++ b/tests/classes/Database.php @@ -0,0 +1,73 @@ +":{"getActors":{"()":[]}}}} + * @return Collection + */ + public function getActors(): Collection + { + if (is_null($this->actors)) { + $this->actors = new Collection(); + foreach (Database::getMovieActors($this->_id) as $row) { + $person = new Person(); + $person->_id = $row['_id']; + $person->name = $row['name']; + $person->born = $row['born']; + $this->actors->add($person); + } + } + + return $this->actors; + } + +} diff --git a/tests/classes/Movies.php b/tests/classes/Movies.php new file mode 100644 index 0000000..71ef79c --- /dev/null +++ b/tests/classes/Movies.php @@ -0,0 +1,70 @@ +count = Database::getMoviesCount(); + } + + /** + * This method is implemented by interface ILoadable and it's called on "[]" + * {"movies": {"[]": []}} + * @param int $offset + * @param int|null $length + * @return IComponent[] + */ + public function load(int $offset, ?int $length): array + { + $items = []; + foreach (array_slice(Database::getMovies(), $offset, $length) as $row) { + $movie = new Movie(); + $movie->_id = $row['_id']; + $movie->title = $row['title']; + $movie->released = $row['released']; + $movie->tagline = $row['tagline']; + $items[] = $movie; + } + return $items; + } + + /** + * RPC method to get movie by title + * {"movies":{"getByTitle":{"()":["The Matrix"]}}} + * @param string $title + * @return Collection + */ + public function getByTitle(string $title): Collection + { + $collection = new self(); + + $movie = new Movie(); + $row = Database::getMovieByTitle($title); + $movie->_id = $row['_id']; + $movie->title = $row['title']; + $movie->released = $row['released']; + $movie->tagline = $row['tagline']; + $collection->add($movie); + + return $collection; + } +} diff --git a/tests/classes/Person.php b/tests/classes/Person.php new file mode 100644 index 0000000..f47b7f3 --- /dev/null +++ b/tests/classes/Person.php @@ -0,0 +1,22 @@ +":{"getActors":{"()":[], "name": true}}}} + * @var string + */ + public $name; + public $born; +} diff --git a/tests/classes/Root.php b/tests/classes/Root.php new file mode 100644 index 0000000..4751c44 --- /dev/null +++ b/tests/classes/Root.php @@ -0,0 +1,38 @@ +invokeQuery + * @package Deepr\tests\classes + * @author Michal Stefanak + * @link https://github.com/stefanak-michal/deepr-php + */ +class Root extends Collection +{ + /** + * Reference to Movies collection + * Only public properties are accessible + * {"movies": ...} + * @internal It can be instance of class Movies directly + * @var string|Collection + */ + public $movies = Movies::class; + + /** + * Sample method + * RPC methods has to be public and returns Collection + * {"date": {"()": []}} + * @return Collection + */ + public function date(): Collection + { + $collection = new Collection(); + $collection->add(new Value('2021-07-20')); + return $collection; + } +} diff --git a/tests/classes/data/actors.json b/tests/classes/data/actors.json new file mode 100644 index 0000000..343c7f2 --- /dev/null +++ b/tests/classes/data/actors.json @@ -0,0 +1,1074 @@ +[ + { + "_id": 1, + "name": "Keanu Reeves", + "born": 1964, + "_movies": [ + 154, + 87, + 100, + 11, + 10, + 9, + 0 + ] + }, + { + "_id": 2, + "name": "Carrie-Anne Moss", + "born": 1967, + "_movies": [ + 10, + 9, + 0 + ] + }, + { + "_id": 3, + "name": "Laurence Fishburne", + "born": 1961, + "_movies": [ + 10, + 9, + 0 + ] + }, + { + "_id": 4, + "name": "Hugo Weaving", + "born": 1960, + "_movies": [ + 105, + 116, + 10, + 9, + 0 + ] + }, + { + "_id": 5, + "name": "Lilly Wachowski", + "born": 1967, + "_movies": [] + }, + { + "_id": 6, + "name": "Lana Wachowski", + "born": 1965, + "_movies": [] + }, + { + "_id": 7, + "name": "Joel Silver", + "born": 1952, + "_movies": [] + }, + { + "_id": 8, + "name": "Emil Eifrem", + "born": 1978, + "_movies": [ + 0 + ] + }, + { + "_id": 12, + "name": "Charlize Theron", + "born": 1975, + "_movies": [ + 85, + 11 + ] + }, + { + "_id": 13, + "name": "Al Pacino", + "born": 1940, + "_movies": [ + 11 + ] + }, + { + "_id": 14, + "name": "Taylor Hackford", + "born": 1944, + "_movies": [] + }, + { + "_id": 16, + "name": "Tom Cruise", + "born": 1962, + "_movies": [ + 37, + 29, + 15 + ] + }, + { + "_id": 17, + "name": "Jack Nicholson", + "born": 1937, + "_movies": [ + 52, + 152, + 154, + 141, + 15 + ] + }, + { + "_id": 18, + "name": "Demi Moore", + "born": 1962, + "_movies": [ + 15 + ] + }, + { + "_id": 19, + "name": "Kevin Bacon", + "born": 1958, + "_movies": [ + 144, + 137, + 15 + ] + }, + { + "_id": 20, + "name": "Kiefer Sutherland", + "born": 1966, + "_movies": [ + 46, + 15 + ] + }, + { + "_id": 21, + "name": "Noah Wyle", + "born": 1971, + "_movies": [ + 15 + ] + }, + { + "_id": 22, + "name": "Cuba Gooding Jr.", + "born": 1968, + "_movies": [ + 56, + 37, + 52, + 15 + ] + }, + { + "_id": 23, + "name": "Kevin Pollak", + "born": 1957, + "_movies": [ + 15 + ] + }, + { + "_id": 24, + "name": "J.T. Walsh", + "born": 1943, + "_movies": [ + 141, + 15 + ] + }, + { + "_id": 25, + "name": "James Marshall", + "born": 1967, + "_movies": [ + 15 + ] + }, + { + "_id": 26, + "name": "Christopher Guest", + "born": 1948, + "_movies": [ + 15 + ] + }, + { + "_id": 27, + "name": "Rob Reiner", + "born": 1947, + "_movies": [] + }, + { + "_id": 28, + "name": "Aaron Sorkin", + "born": 1961, + "_movies": [ + 15 + ] + }, + { + "_id": 30, + "name": "Kelly McGillis", + "born": 1957, + "_movies": [ + 29 + ] + }, + { + "_id": 31, + "name": "Val Kilmer", + "born": 1959, + "_movies": [ + 29 + ] + }, + { + "_id": 32, + "name": "Anthony Edwards", + "born": 1962, + "_movies": [ + 29 + ] + }, + { + "_id": 33, + "name": "Tom Skerritt", + "born": 1933, + "_movies": [ + 29 + ] + }, + { + "_id": 34, + "name": "Meg Ryan", + "born": 1961, + "_movies": [ + 73, + 67, + 29, + 81, + 78 + ] + }, + { + "_id": 35, + "name": "Tony Scott", + "born": 1944, + "_movies": [] + }, + { + "_id": 36, + "name": "Jim Cash", + "born": 1941, + "_movies": [] + }, + { + "_id": 38, + "name": "Renee Zellweger", + "born": 1969, + "_movies": [ + 37 + ] + }, + { + "_id": 39, + "name": "Kelly Preston", + "born": 1962, + "_movies": [ + 37 + ] + }, + { + "_id": 40, + "name": "Jerry O'Connell", + "born": 1974, + "_movies": [ + 37, + 46 + ] + }, + { + "_id": 41, + "name": "Jay Mohr", + "born": 1970, + "_movies": [ + 37 + ] + }, + { + "_id": 42, + "name": "Bonnie Hunt", + "born": 1961, + "_movies": [ + 130, + 37 + ] + }, + { + "_id": 43, + "name": "Regina King", + "born": 1971, + "_movies": [ + 37 + ] + }, + { + "_id": 44, + "name": "Jonathan Lipnicki", + "born": 1996, + "_movies": [ + 37 + ] + }, + { + "_id": 45, + "name": "Cameron Crowe", + "born": 1957, + "_movies": [] + }, + { + "_id": 47, + "name": "River Phoenix", + "born": 1970, + "_movies": [ + 46 + ] + }, + { + "_id": 48, + "name": "Corey Feldman", + "born": 1971, + "_movies": [ + 46 + ] + }, + { + "_id": 49, + "name": "Wil Wheaton", + "born": 1972, + "_movies": [ + 46 + ] + }, + { + "_id": 50, + "name": "John Cusack", + "born": 1966, + "_movies": [ + 46 + ] + }, + { + "_id": 51, + "name": "Marshall Bell", + "born": 1942, + "_movies": [ + 46, + 92 + ] + }, + { + "_id": 53, + "name": "Helen Hunt", + "born": 1963, + "_movies": [ + 52, + 150, + 147 + ] + }, + { + "_id": 54, + "name": "Greg Kinnear", + "born": 1963, + "_movies": [ + 67, + 52 + ] + }, + { + "_id": 55, + "name": "James L. Brooks", + "born": 1940, + "_movies": [] + }, + { + "_id": 57, + "name": "Annabella Sciorra", + "born": 1960, + "_movies": [ + 56 + ] + }, + { + "_id": 58, + "name": "Max von Sydow", + "born": 1929, + "_movies": [ + 56, + 62 + ] + }, + { + "_id": 59, + "name": "Werner Herzog", + "born": 1942, + "_movies": [ + 56 + ] + }, + { + "_id": 60, + "name": "Robin Williams", + "born": 1951, + "_movies": [ + 56, + 157, + 95 + ] + }, + { + "_id": 61, + "name": "Vincent Ward", + "born": 1956, + "_movies": [] + }, + { + "_id": 63, + "name": "Ethan Hawke", + "born": 1970, + "_movies": [ + 62 + ] + }, + { + "_id": 64, + "name": "Rick Yune", + "born": 1971, + "_movies": [ + 128, + 62 + ] + }, + { + "_id": 65, + "name": "James Cromwell", + "born": 1940, + "_movies": [ + 130, + 62 + ] + }, + { + "_id": 66, + "name": "Scott Hicks", + "born": 1953, + "_movies": [] + }, + { + "_id": 68, + "name": "Parker Posey", + "born": 1968, + "_movies": [ + 67 + ] + }, + { + "_id": 69, + "name": "Dave Chappelle", + "born": 1973, + "_movies": [ + 67 + ] + }, + { + "_id": 70, + "name": "Steve Zahn", + "born": 1967, + "_movies": [ + 92, + 67 + ] + }, + { + "_id": 71, + "name": "Tom Hanks", + "born": 1956, + "_movies": [ + 144, + 67, + 162, + 78, + 85, + 111, + 105, + 150, + 130, + 73, + 161, + 159 + ] + }, + { + "_id": 72, + "name": "Nora Ephron", + "born": 1941, + "_movies": [] + }, + { + "_id": 74, + "name": "Rita Wilson", + "born": 1956, + "_movies": [ + 73 + ] + }, + { + "_id": 75, + "name": "Bill Pullman", + "born": 1953, + "_movies": [ + 73 + ] + }, + { + "_id": 76, + "name": "Victor Garber", + "born": 1949, + "_movies": [ + 73 + ] + }, + { + "_id": 77, + "name": "Rosie O'Donnell", + "born": 1962, + "_movies": [ + 162, + 73 + ] + }, + { + "_id": 79, + "name": "John Patrick Stanley", + "born": 1950, + "_movies": [] + }, + { + "_id": 80, + "name": "Nathan Lane", + "born": 1956, + "_movies": [ + 78, + 95 + ] + }, + { + "_id": 82, + "name": "Billy Crystal", + "born": 1948, + "_movies": [ + 81 + ] + }, + { + "_id": 83, + "name": "Carrie Fisher", + "born": 1956, + "_movies": [ + 81 + ] + }, + { + "_id": 84, + "name": "Bruno Kirby", + "born": 1949, + "_movies": [ + 81 + ] + }, + { + "_id": 86, + "name": "Liv Tyler", + "born": 1977, + "_movies": [ + 85 + ] + }, + { + "_id": 88, + "name": "Brooke Langton", + "born": 1970, + "_movies": [ + 87 + ] + }, + { + "_id": 89, + "name": "Gene Hackman", + "born": 1930, + "_movies": [ + 97, + 95, + 87 + ] + }, + { + "_id": 90, + "name": "Orlando Jones", + "born": 1968, + "_movies": [ + 87 + ] + }, + { + "_id": 91, + "name": "Howard Deutch", + "born": 1950, + "_movies": [] + }, + { + "_id": 93, + "name": "Christian Bale", + "born": 1974, + "_movies": [ + 92 + ] + }, + { + "_id": 94, + "name": "Zach Grenier", + "born": 1954, + "_movies": [ + 92, + 147 + ] + }, + { + "_id": 96, + "name": "Mike Nichols", + "born": 1931, + "_movies": [] + }, + { + "_id": 98, + "name": "Richard Harris", + "born": 1930, + "_movies": [ + 97 + ] + }, + { + "_id": 99, + "name": "Clint Eastwood", + "born": 1930, + "_movies": [ + 97 + ] + }, + { + "_id": 101, + "name": "Takeshi Kitano", + "born": 1947, + "_movies": [ + 100 + ] + }, + { + "_id": 102, + "name": "Dina Meyer", + "born": 1968, + "_movies": [ + 100 + ] + }, + { + "_id": 103, + "name": "Ice-T", + "born": 1958, + "_movies": [ + 100 + ] + }, + { + "_id": 104, + "name": "Robert Longo", + "born": 1953, + "_movies": [] + }, + { + "_id": 106, + "name": "Halle Berry", + "born": 1966, + "_movies": [ + 105 + ] + }, + { + "_id": 107, + "name": "Jim Broadbent", + "born": 1949, + "_movies": [ + 105 + ] + }, + { + "_id": 108, + "name": "Tom Tykwer", + "born": 1965, + "_movies": [] + }, + { + "_id": 109, + "name": "David Mitchell", + "born": 1969, + "_movies": [] + }, + { + "_id": 110, + "name": "Stefan Arndt", + "born": 1961, + "_movies": [] + }, + { + "_id": 112, + "name": "Ian McKellen", + "born": 1939, + "_movies": [ + 111 + ] + }, + { + "_id": 113, + "name": "Audrey Tautou", + "born": 1976, + "_movies": [ + 111 + ] + }, + { + "_id": 114, + "name": "Paul Bettany", + "born": 1971, + "_movies": [ + 111 + ] + }, + { + "_id": 115, + "name": "Ron Howard", + "born": 1954, + "_movies": [] + }, + { + "_id": 117, + "name": "Natalie Portman", + "born": 1981, + "_movies": [ + 116 + ] + }, + { + "_id": 118, + "name": "Stephen Rea", + "born": 1946, + "_movies": [ + 116 + ] + }, + { + "_id": 119, + "name": "John Hurt", + "born": 1940, + "_movies": [ + 116 + ] + }, + { + "_id": 120, + "name": "Ben Miles", + "born": 1967, + "_movies": [ + 121, + 128, + 116 + ] + }, + { + "_id": 122, + "name": "Emile Hirsch", + "born": 1985, + "_movies": [ + 121 + ] + }, + { + "_id": 123, + "name": "John Goodman", + "born": 1960, + "_movies": [ + 121 + ] + }, + { + "_id": 124, + "name": "Susan Sarandon", + "born": 1946, + "_movies": [ + 121 + ] + }, + { + "_id": 125, + "name": "Matthew Fox", + "born": 1966, + "_movies": [ + 121 + ] + }, + { + "_id": 126, + "name": "Christina Ricci", + "born": 1980, + "_movies": [ + 121 + ] + }, + { + "_id": 127, + "name": "Rain", + "born": 1982, + "_movies": [ + 121, + 128 + ] + }, + { + "_id": 129, + "name": "Naomie Harris", + "born": null, + "_movies": [ + 128 + ] + }, + { + "_id": 131, + "name": "Michael Clarke Duncan", + "born": 1957, + "_movies": [ + 130 + ] + }, + { + "_id": 132, + "name": "David Morse", + "born": 1953, + "_movies": [ + 130 + ] + }, + { + "_id": 133, + "name": "Sam Rockwell", + "born": 1968, + "_movies": [ + 130, + 137 + ] + }, + { + "_id": 134, + "name": "Gary Sinise", + "born": 1955, + "_movies": [ + 144, + 130 + ] + }, + { + "_id": 135, + "name": "Patricia Clarkson", + "born": 1959, + "_movies": [ + 130 + ] + }, + { + "_id": 136, + "name": "Frank Darabont", + "born": 1959, + "_movies": [] + }, + { + "_id": 138, + "name": "Frank Langella", + "born": 1938, + "_movies": [ + 137 + ] + }, + { + "_id": 139, + "name": "Michael Sheen", + "born": 1969, + "_movies": [ + 137 + ] + }, + { + "_id": 140, + "name": "Oliver Platt", + "born": 1960, + "_movies": [ + 137, + 157 + ] + }, + { + "_id": 142, + "name": "Danny DeVito", + "born": 1944, + "_movies": [ + 141, + 152 + ] + }, + { + "_id": 143, + "name": "John C. Reilly", + "born": 1965, + "_movies": [ + 141 + ] + }, + { + "_id": 145, + "name": "Ed Harris", + "born": 1950, + "_movies": [ + 144 + ] + }, + { + "_id": 146, + "name": "Bill Paxton", + "born": 1955, + "_movies": [ + 147, + 162, + 144 + ] + }, + { + "_id": 148, + "name": "Philip Seymour Hoffman", + "born": 1967, + "_movies": [ + 147, + 159 + ] + }, + { + "_id": 149, + "name": "Jan de Bont", + "born": 1943, + "_movies": [] + }, + { + "_id": 151, + "name": "Robert Zemeckis", + "born": 1951, + "_movies": [] + }, + { + "_id": 153, + "name": "Milos Forman", + "born": 1932, + "_movies": [] + }, + { + "_id": 155, + "name": "Diane Keaton", + "born": 1946, + "_movies": [ + 154 + ] + }, + { + "_id": 156, + "name": "Nancy Meyers", + "born": 1949, + "_movies": [] + }, + { + "_id": 158, + "name": "Chris Columbus", + "born": 1958, + "_movies": [] + }, + { + "_id": 160, + "name": "Julia Roberts", + "born": 1967, + "_movies": [ + 159 + ] + }, + { + "_id": 163, + "name": "Madonna", + "born": 1954, + "_movies": [ + 162 + ] + }, + { + "_id": 164, + "name": "Geena Davis", + "born": 1956, + "_movies": [ + 162 + ] + }, + { + "_id": 165, + "name": "Lori Petty", + "born": 1963, + "_movies": [ + 162 + ] + }, + { + "_id": 166, + "name": "Penny Marshall", + "born": 1943, + "_movies": [] + }, + { + "_id": 167, + "name": "Paul Blythe", + "born": null, + "_movies": [] + }, + { + "_id": 168, + "name": "Angela Scope", + "born": null, + "_movies": [] + }, + { + "_id": 169, + "name": "Jessica Thompson", + "born": null, + "_movies": [] + }, + { + "_id": 170, + "name": "James Thompson", + "born": null, + "_movies": [] + } +] \ No newline at end of file diff --git a/tests/classes/data/movies.json b/tests/classes/data/movies.json new file mode 100644 index 0000000..8288ff3 --- /dev/null +++ b/tests/classes/data/movies.json @@ -0,0 +1,230 @@ +[ + { + "_id": 0, + "title": "The Matrix", + "released": 1999, + "tagline": "Welcome to the Real World" + }, + { + "_id": 9, + "title": "The Matrix Reloaded", + "released": 2003, + "tagline": "Free your mind" + }, + { + "_id": 10, + "title": "The Matrix Revolutions", + "released": 2003, + "tagline": "Everything that has a beginning has an end" + }, + { + "_id": 11, + "title": "The Devil's Advocate", + "released": 1997, + "tagline": "Evil has its winning ways" + }, + { + "_id": 15, + "title": "A Few Good Men", + "released": 1992, + "tagline": "In the heart of the nation's capital, in a courthouse of the U.S. government, one man will stop at nothing to keep his honor, and one will stop at nothing to find the truth." + }, + { + "_id": 29, + "title": "Top Gun", + "released": 1986, + "tagline": "I feel the need, the need for speed." + }, + { + "_id": 37, + "title": "Jerry Maguire", + "released": 2000, + "tagline": "The rest of his life begins now." + }, + { + "_id": 46, + "title": "Stand By Me", + "released": 1986, + "tagline": "For some, it's the last real taste of innocence, and the first real taste of life. But for everyone, it's the time that memories are made of." + }, + { + "_id": 52, + "title": "As Good as It Gets", + "released": 1997, + "tagline": "A comedy from the heart that goes for the throat." + }, + { + "_id": 56, + "title": "What Dreams May Come", + "released": 1998, + "tagline": "After life there is more. The end is just the beginning." + }, + { + "_id": 62, + "title": "Snow Falling on Cedars", + "released": 1999, + "tagline": "First loves last. Forever." + }, + { + "_id": 67, + "title": "You've Got Mail", + "released": 1998, + "tagline": "At odds in life... in love on-line." + }, + { + "_id": 73, + "title": "Sleepless in Seattle", + "released": 1993, + "tagline": "What if someone you never met, someone you never saw, someone you never knew was the only someone for you?" + }, + { + "_id": 78, + "title": "Joe Versus the Volcano", + "released": 1990, + "tagline": "A story of love, lava and burning desire." + }, + { + "_id": 81, + "title": "When Harry Met Sally", + "released": 1998, + "tagline": "Can two friends sleep together and still love each other in the morning?" + }, + { + "_id": 85, + "title": "That Thing You Do", + "released": 1996, + "tagline": "In every life there comes a time when that thing you dream becomes that thing you do" + }, + { + "_id": 87, + "title": "The Replacements", + "released": 2000, + "tagline": "Pain heals, Chicks dig scars... Glory lasts forever" + }, + { + "_id": 92, + "title": "RescueDawn", + "released": 2006, + "tagline": "Based on the extraordinary true story of one man's fight for freedom" + }, + { + "_id": 95, + "title": "The Birdcage", + "released": 1996, + "tagline": "Come as you are" + }, + { + "_id": 97, + "title": "Unforgiven", + "released": 1992, + "tagline": "It's a hell of a thing, killing a man" + }, + { + "_id": 100, + "title": "Johnny Mnemonic", + "released": 1995, + "tagline": "The hottest data on earth. In the coolest head in town" + }, + { + "_id": 105, + "title": "Cloud Atlas", + "released": 2012, + "tagline": "Everything is connected" + }, + { + "_id": 111, + "title": "The Da Vinci Code", + "released": 2006, + "tagline": "Break The Codes" + }, + { + "_id": 116, + "title": "V for Vendetta", + "released": 2006, + "tagline": "Freedom! Forever!" + }, + { + "_id": 121, + "title": "Speed Racer", + "released": 2008, + "tagline": "Speed has no limits" + }, + { + "_id": 128, + "title": "Ninja Assassin", + "released": 2009, + "tagline": "Prepare to enter a secret world of assassins" + }, + { + "_id": 130, + "title": "The Green Mile", + "released": 1999, + "tagline": "Walk a mile you'll never forget." + }, + { + "_id": 137, + "title": "Frost/Nixon", + "released": 2008, + "tagline": "400 million people were waiting for the truth." + }, + { + "_id": 141, + "title": "Hoffa", + "released": 1992, + "tagline": "He didn't want law. He wanted justice." + }, + { + "_id": 144, + "title": "Apollo 13", + "released": 1995, + "tagline": "Houston, we have a problem." + }, + { + "_id": 147, + "title": "Twister", + "released": 1996, + "tagline": "Don't Breathe. Don't Look Back." + }, + { + "_id": 150, + "title": "Cast Away", + "released": 2000, + "tagline": "At the edge of the world, his journey begins." + }, + { + "_id": 152, + "title": "One Flew Over the Cuckoo's Nest", + "released": 1975, + "tagline": "If he's crazy, what does that make you?" + }, + { + "_id": 154, + "title": "Something's Gotta Give", + "released": 2003, + "tagline": null + }, + { + "_id": 157, + "title": "Bicentennial Man", + "released": 1999, + "tagline": "One robot's 200 year journey to become an ordinary man." + }, + { + "_id": 159, + "title": "Charlie Wilson's War", + "released": 2007, + "tagline": "A stiff drink. A little mascara. A lot of nerve. Who said they couldn't bring down the Soviet empire." + }, + { + "_id": 161, + "title": "The Polar Express", + "released": 2004, + "tagline": "This Holiday Season... Believe" + }, + { + "_id": 162, + "title": "A League of Their Own", + "released": 1992, + "tagline": "Once in a lifetime you get a chance to do something different." + } +] \ No newline at end of file diff --git a/tests/jsons/01-input.json b/tests/jsons/01-input.json new file mode 100644 index 0000000..d4b08a7 --- /dev/null +++ b/tests/jsons/01-input.json @@ -0,0 +1,5 @@ +{ + "movies": { + "count": true + } +} \ No newline at end of file diff --git a/tests/jsons/01-output.json b/tests/jsons/01-output.json new file mode 100644 index 0000000..32a6452 --- /dev/null +++ b/tests/jsons/01-output.json @@ -0,0 +1,5 @@ +{ + "movies": { + "count": 38 + } +} \ No newline at end of file diff --git a/tests/jsons/02-input.json b/tests/jsons/02-input.json new file mode 100644 index 0000000..14a6cf6 --- /dev/null +++ b/tests/jsons/02-input.json @@ -0,0 +1,10 @@ +{ + "movies": { + "[]": [ + 0, + 2 + ], + "title": true, + "released": true + } +} \ No newline at end of file diff --git a/tests/jsons/02-output.json b/tests/jsons/02-output.json new file mode 100644 index 0000000..b9ed30b --- /dev/null +++ b/tests/jsons/02-output.json @@ -0,0 +1,12 @@ +{ + "movies": [ + { + "title": "The Matrix", + "released": 1999 + }, + { + "title": "The Matrix Reloaded", + "released": 2003 + } + ] +} \ No newline at end of file diff --git a/tests/jsons/03-input.json b/tests/jsons/03-input.json new file mode 100644 index 0000000..04ee373 --- /dev/null +++ b/tests/jsons/03-input.json @@ -0,0 +1,12 @@ +{ + "movies": { + "=>items": { + "[]": [ + 20, + 3 + ], + "title": true, + "released": true + } + } +} \ No newline at end of file diff --git a/tests/jsons/03-output.json b/tests/jsons/03-output.json new file mode 100644 index 0000000..1cef6d6 --- /dev/null +++ b/tests/jsons/03-output.json @@ -0,0 +1,18 @@ +{ + "movies": { + "items": [ + { + "title": "Johnny Mnemonic", + "released": 1995 + }, + { + "title": "Cloud Atlas", + "released": 2012 + }, + { + "title": "The Da Vinci Code", + "released": 2006 + } + ] + } +} \ No newline at end of file diff --git a/tests/jsons/04-input.json b/tests/jsons/04-input.json new file mode 100644 index 0000000..99933ef --- /dev/null +++ b/tests/jsons/04-input.json @@ -0,0 +1,11 @@ +{ + "movies": { + "=>items": { + "[]": [ + 5, + 5 + ], + "title=>": true + } + } +} \ No newline at end of file diff --git a/tests/jsons/04-output.json b/tests/jsons/04-output.json new file mode 100644 index 0000000..07694c9 --- /dev/null +++ b/tests/jsons/04-output.json @@ -0,0 +1,11 @@ +{ + "movies": { + "items": [ + "Top Gun", + "Jerry Maguire", + "Stand By Me", + "As Good as It Gets", + "What Dreams May Come" + ] + } +} \ No newline at end of file diff --git a/tests/jsons/05-input.json b/tests/jsons/05-input.json new file mode 100644 index 0000000..5be63ec --- /dev/null +++ b/tests/jsons/05-input.json @@ -0,0 +1,11 @@ +{ + "movies": { + "getByTitle=>movie": { + "()": [ + "The Matrix" + ], + "title": true, + "released": true + } + } +} \ No newline at end of file diff --git a/tests/jsons/05-output.json b/tests/jsons/05-output.json new file mode 100644 index 0000000..493cd1e --- /dev/null +++ b/tests/jsons/05-output.json @@ -0,0 +1,8 @@ +{ + "movies": { + "movie": { + "title": "The Matrix", + "released": 1999 + } + } +} \ No newline at end of file diff --git a/tests/jsons/06-input.json b/tests/jsons/06-input.json new file mode 100644 index 0000000..8d388f4 --- /dev/null +++ b/tests/jsons/06-input.json @@ -0,0 +1,20 @@ +{ + "movies": [ + { + "getByTitle=>": { + "()": [ + "Top Gun" + ], + "title": true + } + }, + { + "getByTitle=>": { + "()": [ + "The Matrix" + ], + "title": true + } + } + ] +} \ No newline at end of file diff --git a/tests/jsons/06-output.json b/tests/jsons/06-output.json new file mode 100644 index 0000000..abc45c0 --- /dev/null +++ b/tests/jsons/06-output.json @@ -0,0 +1,10 @@ +{ + "movies": [ + { + "title": "Top Gun" + }, + { + "title": "The Matrix" + } + ] +} \ No newline at end of file diff --git a/tests/jsons/07-input.json b/tests/jsons/07-input.json new file mode 100644 index 0000000..aa7d43f --- /dev/null +++ b/tests/jsons/07-input.json @@ -0,0 +1,12 @@ +{ + "movies": { + "[]": 20, + "=>": { + "title": true, + "getActors=>actors": { + "()": [], + "name": true + } + } + } +} \ No newline at end of file diff --git a/tests/jsons/07-output.json b/tests/jsons/07-output.json new file mode 100644 index 0000000..a425ae6 --- /dev/null +++ b/tests/jsons/07-output.json @@ -0,0 +1,19 @@ +{ + "movies": { + "title": "Johnny Mnemonic", + "actors": [ + { + "name": "Keanu Reeves" + }, + { + "name": "Takeshi Kitano" + }, + { + "name": "Dina Meyer" + }, + { + "name": "Ice-T" + } + ] + } +} \ No newline at end of file diff --git a/tests/jsons/08-input.json b/tests/jsons/08-input.json new file mode 100644 index 0000000..909aa9f --- /dev/null +++ b/tests/jsons/08-input.json @@ -0,0 +1,10 @@ +{ + "movies=>": { + "[]": [ + 0, + 2 + ], + "title": true, + "released": true + } +} \ No newline at end of file diff --git a/tests/jsons/08-output.json b/tests/jsons/08-output.json new file mode 100644 index 0000000..0edd766 --- /dev/null +++ b/tests/jsons/08-output.json @@ -0,0 +1,10 @@ +[ + { + "title": "The Matrix", + "released": 1999 + }, + { + "title": "The Matrix Reloaded", + "released": 2003 + } +] \ No newline at end of file diff --git a/tests/jsons/09-input.json b/tests/jsons/09-input.json new file mode 100644 index 0000000..b47f57c --- /dev/null +++ b/tests/jsons/09-input.json @@ -0,0 +1,5 @@ +{ + "date": { + "()": [] + } +} \ No newline at end of file diff --git a/tests/jsons/09-output.json b/tests/jsons/09-output.json new file mode 100644 index 0000000..882b8b0 --- /dev/null +++ b/tests/jsons/09-output.json @@ -0,0 +1,3 @@ +{ + "date": "2021-07-20" +} \ No newline at end of file diff --git a/tests/jsons/10-input.json b/tests/jsons/10-input.json new file mode 100644 index 0000000..043d94f --- /dev/null +++ b/tests/jsons/10-input.json @@ -0,0 +1,8 @@ +{ + "movies": { + "[]": 20, + "items=>": { + "title": true + } + } +} \ No newline at end of file diff --git a/tests/jsons/10-output.json b/tests/jsons/10-output.json new file mode 100644 index 0000000..75517ac --- /dev/null +++ b/tests/jsons/10-output.json @@ -0,0 +1,5 @@ +{ + "movies": { + "title": "Johnny Mnemonic" + } +} \ No newline at end of file