コード例 #1
0
 public function testSyncCommandWithNotifications()
 {
     $this->notificationRepository->shouldReceive('all')->withNoArgs()->andReturn(new Notifications([Notification::fromArray(array('title' => 'foobar', 'repositoryName' => 'foo/bar', 'url' => 'http://www.example.com/', 'eventDateTime' => 'now'))]));
     $this->notificationRepository->shouldReceive('markRead')->andReturnNull();
     $this->pullRequestRepository->shouldReceive('add')->andReturnNull();
     $this->runCommand();
 }
コード例 #2
0
 public function testImmutability()
 {
     $notifications = new Notifications();
     $notification = Notification::fromArray(['repositoryName' => 'foo/bar', 'title' => 'Title', 'url' => 'http://www.example.com/', 'eventDateTime' => strftime("%Y-%m-%d %H:%M:%S", time())]);
     $newNotifications = $notifications->add($notification);
     $anotherNotifications = $notifications->add($notification);
     $this->assertNotSame($notifications, $newNotifications);
     $this->assertNotSame($notifications, $anotherNotifications);
     $this->assertNotSame($newNotifications, $anotherNotifications);
     $this->assertEquals($newNotifications, $anotherNotifications);
 }
コード例 #3
0
 public function testInstantiationWithGetters()
 {
     $title = 'foobar';
     $repositoryName = 'foo/bar';
     $url = 'https://www.lonelypullrequests.com/';
     $dateTime = 'now';
     $notification = Notification::fromArray(array('title' => $title, 'repositoryName' => $repositoryName, 'url' => $url, 'eventDateTime' => $dateTime));
     $this->assertInstanceOf('\\LonelyPullRequests\\Domain\\Notification', $notification);
     $this->assertInstanceOf('\\LonelyPullRequests\\Domain\\Title', $notification->title());
     $this->assertEquals($title, $notification->title()->toString());
     $this->assertInstanceOf('\\LonelyPullRequests\\Domain\\RepositoryName', $notification->repositoryName());
     $this->assertEquals($repositoryName, $notification->repositoryName()->toString());
     $this->assertInstanceOf('\\LonelyPullRequests\\Domain\\Url', $notification->url());
     $this->assertEquals($url, $notification->url()->toString());
     $this->assertInstanceOf('\\DateTimeInterface', $notification->eventDateTime());
 }
 /**
  * @param array $notificationStruct
  *
  * @return Notification|null
  */
 private function createNotificationFromStruct($notificationStruct)
 {
     Ensure::keyExists($notificationStruct, 'updated_at');
     Ensure::keyExists($notificationStruct, 'repository');
     Ensure::keyExists($notificationStruct['repository'], 'full_name');
     Ensure::keyExists($notificationStruct, 'subject');
     Ensure::keyExists($notificationStruct['subject'], 'title');
     Ensure::keyExists($notificationStruct['subject'], 'url');
     Ensure::keyExists($notificationStruct['subject'], 'type');
     if ($notificationStruct['subject']['type'] !== 'PullRequest') {
         return null;
     }
     // Translate Github API url to public website url
     $url = str_replace('https://api.github.com/repos/', 'https://github.com/', $notificationStruct['subject']['url']);
     $url = str_replace('/pulls/', '/pull/', $url);
     return Notification::fromArray(['repositoryName' => $notificationStruct['repository']['full_name'], 'title' => $notificationStruct['subject']['title'], 'url' => $url, 'eventDateTime' => $notificationStruct['updated_at']]);
 }