-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Entity: get() - fixed converting of value type
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Tester\Assert; | ||
|
||
require_once __DIR__ . '/../bootstrap.php'; | ||
|
||
////////// | ||
|
||
/** | ||
* @property int $id | ||
* @property non-empty-string $name | ||
* @property string|null $description | ||
* @property bool $available | ||
*/ | ||
class Book extends LeanMapper\Entity | ||
{ | ||
} | ||
|
||
|
||
class BookRepository extends \LeanMapper\Repository | ||
{ | ||
/** | ||
* @param $id | ||
* @return Author | ||
* @throws Exception | ||
*/ | ||
public function find($id) | ||
{ | ||
$row = $this->connection->select('*')->from($this->getTable())->where('id = %i', $id)->fetch(); | ||
if ($row === false) { | ||
throw new \Exception('Entity was not found.'); | ||
} | ||
return $this->createEntity($row); | ||
} | ||
} | ||
|
||
////////// | ||
|
||
$connection = Tests::createConnection(); | ||
$mapper = Tests::createMapper(); | ||
$entityFactory = Tests::createEntityFactory(); | ||
|
||
$bookRepository = new BookRepository($connection, $mapper, $entityFactory); | ||
$book = $bookRepository->find(1); | ||
|
||
Assert::same('The Pragmatic Programmer', $book->name); | ||
Assert::null($book->description); | ||
Assert::true($book->available); |