1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagerfanta\Tests\Adapter\DoctrineORM; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
abstract class DoctrineORMTestCase extends TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var \Doctrine\ORM\EntityManager |
11
|
|
|
*/ |
12
|
|
|
protected $entityManager; |
13
|
|
|
|
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
if (!class_exists('Doctrine\ORM\EntityManager')) { |
17
|
|
|
$this->markTestSkipped('Doctrine ORM is not available'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
$config = new \Doctrine\ORM\Configuration(); |
21
|
|
|
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); |
22
|
|
|
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); |
23
|
|
|
$config->setProxyDir(__DIR__.'/_files'); |
24
|
|
|
$config->setProxyNamespace('Pagerfanta\Tests\Adapter\DoctrineORM\Proxies'); |
25
|
|
|
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver()); |
26
|
|
|
|
27
|
|
|
$conn = array( |
28
|
|
|
'driver' => 'pdo_sqlite', |
29
|
|
|
'memory' => true, |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
$this->entityManager = \Doctrine\ORM\EntityManager::create($conn, $config); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @Entity |
38
|
|
|
*/ |
39
|
|
|
class MyBlogPost |
40
|
|
|
{ |
41
|
|
|
/** @Id @column(type="integer") @generatedValue */ |
42
|
|
|
public $id; |
43
|
|
|
/** |
44
|
|
|
* @ManyToOne(targetEntity="Author") |
45
|
|
|
*/ |
46
|
|
|
public $author; |
47
|
|
|
/** |
48
|
|
|
* @ManyToOne(targetEntity="Category") |
49
|
|
|
*/ |
50
|
|
|
public $category; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Entity |
55
|
|
|
*/ |
56
|
|
|
class MyAuthor |
57
|
|
|
{ |
58
|
|
|
/** @Id @column(type="integer") @generatedValue */ |
59
|
|
|
public $id; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Entity |
64
|
|
|
*/ |
65
|
|
|
class MyCategory |
66
|
|
|
{ |
67
|
|
|
/** @id @column(type="integer") @generatedValue */ |
68
|
|
|
public $id; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @Entity |
73
|
|
|
*/ |
74
|
|
|
class BlogPost |
75
|
|
|
{ |
76
|
|
|
/** @Id @column(type="integer") @generatedValue */ |
77
|
|
|
public $id; |
78
|
|
|
/** |
79
|
|
|
* @ManyToOne(targetEntity="Author") |
80
|
|
|
*/ |
81
|
|
|
public $author; |
82
|
|
|
/** |
83
|
|
|
* @ManyToOne(targetEntity="Category") |
84
|
|
|
*/ |
85
|
|
|
public $category; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @Entity |
90
|
|
|
*/ |
91
|
|
|
class Author |
92
|
|
|
{ |
93
|
|
|
/** @Id @column(type="integer") @generatedValue */ |
94
|
|
|
public $id; |
95
|
|
|
/** @Column(type="string") */ |
96
|
|
|
public $name; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @Entity |
101
|
|
|
*/ |
102
|
|
|
class Person |
103
|
|
|
{ |
104
|
|
|
/** @Id @column(type="integer") @generatedValue */ |
105
|
|
|
public $id; |
106
|
|
|
/** @Column(type="string") */ |
107
|
|
|
public $name; |
108
|
|
|
/** @Column(type="string") */ |
109
|
|
|
public $biography; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @Entity |
114
|
|
|
*/ |
115
|
|
|
class Category |
116
|
|
|
{ |
117
|
|
|
/** @id @column(type="integer") @generatedValue */ |
118
|
|
|
public $id; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** @Entity @Table(name="groups") */ |
122
|
|
|
class Group |
123
|
|
|
{ |
124
|
|
|
/** @Id @column(type="integer") @generatedValue */ |
125
|
|
|
public $id; |
126
|
|
|
/** @ManyToMany(targetEntity="User", mappedBy="groups") */ |
127
|
|
|
public $users; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** @Entity */ |
131
|
|
|
class User |
132
|
|
|
{ |
133
|
|
|
/** @Id @column(type="integer") @generatedValue */ |
134
|
|
|
public $id; |
135
|
|
|
/** |
136
|
|
|
* @ManyToMany(targetEntity="Group", inversedBy="users") |
137
|
|
|
* @JoinTable( |
138
|
|
|
* name="user_group", |
139
|
|
|
* joinColumns = {@JoinColumn(name="user_id", referencedColumnName="id")}, |
140
|
|
|
* inverseJoinColumns = {@JoinColumn(name="group_id", referencedColumnName="id")} |
141
|
|
|
* ) |
142
|
|
|
*/ |
143
|
|
|
public $groups; |
144
|
|
|
} |
145
|
|
|
|