File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
src/Bridge/Doctrine/Common
tests/Bridge/Doctrine/Common Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,10 @@ public function persist($data)
51
51
return ;
52
52
}
53
53
54
- $ manager ->persist ($ data );
54
+ if (!$ manager ->contains ($ data )) {
55
+ $ manager ->persist ($ data );
56
+ }
57
+
55
58
$ manager ->flush ();
56
59
$ manager ->refresh ($ data );
57
60
}
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ public function testPersist()
48
48
$ dummy = new Dummy ();
49
49
50
50
$ objectManagerProphecy = $ this ->prophesize (ObjectManager::class);
51
+ $ objectManagerProphecy ->contains ($ dummy )->willReturn (false );
51
52
$ objectManagerProphecy ->persist ($ dummy )->shouldBeCalled ();
52
53
$ objectManagerProphecy ->flush ()->shouldBeCalled ();
53
54
$ objectManagerProphecy ->refresh ($ dummy )->shouldBeCalled ();
@@ -58,6 +59,22 @@ public function testPersist()
58
59
(new DataPersister ($ managerRegistryProphecy ->reveal ()))->persist ($ dummy );
59
60
}
60
61
62
+ public function testPersistIfEntityAlreadyManaged ()
63
+ {
64
+ $ dummy = new Dummy ();
65
+
66
+ $ objectManagerProphecy = $ this ->prophesize (ObjectManager::class);
67
+ $ objectManagerProphecy ->contains ($ dummy )->willReturn (true );
68
+ $ objectManagerProphecy ->persist ($ dummy )->shouldNotBeCalled ();
69
+ $ objectManagerProphecy ->flush ()->shouldBeCalled ();
70
+ $ objectManagerProphecy ->refresh ($ dummy )->shouldBeCalled ();
71
+
72
+ $ managerRegistryProphecy = $ this ->prophesize (ManagerRegistry::class);
73
+ $ managerRegistryProphecy ->getManagerForClass (Dummy::class)->willReturn ($ objectManagerProphecy ->reveal ())->shouldBeCalled ();
74
+
75
+ (new DataPersister ($ managerRegistryProphecy ->reveal ()))->persist ($ dummy );
76
+ }
77
+
61
78
public function testPersistWithNullManager ()
62
79
{
63
80
$ managerRegistryProphecy = $ this ->prophesize (ManagerRegistry::class);
You can’t perform that action at this time.
0 commit comments