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
304
Merge Requests
304
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
b50ffe99
Commit
b50ffe99
authored
Jan 07, 2014
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2159737
by damiankloip: Unit test the Drupal\serialization\Normalizer\NormalizerBase class.
parent
ab0bb61f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
2 deletions
+96
-2
core/modules/serialization/lib/Drupal/serialization/Normalizer/NormalizerBase.php
...on/lib/Drupal/serialization/Normalizer/NormalizerBase.php
+1
-2
core/modules/serialization/tests/Drupal/serialization/Tests/Normalizer/NormalizerBaseTest.php
...pal/serialization/Tests/Normalizer/NormalizerBaseTest.php
+95
-0
No files found.
core/modules/serialization/lib/Drupal/serialization/Normalizer/NormalizerBase.php
View file @
b50ffe99
...
...
@@ -7,7 +7,6 @@
namespace
Drupal\serialization\Normalizer
;
use
Symfony\Component\Serializer\Exception\RuntimeException
;
use
Symfony\Component\Serializer\Normalizer\NormalizerInterface
;
use
Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer
;
...
...
@@ -27,7 +26,7 @@ abstract class NormalizerBase extends SerializerAwareNormalizer implements Norma
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::supportsNormalization().
*/
public
function
supportsNormalization
(
$data
,
$format
=
NULL
)
{
return
is_object
(
$data
)
&&
(
$data
instanceof
$this
->
supportedInterfaceOrClass
);
return
is_object
(
$data
)
&&
(
isset
(
$this
->
supportedInterfaceOrClass
)
&&
(
$data
instanceof
$this
->
supportedInterfaceOrClass
)
);
}
}
core/modules/serialization/tests/Drupal/serialization/Tests/Normalizer/NormalizerBaseTest.php
0 → 100644
View file @
b50ffe99
<?php
/**
* @file
* Contains \Drupal\serialization\Tests\Normalizer\NormalizerBaseTest.
*/
namespace
Drupal\serialization\Tests\Normalizer
;
use
Drupal\Tests\UnitTestCase
;
use
Drupal\serialization\Normalizer\NormalizerBase
;
/**
* Tests the NormalizerBase class.
*
* @see \Drupal\serialization\Normalizer\NormalizerBase
*
* @group Serialization
*/
class
NormalizerBaseTest
extends
UnitTestCase
{
/**
* {@inheritdoc}
*/
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'NormalizerBase'
,
'description'
=>
'Tests the abstract NormalizerBase class.'
,
'group'
=>
'Serialization'
,
);
}
/**
* Tests the supportsNormalization method.
*
* @dataProvider providerTestSupportsNormalization
*
* @param bool $expected_return
* The expected boolean return value from supportNormalization.
* @param mixed $data
* The data passed to supportsNormalization.
* @param string $supported_interface_or_class
* (optional) the supported interface or class to set on the normalizer.
*/
public
function
testSupportsNormalization
(
$expected_return
,
$data
,
$supported_interface_or_class
=
NULL
)
{
$normalizer_base
=
$this
->
getMockForAbstractClass
(
'Drupal\serialization\Tests\Normalizer\TestNormalizerBase'
);
if
(
isset
(
$supported_interface_or_class
))
{
$normalizer_base
->
setSupportedInterfaceOrClass
(
$supported_interface_or_class
);
}
$this
->
assertSame
(
$expected_return
,
$normalizer_base
->
supportsNormalization
(
$data
));
}
/**
* Data provider for testSupportsNormalization.
*
* @return array
* An array of provider data for testSupportsNormalization.
*/
public
function
providerTestSupportsNormalization
()
{
return
array
(
// Something that is not an object should return FALSE immediately.
array
(
FALSE
,
array
()),
// An object with no class set should return FALSE.
array
(
FALSE
,
new
\
stdClass
()),
// Set a supported Class.
array
(
TRUE
,
new
\
stdClass
(),
'stdClass'
),
// Set a supported interface.
array
(
TRUE
,
new
\
RecursiveArrayIterator
(),
'RecursiveIterator'
),
// Set a different class.
array
(
FALSE
,
new
\
stdClass
(),
'ArrayIterator'
),
// Set a different interface.
array
(
FALSE
,
new
\
stdClass
(),
'RecursiveIterator'
),
);
}
}
/**
* Test class for NormalizerBase.
*/
abstract
class
TestNormalizerBase
extends
NormalizerBase
{
/**
* Sets the protected supportedInterfaceOrClass property.
*
* @param string $supported_interface_or_class
* The class name to set.
*/
public
function
setSupportedInterfaceOrClass
(
$supported_interface_or_class
)
{
$this
->
supportedInterfaceOrClass
=
$supported_interface_or_class
;
}
}
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