2014-09-26 20:41:28 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Tests\Dao;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Dao\SnapshotDao;
|
|
|
|
use Szurubooru\Dao\UserDao;
|
|
|
|
use Szurubooru\Entities\Snapshot;
|
|
|
|
use Szurubooru\Entities\User;
|
|
|
|
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
2014-09-26 20:41:28 +02:00
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
final class SnapshotDaoTest extends AbstractDatabaseTestCase
|
2014-09-26 20:41:28 +02:00
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2014-10-08 14:47:47 +02:00
|
|
|
$this->userDaoMock = $this->mock(UserDao::class);
|
2014-09-26 20:41:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaving()
|
|
|
|
{
|
|
|
|
$snapshot = $this->getTestSnapshot();
|
|
|
|
$snapshotDao = $this->getSnapshotDao();
|
|
|
|
$snapshotDao->save($snapshot);
|
|
|
|
$this->assertNotNull($snapshot->getId());
|
|
|
|
$this->assertEntitiesEqual($snapshot, $snapshotDao->findById($snapshot->getId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserLazyLoader()
|
|
|
|
{
|
|
|
|
$snapshot = $this->getTestSnapshot();
|
2014-10-08 14:47:47 +02:00
|
|
|
$snapshot->setUser(new User(5));
|
2014-09-26 20:41:28 +02:00
|
|
|
$this->assertEquals(5, $snapshot->getUserId());
|
|
|
|
$snapshotDao = $this->getSnapshotDao();
|
|
|
|
$snapshotDao->save($snapshot);
|
|
|
|
$savedSnapshot = $snapshotDao->findById($snapshot->getId());
|
|
|
|
$this->assertEquals(5, $savedSnapshot->getUserId());
|
|
|
|
|
|
|
|
$this->userDaoMock
|
|
|
|
->expects($this->once())
|
|
|
|
->method('findById');
|
|
|
|
$savedSnapshot->getUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getTestSnapshot()
|
|
|
|
{
|
2014-10-08 14:47:47 +02:00
|
|
|
$snapshot = new Snapshot();
|
|
|
|
$snapshot->setType(Snapshot::TYPE_POST);
|
2014-09-26 20:41:28 +02:00
|
|
|
$snapshot->setData(['wake up', 'neo', ['follow' => 'white rabbit']]);
|
|
|
|
$snapshot->setPrimaryKey(1);
|
2014-09-28 16:26:44 +02:00
|
|
|
$snapshot->setTime(date('c', mktime(1, 2, 3)));
|
2014-09-26 20:41:28 +02:00
|
|
|
$snapshot->setUserId(null);
|
2014-10-08 14:47:47 +02:00
|
|
|
$snapshot->setOperation(Snapshot::OPERATION_CHANGE);
|
2014-09-26 20:41:28 +02:00
|
|
|
return $snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSnapshotDao()
|
|
|
|
{
|
2014-10-08 14:47:47 +02:00
|
|
|
return new SnapshotDao(
|
2014-09-26 20:41:28 +02:00
|
|
|
$this->databaseConnection,
|
|
|
|
$this->userDaoMock);
|
|
|
|
}
|
|
|
|
}
|