Skip to content

Commit 803bdfb

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: Change branch "master" to "5.x" Change "-t" to "--track" to be more explicit Fix typo [Testing] Updated the contents about getting the container in tests
2 parents f11e511 + 454cb0d commit 803bdfb

File tree

2 files changed

+45
-68
lines changed

2 files changed

+45
-68
lines changed

contributing/code/pull_requests.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ work:
129129
</contributing/code/maintenance>` (you may have to choose a higher branch if
130130
the feature you are fixing was introduced in a later version);
131131

132-
* ``master``, if you are adding a new feature.
132+
* ``5.x``, if you are adding a new feature.
133133

134134
The only exception is when a new :doc:`major Symfony version </contributing/community/releases>`
135135
(4.0, 5.0, etc.) comes out every two years. Because of the
@@ -142,7 +142,7 @@ work:
142142
All bug fixes merged into maintenance branches are also merged into more
143143
recent branches on a regular basis. For instance, if you submit a PR
144144
for the ``3.4`` branch, the PR will also be applied by the core team on
145-
the ``master`` branch.
145+
the ``5.x`` branch.
146146

147147
Create a Topic Branch
148148
~~~~~~~~~~~~~~~~~~~~~
@@ -152,14 +152,14 @@ topic branch:
152152

153153
.. code-block:: terminal
154154
155-
$ git checkout -b BRANCH_NAME master
155+
$ git checkout -b BRANCH_NAME 5.x
156156
157157
Or, if you want to provide a bug fix for the ``3.4`` branch, first track the remote
158158
``3.4`` branch locally:
159159

160160
.. code-block:: terminal
161161
162-
$ git checkout -t origin/3.4
162+
$ git checkout --track origin/3.4
163163
164164
Then create a new branch off the ``3.4`` branch to work on the bug fix:
165165

@@ -277,15 +277,15 @@ while to finish your changes):
277277

278278
.. code-block:: terminal
279279
280-
$ git checkout master
280+
$ git checkout 5.x
281281
$ git fetch upstream
282-
$ git merge upstream/master
282+
$ git merge upstream/5.x
283283
$ git checkout BRANCH_NAME
284-
$ git rebase master
284+
$ git rebase 5.x
285285
286286
.. tip::
287287

288-
Replace ``master`` with the branch you selected previously (e.g. ``3.4``)
288+
Replace ``5.x`` with the branch you selected previously (e.g. ``3.4``)
289289
if you are working on a bug fix.
290290

291291
When doing the ``rebase`` command, you might have to fix merge conflicts.
@@ -402,12 +402,12 @@ Rework your Pull Request
402402
~~~~~~~~~~~~~~~~~~~~~~~~
403403

404404
Based on the feedback on the pull request, you might need to rework your
405-
PR. Before re-submitting the PR, rebase with ``upstream/master`` or
405+
PR. Before re-submitting the PR, rebase with ``upstream/5.x`` or
406406
``upstream/3.4``, don't merge; and force the push to the origin:
407407

408408
.. code-block:: terminal
409409
410-
$ git rebase -f upstream/master
410+
$ git rebase -f upstream/5.x
411411
$ git push --force origin BRANCH_NAME
412412
413413
.. note::

testing.rst

Lines changed: 35 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -534,74 +534,51 @@ You can also get the objects related to the latest request::
534534
Accessing the Container
535535
~~~~~~~~~~~~~~~~~~~~~~~
536536

537-
It's highly recommended that a functional test only tests the response. But
538-
under certain very rare circumstances, you might want to access some services
539-
to write assertions. Given that services are private by default, test classes
540-
define a property that stores a special container created by Symfony which
541-
allows fetching both public and all non-removed private services::
542-
543-
// gives access to the same services used in your test, unless you're using
544-
// $client->insulate() or using real HTTP requests to test your application
545-
// don't forget to call self::bootKernel() before, otherwise, the container
546-
// will be empty
547-
$container = self::$container;
548-
549-
For a list of services available in your application, use the ``debug:container``
550-
command.
551-
552-
If a private service is *never* used in your application (outside of your test),
553-
it is *removed* from the container and cannot be accessed as described above. In
554-
that case, you can create a public alias in the ``test`` environment and access
555-
it via that alias:
537+
Functional tests should only test the response (e.g. its contents or its HTTP
538+
status code). However, in some rare circumstances you may need to access the
539+
container to use some service.
556540

557-
.. configuration-block::
558-
559-
.. code-block:: yaml
560-
561-
# config/services_test.yaml
562-
services:
563-
# access the service in your test via
564-
# self::$container->get('test.App\Test\SomeTestHelper')
565-
test.App\Test\SomeTestHelper:
566-
# the id of the private service
567-
alias: 'App\Test\SomeTestHelper'
568-
public: true
541+
First, you can get the same container used in the application, which only
542+
includes the public services::
569543

570-
.. code-block:: xml
571-
572-
<!-- config/services_test.xml -->
573-
<?xml version="1.0" encoding="UTF-8" ?>
574-
<container xmlns="http://symfony.com/schema/dic/services"
575-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
576-
xsi:schemaLocation="http://symfony.com/schema/dic/services
577-
https://symfony.com/schema/dic/services/services-1.0.xsd">
544+
public function testSomething()
545+
{
546+
$client = self::createClient();
547+
$container = $client->getContainer();
548+
// $someService = $container->get('the-service-ID');
578549

579-
<services>
580-
<!-- ... -->
550+
// ...
551+
}
581552

582-
<service id="test.App\Test\SomeTestHelper" alias="App\Test\SomeTestHelper" public="true"/>
583-
</services>
584-
</container>
553+
Symfony tests also have access to a special container that includes both the
554+
public services and the non-removed :ref:`private services <container-public>`
555+
services::
585556

586-
.. code-block:: php
557+
public function testSomething()
558+
{
559+
// this call is needed; otherwise the container will be empty
560+
self::bootKernel();
587561

588-
// config/services_test.php
589-
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
562+
$container = self::$container;
563+
// $someService = $container->get('the-service-ID');
590564

591-
use App\Service\MessageGenerator;
592-
use App\Service\SiteUpdateManager;
565+
// ...
566+
}
593567

594-
return function(ContainerConfigurator $configurator) {
595-
// ...
568+
Finally, for the most rare edge-cases, Symfony includes a special container
569+
which provides access to all services, public and private. This special
570+
container is a service that can be get via the normal container::
596571

597-
$services->alias('test.App\Test\SomeTestHelper', 'App\Test\SomeTestHelper')->public();
598-
};
572+
public function testSomething()
573+
{
574+
$client = self::createClient();
575+
$normalContainer = $client->getContainer();
576+
$specialContainer = $normalContainer->get('test.service_container');
599577

600-
.. tip::
578+
// $somePrivateService = $specialContainer->get('the-service-ID');
601579

602-
The special container that gives access to private services exists only in
603-
the ``test`` environment and is itself a service that you can get from the
604-
real container using the ``test.service_container`` id.
580+
// ...
581+
}
605582

606583
.. tip::
607584

@@ -909,7 +886,7 @@ their type::
909886
$form['photo']->upload('/path/to/lucas.jpg');
910887

911888
// In the case of a multiple file upload
912-
$form['my_form[field][O]']->upload('/path/to/lucas.jpg');
889+
$form['my_form[field][0]']->upload('/path/to/lucas.jpg');
913890
$form['my_form[field][1]']->upload('/path/to/lisa.jpg');
914891

915892
.. tip::

0 commit comments

Comments
 (0)