Skip to content

Commit

Permalink
added find-by-uuid to task-repository (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Nov 23, 2016
1 parent 3c9a0f6 commit cc16388
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Task/Storage/ArrayStorage/ArrayTaskRepository.php
Expand Up @@ -35,6 +35,19 @@ public function __construct(Collection $tasks = null)
$this->taskCollection = $tasks ?: new ArrayCollection();
}

/**
* {@inheritdoc}
*/
public function findByUuid($uuid)
{
/** @var TaskInterface $task */
foreach ($this->taskCollection as $task) {
if ($task->getUuid() === $uuid) {
return $task;
}
}
}

/**
* {@inheritdoc}
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Task/Storage/TaskRepositoryInterface.php
Expand Up @@ -18,6 +18,15 @@
*/
interface TaskRepositoryInterface
{
/**
* Find task for given uuid.
*
* @param string $uuid
*
* @return TaskInterface
*/
public function findByUuid($uuid);

/**
* Create task.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/Unit/Storage/ArrayStorage/ArrayTaskRepositoryTest.php
Expand Up @@ -24,6 +24,32 @@
*/
class ArrayTaskRepositoryTest extends \PHPUnit_Framework_TestCase
{
public function testFindByUuid()
{
$tasks = [
new Task(\stdClass::class, 'Test 1', '123-123-123'),
new Task(\stdClass::class, 'Test 2'),
new Task(\stdClass::class, 'Test 3'),
];

$repository = new ArrayTaskRepository(new ArrayCollection($tasks));

$this->assertEquals($tasks[0], $repository->findByUuid('123-123-123'));
}

public function testFindByUuidNotExisting()
{
$tasks = [
new Task(\stdClass::class, 'Test 1'),
new Task(\stdClass::class, 'Test 2'),
new Task(\stdClass::class, 'Test 3'),
];

$repository = new ArrayTaskRepository(new ArrayCollection($tasks));

$this->assertNull($repository->findByUuid('123-123-123'));
}

public function testPersist()
{
$collection = $this->prophesize(Collection::class);
Expand Down

0 comments on commit cc16388

Please sign in to comment.