Skip to content

Commit c1847e9

Browse files
committed
Added test to phpcs
1 parent af044c5 commit c1847e9

33 files changed

+488
-725
lines changed

phpcs.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<!-- Directories to be checked -->
1313
<file>src</file>
14+
<file>test</file>
1415

1516
<!-- Include full Doctrine Coding Standard -->
1617
<rule ref="Doctrine">

test/AbstractTest.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace ApiSkeletonsTest\Doctrine\GraphQL;
46

57
use DateTime;
@@ -8,6 +10,9 @@
810
use Doctrine\ORM\Tools\SchemaTool;
911
use Doctrine\ORM\Tools\Setup;
1012
use PHPUnit\Framework\TestCase;
13+
use Ramsey\Uuid\Uuid;
14+
15+
use function date;
1116

1217
require_once __DIR__ . '/../vendor/autoload.php';
1318

@@ -19,18 +24,18 @@ public function setUp(): void
1924
{
2025
// Create a simple "default" Doctrine ORM configuration for Annotations
2126
$isDevMode = true;
22-
$config = Setup::createAttributeMetadataConfiguration([__DIR__ . '/Entity'], $isDevMode);
27+
$config = Setup::createAttributeMetadataConfiguration([__DIR__ . '/Entity'], $isDevMode);
2328

2429
// database configuration parameters
25-
$conn = array(
30+
$conn = [
2631
'driver' => 'pdo_sqlite',
2732
'memory' => true,
28-
);
33+
];
2934

3035
// obtaining the entity manager
3136
$this->entityManager = EntityManager::create($conn, $config);
32-
$tool = new SchemaTool($this->entityManager);
33-
$res = $tool->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata());
37+
$tool = new SchemaTool($this->entityManager);
38+
$res = $tool->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata());
3439

3540
$this->populateData();
3641
}
@@ -40,7 +45,7 @@ protected function getEntityManager(): EntityManager
4045
return $this->entityManager;
4146
}
4247

43-
protected function populateData()
48+
protected function populateData(): void
4449
{
4550
$users = [
4651
[
@@ -51,7 +56,7 @@ protected function populateData()
5156
[
5257
'name' => 'User two',
5358
'email' => '[email protected]',
54-
'password' => 'fdsa'
59+
'password' => 'fdsa',
5560
],
5661
];
5762

@@ -66,17 +71,17 @@ protected function populateData()
6671
. 'Walker; see info file and pub comments for notes; '
6772
. 'possibly "click track" audible on a couple tracks',
6873
'DSBD > 1C > DAT; Seeded to etree by Dan Stephens',
69-
]
74+
],
7075
],
7176
'1969-11-08T00:00:00+00:00' => [
7277
'venue' => 'Fillmore Auditorium',
7378
'city' => 'San Francisco',
7479
'state' => 'California',
7580
],
7681
'1977-05-08T00:00:00+00:00' => [
77-
'venue' => 'Barton Hall, Cornell University',
78-
'city' => 'Ithaca',
79-
'state' => 'New York',
82+
'venue' => 'Barton Hall, Cornell University',
83+
'city' => 'Ithaca',
84+
'state' => 'New York',
8085
],
8186
'1995-07-09T00:00:00+00:00' => [
8287
'venue' => 'Soldier Field',
@@ -94,9 +99,7 @@ protected function populateData()
9499
'venue' => 'E Center',
95100
'city' => 'West Valley City',
96101
'state' => 'Utah',
97-
'recordings' => [
98-
'AKG480 > Aerco preamp > SBM-1',
99-
],
102+
'recordings' => ['AKG480 > Aerco preamp > SBM-1'],
100103
],
101104
'1999-12-31T00:00:00+00:00' => [
102105
'venue' => null,
@@ -135,14 +138,15 @@ protected function populateData()
135138
->setArtist($artist);
136139
$this->entityManager->persist($performance);
137140

138-
if (isset($location['recordings'])) {
139-
foreach ($location['recordings'] as $source) {
140-
$recording = (new Entity\Recording())
141-
->setSource($source)
142-
->setPerformance($performance);
143-
$this->entityManager->persist($recording);
144-
}
141+
if (! isset($location['recordings'])) {
142+
continue;
143+
}
145144

145+
foreach ($location['recordings'] as $source) {
146+
$recording = (new Entity\Recording())
147+
->setSource($source)
148+
->setPerformance($performance);
149+
$this->entityManager->persist($recording);
146150
}
147151
}
148152
}
@@ -165,15 +169,13 @@ protected function populateData()
165169
->setTestDateTimeTZImmutable($immutableDateTime)
166170
->setTestDecimal(314.15)
167171
->setTestJson(['to' => 'json', ['test' => 'testing']])
168-
->setTestSimpleArray(['one','two','three'])
172+
->setTestSimpleArray(['one', 'two', 'three'])
169173
->setTestSmallInt(123)
170174
->setTestTime(new DateTime('2022-08-07T20:10:15.123456'))
171175
->setTestTimeImmutable($immutableDateTime)
172-
->setTestGuid(\Ramsey\Uuid\Uuid::uuid4())
173-
;
176+
->setTestGuid(Uuid::uuid4()->toString());
174177
$this->entityManager->persist($typeTest);
175178

176-
177179
$this->entityManager->flush();
178180
$this->entityManager->clear();
179181
}

test/Entity/Artist.php

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace ApiSkeletonsTest\Doctrine\GraphQL\Entity;
46

57
use ApiSkeletons\Doctrine\GraphQL\Attribute as GraphQL;
8+
use Doctrine\Common\Collections\ArrayCollection;
9+
use Doctrine\Common\Collections\Collection;
610
use Doctrine\ORM\Mapping as ORM;
711

812
/**
@@ -13,48 +17,36 @@
1317
#[ORM\Entity]
1418
class Artist
1519
{
16-
/**
17-
* @var string
18-
*/
1920
#[GraphQL\Field(description: 'Artist name')]
2021
#[GraphQL\Field(group: 'ExcludeCriteriaTest')]
21-
#[ORM\Column(type: "string", nullable: false)]
22-
private $name;
22+
#[ORM\Column(type: 'string', nullable: false)]
23+
private string $name;
2324

24-
/**
25-
* @var int
26-
*/
2725
#[GraphQL\Field(description: 'Primary key')]
2826
#[GraphQL\Field(group: 'ExcludeCriteriaTest')]
2927
#[ORM\Id]
30-
#[ORM\Column(type: "bigint")]
31-
#[ORM\GeneratedValue(strategy: "AUTO")]
32-
private $id;
28+
#[ORM\Column(type: 'bigint')]
29+
#[ORM\GeneratedValue(strategy: 'AUTO')]
30+
private int $id;
3331

34-
/**
35-
* @var \Doctrine\Common\Collections\Collection
36-
*/
32+
/** @var Collection<id, Performance> */
3733
#[GraphQL\Association(description: 'Performances')]
3834
#[GraphQL\Association(group: 'ExcludeCriteriaTest', excludeCriteria: ['neq'])]
39-
#[ORM\OneToMany(targetEntity: "ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance", mappedBy: "artist")]
40-
private $performances;
35+
#[ORM\OneToMany(targetEntity: 'ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance', mappedBy: 'artist')]
36+
private Collection $performances;
4137

4238
/**
4339
* Constructor
4440
*/
4541
public function __construct()
4642
{
47-
$this->performances = new \Doctrine\Common\Collections\ArrayCollection();
43+
$this->performances = new ArrayCollection();
4844
}
4945

5046
/**
5147
* Set name.
52-
*
53-
* @param string $name
54-
*
55-
* @return Artist
5648
*/
57-
public function setName($name)
49+
public function setName(string $name): Artist
5850
{
5951
$this->name = $name;
6052

@@ -63,32 +55,24 @@ public function setName($name)
6355

6456
/**
6557
* Get name.
66-
*
67-
* @return string
6858
*/
69-
public function getName()
59+
public function getName(): string
7060
{
7161
return $this->name;
7262
}
7363

7464
/**
7565
* Get id.
76-
*
77-
* @return int
7866
*/
79-
public function getId()
67+
public function getId(): int
8068
{
8169
return $this->id;
8270
}
8371

8472
/**
8573
* Add performance.
86-
*
87-
* @param \ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance $performance
88-
*
89-
* @return Artist
9074
*/
91-
public function addPerformance(\ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance $performance)
75+
public function addPerformance(Performance $performance): Artist
9276
{
9377
$this->performances[] = $performance;
9478

@@ -98,21 +82,19 @@ public function addPerformance(\ApiSkeletonsTest\Doctrine\GraphQL\Entity\Perform
9882
/**
9983
* Remove performance.
10084
*
101-
* @param \ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance $performance
102-
*
103-
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
85+
* @return bool TRUE if this collection contained the specified element, FALSE otherwise.
10486
*/
105-
public function removePerformance(\ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance $performance)
87+
public function removePerformance(Performance $performance): bool
10688
{
10789
return $this->performances->removeElement($performance);
10890
}
10991

11092
/**
11193
* Get performances.
11294
*
113-
* @return \Doctrine\Common\Collections\Collection
95+
* @return Collection<id, Performance>
11496
*/
115-
public function getPerformances()
97+
public function getPerformances(): Collection
11698
{
11799
return $this->performances;
118100
}

0 commit comments

Comments
 (0)