Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## x.y.z

### Added
- Repository.remove (#278)
- Interface for domain models (#274)
- Trait for database tests and abstract web test (#264)
- Repository methods for querying subscriptions (#253)
Expand Down
16 changes: 16 additions & 0 deletions src/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,20 @@ public function save(DomainModel $model)
$this->getEntityManager()->persist($model);
$this->getEntityManager()->flush();
}

/**
* Removes $model and flushes the entity manager change list.
*
* This method allows controllers to not depend on the entity manager, but only on the repositories instead,
* following the Law of Demeter.
*
* @param DomainModel $model
*
* @return void
*/
public function remove(DomainModel $model)
{
$this->getEntityManager()->remove($model);
$this->getEntityManager()->flush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,23 @@ public function savePersistsAndFlushesModel()

static::assertSame($model, $this->subject->find($model->getId()));
}

/**
* @test
*/
public function removeRemovesModel()
{
$this->getDataSet()->addTable(static::TABLE_NAME, __DIR__ . '/../Fixtures/Administrator.csv');
$this->applyDatabaseChanges();

/** @var Administrator[] $allModels */
$allModels = $this->subject->findAll();
$numberOfModelsBeforeRemove = count($allModels);
$firstModel = $allModels[0];

$this->subject->remove($firstModel);

$numberOfModelsAfterRemove = count($this->subject->findAll());
static::assertSame(1, $numberOfModelsBeforeRemove - $numberOfModelsAfterRemove);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,23 @@ public function savePersistsAndFlushesModel()

static::assertSame($model, $this->subject->find($model->getId()));
}

/**
* @test
*/
public function removeRemovesModel()
{
$this->getDataSet()->addTable(static::TABLE_NAME, __DIR__ . '/../Fixtures/DetachedAdministratorTokens.csv');
$this->applyDatabaseChanges();

/** @var AdministratorToken[] $allModels */
$allModels = $this->subject->findAll();
$numberOfModelsBeforeRemove = count($allModels);
$firstModel = $allModels[0];

$this->subject->remove($firstModel);

$numberOfModelsAfterRemove = count($this->subject->findAll());
static::assertSame(1, $numberOfModelsBeforeRemove - $numberOfModelsAfterRemove);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,23 @@ public function removeAlsoRemovesAssociatedSubscriptions()
$numberOfRemovedSubscriptions = $initialNumberOfSubscriptions - $newNumberOfSubscriptions;
static::assertSame($numberOfAssociatedSubscriptions, $numberOfRemovedSubscriptions);
}

/**
* @test
*/
public function removeRemovesModel()
{
$this->getDataSet()->addTable(static::TABLE_NAME, __DIR__ . '/../Fixtures/SubscriberList.csv');
$this->applyDatabaseChanges();

/** @var SubscriberList[] $allModels */
$allModels = $this->subject->findAll();
$numberOfModelsBeforeRemove = count($allModels);
$firstModel = $allModels[0];

$this->subject->remove($firstModel);

$numberOfModelsAfterRemove = count($this->subject->findAll());
static::assertSame(1, $numberOfModelsBeforeRemove - $numberOfModelsAfterRemove);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,23 @@ public function removeAlsoRemovesAssociatedSubscriptions()
$numberOfRemovedSubscriptions = $initialNumberOfSubscriptions - $newNumberOfSubscriptions;
static::assertSame($numberOfAssociatedSubscriptions, $numberOfRemovedSubscriptions);
}

/**
* @test
*/
public function removeRemovesModel()
{
$this->getDataSet()->addTable(static::TABLE_NAME, __DIR__ . '/../Fixtures/Subscriber.csv');
$this->applyDatabaseChanges();

/** @var Subscriber[] $allModels */
$allModels = $this->subject->findAll();
$numberOfModelsBeforeRemove = count($allModels);
$firstModel = $allModels[0];

$this->subject->remove($firstModel);

$numberOfModelsAfterRemove = count($this->subject->findAll());
static::assertSame(1, $numberOfModelsBeforeRemove - $numberOfModelsAfterRemove);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public function findBySubscriberFindsSubscriptionOnlyWithTheGivenSubscriber()
{
$this->getDataSet()->addTable(static::SUBSCRIBER_TABLE_NAME, __DIR__ . '/../Fixtures/Subscriber.csv');
$this->getDataSet()->addTable(static::TABLE_NAME, __DIR__ . '/../Fixtures/Subscription.csv');
$this->touchDatabaseTable(static::TABLE_NAME);
$this->applyDatabaseChanges();

/** @var Subscriber $subscriber */
Expand All @@ -205,7 +204,6 @@ public function findBySubscriberListFindsSubscriptionOnlyWithTheGivenSubscriberL
{
$this->getDataSet()->addTable(static::SUBSCRIBER_TABLE_NAME, __DIR__ . '/../Fixtures/Subscriber.csv');
$this->getDataSet()->addTable(static::TABLE_NAME, __DIR__ . '/../Fixtures/Subscription.csv');
$this->touchDatabaseTable(static::TABLE_NAME);
$this->applyDatabaseChanges();

/** @var SubscriberList $subscriberList */
Expand All @@ -218,4 +216,23 @@ public function findBySubscriberListFindsSubscriptionOnlyWithTheGivenSubscriberL
static::assertSame($subscriberList, $subscription->getSubscriberList());
}
}

/**
* @test
*/
public function removeRemovesModel()
{
$this->getDataSet()->addTable(static::TABLE_NAME, __DIR__ . '/../Fixtures/Subscription.csv');
$this->applyDatabaseChanges();

/** @var Subscription[] $allModels */
$allModels = $this->subject->findAll();
$numberOfModelsBeforeRemove = count($allModels);
$firstModel = $allModels[0];

$this->subject->remove($firstModel);

$numberOfModelsAfterRemove = count($this->subject->findAll());
static::assertSame(1, $numberOfModelsBeforeRemove - $numberOfModelsAfterRemove);
}
}