Comments for multiple events are flattened and combined
This commit is contained in:
parent
6b8931ef5f
commit
ac520c4ea5
|
@ -13,14 +13,30 @@ class Picker
|
|||
*/
|
||||
private $hosts;
|
||||
|
||||
/**
|
||||
* @var \Tightenco\Collect\Support\Collection
|
||||
*/
|
||||
private $comments;
|
||||
|
||||
/**
|
||||
* Picker constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->comments = collect();
|
||||
$this->hosts = collect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the combined comments for all events.
|
||||
*
|
||||
* @return \Tightenco\Collect\Support\Collection
|
||||
*/
|
||||
public function getComments(): Collection
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the event hosts.
|
||||
*
|
||||
|
@ -48,4 +64,14 @@ class Picker
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comments for the events.
|
||||
*
|
||||
* @param \Tightenco\Collect\Support\Collection $comments
|
||||
*/
|
||||
public function setComments(Collection $comments)
|
||||
{
|
||||
$this->comments = $comments->flatten(1)->values();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,22 @@ class PickerTest extends TestCase
|
|||
/** @test */
|
||||
public function comments_for_multiple_events_are_flattened_and_combined()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$data = [
|
||||
[
|
||||
['comment' => 'Great talk!'],
|
||||
['comment' => 'Could be better.'],
|
||||
],
|
||||
[
|
||||
['comment' => 'Needs more cat pictures.'],
|
||||
],
|
||||
];
|
||||
|
||||
$picker = new Picker();
|
||||
$picker->setComments(collect($data));
|
||||
|
||||
$comments = $picker->getComments();
|
||||
$this->assertInstanceOf(Collection::class, $comments);
|
||||
$this->assertCount(3, $comments);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
|
Loading…
Reference in a new issue