-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathDatePointTest.php
More file actions
85 lines (66 loc) · 2.69 KB
/
DatePointTest.php
File metadata and controls
85 lines (66 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
* This file is part of the Doctrine Behavioral Extensions package.
* (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> 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\SoftDeleteable;
use Carbon\Doctrine\DateTimeType;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Types\Type as DoctrineType;
use Doctrine\DBAL\Types\Types;
use Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter;
use Gedmo\SoftDeleteable\SoftDeleteableListener;
use Gedmo\Tests\SoftDeleteable\Fixture\Entity\BookDatePoint;
use Gedmo\Tests\Tool\BaseTestCaseORM;
use Symfony\Component\Clock\DatePoint;
final class DatePointTest extends BaseTestCaseORM
{
private const SOFT_DELETEABLE_FILTER_NAME = 'soft-deleteable';
private SoftDeleteableListener $softDeleteableListener;
protected function setUp(): void
{
parent::setUp();
$evm = new EventManager();
$this->softDeleteableListener = new SoftDeleteableListener();
$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);
DoctrineType::overrideType(Types::DATETIME_MUTABLE, DateTimeType::class);
}
protected function tearDown(): void
{
parent::tearDown();
DoctrineType::overrideType(Types::DATETIME_MUTABLE, \Doctrine\DBAL\Types\DateTimeType::class);
}
public function testSoftDeleteable(): void
{
$repo = $this->em->getRepository(BookDatePoint::class);
$book0 = new BookDatePoint();
$field = 'title';
$value = 'Title 1';
$book0->setTitle($value);
$this->em->persist($book0);
$this->em->flush();
static::assertNull($book0->getDeletedAt());
$book = $repo->findOneBy([$field => $value]);
$this->em->remove($book);
$this->em->flush();
$book = $repo->findOneBy([$field => $value]);
static::assertNull($book);
// Now we deactivate the filter so we test if the entity appears in the result
$this->em->getFilters()->disable(self::SOFT_DELETEABLE_FILTER_NAME);
$book = $repo->findOneBy([$field => $value]);
static::assertIsObject($book);
static::assertInstanceOf(DatePoint::class, $book->getDeletedAt());
}
protected function getUsedEntityFixtures(): array
{
return [
BookDatePoint::class,
];
}
}