From d79d056c97ccdd61c8cf6b406cac941022ff3a6e Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Thu, 9 Jan 2020 14:02:58 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Remove=20hhvm=20and=20php7.1=20as=20it?= =?UTF-8?q?=E2=80=99s=20out=20of=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lasse Mammen --- .travis.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 30a1f80..e12efbf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,9 @@ language: php php: - - 7.1.18 - 7.2 - 7.3 - + - 7.4 addons: code_climate: @@ -23,10 +22,10 @@ jobs: name: "Static Analyser" before_script: - - if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi - - if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi - - if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then echo "extension = igbinary.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi + - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - echo "extension = igbinary.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - composer install after_script: - - vendor/bin/test-reporter \ No newline at end of file + - vendor/bin/test-reporter From e9ce9916a56a13788c3901f15c6bceb48ec484b7 Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Thu, 9 Jan 2020 14:23:58 +0000 Subject: [PATCH 2/2] Add Journey and Language entity Signed-off-by: Lasse Mammen --- src/Entity/Frontpage.php | 4 +- src/Entity/Journey.php | 147 ++++++++++++++++++++++++++++++++++ src/Entity/Language.php | 81 +++++++++++++++++++ src/Entity/Subscription.php | 2 +- tests/Entity/JourneyTest.php | 66 +++++++++++++++ tests/Entity/LanguageTest.php | 52 ++++++++++++ 6 files changed, 349 insertions(+), 3 deletions(-) create mode 100644 src/Entity/Journey.php create mode 100644 src/Entity/Language.php create mode 100644 tests/Entity/JourneyTest.php create mode 100644 tests/Entity/LanguageTest.php diff --git a/src/Entity/Frontpage.php b/src/Entity/Frontpage.php index 8e069cf..dd3a496 100644 --- a/src/Entity/Frontpage.php +++ b/src/Entity/Frontpage.php @@ -24,7 +24,7 @@ class Frontpage extends Entity */ public static function get(Bookboon $bookboon, array $bookTypes = ['pdf']) : BookboonResponse { - $bResponse = $bookboon->rawRequest("/frontpage", ['bookType' => join(',', $bookTypes)]); + $bResponse = $bookboon->rawRequest('/frontpage', ['bookType' => implode(',', $bookTypes)]); $bResponse->setEntityStore( new EntityStore(Frontpage::getEntitiesFromArray($bResponse->getReturnArray())) @@ -107,4 +107,4 @@ public function getBooks() : array { return Book::getEntitiesFromArray($this->safeGet('books', [])); } -} \ No newline at end of file +} diff --git a/src/Entity/Journey.php b/src/Entity/Journey.php new file mode 100644 index 0000000..f1801da --- /dev/null +++ b/src/Entity/Journey.php @@ -0,0 +1,147 @@ +rawRequest("/journeys/$journeyId"); + + $journeyEntity = new static($bResponse->getReturnArray()); + + if (count($journeyEntity->getBookIds()) > 0) { + $books = Book::getMultiple($bookboon, $journeyEntity->getBookIds(), false); + } + + $journeyEntity->setBooks($books->getEntityStore()->get()); + + $bResponse->setEntityStore( + new EntityStore( + [ + $journeyEntity + ] + ) + ); + + return $bResponse; + } + + /** + * Get all journeys + * + * @param Bookboon $bookboon + * @param array $bookTypes + * @return BookboonResponse + * @throws UsageException + * @throws \Bookboon\Api\Exception\ApiDecodeException + */ + public static function getAll(Bookboon $bookboon, array $bookTypes = ['pdf']) : BookboonResponse + { + $bResponse = $bookboon->rawRequest('/journeys'); + + $bResponse->setEntityStore( + new EntityStore(Journey::getEntitiesFromArray($bResponse->getReturnArray())) + ); + + return $bResponse; + } + + /** + * @return string id + */ + public function getId() : string + { + return $this->safeGet('_id'); + } + + /** + * @return string title + */ + public function getTitle() : string + { + return $this->safeGet('title'); + } + + /** + * @return string abstract + */ + public function getAbstract() : string + { + return $this->safeGet('abstract'); + } + + /** + * @return string description + */ + public function getDescription() : string + { + return $this->safeGet('description'); + } + + /** + * Return publish date. + * + * @return string date of publishing + */ + public function getPublished() : string + { + return $this->safeGet('published'); + } + + /** + * @return bool is featured + */ + public function isFeatured() : bool + { + return $this->safeGet('isFeatured'); + } + + /** + * @return array book ids + */ + public function getBookIds() : array + { + return $this->safeGet('books', []); + } + + /** + * @return array books + */ + public function getBooks() : array + { + return $this->books; + } + + /** + * @param array $books + * @return void + */ + public function setBooks(array $books) : void + { + $this->books = $books; + } + + /** + * Determines whether api response is valid + * + * @param array $array + * @return bool + */ + protected function isValid(array $array): bool + { + return isset($array['_id'], $array['title'], $array['abstract']); + } +} diff --git a/src/Entity/Language.php b/src/Entity/Language.php new file mode 100644 index 0000000..1c0dbdf --- /dev/null +++ b/src/Entity/Language.php @@ -0,0 +1,81 @@ +rawRequest('/languages'); + + $bResponse->setEntityStore( + new EntityStore(Language::getEntitiesFromArray($bResponse->getReturnArray())) + ); + + return $bResponse; + } + + /** + * @return string id + */ + public function getId() : string + { + return $this->safeGet('id'); + } + + /** + * @return string code + */ + public function getCode() : string + { + return $this->safeGet('code'); + } + + /** + * @return string slug + */ + public function getSlug() : string + { + return $this->safeGet('_slug'); + } + + /** + * @return string name + */ + public function getName() : string + { + return $this->safeGet('name'); + } + + /** + * @return string localized name + */ + public function getLocalizedName() : string + { + return $this->safeGet('localizedName'); + } + + /** + * Determines whether api response is valid + * + * @param array $array + * @return bool + */ + protected function isValid(array $array): bool + { + return isset($array['code'], $array['id'], $array['name']); + } +} diff --git a/src/Entity/Subscription.php b/src/Entity/Subscription.php index 212c3a0..e1d4231 100644 --- a/src/Entity/Subscription.php +++ b/src/Entity/Subscription.php @@ -86,4 +86,4 @@ public static function remove(Bookboon $bookboon, string $email, ?string $alias) } } - + diff --git a/tests/Entity/JourneyTest.php b/tests/Entity/JourneyTest.php new file mode 100644 index 0000000..b68979b --- /dev/null +++ b/tests/Entity/JourneyTest.php @@ -0,0 +1,66 @@ + ['getTitle'], + 'getId' => ['getId'], + 'getAbstract' => ['getAbstract'], + 'getDescription' => ['getDescription'], + 'getPublished' => ['getPublished'], + ]; + } + + public function testFirstAllJourneysData() + { + $data = Journey::getAll(self::$bookboon) + ->getEntityStore() + ->get()[0]; + + foreach ($this->methodsToTest as $method) { + $this->assertNotFalse($data->$method()); + } + } + + public function testGetJourney() + { + $data = Journey::get(self::$bookboon, '010e0268-0eec-4859-a67a-ce41ee2315c4') + ->getEntityStore() + ->get()[0]; + + foreach ($this->methodsToTest as $method) { + $this->assertNotFalse($data->$method()); + } + + $this->assertInstanceOf(Book::class, $data->getBooks()[0]); + } + + /** + * @expectedException \Bookboon\Api\Exception\EntityDataException + */ + public function testInvalidJourney() + { + $language = new Language(['blah']); + } +} diff --git a/tests/Entity/LanguageTest.php b/tests/Entity/LanguageTest.php new file mode 100644 index 0000000..aacf200 --- /dev/null +++ b/tests/Entity/LanguageTest.php @@ -0,0 +1,52 @@ +getEntityStore() + ->get()[0]; + } + + public function providerTestGetters() + { + return [ + 'getName' => ['getName'], + 'getId' => ['getId'], + 'getLocalizedName' => ['getLocalizedName'], + 'getCode' => ['getCode'], + ]; + } + + /** + * @dataProvider providerTestGetters + */ + public function testNotFalse($method) + { + $this->assertNotFalse(self::$data->$method()); + } + + /** + * @expectedException \Bookboon\Api\Exception\EntityDataException + */ + public function testInvalidLanguage() + { + $language = new Language(['blah']); + } +}