Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
222
Merge Requests
222
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
673f5b79
Commit
673f5b79
authored
May 18, 2015
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2445497
by Mile23, dawehner: Decouple ContainerBuilderTest from Symfony's tests
parent
e82c6f2a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
33 deletions
+82
-33
core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
...l/Tests/Core/DependencyInjection/ContainerBuilderTest.php
+11
-14
core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
...s/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
+6
-19
core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/BarClass.php
...rupal/Tests/Core/DependencyInjection/Fixture/BarClass.php
+47
-0
core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/BazClass.php
...rupal/Tests/Core/DependencyInjection/Fixture/BazClass.php
+18
-0
No files found.
core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
View file @
673f5b79
...
...
@@ -9,10 +9,9 @@
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Tests\UnitTestCase
;
use
Drupal\Tests\Core\DependencyInjection\Fixture\BazClass
;
use
Drupal\Tests\Core\DependencyInjection\Fixture\BarClass
;
use
Symfony\Component\DependencyInjection\Reference
;
use
Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass
;
require_once
__DIR__
.
'../../../../../../vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php'
;
/**
* @coversDefaultClass \Drupal\Core\DependencyInjection\ContainerBuilder
...
...
@@ -22,40 +21,38 @@ class ContainerBuilderTest extends UnitTestCase {
/**
* Tests set with a synchronized service.
*
* @covers ::set
*/
public
function
testSetOnSynchronizedService
()
{
$container
=
new
ContainerBuilder
();
$container
->
register
(
'baz'
,
'BazClass'
)
$container
->
register
(
'baz'
,
'
\Drupal\Tests\Core\DependencyInjection\Fixture\
BazClass'
)
->
setSynchronized
(
TRUE
);
$container
->
register
(
'bar'
,
'BarClass'
)
$container
->
register
(
'bar'
,
'
\Drupal\Tests\Core\DependencyInjection\Fixture\
BarClass'
)
->
addMethodCall
(
'setBaz'
,
array
(
new
Reference
(
'baz'
)));
// Ensure that we can set services on a compiled container.
$container
->
compile
();
$container
->
set
(
'baz'
,
$baz
=
new
\
BazClass
());
$container
->
set
(
'baz'
,
$baz
=
new
BazClass
());
$this
->
assertSame
(
$baz
,
$container
->
get
(
'bar'
)
->
getBaz
());
$container
->
set
(
'baz'
,
$baz
=
new
\
BazClass
());
$container
->
set
(
'baz'
,
$baz
=
new
BazClass
());
$this
->
assertSame
(
$baz
,
$container
->
get
(
'bar'
)
->
getBaz
());
}
/**
* Tests the get method.
*
* @see \Drupal\Core\DependencyInjection\Container::get()
* @covers ::get
*/
public
function
testGet
()
{
$container
=
new
ContainerBuilder
();
$container
->
register
(
'bar'
,
'BarClass'
);
$container
->
register
(
'bar'
,
'
Drupal\Tests\Core\DependencyInjection\Fixture\
BarClass'
);
$result
=
$container
->
get
(
'bar'
);
$this
->
assertTrue
(
$result
instanceof
\
BarClass
);
$this
->
assertTrue
(
$result
instanceof
BarClass
);
}
/**
* Tests the set() method.
*
* @covers ::set
*/
public
function
testSet
()
{
...
...
core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
View file @
673f5b79
...
...
@@ -9,7 +9,7 @@
use
Drupal\Core\DependencyInjection\Container
;
use
Drupal\Tests\UnitTestCase
;
use
Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses
\BarClass
;
use
Drupal\Tests\Core\DependencyInjection\Fixture
\BarClass
;
/**
* @coversDefaultClass \Drupal\Core\DependencyInjection\Container
...
...
@@ -17,37 +17,24 @@
*/
class
ContainerTest
extends
UnitTestCase
{
/**
* The tested container.
*
* @var \Drupal\Core\DependencyInjection\Container
*/
public
$container
;
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
$this
->
container
=
new
Container
();
}
/**
* Tests serialization.
*
* @expectedException \PHPUnit_Framework_Error
*/
public
function
testSerialize
()
{
serialize
(
$this
->
container
);
$container
=
new
Container
();
serialize
(
$container
);
}
/**
* Tests the set() method.
*
* @covers ::set
*/
public
function
testSet
()
{
$container
=
new
Container
();
$class
=
new
BarClass
();
$this
->
container
->
set
(
'bar'
,
$class
);
$container
->
set
(
'bar'
,
$class
);
// Ensure that _serviceId is set on the object.
$this
->
assertEquals
(
'bar'
,
$class
->
_serviceId
);
}
...
...
core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/BarClass.php
0 → 100644
View file @
673f5b79
<?php
/**
* @file
* Contains \Drupal\Tests\Core\DependencyInjection\Fixture\BarClass.
*/
namespace
Drupal\Tests\Core\DependencyInjection\Fixture
;
/**
* Stub class which acts as a service to test the container.
*
* @see \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest
* @see \Drupal\Tests\Core\DependencyInjection\Fixture\BazClass
*/
class
BarClass
{
/**
* Storage for a protected BazClass object.
*
* @var Drupal\Tests\Core\DependencyInjection\Fixture\BazClass
*/
protected
$baz
;
/**
* Setter for our BazClass object.
*
* This method is called during the service initialization.
*
* @param \Drupal\Tests\Core\DependencyInjection\Fixture\BazClass $baz
* A BazClass object to store.
*/
public
function
setBaz
(
BazClass
$baz
)
{
$this
->
baz
=
$baz
;
}
/**
* Getter for our BazClass object.
*
* @return \Drupal\Tests\Core\DependencyInjection\Fixture\BazClass
* The stored BazClass object.
*/
public
function
getBaz
()
{
return
$this
->
baz
;
}
}
core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/BazClass.php
0 → 100644
View file @
673f5b79
<?php
/**
* @file
* Contains \Drupal\Tests\Core\DependencyInjection\Fixture\BazClass.
*/
namespace
Drupal\Tests\Core\DependencyInjection\Fixture
;
/**
* Stub class which acts as a service dependency, to test the container.
*
* @see \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest
* @see \Drupal\Tests\Core\DependencyInjection\Fixture\BarClass
*/
class
BazClass
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment