1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use Zenstruck\Foundry\AnonymousFactory; |
6
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Entity\Contact; |
7
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Entity\Post; |
8
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Factories\CategoryFactory; |
9
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Factories\PostFactoryWithProxyGenerator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Wouter de Jong <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
final class ProxyGeneratorTest extends ProxyTest |
15
|
|
|
{ |
16
|
|
|
protected static $POST_FACTORY = PostFactoryWithProxyGenerator::class; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @test |
20
|
|
|
*/ |
21
|
|
|
public function can_assert_persisted(): void |
22
|
|
|
{ |
23
|
|
|
$this->markTestSkipped('not supported'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @test |
28
|
|
|
*/ |
29
|
|
|
public function can_remove_and_assert_not_persisted(): void |
30
|
|
|
{ |
31
|
|
|
$this->markTestSkipped('not supported'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
*/ |
37
|
|
|
public function can_refetch_object_if_object_manager_has_been_cleared(): void |
38
|
|
|
{ |
39
|
|
|
$this->markTestSkipped('not supported'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @test |
44
|
|
|
*/ |
45
|
|
|
public function exception_thrown_if_trying_to_refresh_deleted_object(): void |
46
|
|
|
{ |
47
|
|
|
$this->markTestSkipped('not supported'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @test |
52
|
|
|
*/ |
53
|
|
|
public function can_force_set_and_save(): void |
54
|
|
|
{ |
55
|
|
|
$this->markTestSkipped('not supported'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @test |
60
|
|
|
*/ |
61
|
|
|
public function can_force_set_multiple_fields(): void |
62
|
|
|
{ |
63
|
|
|
$this->markTestSkipped('not supported'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @test |
68
|
|
|
*/ |
69
|
|
|
public function exception_thrown_if_trying_to_autorefresh_object_with_unsaved_changes(): void |
70
|
|
|
{ |
71
|
|
|
$post = static::$POST_FACTORY::createOne(['title' => 'old title', 'body' => 'old body']); |
72
|
|
|
|
73
|
|
|
$this->assertSame('old title', $post->getTitle()); |
74
|
|
|
$this->assertSame('old body', $post->getBody()); |
75
|
|
|
|
76
|
|
|
$post->setTitle('new title'); |
77
|
|
|
|
78
|
|
|
$this->expectException(\RuntimeException::class); |
79
|
|
|
|
80
|
|
|
$post->setBody('new body'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @test |
85
|
|
|
*/ |
86
|
|
|
public function can_autorefresh_between_kernel_boots(): void |
87
|
|
|
{ |
88
|
|
|
$this->markTestSkipped('not supported'); |
89
|
|
|
|
90
|
|
|
$post = static::$POST_FACTORY::createOne(['title' => 'old title', 'body' => 'old body']); |
91
|
|
|
|
92
|
|
|
$this->assertSame('old title', $post->getTitle()); |
93
|
|
|
$this->assertSame('old body', $post->getBody()); |
94
|
|
|
|
95
|
|
|
// reboot kernel |
96
|
|
|
static::ensureKernelShutdown(); |
97
|
|
|
static::bootKernel(); |
98
|
|
|
|
99
|
|
|
$this->assertSame('old title', $post->getTitle()); |
100
|
|
|
$this->assertSame('old body', $post->getBody()); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @test |
105
|
|
|
*/ |
106
|
|
|
public function can_autorefresh_entity_with_embedded_object(): void |
107
|
|
|
{ |
108
|
|
|
$contactFactory = AnonymousFactory::new(Contact::class)->withProxyGenerator(); |
109
|
|
|
$contact = $contactFactory->create(['name' => 'john']); |
110
|
|
|
|
111
|
|
|
$this->assertSame('john', $contact->getName()); |
112
|
|
|
|
113
|
|
|
// I discovered when autorefreshing the second time, the embedded |
114
|
|
|
// object is included in the changeset when using UOW::recomputeSingleEntityChangeSet(). |
115
|
|
|
// Changing to UOW::computeChangeSet() fixes this. |
116
|
|
|
$this->assertSame('john', $contact->getName()); |
117
|
|
|
$this->assertNull($contact->getAddress()->getValue()); |
118
|
|
|
|
119
|
|
|
$contact->getAddress()->setValue('address'); |
120
|
|
|
$contactFactory->persist($contact); |
121
|
|
|
|
122
|
|
|
$this->assertSame('address', $contact->getAddress()->getValue()); |
123
|
|
|
|
124
|
|
|
// todo unsupported |
125
|
|
|
//static::ensureKernelShutdown(); |
126
|
|
|
//static::bootKernel(); |
127
|
|
|
|
128
|
|
|
//$this->assertSame('address', $contact->getAddress()->getValue()); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @test |
133
|
|
|
*/ |
134
|
|
|
public function force_set_all_solves_the_auto_refresh_problem(): void |
135
|
|
|
{ |
136
|
|
|
$this->markTestSkipped('not supported'); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @test |
141
|
|
|
*/ |
142
|
|
|
public function without_auto_refresh_solves_the_auto_refresh_problem(): void |
143
|
|
|
{ |
144
|
|
|
$post = static::$POST_FACTORY::createOne(['title' => 'old title', 'body' => 'old body']); |
145
|
|
|
|
146
|
|
|
$this->assertSame('old title', $post->getTitle()); |
147
|
|
|
$this->assertSame('old body', $post->getBody()); |
148
|
|
|
|
149
|
|
|
static::$POST_FACTORY::withoutAutoRefresh($post, static function(Post $post) { |
150
|
|
|
$post->setTitle('new title'); |
151
|
|
|
$post->setBody('new body'); |
152
|
|
|
}); |
153
|
|
|
static::$POST_FACTORY::persist($post); |
154
|
|
|
|
155
|
|
|
$this->assertSame('new title', $post->getTitle()); |
156
|
|
|
$this->assertSame('new body', $post->getBody()); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @test |
161
|
|
|
*/ |
162
|
|
|
public function without_auto_refresh_does_not_enable_auto_refresh_if_it_was_disabled_originally(): void |
163
|
|
|
{ |
164
|
|
|
$post = static::$POST_FACTORY::createOne(['title' => 'old title', 'body' => 'old body']); |
165
|
|
|
|
166
|
|
|
static::$POST_FACTORY::disableAutoRefresh($post); |
167
|
|
|
|
168
|
|
|
$this->assertSame('old title', $post->getTitle()); |
169
|
|
|
$this->assertSame('old body', $post->getBody()); |
170
|
|
|
|
171
|
|
|
static::$POST_FACTORY::withoutAutoRefresh($post, static function(Post $post) { |
172
|
|
|
$post->setTitle('new title'); |
173
|
|
|
$post->setBody('new body'); |
174
|
|
|
}); |
175
|
|
|
|
176
|
|
|
$post->setTitle('another new title'); |
177
|
|
|
$post->setBody('another new body'); |
178
|
|
|
|
179
|
|
|
static::$POST_FACTORY::persist($post); |
180
|
|
|
|
181
|
|
|
$this->assertSame('another new title', $post->getTitle()); |
182
|
|
|
$this->assertSame('another new body', $post->getBody()); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @test |
187
|
|
|
*/ |
188
|
|
|
public function without_auto_refresh_keeps_disabled_if_originally_disabled(): void |
189
|
|
|
{ |
190
|
|
|
$post = static::$POST_FACTORY::createOne(['title' => 'old title', 'body' => 'old body']); |
191
|
|
|
|
192
|
|
|
static::$POST_FACTORY::disableAutoRefresh($post); |
193
|
|
|
|
194
|
|
|
$this->assertSame('old title', $post->getTitle()); |
195
|
|
|
$this->assertSame('old body', $post->getBody()); |
196
|
|
|
|
197
|
|
|
static::$POST_FACTORY::withoutAutoRefresh($post, static function(Post $post) { |
198
|
|
|
$post->setTitle('new title'); |
199
|
|
|
$post->setBody('new body'); |
200
|
|
|
}); |
201
|
|
|
|
202
|
|
|
static::$POST_FACTORY::persist($post); |
203
|
|
|
|
204
|
|
|
$post->setTitle('another new title'); |
205
|
|
|
$post->setBody('another new body'); |
206
|
|
|
|
207
|
|
|
static::$POST_FACTORY::persist($post); |
208
|
|
|
|
209
|
|
|
$this->assertSame('another new title', $post->getTitle()); |
210
|
|
|
$this->assertSame('another new body', $post->getBody()); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|