-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ added Language + updated ApiData * updated tests
- Loading branch information
1 parent
03aebd0
commit 3563142
Showing
6 changed files
with
178 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* Created by PhpStorm. | ||
* User: jeroen | ||
* Date: 20-3-19 | ||
* Time: 21:19 | ||
*/ | ||
|
||
namespace Prismic; | ||
|
||
|
||
class Language | ||
{ | ||
|
||
/** | ||
* Language id | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* Language name | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* Language constructor. | ||
* | ||
* @param string $id | ||
* @param string $name | ||
*/ | ||
private function __construct( | ||
string $id, | ||
string $name | ||
) | ||
{ | ||
$this->id = $id; | ||
$this->name = $name; | ||
} | ||
|
||
|
||
/** | ||
* | ||
* @return string | ||
*/ | ||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* | ||
* @param \stdClass $json | ||
* @return Language | ||
* | ||
* @throws Exception\InvalidArgumentException | ||
*/ | ||
public static function parse(\stdClass $json): self | ||
{ | ||
if (! isset($json->id, $json->name)) { | ||
throw new Exception\InvalidArgumentException( | ||
'The properties id, name should exist in the JSON object for a Language' | ||
); | ||
} | ||
return new self( | ||
$json->id, | ||
$json->name | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* Created by PhpStorm. | ||
* User: jeroen | ||
* Date: 20-3-19 | ||
* Time: 21:24 | ||
*/ | ||
|
||
namespace Prismic\Test; | ||
|
||
|
||
use Prismic\Exception\InvalidArgumentException; | ||
use Prismic\Language; | ||
|
||
class LanguageTest extends TestCase | ||
{ | ||
|
||
/** @var Language */ | ||
private $language; | ||
/** @var \stdClass */ | ||
private $json; | ||
|
||
public function setUp() | ||
{ | ||
$this->json = $json = \json_decode($this->getJsonFixture('language.json')); | ||
$this->language = Language::parse($json); | ||
} | ||
|
||
public function testCorrectId() | ||
{ | ||
$this->assertSame($this->json->id, $this->language->getId()); | ||
$this->assertSame($this->json->name, $this->language->getName()); | ||
} | ||
|
||
/** | ||
* @expectedException InvalidArgumentException | ||
*/ | ||
public function testWrongObjectType() | ||
{ | ||
Language::parse(new \stdClass); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"id": "en-us", | ||
"name": "English - United States" | ||
} |