Skip to content

Commit

Permalink
08 - Add a custom entity Location
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes authored and niklasnatter committed Jun 20, 2022
1 parent 1324c8f commit 4d728de
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 0 deletions.
141 changes: 141 additions & 0 deletions src/Entity/Location.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity(repositoryClass="App\Repository\LocationRepository")
*/
class Location
{
/**
* @var int|null
*
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;

/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $name;

/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $street;

/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $number;

/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $postalCode;

/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $city;

/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $countryCode;

public function getId(): ?int
{
return $this->id;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(string $name): self
{
$this->name = $name;

return $this;
}

public function getStreet(): ?string
{
return $this->street;
}

public function setStreet(string $street): self
{
$this->street = $street;

return $this;
}

public function getNumber(): ?string
{
return $this->number;
}

public function setNumber(string $number): self
{
$this->number = $number;

return $this;
}

public function getPostalCode(): ?string
{
return $this->postalCode;
}

public function setPostalCode(string $postalCode): self
{
$this->postalCode = $postalCode;

return $this;
}

public function getCity(): ?string
{
return $this->city;
}

public function setCity(string $city): self
{
$this->city = $city;

return $this;
}

public function getCountryCode(): ?string
{
return $this->countryCode;
}

public function setCountryCode(string $countryCode): self
{
$this->countryCode = $countryCode;

return $this;
}
}
34 changes: 34 additions & 0 deletions src/Repository/LocationRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace App\Repository;

use App\Entity\Location;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
* @method Location|null find($id, $lockMode = null, $lockVersion = null)
* @method Location|null findOneBy(array $criteria, array $orderBy = null)
* @method Location[] findAll()
* @method Location[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*
* @extends ServiceEntityRepository<Location>
*/
class LocationRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Location::class);
}

public function create(): Location
{
$location = new Location();

$this->getEntityManager()->persist($location);

return $location;
}
}
69 changes: 69 additions & 0 deletions tests/Unit/Entity/LocationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace App\Tests\Unit\Entity;

use App\Entity\Location;
use PHPUnit\Framework\TestCase;

class LocationTest extends TestCase
{
/**
* @var Location
*/
private $location;

protected function setUp(): void
{
$this->location = new Location();
}

public function testName(): void
{
$this->assertNull($this->location->getName());
$this->assertSame($this->location, $this->location->setName('Sulu GmbH'));
$this->assertNotNull($this->location->getName());
$this->assertSame('Sulu GmbH', $this->location->getName());
}

public function testStreet(): void
{
$this->assertNull($this->location->getStreet());
$this->assertSame($this->location, $this->location->setStreet('Teststreet'));
$this->assertNotNull($this->location->getStreet());
$this->assertSame('Teststreet', $this->location->getStreet());
}

public function testNumber(): void
{
$this->assertNull($this->location->getNumber());
$this->assertSame($this->location, $this->location->setNumber('42'));
$this->assertNotNull($this->location->getNumber());
$this->assertSame('42', $this->location->getNumber());
}

public function testPostalCode(): void
{
$this->assertNull($this->location->getPostalCode());
$this->assertSame($this->location, $this->location->setPostalCode('6850'));
$this->assertNotNull($this->location->getPostalCode());
$this->assertSame('6850', $this->location->getPostalCode());
}

public function testCity(): void
{
$this->assertNull($this->location->getCity());
$this->assertSame($this->location, $this->location->setCity('Dornbirn'));
$this->assertNotNull($this->location->getCity());
$this->assertSame('Dornbirn', $this->location->getCity());
}

public function testCountryCode(): void
{
$this->assertNull($this->location->getCountryCode());
$this->assertSame($this->location, $this->location->setCountryCode('AT'));
$this->assertNotNull($this->location->getCountryCode());
$this->assertSame('AT', $this->location->getCountryCode());
}
}

0 comments on commit 4d728de

Please sign in to comment.