Improved test behaviour (too much mocking)

This commit is contained in:
Ingo Schommer 2015-04-08 08:08:35 +12:00
parent cc6aa5cd46
commit b28b179df7
1 changed files with 14 additions and 11 deletions

View File

@ -27,15 +27,24 @@ class SilverStripeContextTest extends \PHPUnit_Framework_TestCase {
public function testGetRegionObjFindsBySelector() {
$context = $this->getContextMock();
$context = $this->returnsElement($context);
$context->getSession()->getPage()
->expects($this->any())
->method('find')
->will($this->returnValue($this->getElementMock()));
$obj = $context->getRegionObj('.some-selector');
$this->assertNotNull($obj);
}
public function testGetRegionObjFindsByRegion() {
$context = $this->getContextMock();
$context = $this->returnsElement($context);
$context->setRegionMap(array('MyRegion' => '.my-region'));
$el = $this->getElementMock();
$context->getSession()->getPage()
->expects($this->any())
->method('find')
->will($this->returnCallback(function($type, $selector) use ($el) {
return ($selector == '.my-region') ? $el : null;
}));
$context->setRegionMap(array('MyRegion' => '.my-asdf'));
$obj = $context->getRegionObj('.my-region');
$this->assertNotNull($obj);
}
@ -64,15 +73,9 @@ class SilverStripeContextTest extends \PHPUnit_Framework_TestCase {
return $context;
}
protected function returnsElement($context) {
$el = $this->getMockBuilder('Behat\Mink\Element\Element')
protected function getElementMock() {
return $this->getMockBuilder('Behat\Mink\Element\Element')
->disableOriginalConstructor()
->getMock();
$context->getSession()->getPage()
->expects($this->any())
->method('find')
->will($this->returnValue($el));
return $context;
}
}