Skip to content

Commit

Permalink
Added test to phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Aug 8, 2022
1 parent af044c5 commit c1847e9
Show file tree
Hide file tree
Showing 33 changed files with 488 additions and 725 deletions.
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<!-- Directories to be checked -->
<file>src</file>
<file>test</file>

<!-- Include full Doctrine Coding Standard -->
<rule ref="Doctrine">
Expand Down
52 changes: 27 additions & 25 deletions test/AbstractTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace ApiSkeletonsTest\Doctrine\GraphQL;

use DateTime;
Expand All @@ -8,6 +10,9 @@
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Tools\Setup;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;

use function date;

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

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

// database configuration parameters
$conn = array(
$conn = [
'driver' => 'pdo_sqlite',
'memory' => true,
);
];

// obtaining the entity manager
$this->entityManager = EntityManager::create($conn, $config);
$tool = new SchemaTool($this->entityManager);
$res = $tool->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata());
$tool = new SchemaTool($this->entityManager);
$res = $tool->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata());

$this->populateData();
}
Expand All @@ -40,7 +45,7 @@ protected function getEntityManager(): EntityManager
return $this->entityManager;
}

protected function populateData()
protected function populateData(): void
{
$users = [
[
Expand All @@ -51,7 +56,7 @@ protected function populateData()
[
'name' => 'User two',
'email' => '[email protected]',
'password' => 'fdsa'
'password' => 'fdsa',
],
];

Expand All @@ -66,17 +71,17 @@ protected function populateData()
. 'Walker; see info file and pub comments for notes; '
. 'possibly "click track" audible on a couple tracks',
'DSBD > 1C > DAT; Seeded to etree by Dan Stephens',
]
],
],
'1969-11-08T00:00:00+00:00' => [
'venue' => 'Fillmore Auditorium',
'city' => 'San Francisco',
'state' => 'California',
],
'1977-05-08T00:00:00+00:00' => [
'venue' => 'Barton Hall, Cornell University',
'city' => 'Ithaca',
'state' => 'New York',
'venue' => 'Barton Hall, Cornell University',
'city' => 'Ithaca',
'state' => 'New York',
],
'1995-07-09T00:00:00+00:00' => [
'venue' => 'Soldier Field',
Expand All @@ -94,9 +99,7 @@ protected function populateData()
'venue' => 'E Center',
'city' => 'West Valley City',
'state' => 'Utah',
'recordings' => [
'AKG480 > Aerco preamp > SBM-1',
],
'recordings' => ['AKG480 > Aerco preamp > SBM-1'],
],
'1999-12-31T00:00:00+00:00' => [
'venue' => null,
Expand Down Expand Up @@ -135,14 +138,15 @@ protected function populateData()
->setArtist($artist);
$this->entityManager->persist($performance);

if (isset($location['recordings'])) {
foreach ($location['recordings'] as $source) {
$recording = (new Entity\Recording())
->setSource($source)
->setPerformance($performance);
$this->entityManager->persist($recording);
}
if (! isset($location['recordings'])) {
continue;
}

foreach ($location['recordings'] as $source) {
$recording = (new Entity\Recording())
->setSource($source)
->setPerformance($performance);
$this->entityManager->persist($recording);
}
}
}
Expand All @@ -165,15 +169,13 @@ protected function populateData()
->setTestDateTimeTZImmutable($immutableDateTime)
->setTestDecimal(314.15)
->setTestJson(['to' => 'json', ['test' => 'testing']])
->setTestSimpleArray(['one','two','three'])
->setTestSimpleArray(['one', 'two', 'three'])
->setTestSmallInt(123)
->setTestTime(new DateTime('2022-08-07T20:10:15.123456'))
->setTestTimeImmutable($immutableDateTime)
->setTestGuid(\Ramsey\Uuid\Uuid::uuid4())
;
->setTestGuid(Uuid::uuid4()->toString());
$this->entityManager->persist($typeTest);


$this->entityManager->flush();
$this->entityManager->clear();
}
Expand Down
60 changes: 21 additions & 39 deletions test/Entity/Artist.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

declare(strict_types=1);

namespace ApiSkeletonsTest\Doctrine\GraphQL\Entity;

use ApiSkeletons\Doctrine\GraphQL\Attribute as GraphQL;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
Expand All @@ -13,48 +17,36 @@
#[ORM\Entity]
class Artist
{
/**
* @var string
*/
#[GraphQL\Field(description: 'Artist name')]
#[GraphQL\Field(group: 'ExcludeCriteriaTest')]
#[ORM\Column(type: "string", nullable: false)]
private $name;
#[ORM\Column(type: 'string', nullable: false)]
private string $name;

/**
* @var int
*/
#[GraphQL\Field(description: 'Primary key')]
#[GraphQL\Field(group: 'ExcludeCriteriaTest')]
#[ORM\Id]
#[ORM\Column(type: "bigint")]
#[ORM\GeneratedValue(strategy: "AUTO")]
private $id;
#[ORM\Column(type: 'bigint')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private int $id;

/**
* @var \Doctrine\Common\Collections\Collection
*/
/** @var Collection<id, Performance> */
#[GraphQL\Association(description: 'Performances')]
#[GraphQL\Association(group: 'ExcludeCriteriaTest', excludeCriteria: ['neq'])]
#[ORM\OneToMany(targetEntity: "ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance", mappedBy: "artist")]
private $performances;
#[ORM\OneToMany(targetEntity: 'ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance', mappedBy: 'artist')]
private Collection $performances;

/**
* Constructor
*/
public function __construct()
{
$this->performances = new \Doctrine\Common\Collections\ArrayCollection();
$this->performances = new ArrayCollection();
}

/**
* Set name.
*
* @param string $name
*
* @return Artist
*/
public function setName($name)
public function setName(string $name): Artist
{
$this->name = $name;

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

/**
* Get name.
*
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* Get id.
*
* @return int
*/
public function getId()
public function getId(): int
{
return $this->id;
}

/**
* Add performance.
*
* @param \ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance $performance
*
* @return Artist
*/
public function addPerformance(\ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance $performance)
public function addPerformance(Performance $performance): Artist
{
$this->performances[] = $performance;

Expand All @@ -98,21 +82,19 @@ public function addPerformance(\ApiSkeletonsTest\Doctrine\GraphQL\Entity\Perform
/**
* Remove performance.
*
* @param \ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance $performance
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
* @return bool TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removePerformance(\ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance $performance)
public function removePerformance(Performance $performance): bool
{
return $this->performances->removeElement($performance);
}

/**
* Get performances.
*
* @return \Doctrine\Common\Collections\Collection
* @return Collection<id, Performance>
*/
public function getPerformances()
public function getPerformances(): Collection
{
return $this->performances;
}
Expand Down
Loading

0 comments on commit c1847e9

Please sign in to comment.