Skip to content

Commit

Permalink
Change business rules of tested entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg0 committed Jul 31, 2023
1 parent 4439ce5 commit a9d437a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
21 changes: 18 additions & 3 deletions tests/Doctrine/Tests/Models/DateTimeCompositeKey/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ class Article
#[Column]
private string $title;

#[Column]
private string $content;

/** @var Collection<int, ArticleAudit> */
#[OneToMany(targetEntity: ArticleAudit::class, mappedBy: 'article', cascade: ['ALL'])]
private Collection $audit;

public function __construct(string $title)
public function __construct(string $title, string $content)
{
$this->title = $title;
$this->audit = new ArrayCollection();
$this->title = $title;
$this->content = $content;
$this->audit = new ArrayCollection();
}

public function changeTitle(string $newTitle): void
Expand All @@ -39,6 +43,12 @@ public function changeTitle(string $newTitle): void
$this->updateAudit('title');
}

public function changeContent(string $newContent): void
{
$this->content = $newContent;
$this->updateAudit('content');
}

public function getId(): ?int
{
return $this->id;
Expand All @@ -57,6 +67,11 @@ public function getTitle(): string
return $this->title;
}

public function getContent(): string
{
return $this->content;
}

private function updateAudit(string $changedKey): void
{
$this->audit[] = new ArticleAudit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\Tests\OrmFunctionalTestCase;

use function dirname;
use function sleep;

/**
* Test the IdentifierFlattener utility class
Expand Down Expand Up @@ -48,10 +47,9 @@ protected function setUp(): void
/** @group utilities */
public function testFlattenIdentifierWithDateTimeId(): void
{
$article = new Article('Some title');
$article = new Article('Some title', 'Lorem ipsum');
$article->changeTitle('New title');
sleep(1);
$article->changeTitle('Newest title');
$article->changeContent('Lorem ipsum dolor sit amet');

$this->storeEntities($article);

Expand All @@ -66,7 +64,7 @@ public function testFlattenIdentifierWithDateTimeId(): void
/** @group utilities */
public function testFindEntityWithCompositeId(): void
{
$article = new Article('Some title');
$article = new Article('Some title', 'Lorem ipsum');
$fakeAudit = new ArticleAudit(
$timestamp = new DateTimeImmutable('2022-03-02'),
'title',
Expand Down

0 comments on commit a9d437a

Please sign in to comment.