-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for blameable on remove #2929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oojacoboo
wants to merge
15
commits into
doctrine-extensions:main
Choose a base branch
from
rentpost:blameable-on-remove
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ae2be60
Add support for blameable on remove
oojacoboo e7f6499
Added remove tracking for soft-delete
oojacoboo 8a1630f
Reverted changes in BlameableTest and created new test class for blam…
oojacoboo 978929e
CS fixes
oojacoboo f0aea30
Updated CHANGELOG
oojacoboo 8cddb62
Simplified TOC
oojacoboo f0d8613
Simplified TOC
oojacoboo 2253cef
Add the preRemove event listener for only blameable
oojacoboo 1b594d0
CS fixes
oojacoboo 0841e14
Merge remote-tracking branch 'doctrine-extensions/main' into blameabl…
oojacoboo 5614da8
Define nullable for column (fixture handling)
oojacoboo c6cb29f
Explicitly define Blameable attribute event
oojacoboo a729496
Add deprecated annotation for PHP 7.x support
oojacoboo 1ddb7ea
Restored superfulous PHPStan docblock tags needed for it to actually …
oojacoboo c016b37
CS fixes
oojacoboo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,6 @@ | |
* extended drivers | ||
* | ||
* @phpstan-template TConfig of array | ||
* @phpstan-template TEventAdapter of AdapterInterface | ||
* | ||
* @author Gediminas Morkevicius <[email protected]> | ||
*/ | ||
|
@@ -256,8 +255,6 @@ public function loadMetadataForObjectClass(ObjectManager $objectManager, $metada | |
* @throws InvalidArgumentException if event is not recognized | ||
* | ||
* @return AdapterInterface | ||
* | ||
* @phpstan-return TEventAdapter | ||
*/ | ||
protected function getEventAdapter(EventArgs $args) | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Doctrine Behavioral Extensions package. | ||
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gedmo\Tests\Blameable; | ||
|
||
use Doctrine\Common\EventManager; | ||
use Gedmo\Blameable\BlameableListener; | ||
use Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter; | ||
use Gedmo\SoftDeleteable\SoftDeleteableListener; | ||
use Gedmo\Tests\Blameable\Fixture\Entity\Article; | ||
use Gedmo\Tests\Blameable\Fixture\Entity\Comment; | ||
use Gedmo\Tests\Blameable\Fixture\Entity\Type; | ||
use Gedmo\Tests\Clock; | ||
use Gedmo\Tests\TestActorProvider; | ||
use Gedmo\Tests\Tool\BaseTestCaseORM; | ||
|
||
/** | ||
* These are tests for Blameable behavior | ||
* | ||
* @author Gediminas Morkevicius <[email protected]> | ||
*/ | ||
final class BlameableWithSoftDeleteTest extends BaseTestCaseORM | ||
{ | ||
private const SOFT_DELETEABLE_FILTER_NAME = 'soft-deleteable'; | ||
|
||
private BlameableListener $blameableListener; | ||
private SoftDeleteableListener $softDeleteableListener; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->blameableListener = new BlameableListener(); | ||
$this->blameableListener->setUserValue('testuser'); | ||
|
||
$this->softDeleteableListener = new SoftDeleteableListener(); | ||
$this->softDeleteableListener->setClock(new Clock()); | ||
|
||
$evm = new EventManager(); | ||
$evm->addEventSubscriber($this->blameableListener); | ||
$evm->addEventSubscriber($this->softDeleteableListener); | ||
|
||
$config = $this->getDefaultConfiguration(); | ||
$config->addFilter(self::SOFT_DELETEABLE_FILTER_NAME, SoftDeleteableFilter::class); | ||
$this->em = $this->getDefaultMockSqliteEntityManager($evm, $config); | ||
$this->em->getFilters()->enable(self::SOFT_DELETEABLE_FILTER_NAME); | ||
} | ||
|
||
public function testBlameable(): void | ||
{ | ||
$article = new Article(); | ||
$article->setTitle('Sport'); | ||
|
||
$comment = new Comment(); | ||
$comment->setMessage('hello'); | ||
$comment->setArticle($article); | ||
$comment->setStatus(0); | ||
|
||
$this->em->persist($article); | ||
$this->em->persist($comment); | ||
$this->em->flush(); | ||
$this->em->clear(); | ||
|
||
$article = $this->em->getRepository(Article::class)->findOneBy(['title' => 'Sport']); | ||
static::assertSame('testuser', $article->getCreated()); | ||
static::assertSame('testuser', $article->getUpdated()); | ||
static::assertNull($article->getPublished()); | ||
|
||
$comment = $this->em->getRepository(Comment::class)->findOneBy(['message' => 'hello']); | ||
static::assertSame('testuser', $comment->getModified()); | ||
static::assertNull($comment->getClosed()); | ||
|
||
$comment->setStatus(1); | ||
$type = new Type(); | ||
$type->setTitle('Published'); | ||
|
||
$article->setTitle('Updated'); | ||
$article->setType($type); | ||
$this->em->persist($article); | ||
$this->em->persist($type); | ||
$this->em->persist($comment); | ||
$this->em->flush(); | ||
$this->em->clear(); | ||
|
||
$comment = $this->em->getRepository(Comment::class)->findOneBy(['message' => 'hello']); | ||
static::assertSame('testuser', $comment->getClosed()); | ||
static::assertSame('testuser', $article->getPublished()); | ||
|
||
// Now delete event | ||
$article = $this->em->getRepository(Article::class)->findOneBy(['title' => 'Updated']); | ||
$this->em->remove($article); | ||
$this->em->flush(); | ||
|
||
static::assertTrue($article->isDeleted()); | ||
static::assertSame('testuser', $article->getDeleted()); | ||
} | ||
|
||
protected function getUsedEntityFixtures(): array | ||
{ | ||
return [ | ||
Article::class, | ||
Comment::class, | ||
Type::class, | ||
]; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.