point-tools/old/tests/Skobkin/PointToolsBundle/Event/UserSubscribersUpdatedEventTest.php

60 lines
2.2 KiB
PHP
Raw Normal View History

2017-01-09 20:51:39 +00:00
<?php
namespace Tests\Skobkin\PointToolsBundle\Event;
use src\PointToolsBundle\Entity\User;
use src\PointToolsBundle\Event\UserSubscribersUpdatedEvent;
2017-01-09 20:51:39 +00:00
class UserSubscribersUpdatedEventTest extends \PHPUnit_Framework_TestCase
{
public function testNameConstant()
{
$this->assertEquals('app.user.subscribers_updated', UserSubscribersUpdatedEvent::NAME, 'Event name changed');
}
public function testCreate()
{
2017-01-17 21:58:53 +00:00
$user = new User(99999, new \DateTime(), 'testuser', 'Test User 1');
2017-01-09 20:51:39 +00:00
$subscribed = [
2017-01-17 21:58:53 +00:00
new User(99998, new \DateTime(), 'testuser2', 'Test User 2'),
2017-01-09 20:51:39 +00:00
];
$unsubscribed = [
2017-01-17 21:58:53 +00:00
new User(99997, new \DateTime(), 'testuser3', 'Test User 3'),
new User(99996, new \DateTime(), 'testuser4', 'Test User 4'),
2017-01-09 20:51:39 +00:00
];
return new UserSubscribersUpdatedEvent($user, $subscribed, $unsubscribed);
}
/**
* @depends testCreate
*/
public function testGetUser(UserSubscribersUpdatedEvent $event)
{
$this->assertNotNull($event->getUser(), 'User cannot be extracted from event');
$this->assertEquals('testuser', $event->getUser()->getLogin(), 'Invalid user login extracted');
$this->assertEquals('Test User 1', $event->getUser()->getName(), 'Invalid user name extracted');
}
/**
* @depends testCreate
*/
public function testGetSubscribedUsers(UserSubscribersUpdatedEvent $event)
{
$this->assertInternalType('array', $event->getSubscribedUsers(), 'Invalid type returned');
$this->assertCount(1, $event->getSubscribedUsers(), 'Not exactly 1 subscribed user extracted');
$this->assertEquals('testuser2', $event->getSubscribedUsers()[0]->getLogin(), 'Invalid subscriber login extracted');
}
/**
* @depends testCreate
*/
public function testGetUnsubscribedUsers(UserSubscribersUpdatedEvent $event)
{
$this->assertInternalType('array', $event->getUnsubscribedUsers(), 'Invalid type returned');
$this->assertCount(2, $event->getUnsubscribedUsers(), 'Not exactly 2 unsubscribed user extracted');
$this->assertEquals('testuser3', $event->getUnsubscribedUsers()[0]->getLogin(), 'Invalid unsubscriber login extracted');
}
}