class ChainEntityResolverTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php \Drupal\Tests\serialization\Unit\EntityResolver\ChainEntityResolverTest
@coversDefaultClass \Drupal\serialization\EntityResolver\ChainEntityResolver @group serialization
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\serialization\Unit\EntityResolver\ChainEntityResolverTest
Expanded class hierarchy of ChainEntityResolverTest
File
- core/
modules/ serialization/ tests/ src/ Unit/ EntityResolver/ ChainEntityResolverTest.php, line 17 - Contains \Drupal\Tests\serialization\Unit\EntityResolver\ChainEntityResolverTest.
Namespace
Drupal\Tests\serialization\Unit\EntityResolverView source
class ChainEntityResolverTest extends UnitTestCase {
/**
* A mocked normalizer.
*
* @var \Symfony\Component\Serializer\Normalizer\NormalizerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $testNormalizer;
/**
* Test data passed to the resolve method.
*
* @var \stdClass
*/
protected $testData;
/**
* A test entity type.
*
* @var string
*/
protected $testEntityType = 'test_type';
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->testNormalizer = $this
->getMock('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface');
$this->testData = new \stdClass();
}
/**
* Test the resolve method with no matching resolvers.
*
* @covers ::__construct
* @covers ::resolve
*/
public function testResolverWithNoneResolved() {
$resolvers = array(
$this
->createEntityResolverMock(),
$this
->createEntityResolverMock(),
);
$resolver = new ChainEntityResolver($resolvers);
$this
->assertNull($resolver
->resolve($this->testNormalizer, $this->testData, $this->testEntityType));
}
/**
* Test the resolve method with no matching resolvers, using addResolver.
*
* @covers ::addResolver
* @covers ::resolve
*/
public function testResolverWithNoneResolvedUsingAddResolver() {
$resolver = new ChainEntityResolver();
$resolver
->addResolver($this
->createEntityResolverMock());
$resolver
->addResolver($this
->createEntityResolverMock());
$this
->assertNull($resolver
->resolve($this->testNormalizer, $this->testData, $this->testEntityType));
}
/**
* Test the resolve method with a matching resolver first.
*
* @covers ::__construct
* @covers ::resolve
*/
public function testResolverWithFirstResolved() {
$resolvers = array(
$this
->createEntityResolverMock(10),
$this
->createEntityResolverMock(NULL, FALSE),
);
$resolver = new ChainEntityResolver($resolvers);
$this
->assertSame(10, $resolver
->resolve($this->testNormalizer, $this->testData, $this->testEntityType));
}
/**
* Test the resolve method with a matching resolver last.
*
* @covers ::__construct
* @covers ::resolve
*/
public function testResolverWithLastResolved() {
$resolvers = array(
$this
->createEntityResolverMock(),
$this
->createEntityResolverMock(10),
);
$resolver = new ChainEntityResolver($resolvers);
$this
->assertSame(10, $resolver
->resolve($this->testNormalizer, $this->testData, $this->testEntityType));
}
/**
* Test the resolve method where one resolver returns 0.
*
* @covers ::__construct
* @covers ::resolve
*/
public function testResolverWithResolvedToZero() {
$resolvers = array(
$this
->createEntityResolverMock(0),
$this
->createEntityResolverMock(NULL, FALSE),
);
$resolver = new ChainEntityResolver($resolvers);
$this
->assertSame(0, $resolver
->resolve($this->testNormalizer, $this->testData, $this->testEntityType));
}
/**
* Creates a mock entity resolver.
*
* @param null|int $return
* Whether the mocked resolve method should return TRUE or FALSE.
*
* @param bool $called
* Whether or not the resolve method is expected to be called.
*
* @return \Drupal\serialization\EntityResolver\EntityResolverInterface|\PHPUnit_Framework_MockObject_MockObject
* The mocked entity resolver.
*/
protected function createEntityResolverMock($return = NULL, $called = TRUE) {
$mock = $this
->getMock('Drupal\\serialization\\EntityResolver\\EntityResolverInterface');
if ($called) {
$mock
->expects($this
->once())
->method('resolve')
->with($this->testNormalizer, $this->testData, $this->testEntityType)
->will($this
->returnValue($return));
}
else {
$mock
->expects($this
->never())
->method('resolve');
}
return $mock;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChainEntityResolverTest:: |
protected | property | Test data passed to the resolve method. | |
ChainEntityResolverTest:: |
protected | property | A test entity type. | |
ChainEntityResolverTest:: |
protected | property | A mocked normalizer. | |
ChainEntityResolverTest:: |
protected | function | Creates a mock entity resolver. | |
ChainEntityResolverTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ChainEntityResolverTest:: |
public | function | Test the resolve method with a matching resolver first. | |
ChainEntityResolverTest:: |
public | function | Test the resolve method with a matching resolver last. | |
ChainEntityResolverTest:: |
public | function | Test the resolve method with no matching resolvers. | |
ChainEntityResolverTest:: |
public | function | Test the resolve method with no matching resolvers, using addResolver. | |
ChainEntityResolverTest:: |
public | function | Test the resolve method where one resolver returns 0. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |