├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src └── DependencyInjection │ ├── ContainerMocks.php │ ├── DefinitionLoader.php │ ├── TestContainer.php │ └── TestKernelTrait.php └── tests ├── DependencyInjection ├── ClassDetectionTest.php ├── KernelTraitTest.php └── TestContainerTest.php └── Fixtures ├── .gitignore ├── TestKernel.php ├── TestKernelTrait.php └── config.php /.gitignore: -------------------------------------------------------------------------------- 1 | /phpunit.xml 2 | /vendor 3 | /composer.lock 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | cache: 6 | directory: 7 | - $HOME/.composer/cache 8 | 9 | php: 10 | - 5.6 11 | - 7.0 12 | - 7.1 13 | - 7.2 14 | - nightly 15 | 16 | env: 17 | - SYMFONY_VERSION=2.7.* 18 | - SYMFONY_VERSION=2.8.* 19 | - SYMFONY_VERSION=3.0.* 20 | - SYMFONY_VERSION=3.1.* 21 | - SYMFONY_VERSION=3.2.* 22 | - SYMFONY_VERSION=3.3.* 23 | - SYMFONY_VERSION=3.4.* 24 | 25 | matrix: 26 | fast_finish: true 27 | allow_failures: 28 | - php: nightly 29 | 30 | install: 31 | - if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/dependency-injection:${SYMFONY_VERSION} symfony/framework-bundle:${SYMFONY_VERSION} symfony/http-kernel:${SYMFONY_VERSION}; fi; 32 | 33 | before_script: 34 | - composer update --prefer-dist --prefer-stable --no-ansi -n --no-progress 35 | 36 | after_success: 37 | - travis_retry php vendor/bin/php-coveralls -v 38 | 39 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at symfony@ramuno.lt. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ramūnas Dronga 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Symfony Container Mocks 2 | 3 | [![Build Status](https://travis-ci.org/ramunasd/symfony-container-mocks.svg?branch=master)](https://travis-ci.org/ramunasd/symfony-container-mocks) 4 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ramunasd/symfony-container-mocks/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ramunasd/symfony-container-mocks/?branch=master) 5 | [![PHP-Eye](https://php-eye.com/badge/ramunasd/symfony-container-mocks/tested.svg?style=flat)](https://php-eye.com/package/ramunasd/symfony-container-mocks) 6 | [![Coverage Status](https://coveralls.io/repos/github/ramunasd/symfony-container-mocks/badge.svg?branch=coveralls)](https://coveralls.io/github/ramunasd/symfony-container-mocks?branch=coveralls) 7 | 8 | 9 | This container enables you to mock services in the Symfony dependency 10 | injection container. It is particularly useful in functional tests. 11 | 12 | ## Features 13 | 14 | * Can replace any Symfony service or parameter 15 | * Automatically detects service class from service definition 16 | * Can be used with any mocking framework 17 | * Compatible with Symfony versions 2.7 - 3.4 18 | * Works on all supported version of PHP 19 | 20 | ## OTB supported mocking frameworks 21 | 22 | * [phpspec/prophecy](https://github.com/phpspec/prophecy) 23 | 24 | ## Installation 25 | 26 | Add SymfonyContainerMocks using composer: 27 | 28 | `composer require "ramunasd/symfony-container-mocks"` 29 | 30 | or edit your composer.json: 31 | 32 | ```js 33 | { 34 | "require": { 35 | "ramunasd/symfony-container-mocks": "*" 36 | } 37 | } 38 | ``` 39 | 40 | 41 | Replace base container class for test environment in `app/AppKernel.php` 42 | 43 | ```php 44 | client = static::createClient(); 95 | } 96 | 97 | public function tearDown() 98 | { 99 | $this->client->getContainer()->tearDown(); 100 | $this->client = null; 101 | 102 | parent::tearDown(); 103 | } 104 | 105 | public function testSomethingWithMockedService() 106 | { 107 | $this->client->getContainer()->prophesize('acme.service.custom', Custom::class) 108 | ->someMethod([]) 109 | ->willReturn(false) 110 | ->shouldBeCalledTimes(2); 111 | 112 | // ... 113 | } 114 | } 115 | ``` 116 | 117 | ### Inject automatically mocked service 118 | 119 | > feature works only with flag "debug" enabled. 120 | 121 | ```php 122 | $mock = $this->client->getContainer()->prophesize('acme.service.custom'); 123 | $mock 124 | ->myMethod() 125 | ->willReturn(true); 126 | ``` 127 | 128 | ### Other mocking frameworks 129 | 130 | ```php 131 | // create stub 132 | $mock = $this->getMock(Custom::class); 133 | 134 | // inject service mock 135 | self::$kernel->getContainer()->setMock('acme.service.custom', $mock); 136 | 137 | // reset container state 138 | self::$kernel->getContainer()->unMock('acme.service.custom'); 139 | 140 | ``` 141 | 142 | ### Set specific framework parameter 143 | 144 | ```php 145 | // set custom value during test 146 | self::$kernel->getContainer()->setMockedParameter('acme.service.parameter1', 'customValue1'); 147 | 148 | // trigger service, assert results 149 | 150 | // reset all parameters to original values 151 | self::$kernel->getContainer()->clearMockedParameters(); 152 | ``` 153 | 154 | 155 | ## Things TO DO 156 | 157 | * Symfony 4.x support 158 | * PSR-11 adoption 159 | 160 | 161 | ## Similar/Related projects 162 | 163 | * https://github.com/jakzal/phpunit-injector - inject Symfony services into PHPUnit test cases 164 | 165 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ramunasd/symfony-container-mocks", 3 | "description": "Provides extended Symfony dependency injection container enabling service mocking.", 4 | "keywords": [ 5 | "symfony", 6 | "container", 7 | "prophecy", 8 | "phpunit", 9 | "tdd", 10 | "test" 11 | ], 12 | "homepage": "https://github.com/ramunasd/symfony-container-mocks", 13 | "license": "MIT", 14 | "require": { 15 | "php": ">=5.6", 16 | "symfony/dependency-injection": ">=2.3", 17 | "phpspec/prophecy": "~1.6" 18 | }, 19 | "require-dev": { 20 | "symfony/http-kernel": ">=2.3", 21 | "symfony/config": ">=2.3", 22 | "symfony/framework-bundle": ">=2.3", 23 | "phpunit/phpunit": "^5.7", 24 | "php-coveralls/php-coveralls": "^2.1" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "RDV\\SymfonyContainerMocks\\": "src/" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "prs-4": { 33 | "RDV\\Tests\\SymfonyContainerMocks\\": "tests/" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tests 6 | 7 | 8 | 9 | 10 | src 11 | 12 | ./tests 13 | ./vendor 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/DependencyInjection/ContainerMocks.php: -------------------------------------------------------------------------------- 1 | hasParameter('debug.container.dump')) { 19 | throw new \BadMethodCallException('Class autodetection works only with "debug" enabled'); 20 | } 21 | 22 | $dump = $container->getParameter('debug.container.dump'); 23 | $xml = simplexml_load_file($dump); 24 | 25 | foreach ($xml->services->service as $service) { 26 | $attributes = $service->attributes(); 27 | $id = (string)$attributes['id']; 28 | $class = (string)$attributes['class']; 29 | if (!empty($class)) { 30 | self::$definitions[$id] = $class; 31 | } 32 | } 33 | } 34 | } 35 | 36 | /** 37 | * Unload all cached definitions 38 | */ 39 | public static function unload() 40 | { 41 | self::$definitions = []; 42 | } 43 | 44 | /** 45 | * @param string $service 46 | * @param Container $container 47 | * @return string mixed 48 | */ 49 | public static function getClassName($service, Container $container) 50 | { 51 | self::loadDefinitions($container); 52 | 53 | if (empty(self::$definitions[$service])) { 54 | throw new \InvalidArgumentException( 55 | sprintf('Service "%s" is not defined or class name cannot be detected', $service) 56 | ); 57 | } 58 | 59 | return self::$definitions[$service]; 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /src/DependencyInjection/TestContainer.php: -------------------------------------------------------------------------------- 1 | mocked)) { 41 | throw new \InvalidArgumentException('This service already mocked and can have references'); 42 | } 43 | 44 | if (empty($class)) { 45 | $class = $this->detectClass($id); 46 | } 47 | 48 | $mock = $this->getProphet()->prophesize($class); 49 | $this->mocked[$id] = $mock->reveal(); 50 | 51 | return $mock; 52 | } 53 | 54 | /** 55 | * Remove all mocked services 56 | */ 57 | public function tearDown() 58 | { 59 | $this->mocked = []; 60 | $this->clearMockedParameters(); 61 | } 62 | 63 | /** 64 | * {@inheritdoc} 65 | */ 66 | public function reset() 67 | { 68 | if (interface_exists('Symfony\Component\DependencyInjection\ResettableContainerInterface') 69 | && $this instanceof \Symfony\Component\DependencyInjection\ResettableContainerInterface) { 70 | parent::reset(); 71 | } 72 | $this->tearDown(); 73 | } 74 | 75 | /** 76 | * @param string $id 77 | * @param mixed $mock 78 | */ 79 | public function setMock($id, $mock) 80 | { 81 | $this->mocked[$id] = $mock; 82 | } 83 | 84 | /** 85 | * @param string $id 86 | */ 87 | public function unMock($id) 88 | { 89 | unset($this->mocked[$id]); 90 | } 91 | 92 | /** 93 | * {@inheritdoc} 94 | */ 95 | public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) 96 | { 97 | if (array_key_exists($id, $this->mocked)) { 98 | return $this->mocked[$id]; 99 | } 100 | 101 | return parent::get($id, $invalidBehavior); 102 | } 103 | 104 | /** 105 | * {@inheritdoc} 106 | */ 107 | public function has($id) 108 | { 109 | if (array_key_exists($id, $this->mocked)) { 110 | return true; 111 | } 112 | 113 | return parent::has($id); 114 | } 115 | 116 | /** 117 | * {@inheritdoc} 118 | */ 119 | public function initialized($id) 120 | { 121 | if (array_key_exists($id, $this->mocked)) { 122 | return true; 123 | } 124 | 125 | return parent::initialized($id); 126 | } 127 | 128 | /** 129 | * @return array 130 | */ 131 | public function getMockedServices() 132 | { 133 | return $this->mocked; 134 | } 135 | 136 | /** 137 | * @return Prophet 138 | */ 139 | public function getProphet() 140 | { 141 | if (!$this->prophet) { 142 | $this->prophet = new Prophet(); 143 | } 144 | 145 | return $this->prophet; 146 | } 147 | 148 | /** 149 | * @param string $service 150 | * @return string 151 | * @throws \BadMethodCallException 152 | */ 153 | protected function detectClass($service) 154 | { 155 | return DefinitionLoader::getClassName($service, $this); 156 | } 157 | 158 | /** 159 | * @param string $name 160 | * @param mixed $value 161 | * @throws \ReflectionException 162 | */ 163 | public function setMockedParameter($name, $value) 164 | { 165 | $reflection = $this->getParametersReflection(); 166 | $parameters = $reflection->getValue($this); 167 | if (!$this->parametersOriginal) { 168 | $this->parametersOriginal = $parameters; 169 | } 170 | $parameters[$name] = $value; 171 | $reflection->setValue($this, $parameters); 172 | } 173 | 174 | /** 175 | * @throws \ReflectionException 176 | */ 177 | public function clearMockedParameters() 178 | { 179 | if ($this->parametersOriginal) { 180 | $reflection = $this->getParametersReflection(); 181 | $reflection->setValue($this, $this->parametersOriginal); 182 | $this->parametersOriginal = null; 183 | } 184 | } 185 | 186 | /** 187 | * @return \ReflectionProperty 188 | * @throws \ReflectionException 189 | */ 190 | private function getParametersReflection() 191 | { 192 | if (!$this->parametersReflection) { 193 | $this->parametersReflection = new \ReflectionProperty($this, 'parameters'); 194 | $this->parametersReflection->setAccessible(true); 195 | } 196 | 197 | return $this->parametersReflection; 198 | } 199 | } 200 | 201 | -------------------------------------------------------------------------------- /src/DependencyInjection/TestKernelTrait.php: -------------------------------------------------------------------------------- 1 | environment) { 13 | return TestContainer::class; 14 | } 15 | 16 | return parent::getContainerBaseClass(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tests/DependencyInjection/ClassDetectionTest.php: -------------------------------------------------------------------------------- 1 | getKernel(); 20 | /** @var TestContainer $container */ 21 | $container = $kernel->getContainer(); 22 | $mock = $container->prophesize('test_service'); 23 | $this->assertInstanceOf('Prophecy\Prophecy\ObjectProphecy', $mock); 24 | } 25 | 26 | /** 27 | * @expectedException \BadMethodCallException 28 | */ 29 | public function testExceptionIsThrownWhenDebugIsDisabled() 30 | { 31 | $kernel = $this->getKernel(false); 32 | $kernel->getContainer()->prophesize('test_service'); 33 | } 34 | 35 | /** 36 | * @expectedException \InvalidArgumentException 37 | */ 38 | public function testExceptionIsThrownOnUnknownService() 39 | { 40 | $kernel = $this->getKernel(); 41 | $kernel->getContainer()->prophesize('test_service2'); 42 | } 43 | 44 | /** 45 | * @param bool $debug 46 | * @return TestKernel 47 | */ 48 | protected function getKernel($debug = true) 49 | { 50 | include_once __DIR__ . '/../Fixtures/TestKernel.php'; 51 | $kernel = new TestKernel('test', $debug); 52 | $kernel->boot(); 53 | 54 | return $kernel; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/DependencyInjection/KernelTraitTest.php: -------------------------------------------------------------------------------- 1 | container = new $class; 26 | 27 | foreach (array('service1', 'service2', 'service3') as $id) { 28 | $service = new \stdClass(); 29 | $service->id = $id; 30 | 31 | $this->services[$id] = $service; 32 | $this->container->set($id, $service); 33 | } 34 | } 35 | 36 | protected function tearDown() 37 | { 38 | $this->container->tearDown(); 39 | } 40 | 41 | public function testCustomMockSetClear() 42 | { 43 | $id = mt_rand(); 44 | $service = $this->createMock('Symfony\Component\Config\Loader\LoaderInterface'); 45 | $service 46 | ->expects($this->once()) 47 | ->method('load') 48 | ->willReturn(true); 49 | $this->container->setMock($id, $service); 50 | 51 | // simulate call on mock 52 | $this->assertTrue($this->container->get($id)->load('test')); 53 | 54 | // clear container state 55 | $this->container->unMock($id); 56 | 57 | // must fail cause service does not exist 58 | try { 59 | $this->container->get($id); 60 | } catch (\Exception $e) { 61 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e); 62 | } 63 | } 64 | 65 | public function testBehaviorDoesNotChangeByDefault() 66 | { 67 | $this->assertTrue($this->container->has('service1')); 68 | $this->assertTrue($this->container->has('service2')); 69 | $this->assertTrue($this->container->has('service3')); 70 | $this->assertSame($this->services['service1'], $this->container->get('service1')); 71 | $this->assertSame($this->services['service2'], $this->container->get('service2')); 72 | $this->assertSame($this->services['service3'], $this->container->get('service3')); 73 | } 74 | 75 | public function testExistingServiceCanBeMocked() 76 | { 77 | $id = 'service1'; 78 | $mock = $this->container->prophesize($id, 'stdClass'); 79 | 80 | $this->assertInstanceOf('Prophecy\Prophecy\ObjectProphecy', $mock); 81 | $this->assertTrue($this->container->has($id)); 82 | $this->assertNotSame($this->services[$id], $this->container->get($id)); 83 | $this->assertSame($mock->reveal(), $this->container->get($id)); 84 | } 85 | 86 | public function testNonExistingServiceCanBeMocked() 87 | { 88 | $mock = $this->container->prophesize('serviceX', 'stdClass'); 89 | $this->assertInstanceOf('Prophecy\Prophecy\ObjectProphecy', $mock); 90 | } 91 | 92 | /** 93 | * @expectedException \InvalidArgumentException 94 | * @expectedExceptionMessage This service already mocked and can have references 95 | */ 96 | public function testServiceCannotBeMockedTwice() 97 | { 98 | $id = 'service1'; 99 | $this->container->prophesize($id, 'stdClass'); 100 | $this->container->prophesize($id, 'stdClass'); 101 | } 102 | 103 | public function testMockedServicesAreAccessible() 104 | { 105 | $mock1 = $this->container->prophesize('service1', 'stdClass'); 106 | $mock2 = $this->container->prophesize('service2', 'stdClass'); 107 | 108 | $mockedServices = $this->container->getMockedServices(); 109 | 110 | $this->assertEquals(array('service1' => $mock1->reveal(), 'service2' => $mock2->reveal()), $mockedServices); 111 | } 112 | 113 | public function testMockCanBeRemovedAndContainerFallsBackToTheOriginalService() 114 | { 115 | $id = 'service1'; 116 | $this->container->prophesize($id, 'stdClass'); 117 | $this->container->unMock($id); 118 | 119 | $this->assertTrue($this->container->has($id)); 120 | $this->assertEquals($this->services[$id], $this->container->get($id)); 121 | } 122 | 123 | public function testContainerResetClearsMockedService() 124 | { 125 | $this->container->prophesize('service1', 'stdClass'); 126 | $this->assertNotEmpty($this->container->getMockedServices()); 127 | $this->container->reset(); 128 | $this->assertEmpty($this->container->getMockedServices()); 129 | } 130 | 131 | public function testMockedServiceMustBeInitialized() 132 | { 133 | $id = 'service1'; 134 | $this->assertTrue($this->container->initialized($id)); 135 | 136 | $this->container->prophesize($id, 'stdClass'); 137 | $this->assertTrue($this->container->initialized($id)); 138 | 139 | $id = 'serviceX'; 140 | $this->container->prophesize($id, 'stdClass'); 141 | $this->assertTrue($this->container->initialized($id)); 142 | } 143 | 144 | public function testGetProphecyReturnsSameObjectTwice() 145 | { 146 | $prophet = $this->container->getProphet(); 147 | $this->assertSame($prophet, $this->container->getProphet()); 148 | } 149 | 150 | public function testContainerParametersCanBeMocked() 151 | { 152 | $kernel = new TestKernel('test', false); 153 | $kernel->boot(); 154 | $container = $kernel->getContainer(); 155 | 156 | $param = 'test_parameter1'; 157 | $original = 'original_value'; 158 | $this->assertEquals($original, $container->getParameter($param)); 159 | 160 | $container->setMockedParameter($param, $mocked = 'mocked_value'); 161 | $this->assertEquals($mocked, $container->getParameter($param)); 162 | 163 | $container->clearMockedParameters(); 164 | $this->assertEquals($original, $container->getParameter($param)); 165 | } 166 | } 167 | 168 | -------------------------------------------------------------------------------- /tests/Fixtures/.gitignore: -------------------------------------------------------------------------------- 1 | /cache 2 | /logs 3 | -------------------------------------------------------------------------------- /tests/Fixtures/TestKernel.php: -------------------------------------------------------------------------------- 1 | load($this->getRootDir().'/config.php'); 22 | } 23 | 24 | protected function prepareContainer(ContainerBuilder $container) 25 | { 26 | $container->register('test_service', 'stdClass'); 27 | 28 | parent::prepareContainer($container); 29 | } 30 | 31 | protected function getContainerBaseClass() 32 | { 33 | if ('test' === $this->environment) { 34 | return '\RDV\SymfonyContainerMocks\DependencyInjection\TestContainer'; 35 | } 36 | 37 | return parent::getContainerBaseClass(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Fixtures/TestKernelTrait.php: -------------------------------------------------------------------------------- 1 | load($this->getRootDir().'/config.php'); 26 | } 27 | 28 | protected function prepareContainer(ContainerBuilder $container) 29 | { 30 | $container->register('test_service', 'stdClass'); 31 | 32 | parent::prepareContainer($container); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Fixtures/config.php: -------------------------------------------------------------------------------- 1 | setParameter('test_parameter1', 'original_value'); 4 | $container->loadFromExtension('framework', array( 5 | 'secret' => 'secret', 6 | )); 7 | --------------------------------------------------------------------------------