Skip to content

Commit

Permalink
Removed the getter for the SelectorsHandler in the Session
Browse files Browse the repository at this point in the history
This allows getting rid of the SelectorsHandler as a collaborator of the
Session class.
People needing to access the SelectorsHandler directly should instantiate
the ElementFinder explicitly with a SelectorsHandler, and keep a reference
to it.
  • Loading branch information
stof committed Feb 19, 2015
1 parent 7bae673 commit 4ee85ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
32 changes: 7 additions & 25 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Element\ElementFinder;
use Behat\Mink\Selector\SelectorsHandler;
use Behat\Mink\Element\DocumentElement;

/**
Expand All @@ -24,7 +23,6 @@ class Session
{
private $driver;
private $page;
private $selectorsHandler;

/**
* @var Element\ElementFinder
Expand All @@ -34,24 +32,18 @@ class Session
/**
* Initializes session.
*
* @param DriverInterface $driver
* @param SelectorsHandler|null $selectorsHandler
* @param ElementFinder|null $elementFinder
* @param DriverInterface $driver
* @param ElementFinder|null $elementFinder
*/
public function __construct(DriverInterface $driver, SelectorsHandler $selectorsHandler = null, ElementFinder $elementFinder = null)
public function __construct(DriverInterface $driver, ElementFinder $elementFinder = null)
{
if (null === $selectorsHandler) {
$selectorsHandler = new SelectorsHandler();
}

if (null === $elementFinder) {
$elementFinder = new ElementFinder($driver, $selectorsHandler);
$elementFinder = new ElementFinder($driver);
}

$this->driver = $driver;
$this->selectorsHandler = $selectorsHandler;
$this->elementFinder = $elementFinder;
$this->page = new DocumentElement($driver, $elementFinder);
$this->driver = $driver;
$this->elementFinder = $elementFinder;
$this->page = new DocumentElement($driver, $elementFinder);
}

/**
Expand Down Expand Up @@ -133,16 +125,6 @@ public function getPage()
return $this->page;
}

/**
* Returns selectors handler.
*
* @return SelectorsHandler
*/
public function getSelectorsHandler()
{
return $this->selectorsHandler;
}

/**
* Visit specified URL.
*
Expand Down
13 changes: 3 additions & 10 deletions tests/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class SessionTest extends \PHPUnit_Framework_TestCase
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $driver;
private $selectorsHandler;

/**
* Session.
Expand All @@ -22,8 +21,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();
$this->selectorsHandler = $this->getMockBuilder('Behat\Mink\Selector\SelectorsHandler')->getMock();
$this->session = new Session($this->driver, $this->selectorsHandler);
$this->session = new Session($this->driver);
}

public function testGetDriver()
Expand All @@ -36,16 +34,11 @@ public function testGetPage()
$this->assertInstanceOf('Behat\Mink\Element\DocumentElement', $this->session->getPage());
}

public function testGetSelectorsHandler()
{
$this->assertSame($this->selectorsHandler, $this->session->getSelectorsHandler());
}

public function testInstantiateWithoutOptionalDeps()
{
$session = new Session($this->driver);
new Session($this->driver);

$this->assertInstanceOf('Behat\Mink\Selector\SelectorsHandler', $session->getSelectorsHandler());
$this->assertTrue(true, 'The instantiation should work.');
}

public function testIsStarted()
Expand Down

0 comments on commit 4ee85ec

Please sign in to comment.