@@ -29,7 +29,7 @@ public function testAddCheckStatusUpSuccess(): void
29
29
$ healthController = new HealthController ();
30
30
$ healthController ->addHealthCheck (new StatusUpCheck ());
31
31
32
- $ response = $ healthController ->healthCheckAction ();
32
+ $ response = $ healthController ->check ();
33
33
34
34
self ::assertSame (200 , $ response ->getStatusCode ());
35
35
self ::assertSame (
@@ -45,7 +45,7 @@ public function testEnvironmentCheckCouldNotDetermine(): void
45
45
$ healthController = new HealthController ();
46
46
$ healthController ->addHealthCheck (new EnvironmentCheck (new ContainerBuilder ()));
47
47
48
- $ response = $ healthController ->healthCheckAction ();
48
+ $ response = $ healthController ->check ();
49
49
50
50
self ::assertSame (200 , $ response ->getStatusCode ());
51
51
self ::assertSame (
@@ -64,7 +64,7 @@ public function testDoctrineCheckServiceNotFoundException(): void
64
64
$ healthController = new HealthController ();
65
65
$ healthController ->addHealthCheck (new DoctrineCheck (new ContainerBuilder ()));
66
66
67
- $ response = $ healthController ->healthCheckAction ();
67
+ $ response = $ healthController ->check ();
68
68
self ::assertSame (200 , $ response ->getStatusCode ());
69
69
self ::assertSame (
70
70
json_encode ([[
@@ -83,7 +83,7 @@ public function testTwoCheckSuccess(): void
83
83
$ healthController ->addHealthCheck (new StatusUpCheck ());
84
84
$ healthController ->addHealthCheck (new EnvironmentCheck (new ContainerBuilder ()));
85
85
86
- $ response = $ healthController ->healthCheckAction ();
86
+ $ response = $ healthController ->check ();
87
87
88
88
self ::assertSame (200 , $ response ->getStatusCode ());
89
89
self ::assertSame (
@@ -108,7 +108,7 @@ public function testEnvironmentCheckSuccess(): void
108
108
{
109
109
$ healthController = new HealthController ();
110
110
$ healthController ->addHealthCheck (new EnvironmentCheck (static ::bootKernel ()->getContainer ()));
111
- $ response = $ healthController ->healthCheckAction ();
111
+ $ response = $ healthController ->check ();
112
112
113
113
self ::assertSame (200 , $ response ->getStatusCode ());
114
114
self ::assertSame (
@@ -131,4 +131,41 @@ public function testAddCheckFailed(): void
131
131
$ healthController = new HealthController ();
132
132
$ healthController ->addHealthCheck (new HealthController ());
133
133
}
134
+
135
+ public function testCustomErrorCodeIfOneOfChecksIsFalse (): void
136
+ {
137
+ $ healthController = new HealthController ();
138
+ $ healthController ->addHealthCheck (new EnvironmentCheck (new ContainerBuilder ()));
139
+ $ healthController ->setCustomResponseCode (500 );
140
+
141
+ $ response = $ healthController ->check ();
142
+
143
+ self ::assertSame (500 , $ response ->getStatusCode ());
144
+ self ::assertSame (
145
+ json_encode ([[
146
+ 'name ' => 'environment ' ,
147
+ 'result ' => false ,
148
+ 'message ' => 'Could not determine ' ,
149
+ 'params ' => []
150
+ ]]),
151
+ $ response ->getContent ()
152
+ );
153
+ }
154
+
155
+ public function testCustomErrorCodeDoesNotAffectSuccessResponse (): void
156
+ {
157
+ $ healthController = new HealthController ();
158
+ $ healthController ->addHealthCheck (new StatusUpCheck ());
159
+ $ healthController ->setCustomResponseCode (500 );
160
+
161
+ $ response = $ healthController ->check ();
162
+
163
+ self ::assertSame (200 , $ response ->getStatusCode ());
164
+ self ::assertSame (
165
+ json_encode ([[
166
+ 'name ' => 'status ' , 'result ' => true , 'message ' => 'up ' , 'params ' => [],
167
+ ]]),
168
+ $ response ->getContent ()
169
+ );
170
+ }
134
171
}
0 commit comments