Files
kimai2/tests/Event/UserPreferenceEventTest.php
2019-10-24 17:35:05 +02:00

57 lines
1.4 KiB
PHP

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Event;
use App\Entity\User;
use App\Entity\UserPreference;
use App\Event\UserPreferenceEvent;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Event\UserPreferenceEvent
*/
class UserPreferenceEventTest extends TestCase
{
public function testGetterAndSetter()
{
$user = new User();
$user->setAlias('foo');
$pref = new UserPreference();
$pref->setName('foo')->setValue('bar');
$sut = new UserPreferenceEvent($user, []);
$this->assertEquals($user, $sut->getUser());
$this->assertEquals([], $sut->getPreferences());
$sut->addPreference($pref);
$this->assertEquals([$pref], $sut->getPreferences());
}
public function testDuplicatePreferenceThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$user = new User();
$user->setAlias('foo');
$pref = new UserPreference();
$pref->setName('foo')->setValue('bar');
$pref2 = new UserPreference();
$pref2->setName('foo')->setValue('hello');
$sut = new UserPreferenceEvent($user, []);
$sut->addUserPreference($pref); // change me, once the deprecated method will be deleted
$sut->addPreference($pref2);
}
}