|  | 
| 6 | 6 | use Http\HttplugBundle\DependencyInjection\HttplugExtension; | 
| 7 | 7 | use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; | 
| 8 | 8 | use Symfony\Component\DependencyInjection\Reference; | 
|  | 9 | +use Symfony\Component\HttpKernel\Kernel; | 
| 9 | 10 | 
 | 
| 10 | 11 | /** | 
| 11 | 12 |  * @author David Buchmann <[email protected]> | 
| @@ -267,4 +268,145 @@ private function verifyProfilingDisabled() | 
| 267 | 268 |             ); | 
| 268 | 269 |         } | 
| 269 | 270 |     } | 
|  | 271 | + | 
|  | 272 | +    public function testClientShouldHaveDefaultVisibility() | 
|  | 273 | +    { | 
|  | 274 | +        $this->load([ | 
|  | 275 | +            'clients' => [ | 
|  | 276 | +                'acme' => [], | 
|  | 277 | +            ], | 
|  | 278 | +        ]); | 
|  | 279 | + | 
|  | 280 | +        $this->assertContainerBuilderHasService('httplug.client.acme'); | 
|  | 281 | + | 
|  | 282 | +        if (version_compare(Kernel::VERSION, '3.4', '>=')) { | 
|  | 283 | +            // Symfony made services private by default starting from 3.4 | 
|  | 284 | +            $this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPublic()); | 
|  | 285 | +            $this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPrivate()); | 
|  | 286 | +        } else { | 
|  | 287 | +            // Legacy Symfony | 
|  | 288 | +            $this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPublic()); | 
|  | 289 | +        } | 
|  | 290 | +    } | 
|  | 291 | + | 
|  | 292 | +    public function testFlexibleClientShouldBePrivateByDefault() | 
|  | 293 | +    { | 
|  | 294 | +        $this->load([ | 
|  | 295 | +            'clients' => [ | 
|  | 296 | +                'acme' => [ | 
|  | 297 | +                    'flexible_client' => true, | 
|  | 298 | +                ], | 
|  | 299 | +            ], | 
|  | 300 | +        ]); | 
|  | 301 | + | 
|  | 302 | +        $this->assertContainerBuilderHasService('httplug.client.acme'); | 
|  | 303 | +        $this->assertFalse($this->container->getDefinition('httplug.client.acme.flexible')->isPublic()); | 
|  | 304 | +    } | 
|  | 305 | + | 
|  | 306 | +    public function testHttpMethodsClientShouldBePrivateByDefault() | 
|  | 307 | +    { | 
|  | 308 | +        $this->load([ | 
|  | 309 | +            'clients' => [ | 
|  | 310 | +                'acme' => [ | 
|  | 311 | +                    'http_methods_client' => true, | 
|  | 312 | +                ], | 
|  | 313 | +            ], | 
|  | 314 | +        ]); | 
|  | 315 | + | 
|  | 316 | +        $this->assertContainerBuilderHasService('httplug.client.acme'); | 
|  | 317 | +        $this->assertFalse($this->container->getDefinition('httplug.client.acme.http_methods')->isPublic()); | 
|  | 318 | +    } | 
|  | 319 | + | 
|  | 320 | +    public function testBatchClientShouldBePrivateByDefault() | 
|  | 321 | +    { | 
|  | 322 | +        $this->load([ | 
|  | 323 | +            'clients' => [ | 
|  | 324 | +                'acme' => [ | 
|  | 325 | +                    'batch_client' => true, | 
|  | 326 | +                ], | 
|  | 327 | +            ], | 
|  | 328 | +        ]); | 
|  | 329 | + | 
|  | 330 | +        $this->assertContainerBuilderHasService('httplug.client.acme'); | 
|  | 331 | +        $this->assertFalse($this->container->getDefinition('httplug.client.acme.batch_client')->isPublic()); | 
|  | 332 | +    } | 
|  | 333 | + | 
|  | 334 | +    public function testClientCanBePublic() | 
|  | 335 | +    { | 
|  | 336 | +        $this->load([ | 
|  | 337 | +            'clients' => [ | 
|  | 338 | +                'acme' => [ | 
|  | 339 | +                    'public' => true, | 
|  | 340 | +                ], | 
|  | 341 | +            ], | 
|  | 342 | +        ]); | 
|  | 343 | + | 
|  | 344 | +        $this->assertContainerBuilderHasService('httplug.client.acme'); | 
|  | 345 | +        $this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPublic()); | 
|  | 346 | + | 
|  | 347 | +        if (version_compare(Kernel::VERSION, '3.4', '>=')) { | 
|  | 348 | +            // Symfony made services private by default starting from 3.4 | 
|  | 349 | +            $this->assertFalse($this->container->getDefinition('httplug.client.acme')->isPrivate()); | 
|  | 350 | +        } | 
|  | 351 | +    } | 
|  | 352 | + | 
|  | 353 | +    public function testFlexibleClientCanBePublic() | 
|  | 354 | +    { | 
|  | 355 | +        $this->load([ | 
|  | 356 | +            'clients' => [ | 
|  | 357 | +                'acme' => [ | 
|  | 358 | +                    'public' => true, | 
|  | 359 | +                    'flexible_client' => true, | 
|  | 360 | +                ], | 
|  | 361 | +            ], | 
|  | 362 | +        ]); | 
|  | 363 | + | 
|  | 364 | +        $this->assertContainerBuilderHasService('httplug.client.acme'); | 
|  | 365 | +        $this->assertTrue($this->container->getDefinition('httplug.client.acme.flexible')->isPublic()); | 
|  | 366 | + | 
|  | 367 | +        if (version_compare(Kernel::VERSION, '3.4', '>=')) { | 
|  | 368 | +            // Symfony made services private by default starting from 3.4 | 
|  | 369 | +            $this->assertFalse($this->container->getDefinition('httplug.client.acme.flexible')->isPrivate()); | 
|  | 370 | +        } | 
|  | 371 | +    } | 
|  | 372 | + | 
|  | 373 | +    public function testHttpMethodsClientCanBePublic() | 
|  | 374 | +    { | 
|  | 375 | +        $this->load([ | 
|  | 376 | +            'clients' => [ | 
|  | 377 | +                'acme' => [ | 
|  | 378 | +                    'public' => true, | 
|  | 379 | +                    'http_methods_client' => true, | 
|  | 380 | +                ], | 
|  | 381 | +            ], | 
|  | 382 | +        ]); | 
|  | 383 | + | 
|  | 384 | +        $this->assertContainerBuilderHasService('httplug.client.acme'); | 
|  | 385 | +        $this->assertTrue($this->container->getDefinition('httplug.client.acme.http_methods')->isPublic()); | 
|  | 386 | + | 
|  | 387 | +        if (version_compare(Kernel::VERSION, '3.4', '>=')) { | 
|  | 388 | +            // Symfony made services private by default starting from 3.4 | 
|  | 389 | +            $this->assertFalse($this->container->getDefinition('httplug.client.acme.http_methods')->isPrivate()); | 
|  | 390 | +        } | 
|  | 391 | +    } | 
|  | 392 | + | 
|  | 393 | +    public function testBatchClientCanBePublic() | 
|  | 394 | +    { | 
|  | 395 | +        $this->load([ | 
|  | 396 | +            'clients' => [ | 
|  | 397 | +                'acme' => [ | 
|  | 398 | +                    'public' => true, | 
|  | 399 | +                    'batch_client' => true, | 
|  | 400 | +                ], | 
|  | 401 | +            ], | 
|  | 402 | +        ]); | 
|  | 403 | + | 
|  | 404 | +        $this->assertContainerBuilderHasService('httplug.client.acme'); | 
|  | 405 | +        $this->assertTrue($this->container->getDefinition('httplug.client.acme.batch_client')->isPublic()); | 
|  | 406 | + | 
|  | 407 | +        if (version_compare(Kernel::VERSION, '3.4', '>=')) { | 
|  | 408 | +            // Symfony made services private by default starting from 3.4 | 
|  | 409 | +            $this->assertFalse($this->container->getDefinition('httplug.client.acme.batch_client')->isPrivate()); | 
|  | 410 | +        } | 
|  | 411 | +    } | 
| 270 | 412 | } | 
0 commit comments