Skip to content

Commit

Permalink
added a new unit test. Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Emre Sokullu committed Jun 27, 2017
1 parent 8599afb commit 2031772
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Pho/Framework/AbstractNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ abstract public function __toString(): string;
public function toArray(): array
{
return array(
"edge" => $this->edge_id
"label" => $this->label(),
"edge" => (string) $this->edge_id
);
}

public function label(): string
{
return (new \ReflectionObject($this))->getShortName();
}

/*
public function serialize(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Pho/Framework/NotificationList.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function toArray(): array
{
return array_map(function(AbstractNotification $notification) {
return $notification->toArray();
}, $this->notifications);
}, $this->list);
}

// also deletes
Expand Down
82 changes: 82 additions & 0 deletions tests/Pho/Framework/NotificationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

/*
* This file is part of the Pho package.
*
* (c) Emre Sokullu <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Pho\Framework;

use Pho\Lib\Graph;

class NotificationTest extends \PHPUnit\Framework\TestCase
{
private $graph;

public function setUp() {
$this->graph = new Space();
}

public function tearDown() {
unset($this->graph);
}

public function testSubscriptionNotifications() {
$actor = new Actor($this->graph);
$friend = new Actor($this->graph);
$friend->subscribe($actor);
$obj = new Object($actor, $this->graph);
$edge = $actor->write($obj);
$this->assertEquals(0, $actor->notifications()->count());
$this->assertEquals(1, $friend->notifications()->count());
$this->assertCount(1, $friend->notifications()->toArray());
$this->assertEquals($edge->id()->toString(), $friend->notifications()->toArray()[0]["edge"]);
}


public function testMentionNotifications() {
$actor = new Actor($this->graph);
$friend = new Actor($this->graph);
$obj = new Object($actor, $this->graph);
$edge = $obj->mention($friend);
$this->assertEquals(0, $actor->notifications()->count());
$this->assertEquals(1, $friend->notifications()->count());
$this->assertCount(1, $friend->notifications()->toArray());
$this->assertEquals($edge->id()->toString(), $friend->notifications()->toArray()[0]["edge"]);
}


public function testMultiSubscriptionNotifications() {
$actor = new Actor($this->graph);
$friend1 = new Actor($this->graph);
$friend2 = new Actor($this->graph);
$friend1->subscribe($actor);
$friend2->subscribe($actor);
$obj = new Object($actor, $this->graph);
$edge = $actor->write($obj);
$this->assertEquals(0, $actor->notifications()->count());
$this->assertEquals(1, $friend1->notifications()->count());
$this->assertEquals(1, $friend2->notifications()->count());
$this->assertEquals($edge->id()->toString(), $friend1->notifications()->toArray()[0]["edge"]);
$this->assertEquals($edge->id()->toString(), $friend2->notifications()->toArray()[0]["edge"]);
}

public function testMultiMentionNotifications() {
$actor = new Actor($this->graph);
$friend1 = new Actor($this->graph);
$friend2 = new Actor($this->graph);
$obj = new Object($actor, $this->graph);
$edge1 = $obj->mention($friend1);
$edge2 = $obj->mention($friend2);
$this->assertEquals(0, $actor->notifications()->count());
$this->assertEquals(1, $friend1->notifications()->count());
$this->assertCount(1, $friend2->notifications()->toArray());
$this->assertEquals($edge1->id()->toString(), $friend1->notifications()->toArray()[0]["edge"]);
$this->assertEquals($edge2->id()->toString(), $friend2->notifications()->toArray()[0]["edge"]);
}

}

0 comments on commit 2031772

Please sign in to comment.