55namespace Doctrine \Tests \ORM \Functional \Ticket ;
66
77use Doctrine \Common \Collections \ArrayCollection ;
8+ use Doctrine \Common \Collections \Collection ;
89use Doctrine \DBAL \Schema \ForeignKeyConstraint ;
910use Doctrine \DBAL \Schema \ForeignKeyConstraintEditor ;
1011use Doctrine \DBAL \Schema \Name \UnqualifiedName ;
2021use Doctrine \ORM \Mapping \ManyToOne ;
2122use Doctrine \ORM \Mapping \OneToMany ;
2223use Doctrine \ORM \Mapping \Table ;
23- use Doctrine \Tests \ORM \Functional \Ticket \Doctrine \Common \Collections \Collection ;
2424use Doctrine \Tests \OrmFunctionalTestCase ;
2525use PHPUnit \Framework \Attributes \Group ;
26+ use PHPUnit \Framework \Attributes \IgnoreDeprecations ;
2627
2728use function array_map ;
2829use function assert ;
3132
3233class DDC2138Test extends OrmFunctionalTestCase
3334{
35+ /**
36+ * With this test, we will create the same foreign key twice which is fine, but we will tap a deprecation
37+ * in DBAL 4.4. This has to be fixed during the validation of metadata. For now, we will simply ignore that
38+ * deprecation.
39+ */
3440 #[Group('DDC-2138 ' )]
41+ #[IgnoreDeprecations]
3542 public function testForeignKeyOnSTIWithMultipleMapping (): void
3643 {
37- $ em = $ this ->_em ;
3844 $ schema = $ this ->getSchemaForModels (
3945 DDC2138User::class,
4046 DDC2138Structure::class,
@@ -86,15 +92,13 @@ private static function columnIsIndexed(DbalTable $table, string $column): bool
8692#[Entity]
8793class DDC2138Structure
8894{
89- /** @var int */
9095 #[Id]
91- #[Column(type: ' integer ' ) ]
96+ #[Column]
9297 #[GeneratedValue(strategy: 'AUTO ' )]
93- protected $ id ;
98+ protected int | null $ id = null ;
9499
95- /** @var string */
96- #[Column(type: 'string ' , length: 32 , nullable: true )]
97- protected $ name ;
100+ #[Column(length: 32 , nullable: true )]
101+ protected string |null $ name = null ;
98102}
99103
100104#[Table(name: 'users_followed_objects ' )]
@@ -104,19 +108,10 @@ class DDC2138Structure
104108#[DiscriminatorMap([4 => 'DDC2138UserFollowedUser ' , 3 => 'DDC2138UserFollowedStructure ' ])]
105109abstract class DDC2138UserFollowedObject
106110{
107- /** @var int $id */
108111 #[Column(name: 'id ' , type: 'integer ' )]
109112 #[Id]
110113 #[GeneratedValue(strategy: 'AUTO ' )]
111- protected $ id ;
112-
113- /**
114- * Get id
115- */
116- public function getId (): int
117- {
118- return $ this ->id ;
119- }
114+ public int |null $ id = null ;
120115}
121116
122117#[Entity]
@@ -126,27 +121,14 @@ class DDC2138UserFollowedStructure extends DDC2138UserFollowedObject
126121 * Construct a UserFollowedStructure entity
127122 */
128123 public function __construct (
129- #[ManyToOne(targetEntity: ' DDC2138User ' , inversedBy: 'followedStructures ' )]
124+ #[ManyToOne(inversedBy: 'followedStructures ' )]
130125 #[JoinColumn(name: 'user_id ' , referencedColumnName: 'id ' , nullable: false )]
131- protected User $ user ,
132- #[ManyToOne(targetEntity: ' DDC2138Structure ' ) ]
126+ public DDC2138User $ user ,
127+ #[ManyToOne]
133128 #[JoinColumn(name: 'object_id ' , referencedColumnName: 'id ' , nullable: false )]
134- private Structure $ followedStructure ,
129+ public DDC2138Structure $ followedStructure ,
135130 ) {
136131 }
137-
138- public function getUser (): User
139- {
140- return $ this ->user ;
141- }
142-
143- /**
144- * Gets followed structure
145- */
146- public function getFollowedStructure (): Structure
147- {
148- return $ this ->followedStructure ;
149- }
150132}
151133
152134#[Entity]
@@ -156,92 +138,39 @@ class DDC2138UserFollowedUser extends DDC2138UserFollowedObject
156138 * Construct a UserFollowedUser entity
157139 */
158140 public function __construct (
159- #[ManyToOne(targetEntity: ' DDC2138User ' , inversedBy: 'followedUsers ' )]
141+ #[ManyToOne(inversedBy: 'followedUsers ' )]
160142 #[JoinColumn(name: 'user_id ' , referencedColumnName: 'id ' , nullable: false )]
161- protected User $ user ,
162- #[ManyToOne(targetEntity: ' DDC2138User ' ) ]
143+ public DDC2138User $ user ,
144+ #[ManyToOne]
163145 #[JoinColumn(name: 'object_id ' , referencedColumnName: 'id ' , nullable: false )]
164- private User $ followedUser ,
146+ public DDC2138User $ followedUser ,
165147 ) {
166148 }
167-
168- public function getUser (): User
169- {
170- return $ this ->user ;
171- }
172-
173- /**
174- * Gets followed user
175- */
176- public function getFollowedUser (): User
177- {
178- return $ this ->followedUser ;
179- }
180149}
181150
182151#[Table(name: 'users ' )]
183152#[Entity]
184153class DDC2138User
185154{
186- /** @var int */
187155 #[Id]
188- #[Column(type: ' integer ' ) ]
156+ #[Column]
189157 #[GeneratedValue(strategy: 'AUTO ' )]
190- protected $ id ;
158+ public int | null $ id = null ;
191159
192- /** @var string */
193- #[Column(type: 'string ' , length: 32 , nullable: true )]
194- protected $ name ;
160+ #[Column(length: 32 , nullable: true )]
161+ public string |null $ name = null ;
195162
196- /** @var ArrayCollection $followedUsers */
197- #[OneToMany(targetEntity: ' DDC2138UserFollowedUser ' , mappedBy: 'user ' , cascade: ['persist ' ], orphanRemoval: true )]
198- protected $ followedUsers ;
163+ /** @var Collection<int, DDC2138UserFollowedUser> */
164+ #[OneToMany(targetEntity: DDC2138UserFollowedUser::class , mappedBy: 'user ' , cascade: ['persist ' ], orphanRemoval: true )]
165+ public Collection $ followedUsers ;
199166
200- /** @var ArrayCollection $followedStructures */
201- #[OneToMany(targetEntity: ' DDC2138UserFollowedStructure ' , mappedBy: 'user ' , cascade: ['persist ' ], orphanRemoval: true )]
202- protected $ followedStructures ;
167+ /** @var Collection<int, DDC2138UserFollowedStructure> */
168+ #[OneToMany(targetEntity: DDC2138UserFollowedStructure::class , mappedBy: 'user ' , cascade: ['persist ' ], orphanRemoval: true )]
169+ public Collection $ followedStructures ;
203170
204171 public function __construct ()
205172 {
206173 $ this ->followedUsers = new ArrayCollection ();
207174 $ this ->followedStructures = new ArrayCollection ();
208175 }
209-
210- public function addFollowedUser (UserFollowedUser $ followedUsers ): User
211- {
212- $ this ->followedUsers [] = $ followedUsers ;
213-
214- return $ this ;
215- }
216-
217- public function removeFollowedUser (UserFollowedUser $ followedUsers ): User
218- {
219- $ this ->followedUsers ->removeElement ($ followedUsers );
220-
221- return $ this ;
222- }
223-
224- public function getFollowedUsers (): Collection
225- {
226- return $ this ->followedUsers ;
227- }
228-
229- public function addFollowedStructure (UserFollowedStructure $ followedStructures ): User
230- {
231- $ this ->followedStructures [] = $ followedStructures ;
232-
233- return $ this ;
234- }
235-
236- public function removeFollowedStructure (UserFollowedStructure $ followedStructures ): User
237- {
238- $ this ->followedStructures ->removeElement ($ followedStructures );
239-
240- return $ this ;
241- }
242-
243- public function getFollowedStructures (): Collection
244- {
245- return $ this ->followedStructures ;
246- }
247176}
0 commit comments