mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Improved test behaviour (too much mocking)
This commit is contained in:
parent
cc6aa5cd46
commit
b28b179df7
@ -27,15 +27,24 @@ class SilverStripeContextTest extends \PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
public function testGetRegionObjFindsBySelector() {
|
public function testGetRegionObjFindsBySelector() {
|
||||||
$context = $this->getContextMock();
|
$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');
|
$obj = $context->getRegionObj('.some-selector');
|
||||||
$this->assertNotNull($obj);
|
$this->assertNotNull($obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRegionObjFindsByRegion() {
|
public function testGetRegionObjFindsByRegion() {
|
||||||
$context = $this->getContextMock();
|
$context = $this->getContextMock();
|
||||||
$context = $this->returnsElement($context);
|
$el = $this->getElementMock();
|
||||||
$context->setRegionMap(array('MyRegion' => '.my-region'));
|
$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');
|
$obj = $context->getRegionObj('.my-region');
|
||||||
$this->assertNotNull($obj);
|
$this->assertNotNull($obj);
|
||||||
}
|
}
|
||||||
@ -64,15 +73,9 @@ class SilverStripeContextTest extends \PHPUnit_Framework_TestCase {
|
|||||||
return $context;
|
return $context;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function returnsElement($context) {
|
protected function getElementMock() {
|
||||||
$el = $this->getMockBuilder('Behat\Mink\Element\Element')
|
return $this->getMockBuilder('Behat\Mink\Element\Element')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$context->getSession()->getPage()
|
|
||||||
->expects($this->any())
|
|
||||||
->method('find')
|
|
||||||
->will($this->returnValue($el));
|
|
||||||
|
|
||||||
return $context;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user