test unique index constraint for episode actions
This commit is contained in:
parent
ba0d4f4357
commit
ae27f7cf34
24
tests/Helper/DatabaseTransaction.php
Normal file
24
tests/Helper/DatabaseTransaction.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace tests\Helper;
|
||||||
|
|
||||||
|
use OC;
|
||||||
|
use OCP\IDBConnection;
|
||||||
|
|
||||||
|
trait DatabaseTransaction {
|
||||||
|
|
||||||
|
public function startTransaction() {
|
||||||
|
/* @var $db IDBConnection */
|
||||||
|
$db = OC::$server->get(IDBConnection::class);
|
||||||
|
|
||||||
|
$db->beginTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rollbackTransation() {
|
||||||
|
/* @var $db IDBConnection */
|
||||||
|
$db = OC::$server->get(IDBConnection::class);
|
||||||
|
|
||||||
|
$db->rollBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
65
tests/Integration/EpisodeActionGuidMigrationTest.php
Normal file
65
tests/Integration/EpisodeActionGuidMigrationTest.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests\Integration;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||||
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionEntity;
|
||||||
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionWriter;
|
||||||
|
use OCP\AppFramework\App;
|
||||||
|
use Test\TestCase;
|
||||||
|
use tests\Helper\DatabaseTransaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DB
|
||||||
|
*/
|
||||||
|
class EpisodeActionGuidMigrationTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseTransaction;
|
||||||
|
|
||||||
|
private \OCP\AppFramework\IAppContainer $container;
|
||||||
|
|
||||||
|
public function setUp(): void {
|
||||||
|
parent::setUp();
|
||||||
|
$app = new App('gpoddersync');
|
||||||
|
$this->container = $app->getContainer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @before
|
||||||
|
*/
|
||||||
|
public function before()
|
||||||
|
{
|
||||||
|
$this->startTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateSameEpisodeActionTriggersUniqueConstraintViolationException()
|
||||||
|
{
|
||||||
|
self::expectException(UniqueConstraintViolationException::class);
|
||||||
|
|
||||||
|
/** @var EpisodeActionWriter $episodeActionWriter */
|
||||||
|
$episodeActionWriter = $this->container->get('OCA\GPodderSync\Db\EpisodeAction\EpisodeActionWriter');
|
||||||
|
|
||||||
|
$episodeActionEntity = new EpisodeActionEntity();
|
||||||
|
$episodeActionEntity->setPodcast("https://podcast_01.url");
|
||||||
|
$episodeActionEntity->setEpisode("https://episode_01.url");
|
||||||
|
$episodeActionEntity->setAction("PLAY");
|
||||||
|
$episodeActionEntity->setPosition(5);
|
||||||
|
$episodeActionEntity->setStarted(0);
|
||||||
|
$episodeActionEntity->setTotal(123);
|
||||||
|
$episodeActionEntity->setTimestamp("Mon Aug 23 01:58:56 GMT+02:00 2021");
|
||||||
|
$episodeActionEntity->setUserId("user0@127.0.0.1");
|
||||||
|
$episodeActionWriter->save($episodeActionEntity);
|
||||||
|
|
||||||
|
$episodeActionWriter->save($episodeActionEntity);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @after
|
||||||
|
*/
|
||||||
|
public function after()
|
||||||
|
{
|
||||||
|
$this->rollbackTransation();
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ if (!defined('PHPUNIT_RUN')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../lib/base.php';
|
require_once __DIR__ . '/../../../lib/base.php';
|
||||||
|
require_once __DIR__ . '/Helper/DatabaseTransaction.php';
|
||||||
// Fix for "Autoload path not allowed: .../tests/lib/testcase.php"
|
// Fix for "Autoload path not allowed: .../tests/lib/testcase.php"
|
||||||
OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests');
|
OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user