Use stdClass rather than arrays

This commit is contained in:
Oliver Davies 2019-02-14 02:14:32 +00:00
parent 119afd9f24
commit c030a9658d
2 changed files with 44 additions and 48 deletions

View file

@ -77,8 +77,8 @@ class Picker
{ {
$this->comments = $comments $this->comments = $comments
->flatten(1) ->flatten(1)
->filter(function (array $comment) { ->filter(function (\stdClass $comment) {
return !$this->isUserAnEventHost($comment['user_display_name']); return !$this->isUserAnEventHost($comment->user_display_name);
}) })
->values(); ->values();

View file

@ -40,23 +40,21 @@ class PickerTest extends TestCase
/** @test */ /** @test */
public function comments_for_multiple_events_are_flattened_and_combined() public function comments_for_multiple_events_are_flattened_and_combined()
{ {
$comment1 = new \stdClass();
$comment1->comment = 'Great talk!';
$comment1->user_display_name = 'Dan Ackroyd';
$comment2 = new \stdClass();
$comment2->comment = 'Could be better.';
$comment2->user_display_name = 'Lucia Velasco';
$comment3 = new \stdClass();
$comment3->comment = 'Needs more cat pictures.';
$comment3->user_display_name = 'Rupert Jabelman';
$data = [ $data = [
[ [$comment1, $comment2],
[ [$comment3],
'comment' => 'Great talk!',
'user_display_name' => 'Dan Ackroyd',
],
[
'comment' => 'Could be better.',
'user_display_name' => 'Lucia Velasco',
],
],
[
[
'comment' => 'Needs more cat pictures.',
'user_display_name' => 'Rupert Jabelman',
],
],
]; ];
$comments = (new Picker()) $comments = (new Picker())
@ -76,21 +74,20 @@ class PickerTest extends TestCase
], ],
]; ];
$comment1 = new \stdClass();
$comment1->comment = 'Great talk!';
$comment1->user_display_name = 'Peter Fisher';
$comment2 = new \stdClass();
$comment2->comment = 'Text on slides could be bigger.';
$comment2->user_display_name = 'Oliver Davies';
$comment3 = new \stdClass();
$comment3->comment = 'Speak slower.';
$comment3->user_display_name = 'Zan Baldwin';
$comments = [ $comments = [
[ [$comment1, $comment2, $comment3],
[
'comment' => 'Great talk!',
'user_display_name' => 'Peter Fisher',
],
[
'comment' => 'Text on slides could be bigger.',
'user_display_name' => 'Oliver Davies',
],
[
'comment' => 'Speak slower.',
'user_display_name' => 'Zan Baldwin',
],
],
]; ];
$comments = (new Picker()) $comments = (new Picker())
@ -99,28 +96,27 @@ class PickerTest extends TestCase
->getComments(); ->getComments();
$this->assertCount(2, $comments); $this->assertCount(2, $comments);
$this->assertSame('Peter Fisher', $comments[0]['user_display_name']); $this->assertSame('Peter Fisher', $comments[0]->user_display_name);
$this->assertSame('Zan Baldwin', $comments[1]['user_display_name']); $this->assertSame('Zan Baldwin', $comments[1]->user_display_name);
} }
/** @test */ /** @test */
public function winners_can_be_selected() public function winners_can_be_selected()
{ {
$comment1 = new \stdClass();
$comment1->comment = 'Great talk!';
$comment1->user_display_name = 'Peter Fisher';
$comment2 = new \stdClass();
$comment2->comment = 'Text on slides could be bigger.';
$comment2->user_display_name = 'Michael Bush';
$comment3 = new \stdClass();
$comment3->comment = 'Speak slower.';
$comment3->user_display_name = 'Zan Baldwin';
$comments = [ $comments = [
[ [$comment1, $comment2, $comment3],
[
'comment' => 'Great talk!',
'user_display_name' => 'Peter Fisher',
],
[
'comment' => 'Text on slides could be bigger.',
'user_display_name' => 'Michael Bush',
],
[
'comment' => 'Speak slower.',
'user_display_name' => 'Zan Baldwin',
],
],
]; ];
$picker = new Picker(); $picker = new Picker();