Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #27048 [FrameworkBundle] Register all private services on the tes…
…t service container (jakzal) This PR was merged into the 4.1-dev branch. Discussion ---------- [FrameworkBundle] Register all private services on the test service container | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Before this fix, only services explicitly configured with public=false were exposed via the test service container: ```php $container->register(PrivateService::class, PrivateService::class)->setPublic(false); ``` but not those explicitly configured as private: ```php $container->register(PrivateService::class, PrivateService::class)->setPrivate(true); ``` nor those implicitly configured as private: ```php $container->register(PrivateService::class, PrivateService::class); ``` Commits ------- 6677393 [FrameworkBundle] Register all private services on the test service container
- Loading branch information
Showing
10 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...meworkBundle/Tests/Functional/Bundle/TestBundle/TestServiceContainer/NonPublicService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer; | ||
|
||
class NonPublicService | ||
{ | ||
} |
7 changes: 7 additions & 0 deletions
7
...rameworkBundle/Tests/Functional/Bundle/TestBundle/TestServiceContainer/PrivateService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer; | ||
|
||
class PrivateService | ||
{ | ||
} |
16 changes: 16 additions & 0 deletions
16
...FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestServiceContainer/PublicService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer; | ||
|
||
class PublicService | ||
{ | ||
private $nonPublicService; | ||
|
||
private $privateService; | ||
|
||
public function __construct(NonPublicService $nonPublicService, PrivateService $privateService) | ||
{ | ||
$this->nonPublicService = $nonPublicService; | ||
$this->privateService = $privateService; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...rkBundle/Tests/Functional/Bundle/TestBundle/TestServiceContainer/UnusedPrivateService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer; | ||
|
||
class UnusedPrivateService | ||
{ | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/TestServiceContainerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\TestContainer; | ||
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\NonPublicService; | ||
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService; | ||
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PublicService; | ||
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\UnusedPrivateService; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
class TestServiceContainerTest extends WebTestCase | ||
{ | ||
public function testThatPrivateServicesAreUnavailableIfTestConfigIsDisabled() | ||
{ | ||
static::bootKernel(array('test_case' => 'TestServiceContainer', 'root_config' => 'test_disabled.yml', 'environment' => 'test_disabled')); | ||
|
||
$this->assertInstanceOf(ContainerInterface::class, static::$container); | ||
$this->assertNotInstanceOf(TestContainer::class, static::$container); | ||
$this->assertTrue(static::$container->has(PublicService::class)); | ||
$this->assertFalse(static::$container->has(NonPublicService::class)); | ||
$this->assertFalse(static::$container->has(PrivateService::class)); | ||
$this->assertFalse(static::$container->has('private_service')); | ||
$this->assertFalse(static::$container->has(UnusedPrivateService::class)); | ||
} | ||
|
||
public function testThatPrivateServicesAreAvailableIfTestConfigIsEnabled() | ||
{ | ||
static::bootKernel(array('test_case' => 'TestServiceContainer')); | ||
|
||
$this->assertInstanceOf(TestContainer::class, static::$container); | ||
$this->assertTrue(static::$container->has(PublicService::class)); | ||
$this->assertTrue(static::$container->has(NonPublicService::class)); | ||
$this->assertTrue(static::$container->has(PrivateService::class)); | ||
$this->assertTrue(static::$container->has('private_service')); | ||
$this->assertTrue(static::$container->has(UnusedPrivateService::class)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/TestServiceContainer/bundles.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
|
||
return array( | ||
new FrameworkBundle(), | ||
); |
6 changes: 6 additions & 0 deletions
6
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/TestServiceContainer/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
imports: | ||
- { resource: ../config/default.yml } | ||
- { resource: services.yml } | ||
|
||
framework: | ||
test: true |
15 changes: 15 additions & 0 deletions
15
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/TestServiceContainer/services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
services: | ||
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\NonPublicService: | ||
public: false | ||
|
||
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService: ~ | ||
|
||
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\UnusedPrivateService: ~ | ||
|
||
private_service: '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService' | ||
|
||
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PublicService: | ||
public: true | ||
arguments: | ||
- '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\NonPublicService' | ||
- '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService' |
6 changes: 6 additions & 0 deletions
6
...ymfony/Bundle/FrameworkBundle/Tests/Functional/app/TestServiceContainer/test_disabled.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
imports: | ||
- { resource: ../config/default.yml } | ||
- { resource: services.yml } | ||
|
||
framework: | ||
test: false |