Skip to content

Commit

Permalink
Merge pull request #36 from cultuurnet/feature/III-2534
Browse files Browse the repository at this point in the history
III-2534: Add method to get first detail from a list
  • Loading branch information
cyberwolf committed Jul 3, 2018
2 parents cd9db38 + c322951 commit e6305e7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/CultureFeed/Cdb/Data/DetailList.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,16 @@ public function getDetailByLanguage($language_code)
}
}
}

/**
* Get the first detail.
*
* @return CultureFeed_Cdb_Data_Detail|NULL
*/
public function getFirst()
{
// Reset indices to 0, 1, 2, ... before trying to get the value for index 0.
$details = array_values($this->details);
return isset($details[0]) ? $details[0] : null;
}
}
57 changes: 57 additions & 0 deletions tests/CultureFeed/Cdb/Data/DetailListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

class CultureFeed_Cdb_Data_DetailListTest extends PHPUnit_Framework_TestCase
{
/**
* @var \CultureFeed_Cdb_Data_DetailList
*/
private $details;

public function setUp()
{
$this->details = $this->getMockForAbstractClass('\CultureFeed_Cdb_Data_DetailList');
}

public function testGetFirstWithOneDetail()
{
$first = $this->createDetail();
$first->setTitle('Foo bar');

$this->details->add($first);

$this->assertEquals($first, $this->details->getFirst());
}

public function testGetFirstWithMultipleDetails()
{
$first = $this->createDetail();
$first->setTitle('Foo bar');

$second = $this->createDetail();
$second->setTitle('Lorem ipsum');

$third = $this->createDetail();
$third->setTitle('Acme');

$this->details->add($first);
$this->details->add($second);
$this->details->add($third);

$this->assertEquals($first, $this->details->getFirst());
}

public function testGetFirstWithNoDetails()
{
$this->assertNull($this->details->getFirst());
}

/**
* @return CultureFeed_Cdb_Data_Detail
*/
private function createDetail()
{
/* @var CultureFeed_Cdb_Data_Detail $mock */
$mock = $this->getMockForAbstractClass('\CultureFeed_Cdb_Data_Detail');
return $mock;
}
}

0 comments on commit e6305e7

Please sign in to comment.