Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created November 5, 2013 01:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eminetto/7312242 to your computer and use it in GitHub Desktop.
Save eminetto/7312242 to your computer and use it in GitHub Desktop.
<?php
namespace DoctrineNaPratica\Model;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="User")
*/
class User
{
/**
* @ORM\Id @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @var integer
*/
protected $id;
/**
* @ORM\Column(type="string", length=150)
*
* @var string
*/
private $name;
/**
* @ORM\Column(type="string", length=20, unique=true)
*
* @var string
*/
private $login;
/**
* @ORM\Column(type="string", length=150, nullable=true)
*
* @var string
*/
private $email;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $avatar;
/**
* @ORM\OneToOne(targetEntity="Subscription", mappedBy="user")
**/
private $subscription;
/**
* @ORM\OneToMany(targetEntity="Enrollment", mappedBy="user", cascade={"all"}, orphanRemoval=true, fetch="LAZY")
*/
private $enrollmentCollection;
/**
* @ORM\OneToMany(targetEntity="Course", mappedBy="teacher", cascade={"all"}, orphanRemoval=true, fetch="LAZY")
*
* @var Doctrine\Common\Collections\Collection
*/
protected $courseCollection;
/**
* @ORM\ManyToMany(targetEntity="Lesson", inversedBy="userLessons", cascade={"all"})
* @ORM\JoinTable(name="LessonUser",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="lesson_id", referencedColumnName="id")}
* )
*/
private $lessonCollection;
/**
* @return integer
*/
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
return $this->name = $name;
}
public function getLogin()
{
return $this->login;
}
public function setLogin($login)
{
return $this->login = $login;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
return $this->email = $email;
}
public function getAvatar()
{
return $this->avatar;
}
public function setAvatar($avatar)
{
return $this->avatar = $avatar;
}
public function getSubscription()
{
return $this->subscription;
}
public function setSubscription($subscription)
{
return $this->subscription = $subscription;
}
public function getEnrollmentCollection()
{
return $this->enrollmentCollection;
}
public function setEnrollmentCollection($enrollmentCollection)
{
return $this->enrollmentCollection = $enrollmentCollection;
}
public function getCourseCollection()
{
return $this->courseCollection;
}
public function setCourseCollection($courseCollection)
{
return $this->courseCollection = $courseCollection;
}
public function getLessonCollection()
{
return $this->lessonCollection;
}
public function setLessonCollection($lessonCollection)
{
return $this->lessonCollection = $lessonCollection;
}
public function __construct()
{
$this->courseCollection = new ArrayCollection;
$this->lessonCollection = new ArrayCollection;
$this->enrollmentCollection = new ArrayCollection;
}
}
@caionitro
Copy link

Olá Minetto,
não precisamos adicionar:
use Doctrine\Common\Collections\ArrayCollection;

para que o construtor instancie o ArrayCollection?
O meu PHPUnit não estava rodando, dando erro no construtor, não estava achando a classe ArrayCollection.

@SamirSouzaSys
Copy link

Também tive q adicionar conforme citado acima.

@efantinij
Copy link

Para o meu PHPUnit rodar, também tive que incluir
use Doctrine\Common\Collections\ArrayCollection;

@mvnp
Copy link

mvnp commented Jul 5, 2020

No meu caso, mesmo adicionando o use Doctrine\Common\Collections\ArrayCollection ele continua informando que está faltando a classe. Minha config é PHPUnit 9 e PHP 7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment