Skip to content

Commit c456409

Browse files
committed
Fix TU
1 parent b47f77b commit c456409

File tree

5 files changed

+105
-31
lines changed

5 files changed

+105
-31
lines changed

src/Entity/Library/Book.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
1010
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
1111
use ApiPlatform\Core\Exception\InvalidArgumentException;
12-
use DateTime;
12+
use DateTimeInterface;
1313
use Doctrine\Common\Collections\ArrayCollection;
1414
use Doctrine\Common\Collections\Collection;
1515
use Doctrine\ORM\Mapping as ORM;
@@ -476,12 +476,12 @@ public function addEditors(ProjectBookEdition $project): self
476476

477477
/**
478478
* @param Editor $editor
479-
* @param DateTime $date
479+
* @param DateTimeInterface $date
480480
* @param string $isbn
481481
* @param string $collection
482482
* @return self
483483
*/
484-
public function addEditor(Editor $editor, DateTime $date, $isbn = null, $collection = null): self
484+
public function addEditor(Editor $editor, DateTimeInterface $date, string $isbn = null, string $collection = null): self
485485
{
486486
$project = (new ProjectBookEdition())
487487
->setBook($this)

src/Entity/Library/Loan.php

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
99
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
1010
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
11+
use DateTimeInterface;
12+
use DateTime;
1113
use Doctrine\ORM\Mapping as ORM;
1214
use Exception;
1315
use Symfony\Component\Serializer\Annotation\Groups;
1416
use Symfony\Component\Serializer\Annotation\MaxDepth;
1517
use Symfony\Component\Validator\Constraints as Assert;
16-
use \DateTime;
1718

1819
/**
1920
* @ApiResource(
@@ -122,9 +123,9 @@ class Loan implements LibraryInterface
122123
* @Assert\DateTime()
123124
* @Assert\NotBlank()
124125
*
125-
* @var DateTime
126+
* @var DateTimeInterface
126127
*/
127-
protected DateTime $startLoan;
128+
protected DateTimeInterface $startLoan;
128129

129130
/**
130131
* @Groups({"loan:read", "loan:write"})
@@ -134,9 +135,9 @@ class Loan implements LibraryInterface
134135
* @Assert\DateTime()
135136
* @Assert\Blank()
136137
*
137-
* @var DateTime|null
138+
* @var DateTimeInterface|null
138139
*/
139-
protected ?DateTime $endLoan;
140+
protected ?DateTimeInterface $endLoan;
140141

141142
/**
142143
* Loan constructor.
@@ -212,7 +213,7 @@ public function setBorrower(Reader $reader, bool $updateRelation = true): self
212213
$this->borrower = $reader;
213214

214215
if ($updateRelation) {
215-
$this->borrower->addLoan($this, false);
216+
$this->borrower->addBorrow($this, false);
216217
}
217218

218219
return $this;
@@ -243,37 +244,37 @@ public function setLoaner(Reader $reader, bool $updateRelation = true): self
243244
}
244245

245246
/**
246-
* @return DateTime|null
247+
* @return DateTimeInterface|null
247248
*/
248-
public function getStartLoan(): ?DateTime
249+
public function getStartLoan(): ?DateTimeInterface
249250
{
250251
return $this->startLoan;
251252
}
252253

253254
/**
254-
* @param DateTime $startLoan
255+
* @param DateTimeInterface $startLoan
255256
* @return self
256257
*/
257-
public function setStartLoan(DateTime $startLoan): self
258+
public function setStartLoan(DateTimeInterface $startLoan): self
258259
{
259260
$this->startLoan = $startLoan;
260261

261262
return $this;
262263
}
263264

264265
/**
265-
* @return DateTime|null
266+
* @return DateTimeInterface|null
266267
*/
267-
public function getEndLoan(): ?DateTime
268+
public function getEndLoan(): ?DateTimeInterface
268269
{
269270
return $this->endLoan;
270271
}
271272

272273
/**
273-
* @param DateTime $endLoan
274+
* @param DateTimeInterface $endLoan
274275
* @return Loan
275276
*/
276-
public function setEndLoan(DateTime $endLoan): self
277+
public function setEndLoan(DateTimeInterface $endLoan): self
277278
{
278279
$this->endLoan = $endLoan;
279280

src/Entity/Library/ProjectBookEdition.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Exception;
1212
use Symfony\Component\Serializer\Annotation\Groups;
1313
use Symfony\Component\Validator\Constraints as Assert;
14+
use DateTimeInterface;
1415
use DateTime;
1516

1617
/**
@@ -44,9 +45,9 @@ class ProjectBookEdition implements LibraryInterface
4445
*
4546
* @Assert\DateTime()
4647
*
47-
* @var ?DateTime
48+
* @var ?DateTimeInterface
4849
*/
49-
protected ?DateTime $publicationDate;
50+
protected ?DateTimeInterface $publicationDate;
5051

5152
/**
5253
* @Groups({"book:detail:read", "book:detail:write"})
@@ -132,15 +133,15 @@ public function setId(int $id): self
132133
}
133134

134135
/**
135-
* @return DateTime
136+
* @return DateTimeInterface
136137
*/
137-
public function getPublicationDate(): DateTime
138+
public function getPublicationDate(): DateTimeInterface
138139
{
139140
return $this->publicationDate;
140141
}
141142

142143
/**
143-
* @param DateTime|string $publicationDate
144+
* @param DateTimeInterface|string $publicationDate
144145
* @return self
145146
*/
146147
public function setPublicationDate($publicationDate): self
@@ -158,9 +159,9 @@ public function setPublicationDate($publicationDate): self
158159
} catch (Exception $e) {
159160
throw new ORMInvalidArgumentException(sprintf('Wrong input for publicationDate, %s', $dateString), 500, $e);
160161
}
161-
} elseif (!($publicationDate instanceof DateTime)) {
162+
} elseif (!($publicationDate instanceof DateTimeInterface)) {
162163
throw new ORMInvalidArgumentException(sprintf(
163-
'Wrong input for publicationDate, should be \DateTime or valid date string or unixTimestamp, %s',
164+
'Wrong input for publicationDate, should be \DateTimeInterface or valid date string or unixTimestamp, %s',
164165
is_object($publicationDate) ? $publicationDate->format('r') : $publicationDate
165166
), 500);
166167
}

src/Entity/Library/Review.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use ApiPlatform\Core\Annotation\ApiSubresource;
88
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
99
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
10+
use DateTimeInterface;
1011
use DateTime;
1112
use Doctrine\ORM\Mapping as ORM;
1213
use Doctrine\ORM\ORMInvalidArgumentException;
@@ -87,9 +88,9 @@ class Review implements LibraryInterface
8788
* @Assert\NotBlank()
8889
* @Assert\DateTime()
8990
*
90-
* @var DateTime
91+
* @var DateTimeInterface
9192
*/
92-
protected DateTime $publicationDate;
93+
protected DateTimeInterface $publicationDate;
9394

9495
/**
9596
* @ApiProperty(
@@ -194,15 +195,15 @@ public function setUsername($username): self
194195
}
195196

196197
/**
197-
* @return DateTime|null
198+
* @return DateTimeInterface|null
198199
*/
199-
public function getPublicationDate(): ?DateTime
200+
public function getPublicationDate(): ?DateTimeInterface
200201
{
201202
return $this->publicationDate;
202203
}
203204

204205
/**
205-
* @param DateTime|string $publicationDate
206+
* @param DateTimeInterface|string $publicationDate
206207
* @return self
207208
*/
208209
public function setPublicationDate($publicationDate): self
@@ -220,9 +221,9 @@ public function setPublicationDate($publicationDate): self
220221
} catch (Exception $e) {
221222
throw new ORMInvalidArgumentException(sprintf('Wrong input for publicationDate, %s', $dateString), 500, $e);
222223
}
223-
} elseif (!($publicationDate instanceof DateTime)) {
224+
} elseif (!($publicationDate instanceof DateTimeInterface)) {
224225
throw new ORMInvalidArgumentException(sprintf(
225-
'Wrong input for publicationDate, should be \DateTime or valid date string or unixTimestamp, %s',
226+
'Wrong input for publicationDate, should be \DateTimeInterface or valid date string or unixTimestamp, %s',
226227
is_object($publicationDate) ? $publicationDate->format('r') : $publicationDate
227228
), 500);
228229
}

tests/Entity/Library/LoanTest.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace App\Tests\Entity\Library;
4+
5+
use App\Entity\Library\Author;
6+
use App\Entity\Library\Book;
7+
use App\Entity\Library\Job;
8+
use App\Entity\Library\Loan;
9+
use App\Entity\Library\ProjectBookCreation;
10+
use App\Entity\Library\Reader;
11+
use App\Tests\Common\ApiAbstract;
12+
use App\Tests\Common\ToolsAbstract;
13+
use App\Tests\Common\WebPagesAbstract;
14+
use Doctrine\Common\Collections\ArrayCollection;
15+
use Doctrine\DBAL\DBALException;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class LoanTest extends WebPagesAbstract
19+
{
20+
use \App\Tests\Common\TestCase;
21+
22+
/**
23+
* @var Book
24+
*/
25+
public Book $book;
26+
27+
/**
28+
* @var Reader
29+
*/
30+
public Reader $owner;
31+
32+
/**
33+
* @var Reader
34+
*/
35+
public Reader $borrower;
36+
37+
public function setUp(): void
38+
{
39+
parent::setUp(); // TODO: Change the autogenerated stub
40+
41+
$this->book = new Book();
42+
$this->book->setTitle('Test BookTest');
43+
44+
$this->owner = new Reader();
45+
$this->owner
46+
->setId(1)
47+
->setEmail('johndo@gmail.com')
48+
->setFirstname('John')
49+
->setLastname('Do')
50+
->addBook($this->book);
51+
52+
$this->borrower = new Reader();
53+
$this->borrower
54+
->setId(2)
55+
->setEmail('nashjackson@orange.com')
56+
->setFirstname('Nash')
57+
->setLastname('Jackson');
58+
}
59+
60+
public function testDoLoan()
61+
{
62+
$loan = new Loan();
63+
$loan->setBook($this->book)
64+
->setLoaner($this->owner)
65+
->setBorrower($this->borrower)
66+
->setStartLoan(new \DateTimeImmutable(new \DateInterval('P1D')));
67+
68+
$this->assertEquals($this->borrower, $loan->getBorrower());
69+
$this->assertEquals($this->owner, $loan->getLoaner());
70+
}
71+
}

0 commit comments

Comments
 (0)