From baca225775ac6f976f57e42b5a982ac8dcf01f2c Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 23 Nov 2018 18:17:00 +0100 Subject: [PATCH] Implemented slug for sources --- .../src/Entity/Attribut/SlugAttribut.php | 21 ++++++++++ .../Entity/Attribut/SlugAttributInterface.php | 10 +++++ .../src/Entity/Source/AbstractSource.php | 17 ++++++++- .../src/Entity/Source/SourceInterface.php | 3 +- .../Unit/Entity/Attribut/SlugAttributTest.php | 38 +++++++++++++++++++ .../Unit/Entity/Source/AbstractSourceTest.php | 6 +++ 6 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 application/src/Entity/Attribut/SlugAttribut.php create mode 100644 application/src/Entity/Attribut/SlugAttributInterface.php create mode 100644 application/tests/Unit/Entity/Attribut/SlugAttributTest.php diff --git a/application/src/Entity/Attribut/SlugAttribut.php b/application/src/Entity/Attribut/SlugAttribut.php new file mode 100644 index 0000000..c38d198 --- /dev/null +++ b/application/src/Entity/Attribut/SlugAttribut.php @@ -0,0 +1,21 @@ +slug = $slug; + } + + public function getSlug(): string + { + return $this->slug; + } +} diff --git a/application/src/Entity/Attribut/SlugAttributInterface.php b/application/src/Entity/Attribut/SlugAttributInterface.php new file mode 100644 index 0000000..d106d87 --- /dev/null +++ b/application/src/Entity/Attribut/SlugAttributInterface.php @@ -0,0 +1,10 @@ +slugAttribut = new class() implements SlugAttributInterface { + use SlugAttribut; + }; + } + + public function testConstructor(): void + { + $this->expectException(\TypeError::class); + $this->slugAttribut->getSlug(); + } + + public function testAccessors(): void + { + $slug = 'goodslug'; + $this->assertNull($this->slugAttribut->setSlug($slug)); + $this->assertEquals($slug, $this->slugAttribut->getSlug()); + } +} diff --git a/application/tests/Unit/Entity/Source/AbstractSourceTest.php b/application/tests/Unit/Entity/Source/AbstractSourceTest.php index 24d2299..26dada2 100644 --- a/application/tests/Unit/Entity/Source/AbstractSourceTest.php +++ b/application/tests/Unit/Entity/Source/AbstractSourceTest.php @@ -33,4 +33,10 @@ class AbstractSourceTest extends TestCase $this->assertInstanceOf(Collection::class, $this->source->getMemberships()); $this->assertInstanceOf(LawInterface::class, $this->source->getLaw()); } + + public function testSlugInit(): void + { + $this->expectException(\TypeError::class); + $this->source->getSlug(); + } }