@@ -18,21 +18,7 @@ class UriRepositoryTest extends WebTestCase
18
18
*/
19
19
private $ entityManager ;
20
20
21
- /**
22
- * {@inheritDoc}
23
- */
24
- protected function setUp ()
25
- {
26
- $ kernel = self ::bootKernel ();
27
-
28
- $ this ->initDatabase ($ kernel );
29
-
30
- $ this ->entityManager = $ kernel ->getContainer ()
31
- ->get ('doctrine ' )
32
- ->getManager ();
33
- }
34
-
35
- public function testRepositoryCanBeInstantiated ()
21
+ public function testRepositoryCanBeInstantiated (): void
36
22
{
37
23
$ repository = $ this ->entityManager ->getRepository (Uri::class);
38
24
$ this ->assertInstanceOf (UriRepository::class, $ repository );
@@ -43,7 +29,7 @@ public function testRepositoryCanBeInstantiated()
43
29
* @throws \Doctrine\ORM\ORMException
44
30
* @throws \Doctrine\ORM\OptimisticLockException
45
31
*/
46
- public function testNewEntityCanBeSavedThroughRepository ()
32
+ public function testNewEntityCanBeSavedThroughRepository (): void
47
33
{
48
34
/** @var UriRepository $repository */
49
35
$ repository = $ this ->entityManager ->getRepository (Uri::class);
@@ -69,7 +55,7 @@ public function testNewEntityCanBeSavedThroughRepository()
69
55
* @throws \Doctrine\ORM\ORMException
70
56
* @throws \Doctrine\ORM\OptimisticLockException
71
57
*/
72
- public function testUriCanBeFoundByShortCode ()
58
+ public function testUriCanBeFoundByShortCode (): void
73
59
{
74
60
$ this ->createDemoRecord ();
75
61
@@ -85,12 +71,31 @@ public function testUriCanBeFoundByShortCode()
85
71
);
86
72
}
87
73
74
+ /**
75
+ * @throws \Doctrine\ORM\ORMException
76
+ * @throws \Doctrine\ORM\OptimisticLockException
77
+ */
78
+ private function createDemoRecord (): void
79
+ {
80
+ /** @var UriRepository $repository */
81
+ $ repository = $ this ->entityManager ->getRepository (Uri::class);
82
+
83
+ $ putRequest = new PutUriRequest ('www.bar.com ' );
84
+
85
+ $ entity = new Uri ();
86
+ $ entity ->setOriginalUrl ($ putRequest ->getUrl ());
87
+ $ entity ->setUrlHash ($ putRequest ->getUrlHash ());
88
+ $ entity ->setShortCode ($ putRequest ->getShortCode ());
89
+
90
+ $ repository ->saveUri ($ entity );
91
+ }
92
+
88
93
/**
89
94
* @throws \Doctrine\ORM\NonUniqueResultException
90
95
* @throws \Doctrine\ORM\ORMException
91
96
* @throws \Doctrine\ORM\OptimisticLockException
92
97
*/
93
- public function testUriCanBeFoundByUrlHash ()
98
+ public function testUriCanBeFoundByUrlHash (): void
94
99
{
95
100
$ this ->createDemoRecord ();
96
101
@@ -109,19 +114,23 @@ public function testUriCanBeFoundByUrlHash()
109
114
/**
110
115
* {@inheritDoc}
111
116
*/
112
- protected function tearDown ()
117
+ protected function setUp ()
113
118
{
114
- parent :: tearDown ();
119
+ $ kernel = self :: bootKernel ();
115
120
116
- $ this ->entityManager ->close ();
117
- $ this ->entityManager = null ; // avoid memory leaks
121
+ $ this ->initDatabase ($ kernel );
122
+
123
+ $ this ->entityManager = $ kernel ->getContainer ()
124
+ ->get ('doctrine ' )
125
+ ->getManager ();
118
126
}
119
127
120
128
/**
121
129
* @param KernelInterface $kernel
130
+ *
122
131
* @throws \Exception
123
132
*/
124
- private function initDatabase (KernelInterface $ kernel )
133
+ private function initDatabase (KernelInterface $ kernel ): void
125
134
{
126
135
$ application = new Application ($ kernel );
127
136
$ application ->setAutoExit (false );
@@ -143,30 +152,21 @@ private function initDatabase(KernelInterface $kernel)
143
152
144
153
// run migrations
145
154
$ input = new ArrayInput ([
146
- 'command ' => 'doctrine:migrations:migrate ' ,
155
+ 'command ' => 'doctrine:migrations:migrate ' ,
147
156
'--no-interaction ' => true
148
157
149
158
]);
150
159
$ application ->run ($ input , new NullOutput ());
151
-
152
160
}
153
161
154
162
/**
155
- * @throws \Doctrine\ORM\ORMException
156
- * @throws \Doctrine\ORM\OptimisticLockException
163
+ * {@inheritDoc}
157
164
*/
158
- private function createDemoRecord ()
165
+ protected function tearDown ()
159
166
{
160
- /** @var UriRepository $repository */
161
- $ repository = $ this ->entityManager ->getRepository (Uri::class);
162
-
163
- $ putRequest = new PutUriRequest ('www.bar.com ' );
164
-
165
- $ entity = new Uri ();
166
- $ entity ->setOriginalUrl ($ putRequest ->getUrl ());
167
- $ entity ->setUrlHash ($ putRequest ->getUrlHash ());
168
- $ entity ->setShortCode ($ putRequest ->getShortCode ());
167
+ parent ::tearDown ();
169
168
170
- $ repository ->saveUri ($ entity );
169
+ $ this ->entityManager ->close ();
170
+ $ this ->entityManager = null ; // avoid memory leaks
171
171
}
172
172
}
0 commit comments