23
23
use Symfony \Component \HttpKernel \HttpKernelInterface ;
24
24
25
25
/**
26
- * @author Amrouche Hamza <[email protected] >
27
- *
28
26
* @group legacy
29
27
*/
30
28
class WriteListenerTest extends TestCase
@@ -41,7 +39,7 @@ public function testOnKernelViewWithControllerResultAndPostMethod()
41
39
$ objectManagerProphecy ->persist ($ dummy )->shouldBeCalled ();
42
40
$ objectManagerProphecy ->flush ()->shouldBeCalled ();
43
41
$ managerRegistryProphecy = $ this ->prophesize (ManagerRegistry::class);
44
- $ managerRegistryProphecy ->getManagerForClass ('Dummy ' )->willReturn ($ objectManagerProphecy-> reveal () );
42
+ $ managerRegistryProphecy ->getManagerForClass ('Dummy ' )->willReturn ($ objectManagerProphecy );
45
43
46
44
$ writeListener = new WriteListener ($ managerRegistryProphecy ->reveal ());
47
45
$ httpKernelProphecy = $ this ->prophesize (HttpKernelInterface::class);
@@ -50,8 +48,7 @@ public function testOnKernelViewWithControllerResultAndPostMethod()
50
48
$ request ->attributes ->set ('_api_resource_class ' , 'Dummy ' );
51
49
$ event = new GetResponseForControllerResultEvent ($ httpKernelProphecy ->reveal (), $ request , HttpKernelInterface::MASTER_REQUEST , $ dummy );
52
50
53
- $ this ->assertNull ($ writeListener ->onKernelView ($ event ));
54
- $ this ->assertNotEquals ($ dummy , $ writeListener ->onKernelView ($ event ));
51
+ $ writeListener ->onKernelView ($ event );
55
52
}
56
53
57
54
/**
@@ -66,18 +63,18 @@ public function testOnKernelViewWithControllerResultAndDeleteMethod()
66
63
$ objectManagerProphecy ->remove ($ dummy )->shouldBeCalled ();
67
64
$ objectManagerProphecy ->flush ()->shouldBeCalled ();
68
65
$ managerRegistryProphecy = $ this ->prophesize (ManagerRegistry::class);
69
- $ managerRegistryProphecy ->getManagerForClass ('Dummy ' )->willReturn ($ objectManagerProphecy-> reveal () );
66
+ $ managerRegistryProphecy ->getManagerForClass ('Dummy ' )->willReturn ($ objectManagerProphecy );
70
67
71
68
$ writeListener = new WriteListener ($ managerRegistryProphecy ->reveal ());
72
69
$ request = new Request ();
73
70
$ request ->setMethod ('DELETE ' );
74
71
$ request ->attributes ->set ('_api_resource_class ' , 'Dummy ' );
75
- $ event = $ this ->prophesize (GetResponseForControllerResultEvent::class);
76
- $ event ->setControllerResult (null )->shouldBeCalled ();
77
- $ event ->getRequest ()->willReturn ($ request );
78
- $ event ->getControllerResult ()->willReturn ($ dummy );
79
- $ this -> assertNull ( $ writeListener -> onKernelView ( $ event -> reveal ()));
80
- $ this -> assertNotEquals ( $ dummy , $ writeListener ->onKernelView ($ event ->reveal () ));
72
+ $ eventProphecy = $ this ->prophesize (GetResponseForControllerResultEvent::class);
73
+ $ eventProphecy ->setControllerResult (null )->shouldBeCalled ();
74
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
75
+ $ eventProphecy ->getControllerResult ()->willReturn ($ dummy );
76
+
77
+ $ writeListener ->onKernelView ($ eventProphecy ->reveal ());
81
78
}
82
79
83
80
/**
@@ -88,16 +85,19 @@ public function testOnKernelViewWithSafeMethod()
88
85
$ dummy = new Dummy ();
89
86
$ dummy ->setName ('Dummyrino ' );
90
87
88
+ $ objectManagerProphecy = $ this ->prophesize (ObjectManager::class);
89
+ $ objectManagerProphecy ->flush ()->shouldNotBeCalled ();
91
90
$ managerRegistryProphecy = $ this ->prophesize (ManagerRegistry::class);
91
+ $ managerRegistryProphecy ->getManagerForClass ('Dummy ' )->willReturn ($ objectManagerProphecy );
92
92
93
93
$ writeListener = new WriteListener ($ managerRegistryProphecy ->reveal ());
94
94
$ httpKernelProphecy = $ this ->prophesize (HttpKernelInterface::class);
95
95
$ request = new Request ();
96
96
$ request ->setMethod ('HEAD ' );
97
+ $ request ->attributes ->set ('_api_resource_class ' , 'Dummy ' );
97
98
$ event = new GetResponseForControllerResultEvent ($ httpKernelProphecy ->reveal (), $ request , HttpKernelInterface::MASTER_REQUEST , $ dummy );
98
99
99
- $ this ->assertNull ($ writeListener ->onKernelView ($ event ));
100
- $ this ->assertNotEquals ($ dummy , $ writeListener ->onKernelView ($ event ));
100
+ $ writeListener ->onKernelView ($ event );
101
101
}
102
102
103
103
/**
@@ -108,20 +108,23 @@ public function testOnKernelViewWithNoResourceClass()
108
108
$ dummy = new Dummy ();
109
109
$ dummy ->setName ('Dummyrino ' );
110
110
111
+ $ objectManagerProphecy = $ this ->prophesize (ObjectManager::class);
112
+ $ objectManagerProphecy ->flush ()->shouldNotBeCalled ();
111
113
$ managerRegistryProphecy = $ this ->prophesize (ManagerRegistry::class);
114
+ $ managerRegistryProphecy ->getManagerForClass ('Dummy ' )->willReturn ($ objectManagerProphecy );
112
115
113
116
$ writeListener = new WriteListener ($ managerRegistryProphecy ->reveal ());
114
117
$ httpKernelProphecy = $ this ->prophesize (HttpKernelInterface::class);
115
118
$ request = new Request ();
116
119
$ request ->setMethod ('POST ' );
117
120
$ event = new GetResponseForControllerResultEvent ($ httpKernelProphecy ->reveal (), $ request , HttpKernelInterface::MASTER_REQUEST , $ dummy );
118
121
119
- $ this ->assertNull ($ writeListener ->onKernelView ($ event ));
120
- $ this ->assertNotEquals ($ dummy , $ writeListener ->onKernelView ($ event ));
122
+ $ writeListener ->onKernelView ($ event );
121
123
}
122
124
123
125
/**
124
126
* @expectedDeprecation The ApiPlatform\Core\Bridge\Doctrine\EventListener\WriteListener class is deprecated since version 2.2 and will be removed in 3.0. Use the ApiPlatform\Core\EventListener\WriteListener class instead.
127
+ * @doesNotPerformAssertions
125
128
*/
126
129
public function testOnKernelViewWithNoManager ()
127
130
{
@@ -138,7 +141,6 @@ public function testOnKernelViewWithNoManager()
138
141
$ request ->attributes ->set ('_api_resource_class ' , 'Dummy ' );
139
142
$ event = new GetResponseForControllerResultEvent ($ httpKernelProphecy ->reveal (), $ request , HttpKernelInterface::MASTER_REQUEST , $ dummy );
140
143
141
- $ this ->assertNull ($ writeListener ->onKernelView ($ event ));
142
- $ this ->assertNotEquals ($ dummy , $ writeListener ->onKernelView ($ event ));
144
+ $ writeListener ->onKernelView ($ event );
143
145
}
144
146
}
0 commit comments