Selaa lähdekoodia

add test for mapped superclass without identifier

Gunther Konig 12 vuotta sitten
vanhempi
commit
e06958f492

+ 34 - 0
tests/Gedmo/Sluggable/Fixture/MappedSuperclass/Car.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace Sluggable\Fixture\MappedSuperclass;
+
+use Doctrine\ORM\Mapping as ORM;
+use Gedmo\Mapping\Annotation as Gedmo;
+
+/**
+ * @ORM\Entity
+ */
+class Car extends Vehicle
+{
+    /**
+     * @ORM\Id
+     * @ORM\GeneratedValue
+     * @ORM\Column(type="integer")
+     */
+    private $id;
+
+    /**
+     * @ORM\Column(length=128)
+     */
+    private $description;
+
+    public function setDescription($description)
+    {
+        $this->description = $description;
+    }
+
+    public function getDescription()
+    {
+        return $this->description;
+    }
+}

+ 43 - 0
tests/Gedmo/Sluggable/Fixture/MappedSuperclass/Vehicle.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace Sluggable\Fixture\MappedSuperclass;
+
+use Doctrine\ORM\Mapping as ORM;
+use Gedmo\Mapping\Annotation as Gedmo;
+
+/**
+ * @ORM\MappedSuperclass
+ */
+class Vehicle
+{
+    /**
+     * @ORM\Column(length=128)
+     */
+    private $title;
+
+    /**
+     * @Gedmo\Slug(fields={"title"})
+     * @ORM\Column(length=128, unique=true)
+     */
+    private $slug;
+
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    public function getTitle()
+    {
+        return $this->title;
+    }
+
+    public function getSlug()
+    {
+        return $this->slug;
+    }
+}

+ 52 - 0
tests/Gedmo/Sluggable/MappedSuperclassTest.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace Gedmo\Sluggable;
+
+use Doctrine\Common\EventManager;
+use Tool\BaseTestCaseORM;
+use Sluggable\Fixture\Article;
+
+/**
+ * These are tests for sluggable behavior
+ *
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo.Sluggable
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class MappedSuperclassTest extends BaseTestCaseORM
+{
+    const CAR = 'Sluggable\\Fixture\\MappedSuperclass\\Car';
+    
+    protected function setUp()
+    {
+        parent::setUp();
+    }
+
+    /**
+     * If the MappedSuperclass doesn't have an identifier, SluggableListener generates a notice
+     * Undefined offset: 0 in Doctrine/ORM/Mapping/ClassMetadataInfo.php:986
+     * @test
+     */
+    public function shouldntGenerateNotice()
+    {
+        $evm = new EventManager;
+        $evm->addEventSubscriber(new SluggableListener);
+        $this->getMockSqliteEntityManager($evm);
+
+        $audi = new Car;
+        $audi->setDescription('audi car');
+        $audi->setTitle('Audi');
+
+        $this->em->persist($audi);
+        $this->em->flush();
+        
+    }
+
+    protected function getUsedEntityFixtures()
+    {
+        return array(
+            self::CAR
+        );
+    }
+}