Skip to content

Commit

Permalink
Move DB mapper tests from unit to integration testing
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Schwörer <[email protected]>
  • Loading branch information
paulschwoerer committed Feb 5, 2020
1 parent 7887f0a commit 0a02734
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion phpunit.integration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<filter>
<whitelist>
<directory suffix=".php">appinfo</directory>
<directory suffix=".php">lib</directory>
<exclude>
<directory suffix=".php">lib</directory>
<directory suffix=".php">templates</directory>
</exclude>
</whitelist>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
*/

namespace tests\Unit\Mapper;
namespace tests\Integration\Db;


use ChristophWurst\Nextcloud\Testing\DatabaseTransaction;
Expand All @@ -36,20 +36,20 @@ class FavoriteShareMapperTest extends TestCase {
use DatabaseTransaction;

/* @var FavoriteShareMapper */
private $favoriteShareMapper;
private $mapper;

public function setUp(): void {
parent::setUp();

$this->favoriteShareMapper = new FavoriteShareMapper(
$this->mapper = new FavoriteShareMapper(
OC::$server->getDatabaseConnection(),
OC::$server->getSecureRandom()
);
}

public function testCreateByOwnerAndTokenIsSuccessful() {
/* @var FavoriteShare */
$share = $this->favoriteShareMapper->create("testUser", "testCategory");
$share = $this->mapper->create("testUser", "testCategory");

$this->assertIsString($share->getToken());
$this->assertEquals("testUser", $share->getOwner());
Expand All @@ -58,10 +58,10 @@ public function testCreateByOwnerAndTokenIsSuccessful() {

public function testFindByTokenIsSuccessful() {
/* @var FavoriteShare */
$shareExpected = $this->favoriteShareMapper->create("testUser", "testCategory");
$shareExpected = $this->mapper->create("testUser", "testCategory");

/* @var FavoriteShare */
$shareActual = $this->favoriteShareMapper->findByToken($shareExpected->getToken());
$shareActual = $this->mapper->findByToken($shareExpected->getToken());

$this->assertEquals($shareExpected->getToken(), $shareActual->getToken());
$this->assertEquals($shareExpected->getOwner(), $shareActual->getOwner());
Expand All @@ -70,10 +70,10 @@ public function testFindByTokenIsSuccessful() {

public function testFindByOwnerAndCategoryIsSuccessful() {
/* @var FavoriteShare */
$shareExpected = $this->favoriteShareMapper->create("testUser", "testCategory");
$shareExpected = $this->mapper->create("testUser", "testCategory");

/* @var FavoriteShare */
$shareActual = $this->favoriteShareMapper->findByOwnerAndCategory("testUser", "testCategory");
$shareActual = $this->mapper->findByOwnerAndCategory("testUser", "testCategory");

$this->assertEquals($shareExpected->getToken(), $shareActual->getToken());
$this->assertEquals($shareExpected->getOwner(), $shareActual->getOwner());
Expand All @@ -82,15 +82,15 @@ public function testFindByOwnerAndCategoryIsSuccessful() {

public function testFindAllByOwnerIsSuccessfulAndDoesNotContainOtherShares() {
/* @var FavoriteShare */
$share1 = $this->favoriteShareMapper->create("testUser", "testCategory1");
$share1 = $this->mapper->create("testUser", "testCategory1");

/* @var FavoriteShare */
$share2 = $this->favoriteShareMapper->create("testUser", "testCategory2");
$share2 = $this->mapper->create("testUser", "testCategory2");

$this->favoriteShareMapper->create("testUser2", "testCategory");
$this->mapper->create("testUser2", "testCategory");

/* @var array */
$shares = $this->favoriteShareMapper->findAllByOwner("testUser");
$shares = $this->mapper->findAllByOwner("testUser");

$shareTokens = array_map(function ($share) {
return $share->getToken();
Expand All @@ -103,7 +103,7 @@ public function testFindAllByOwnerIsSuccessfulAndDoesNotContainOtherShares() {

public function testFindOrCreateByOwnerAndCategoryIsSuccessful() {
/* @var FavoriteShare */
$share = $this->favoriteShareMapper->findOrCreateByOwnerAndCategory("testUser", "testCategory");
$share = $this->mapper->findOrCreateByOwnerAndCategory("testUser", "testCategory");

$this->assertIsString($share->getToken());
$this->assertEquals("testUser", $share->getOwner());
Expand All @@ -112,13 +112,13 @@ public function testFindOrCreateByOwnerAndCategoryIsSuccessful() {

public function testRemoveByOwnerAndCategoryIsSuccessful() {
/* @var FavoriteShare */
$share = $this->favoriteShareMapper->create("testUser", "testCategory");
$share = $this->mapper->create("testUser", "testCategory");

$this->favoriteShareMapper->removeByOwnerAndCategory($share->getOwner(), $share->getCategory());
$this->mapper->removeByOwnerAndCategory($share->getOwner(), $share->getCategory());

$this->expectException(DoesNotExistException::class);

$this->favoriteShareMapper->findByOwnerAndCategory($share->getOwner(), $share->getCategory());
$this->mapper->findByOwnerAndCategory($share->getOwner(), $share->getCategory());
}

}

0 comments on commit 0a02734

Please sign in to comment.