Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Move Mink toward 2.0 #542

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: CI

on:
push:
branches-ignore:
- '2-architecture-changes'
pull_request:

defaults:
Expand Down
27 changes: 2 additions & 25 deletions src/Driver/CoreDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

namespace Behat\Mink\Driver;

use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\Mink\KeyModifier;
use Behat\Mink\Session;

/**
* Core driver.
Expand All @@ -23,21 +21,6 @@
*/
abstract class CoreDriver implements DriverInterface
{
/**
* @var Session
*/
private $session;

/**
* @return void
*
* @final since 1.11
*/
public function setSession(Session $session)
{
$this->session = $session;
}

/**
* @return void
*/
Expand Down Expand Up @@ -99,19 +82,13 @@ public function getContent()
/**
* @param string $xpath
*
* @return NodeElement[]
* @return string[]
*
* @final since 1.11
*/
public function find($xpath)
{
$elements = array();

foreach ($this->findElementXpaths($xpath) as $xpath) {
$elements[] = new NodeElement($xpath, $this->session);
}

return $elements;
return $this->findElementXpaths($xpath);
}

/**
Expand Down
13 changes: 1 addition & 12 deletions src/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@

namespace Behat\Mink\Driver;

use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\Mink\KeyModifier;
use Behat\Mink\Session;

/**
* Driver interface.
Expand All @@ -23,15 +21,6 @@
*/
interface DriverInterface
{
/**
* Sets driver's current session.
*
* @param Session $session
*
* @return void
*/
public function setSession(Session $session);

/**
* Starts driver.
*
Expand Down Expand Up @@ -299,7 +288,7 @@ public function getWindowName();
*
* @param string $xpath
*
* @return NodeElement[]
* @return string[] An array of XPath queries for the found elements
*
* @throws UnsupportedDriverActionException When operation not supported by the driver
* @throws DriverException When the operation cannot be done
Expand Down
69 changes: 4 additions & 65 deletions src/Element/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
namespace Behat\Mink\Element;

use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Exception\ElementNotFoundException;
use Behat\Mink\Selector\SelectorsHandler;
use Behat\Mink\Session;

/**
* Base element.
Expand All @@ -22,11 +19,6 @@
*/
abstract class Element implements ElementInterface
{
/**
* @var Session
*/
private $session;

/**
* Driver.
*
Expand All @@ -39,31 +31,10 @@ abstract class Element implements ElementInterface
*/
private $elementFinder;

/**
* Initialize element.
*
* @param Session $session
*/
public function __construct(Session $session)
{
$this->session = $session;

$this->driver = $session->getDriver();
$this->elementFinder = $session->getElementFinder();
}

/**
* Returns element session.
*
* @return Session
*
* @deprecated Accessing the session from the element is deprecated as of 1.6 and will be impossible in 2.0.
*/
public function getSession()
public function __construct(DriverInterface $driver, ElementFinder $elementFinder)
{
@trigger_error(sprintf('The method %s is deprecated as of 1.6 and will be removed in 2.0', __METHOD__), E_USER_DEPRECATED);

return $this->session;
$this->driver = $driver;
$this->elementFinder = $elementFinder;
}

/**
Expand All @@ -76,20 +47,6 @@ protected function getDriver()
return $this->driver;
}

/**
* Returns selectors handler.
*
* @return SelectorsHandler
*
* @deprecated Accessing the selectors handler in the element is deprecated as of 1.7 and will be impossible in 2.0.
*/
protected function getSelectorsHandler()
{
@trigger_error(sprintf('The method %s is deprecated as of 1.7 and will be removed in 2.0', __METHOD__), E_USER_DEPRECATED);

return $this->session->getSelectorsHandler();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -138,7 +95,7 @@ public function find($selector, $locator)
{
$items = $this->findAll($selector, $locator);

return count($items) ? current($items) : null;
return count($items) ? $items[0] : null;
}

/**
Expand Down Expand Up @@ -174,22 +131,4 @@ public function getOuterHtml()
{
return $this->getDriver()->getOuterHtml($this->getXpath());
}

/**
* Builds an ElementNotFoundException.
*
* @param string $type
* @param string|null $selector
* @param string|null $locator
*
* @return ElementNotFoundException
*
* @deprecated as of 1.7, to be removed in 2.0
*/
protected function elementNotFound($type, $selector = null, $locator = null)
{
@trigger_error(sprintf('The method %s is deprecated as of 1.7 and will be removed in 2.0', __METHOD__), E_USER_DEPRECATED);

return new ElementNotFoundException($this->driver, $type, $selector, $locator);
}
}
12 changes: 9 additions & 3 deletions src/Element/ElementFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function __construct(DriverInterface $driver, SelectorsHandler $selectors
/**
* @param string|array $locator
*
* @return NodeElement[]
* @return list<NodeElement>
*/
public function findAll(string $selector, $locator, string $parentXpath)
public function findAll(string $selector, $locator, string $parentXpath): array
{
if ('named' === $selector) {
$items = $this->findAll('named_exact', $locator, $parentXpath);
Expand All @@ -59,6 +59,12 @@ public function findAll(string $selector, $locator, string $parentXpath)
$xpath = $this->selectorsHandler->selectorToXpath($selector, $locator);
$xpath = $this->xpathManipulator->prepend($xpath, $parentXpath);

return $this->driver->find($xpath);
$elements = array();

foreach ($this->driver->find($xpath) as $elementXpath) {
$elements[] = new NodeElement($elementXpath, $this->driver, $this);
}

return $elements;
}
}
11 changes: 0 additions & 11 deletions src/Element/ElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace Behat\Mink\Element;

use Behat\Mink\Session;

/**
* Element interface.
*
Expand All @@ -26,15 +24,6 @@ interface ElementInterface
*/
public function getXpath();

/**
* Returns element's session.
*
* @return Session
*
* @deprecated Accessing the session from the element is deprecated as of 1.6 and will be impossible in 2.0.
*/
public function getSession();

/**
* Checks whether element with specified selector exists inside the current element.
*
Expand Down
11 changes: 6 additions & 5 deletions src/Element/NodeElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use Behat\Mink\Exception\DriverException;
use Behat\Mink\KeyModifier;
use Behat\Mink\Session;
use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Exception\ElementNotFoundException;

/**
Expand All @@ -30,14 +30,15 @@ class NodeElement extends TraversableElement
/**
* Initializes node element.
*
* @param string $xpath element xpath
* @param Session $session session instance
* @param string $xpath element xpath
* @param DriverInterface $driver
* @param ElementFinder $elementFinder
*/
public function __construct($xpath, Session $session)
public function __construct($xpath, DriverInterface $driver, ElementFinder $elementFinder)
{
$this->xpath = $xpath;

parent::__construct($session);
parent::__construct($driver, $elementFinder);
}

/**
Expand Down
63 changes: 0 additions & 63 deletions src/Exception/ElementException.php

This file was deleted.

9 changes: 4 additions & 5 deletions src/Exception/ElementHtmlException.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\Element;
use Behat\Mink\Session;

/**
* Exception thrown when an expectation on the HTML of an element fails.
Expand All @@ -31,12 +30,12 @@ class ElementHtmlException extends ExpectationException
/**
* Initializes exception.
*
* @param string $message optional message
* @param DriverInterface|Session $driver driver instance
* @param Element $element element
* @param string $message optional message
* @param DriverInterface $driver driver instance
* @param Element $element element
* @param \Exception|null $exception expectation exception
*/
public function __construct($message, $driver, Element $element, \Exception $exception = null)
public function __construct($message, DriverInterface $driver, Element $element, \Exception $exception = null)
{
$this->element = $element;

Expand Down
Loading