From 2b69136e39bb4f2a78d425e43898c20505df4e99 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 10 May 2014 21:12:53 +0200 Subject: [PATCH 1/5] Removed deprecated features --- src/Element/Element.php | 55 ---------------- src/Element/ElementInterface.php | 11 ---- src/Exception/ElementException.php | 63 ------------------- src/Exception/ElementHtmlException.php | 11 ++-- src/Exception/ElementNotFoundException.php | 11 ++-- src/Exception/ExpectationException.php | 43 ++----------- src/Selector/NamedSelector.php | 15 ----- src/Selector/SelectorsHandler.php | 39 ------------ src/Session.php | 21 +------ tests/Element/DocumentElementTest.php | 8 --- tests/Exception/ElementExceptionTest.php | 44 ------------- .../ElementNotFoundExceptionTest.php | 18 ------ tests/Exception/ExpectationExceptionTest.php | 18 ------ tests/Selector/NamedSelectorTestCase.php | 14 ----- tests/Selector/SelectorsHandlerTest.php | 23 ------- tests/SessionTest.php | 18 ------ 16 files changed, 16 insertions(+), 396 deletions(-) delete mode 100644 src/Exception/ElementException.php delete mode 100644 tests/Exception/ElementExceptionTest.php diff --git a/src/Element/Element.php b/src/Element/Element.php index 47fefcab8..3172c2612 100644 --- a/src/Element/Element.php +++ b/src/Element/Element.php @@ -11,8 +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; /** @@ -22,11 +20,6 @@ */ abstract class Element implements ElementInterface { - /** - * @var Session - */ - private $session; - /** * Driver. * @@ -46,26 +39,10 @@ abstract class Element implements ElementInterface */ 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() - { - @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; - } - /** * Returns element's driver. * @@ -76,20 +53,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} */ @@ -167,22 +130,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(string $type, ?string $selector = null, ?string $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); - } } diff --git a/src/Element/ElementInterface.php b/src/Element/ElementInterface.php index d57dd2520..263dc7c24 100644 --- a/src/Element/ElementInterface.php +++ b/src/Element/ElementInterface.php @@ -10,8 +10,6 @@ namespace Behat\Mink\Element; -use Behat\Mink\Session; - /** * Element interface. * @@ -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. * diff --git a/src/Exception/ElementException.php b/src/Exception/ElementException.php deleted file mode 100644 index a35951f5e..000000000 --- a/src/Exception/ElementException.php +++ /dev/null @@ -1,63 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Behat\Mink\Exception; - -@trigger_error('The class '.__NAMESPACE__.'\ElementException is deprecated as of Mink 1.6 and will be removed in 2.0', E_USER_DEPRECATED); - -use Behat\Mink\Element\Element; - -/** - * A standard way for elements to re-throw exceptions. - * - * @deprecated This exception class is not used anymore in Mink 1.6 and will be removed in 2.0 - * - * @author Chris Worfolk - */ -class ElementException extends Exception -{ - /** - * @var Element - */ - private $element; - - /** - * Initialises exception. - * - * @param Element $element optional message - * @param \Exception $exception exception - */ - public function __construct(Element $element, \Exception $exception) - { - $this->element = $element; - - parent::__construct(sprintf("Exception thrown by %s\n%s", $element->getXpath(), $exception->getMessage())); - } - - /** - * Override default toString so we don't send a full backtrace in verbose mode. - * - * @return string - */ - public function __toString() - { - return $this->getMessage(); - } - - /** - * Get the element that caused the exception. - * - * @return Element - */ - public function getElement() - { - return $this->element; - } -} diff --git a/src/Exception/ElementHtmlException.php b/src/Exception/ElementHtmlException.php index 6d7a025f9..6aff79d20 100644 --- a/src/Exception/ElementHtmlException.php +++ b/src/Exception/ElementHtmlException.php @@ -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. @@ -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 \Throwable|null $exception expectation exception + * @param string $message optional message + * @param DriverInterface $driver driver instance + * @param Element $element element + * @param \Throwable|null $exception expectation exception */ - public function __construct(string $message, $driver, Element $element, ?\Throwable $exception = null) + public function __construct(string $message, DriverInterface $driver, Element $element, ?\Throwable $exception = null) { $this->element = $element; diff --git a/src/Exception/ElementNotFoundException.php b/src/Exception/ElementNotFoundException.php index 1bc783cd6..8e4668ac7 100644 --- a/src/Exception/ElementNotFoundException.php +++ b/src/Exception/ElementNotFoundException.php @@ -11,7 +11,6 @@ namespace Behat\Mink\Exception; use Behat\Mink\Driver\DriverInterface; -use Behat\Mink\Session; /** * Exception thrown when an expected element is not found. @@ -23,12 +22,12 @@ class ElementNotFoundException extends ExpectationException /** * Initializes exception. * - * @param DriverInterface|Session $driver driver instance - * @param string|null $type element type - * @param string|null $selector element selector type - * @param string|null $locator element locator + * @param DriverInterface $driver driver instance + * @param string|null $type element type + * @param string|null $selector element selector type + * @param string|null $locator element locator */ - public function __construct($driver, ?string $type = null, ?string $selector = null, ?string $locator = null) + public function __construct(DriverInterface $driver, ?string $type = null, ?string $selector = null, ?string $locator = null) { $message = ''; diff --git a/src/Exception/ExpectationException.php b/src/Exception/ExpectationException.php index c83a53a3e..199d47241 100644 --- a/src/Exception/ExpectationException.php +++ b/src/Exception/ExpectationException.php @@ -11,7 +11,6 @@ namespace Behat\Mink\Exception; use Behat\Mink\Driver\DriverInterface; -use Behat\Mink\Session; /** * Exception thrown for failed expectations. @@ -22,10 +21,6 @@ */ class ExpectationException extends Exception { - /** - * @var Session|null - */ - private $session; /** * @var DriverInterface */ @@ -34,23 +29,13 @@ class ExpectationException extends Exception /** * Initializes exception. * - * @param string $message optional message - * @param DriverInterface|Session $driver driver instance (or session for BC) - * @param \Throwable|null $exception expectation exception + * @param string $message optional message + * @param DriverInterface $driver driver instance + * @param \Throwable|null $exception expectation exception */ - public function __construct(string $message, $driver, ?\Throwable $exception = null) + public function __construct(string $message, DriverInterface $driver, ?\Throwable $exception = null) { - if ($driver instanceof Session) { - @trigger_error('Passing a Session object to the ExpectationException constructor is deprecated as of Mink 1.7. Pass the driver instead.', E_USER_DEPRECATED); - - $this->session = $driver; - $this->driver = $driver->getDriver(); - } elseif (!$driver instanceof DriverInterface) { - // Trigger an exception as we cannot typehint a disjunction - throw new \InvalidArgumentException('The ExpectationException constructor expects a DriverInterface or a Session.'); - } else { - $this->driver = $driver; - } + $this->driver = $driver; if (!$message && null !== $exception) { $message = $exception->getMessage(); @@ -96,24 +81,6 @@ protected function getDriver() return $this->driver; } - /** - * Returns exception session. - * - * @return Session - * - * @deprecated since 1.7, to be removed in 2.0. Use getDriver and the driver API instead. - */ - protected function getSession() - { - if (null === $this->session) { - throw new \LogicException(sprintf('The deprecated method %s cannot be used when passing a driver in the constructor', __METHOD__)); - } - - @trigger_error(sprintf('The method %s is deprecated as of Mink 1.7 and will be removed in 2.0. Use getDriver and the driver API instead.', __METHOD__), E_USER_DEPRECATED); - - return $this->session; - } - /** * Prepends every line in a string with pipe (|). * diff --git a/src/Selector/NamedSelector.php b/src/Selector/NamedSelector.php index b5d3e722e..8881ff4be 100644 --- a/src/Selector/NamedSelector.php +++ b/src/Selector/NamedSelector.php @@ -272,21 +272,6 @@ public function registerReplacement(string $from, string $to) private function escapeLocator(string $locator): string { - // If the locator looks like an escaped one, don't escape it again for BC reasons. - if ( - preg_match('/^\'[^\']*+\'$/', $locator) - || (false !== strpos($locator, '\'') && preg_match('/^"[^"]*+"$/', $locator)) - || ((8 < $length = strlen($locator)) && 'concat(' === substr($locator, 0, 7) && ')' === $locator[$length - 1]) - ) { - @trigger_error( - 'Passing an escaped locator to the named selector is deprecated as of 1.7 and will be removed in 2.0.' - .' Pass the raw value instead.', - E_USER_DEPRECATED - ); - - return $locator; - } - return $this->xpathEscaper->escapeLiteral($locator); } } diff --git a/src/Selector/SelectorsHandler.php b/src/Selector/SelectorsHandler.php index 70ea819b2..ed5a160bb 100644 --- a/src/Selector/SelectorsHandler.php +++ b/src/Selector/SelectorsHandler.php @@ -10,8 +10,6 @@ namespace Behat\Mink\Selector; -use Behat\Mink\Selector\Xpath\Escaper; - /** * Selectors handler. * @@ -23,10 +21,6 @@ class SelectorsHandler * @var array */ private $selectors = []; - /** - * @var Escaper - */ - private $escaper; /** * Initializes selectors handler. @@ -35,8 +29,6 @@ class SelectorsHandler */ public function __construct(array $selectors = array()) { - $this->escaper = new Escaper(); - $this->registerSelector('named_partial', new PartialNamedSelector()); $this->registerSelector('named_exact', new ExactNamedSelector()); $this->registerSelector('css', new CssSelector()); @@ -82,15 +74,6 @@ public function isSelectorRegistered(string $name) */ public function getSelector(string $name) { - if ('named' === $name) { - @trigger_error( - 'Using the "named" selector directly from the handler is deprecated as of 1.6 and will be removed in 2.0.' - .' Use the "named_partial" or use the "named" selector through the Element API instead.', - E_USER_DEPRECATED - ); - $name = 'named_partial'; - } - if (!$this->isSelectorRegistered($name)) { throw new \InvalidArgumentException("Selector \"$name\" is not registered."); } @@ -118,26 +101,4 @@ public function selectorToXpath(string $selector, $locator) return $this->getSelector($selector)->translateToXPath($locator); } - - /** - * Translates string to XPath literal. - * - * @deprecated since Mink 1.7. Use \Behat\Mink\Selector\Xpath\Escaper::escapeLiteral when building Xpath - * or pass the unescaped value when using the named selector. - * - * @param string $s - * - * @return string - */ - public function xpathLiteral(string $s) - { - @trigger_error( - 'The '.__METHOD__.' method is deprecated as of 1.7 and will be removed in 2.0.' - .' Use \Behat\Mink\Selector\Xpath\Escaper::escapeLiteral instead when building Xpath' - .' or pass the unescaped value when using the named selector.', - E_USER_DEPRECATED - ); - - return $this->escaper->escapeLiteral($s); - } } diff --git a/src/Session.php b/src/Session.php index 78e9f12fc..71c4e0700 100644 --- a/src/Session.php +++ b/src/Session.php @@ -34,16 +34,11 @@ class Session * @var ElementFinder */ private $elementFinder; - /** - * @var SelectorsHandler - */ - private $selectorsHandler; public function __construct(DriverInterface $driver, ?SelectorsHandler $selectorsHandler = null) { $this->driver = $driver; - $this->selectorsHandler = $selectorsHandler ?? new SelectorsHandler(); - $this->elementFinder = new ElementFinder($driver, $this->selectorsHandler); + $this->elementFinder = new ElementFinder($driver, $selectorsHandler ?? new SelectorsHandler()); $this->page = new DocumentElement($this); $driver->setSession($this); @@ -144,20 +139,6 @@ public function getElementFinder(): ElementFinder return $this->elementFinder; } - /** - * Returns selectors handler. - * - * @return SelectorsHandler - * - * @deprecated since 1.11 - */ - public function getSelectorsHandler() - { - @trigger_error(sprintf('The method %s is deprecated as of 1.11 and will be removed in 2.0', __METHOD__), E_USER_DEPRECATED); - - return $this->selectorsHandler; - } - /** * Visit specified URL and automatically start session if not already running. * diff --git a/tests/Element/DocumentElementTest.php b/tests/Element/DocumentElementTest.php index cca3e295e..aa13997dd 100644 --- a/tests/Element/DocumentElementTest.php +++ b/tests/Element/DocumentElementTest.php @@ -23,14 +23,6 @@ protected function prepareSession(): void $this->document = new DocumentElement($this->session); } - /** - * @group legacy - */ - public function testGetSession() - { - $this->assertEquals($this->session, $this->document->getSession()); - } - public function testFindAll() { $node1 = $this->createStub(NodeElement::class); diff --git a/tests/Exception/ElementExceptionTest.php b/tests/Exception/ElementExceptionTest.php deleted file mode 100644 index 9c1bb9cf3..000000000 --- a/tests/Exception/ElementExceptionTest.php +++ /dev/null @@ -1,44 +0,0 @@ -getElementMock(), new \Exception('Something went wrong')); - - $expectedMessage = "Exception thrown by element XPath\nSomething went wrong"; - $this->assertEquals($expectedMessage, $exception->getMessage()); - $this->assertEquals($expectedMessage, (string) $exception); - } - - public function testElement() - { - $element = $this->getElementMock(); - - $exception = new ElementException($element, new \Exception('Something went wrong')); - - $this->assertSame($element, $exception->getElement()); - } - - private function getElementMock(): Element - { - $mock = $this->getMockBuilder('Behat\Mink\Element\Element') - ->disableOriginalConstructor() - ->getMock(); - - $mock->expects($this->any()) - ->method('getXPath') - ->will($this->returnValue('element XPath')); - - return $mock; - } -} diff --git a/tests/Exception/ElementNotFoundExceptionTest.php b/tests/Exception/ElementNotFoundExceptionTest.php index 2ab2d7249..07f9f8a2a 100644 --- a/tests/Exception/ElementNotFoundExceptionTest.php +++ b/tests/Exception/ElementNotFoundExceptionTest.php @@ -30,22 +30,4 @@ public static function provideExceptionMessage() array('Tag with name "foobar" not found.', null, 'name', 'foobar'), ); } - - /** - * @group legacy - */ - public function testConstructWithSession() - { - $driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock(); - $session = $this->getMockBuilder('Behat\Mink\Session') - ->disableOriginalConstructor() - ->getMock(); - $session->expects($this->any()) - ->method('getDriver') - ->will($this->returnValue($driver)); - - $exception = new ElementNotFoundException($session); - - $this->assertEquals('Tag not found.', $exception->getMessage()); - } } diff --git a/tests/Exception/ExpectationExceptionTest.php b/tests/Exception/ExpectationExceptionTest.php index 9dbbfebb4..10e48512f 100644 --- a/tests/Exception/ExpectationExceptionTest.php +++ b/tests/Exception/ExpectationExceptionTest.php @@ -128,22 +128,4 @@ public function testExceptionWhileRenderingString() $this->assertEquals('Expectation failure', $exception->__toString()); } - - /** - * @group legacy - */ - public function testConstructWithSession() - { - $driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock(); - $session = $this->getMockBuilder('Behat\Mink\Session') - ->disableOriginalConstructor() - ->getMock(); - $session->expects($this->any()) - ->method('getDriver') - ->will($this->returnValue($driver)); - - $exception = new ExpectationException('', $session, new \Exception('Something failed')); - - $this->assertEquals('Something failed', $exception->getMessage()); - } } diff --git a/tests/Selector/NamedSelectorTestCase.php b/tests/Selector/NamedSelectorTestCase.php index a79c94af7..a0088cdc5 100644 --- a/tests/Selector/NamedSelectorTestCase.php +++ b/tests/Selector/NamedSelectorTestCase.php @@ -3,7 +3,6 @@ namespace Behat\Mink\Tests\Selector; use Behat\Mink\Selector\NamedSelector; -use Behat\Mink\Selector\Xpath\Escaper; use PHPUnit\Framework\TestCase; abstract class NamedSelectorTestCase extends TestCase @@ -92,19 +91,6 @@ public function testLateRegisteredReplacements(string $fixtureFile, array $repla $this->assertEquals($expectedCount, $nodeList->length); } - /** - * @dataProvider getSelectorTests - * @group legacy - */ - public function testEscapedSelectors(string $fixtureFile, string $selector, string $locator, int $expectedExactCount, ?int $expectedPartialCount = null) - { - // Escape the locator as Mink 1.x expects the caller of the NamedSelector to handle it - $escaper = new Escaper(); - $locator = $escaper->escapeLiteral($locator); - - $this->testSelectors($fixtureFile, $selector, $locator, $expectedExactCount, $expectedPartialCount); - } - public static function getSelectorTests() { $fieldCount = 8; // fields without `type` attribute diff --git a/tests/Selector/SelectorsHandlerTest.php b/tests/Selector/SelectorsHandlerTest.php index e3d0152cf..aae9a422c 100644 --- a/tests/Selector/SelectorsHandlerTest.php +++ b/tests/Selector/SelectorsHandlerTest.php @@ -70,27 +70,4 @@ public function testSelectorToXpath() $handler->selectorToXpath('undefined', 'asd'); } - - /** - * @group legacy - */ - public function testXpathLiteral() - { - $handler = new SelectorsHandler(); - - $this->assertEquals("'some simple string'", $handler->xpathLiteral('some simple string')); - } - - /** - * @group legacy - */ - public function testBcLayer() - { - $selector = $this->getMockBuilder('Behat\Mink\Selector\SelectorInterface')->getMock(); - $handler = new SelectorsHandler(); - - $handler->registerSelector('named_partial', $selector); - - $this->assertSame($selector, $handler->getSelector('named')); - } } diff --git a/tests/SessionTest.php b/tests/SessionTest.php index b2dabf76a..9be846a64 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -46,24 +46,6 @@ public function testGetPage() $this->assertInstanceOf('Behat\Mink\Element\DocumentElement', $this->session->getPage()); } - /** - * @group legacy - */ - public function testGetSelectorsHandler() - { - $this->assertSame($this->selectorsHandler, $this->session->getSelectorsHandler()); - } - - /** - * @group legacy - */ - public function testInstantiateWithoutOptionalDeps() - { - $session = new Session($this->driver); - - $this->assertInstanceOf('Behat\Mink\Selector\SelectorsHandler', $session->getSelectorsHandler()); - } - public function testIsStarted() { $this->driver->expects($this->once()) From ce9147697bd406a50a1db3969e80e8087f4b12fa Mon Sep 17 00:00:00 2001 From: Alexander Obuhovich Date: Tue, 14 Jan 2014 22:37:27 +0200 Subject: [PATCH 2/5] =?UTF-8?q?NamedSelector=20wasn=E2=80=99t=20matching?= =?UTF-8?q?=20buttons=20by=20`name`=20attribute=20in=20`link=5For=5Fbutton?= =?UTF-8?q?`=20selector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Selector/NamedSelector.php | 9 ++++++--- tests/Selector/NamedSelectorTestCase.php | 8 ++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Selector/NamedSelector.php b/src/Selector/NamedSelector.php index 8881ff4be..da0ae5572 100644 --- a/src/Selector/NamedSelector.php +++ b/src/Selector/NamedSelector.php @@ -99,16 +99,19 @@ class NamedSelector implements SelectorInterface [./@href][(%linkMatch% or %imgAltMatch%)] | .//input -[%buttonTypeFilter%][(%idOrValueMatch% or %titleMatch%)] +[%buttonTypeFilter%][(%buttonMatch%)] | .//input [%lowercaseType% = 'image'][%altMatch%] | .//button -[(%idOrValueMatch% or %titleMatch% or %tagTextMatch%)] +[(%buttonMatch% or %tagTextMatch%)] +| +.//* +[%lowercaseRole% = 'link'][(%idOrValueMatch% or %titleMatch% or %tagTextMatch%)] | .//* -[(%lowercaseRole% = 'button' or %lowercaseRole% = 'link')][(%idOrValueMatch% or %titleMatch% or %tagTextMatch%)] +[%lowercaseRole% = 'button'][(%buttonMatch% or %tagTextMatch%)] XPATH ,'content' => << array('test.html', 'link_or_button', 'link-text', 5, 9), 'link_or_button (without-href) ignored' => array('test.html', 'link_or_button', 'bad-link-text', 0), 'link_or_button* (role=link)' => array('test.html', 'link_or_button', 'link-role-text', 4, 7), - - // bug in selector: 17 instead of 25 and 34 instead of 42, because 8 buttons with `name` attribute were not matched - 'link_or_button (input, name/value/title)' => array('test.html', 'link_or_button', 'button-text', 17, 34), + 'link_or_button (input, name/value/title)' => array('test.html', 'link_or_button', 'button-text', 25, 42), 'link_or_button (type=image, with-alt)' => array('test.html', 'link_or_button', 'button-alt-text', 1, 2), 'link_or_button (input type=submit, with-id)' => array('test.html', 'link_or_button', 'input-submit-button', 1), 'link_or_button (input type=image, with-id)' => array('test.html', 'link_or_button', 'input-image-button', 1), @@ -147,9 +145,7 @@ public static function getSelectorTests() 'link_or_button (button type=image, with-id)' => array('test.html', 'link_or_button', 'button-image-button', 1), 'link_or_button (button type=button, with-id)' => array('test.html', 'link_or_button', 'button-button-button', 1), 'link_or_button (button type=reset, with-id)' => array('test.html', 'link_or_button', 'button-reset-button', 1), - - // bug in selector: 8 instead of 12 and 16 instead of 20, because 4 buttons with `name` attribute were not matched - 'link_or_button* (role=button, name/value/title)' => array('test.html', 'link_or_button', 'button-role-text', 8, 16), + 'link_or_button* (role=button, name/value/title)' => array('test.html', 'link_or_button', 'button-role-text', 12, 20), 'link_or_button* (role=button type=submit, with-id)' => array('test.html', 'link_or_button', 'role-button-submit-button', 1), 'link_or_button* (role=button type=image, with-id)' => array('test.html', 'link_or_button', 'role-button-image-button', 1), 'link_or_button* (role=button type=button, with-id)' => array('test.html', 'link_or_button', 'role-button-button-button', 1), From 4a141144a78d2b350d6e70a893e4f861da5142c6 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 28 Dec 2013 10:15:10 +0100 Subject: [PATCH 3/5] Change the constructor arguments of the elements to their dependencies The constructor now receives the driver and the element finder instead of the session. --- src/Driver/CoreDriver.php | 2 +- src/Element/Element.php | 12 ++--- src/Element/NodeElement.php | 11 ++-- src/Session.php | 2 +- tests/Driver/CoreDriverTest.php | 3 ++ tests/Element/DocumentElementTest.php | 2 +- tests/Element/ElementTestCase.php | 12 ----- tests/Element/NodeElementTest.php | 76 +++++++++++++-------------- 8 files changed, 53 insertions(+), 67 deletions(-) diff --git a/src/Driver/CoreDriver.php b/src/Driver/CoreDriver.php index 9c3ef242b..4e05aa6ec 100644 --- a/src/Driver/CoreDriver.php +++ b/src/Driver/CoreDriver.php @@ -294,7 +294,7 @@ public function find(string $xpath) $elements = array(); foreach ($this->findElementXpaths($xpath) as $xpath) { - $elements[] = new NodeElement($xpath, $this->session); + $elements[] = new NodeElement($xpath, $this, $this->session->getElementFinder()); } return $elements; diff --git a/src/Element/Element.php b/src/Element/Element.php index 3172c2612..c49455d2f 100644 --- a/src/Element/Element.php +++ b/src/Element/Element.php @@ -11,7 +11,6 @@ namespace Behat\Mink\Element; use Behat\Mink\Driver\DriverInterface; -use Behat\Mink\Session; /** * Base element. @@ -32,15 +31,10 @@ abstract class Element implements ElementInterface */ private $elementFinder; - /** - * Initialize element. - * - * @param Session $session - */ - public function __construct(Session $session) + public function __construct(DriverInterface $driver, ElementFinder $elementFinder) { - $this->driver = $session->getDriver(); - $this->elementFinder = $session->getElementFinder(); + $this->driver = $driver; + $this->elementFinder = $elementFinder; } /** diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index 65d98c3cd..4f9588a7d 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -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; /** @@ -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(string $xpath, Session $session) + public function __construct(string $xpath, DriverInterface $driver, ElementFinder $elementFinder) { $this->xpath = $xpath; - parent::__construct($session); + parent::__construct($driver, $elementFinder); } /** diff --git a/src/Session.php b/src/Session.php index 71c4e0700..2819b526d 100644 --- a/src/Session.php +++ b/src/Session.php @@ -39,7 +39,7 @@ public function __construct(DriverInterface $driver, ?SelectorsHandler $selector { $this->driver = $driver; $this->elementFinder = new ElementFinder($driver, $selectorsHandler ?? new SelectorsHandler()); - $this->page = new DocumentElement($this); + $this->page = new DocumentElement($driver, $this->elementFinder); $driver->setSession($this); } diff --git a/tests/Driver/CoreDriverTest.php b/tests/Driver/CoreDriverTest.php index d7d7e4ae9..b75dc4b82 100644 --- a/tests/Driver/CoreDriverTest.php +++ b/tests/Driver/CoreDriverTest.php @@ -2,6 +2,7 @@ namespace Behat\Mink\Tests\Driver; +use Behat\Mink\Element\ElementFinder; use Behat\Mink\Element\NodeElement; use PHPUnit\Framework\TestCase; @@ -30,6 +31,8 @@ public function testCreateNodeElements() ->disableOriginalConstructor() ->getMock(); + $session->method('getElementFinder')->willReturn($this->createMock(ElementFinder::class)); + $driver->setSession($session); $driver->expects($this->once()) diff --git a/tests/Element/DocumentElementTest.php b/tests/Element/DocumentElementTest.php index aa13997dd..dfc61ab18 100644 --- a/tests/Element/DocumentElementTest.php +++ b/tests/Element/DocumentElementTest.php @@ -20,7 +20,7 @@ class DocumentElementTest extends ElementTestCase protected function prepareSession(): void { parent::prepareSession(); - $this->document = new DocumentElement($this->session); + $this->document = new DocumentElement($this->driver, $this->elementFinder); } public function testFindAll() diff --git a/tests/Element/ElementTestCase.php b/tests/Element/ElementTestCase.php index 15a3b8131..d7c146412 100644 --- a/tests/Element/ElementTestCase.php +++ b/tests/Element/ElementTestCase.php @@ -4,19 +4,11 @@ use Behat\Mink\Driver\DriverInterface; use Behat\Mink\Element\ElementFinder; -use Behat\Mink\Session; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; abstract class ElementTestCase extends TestCase { - /** - * Session. - * - * @var Session - */ - protected $session; - /** * @var DriverInterface&MockObject */ @@ -33,10 +25,6 @@ abstract class ElementTestCase extends TestCase protected function prepareSession(): void { $this->driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock(); - $this->elementFinder = $this->createMock(ElementFinder::class); - $this->session = $this->createStub(Session::class); - $this->session->method('getDriver')->willReturn($this->driver); - $this->session->method('getElementFinder')->willReturn($this->elementFinder); } } diff --git a/tests/Element/NodeElementTest.php b/tests/Element/NodeElementTest.php index be354af85..4e51eb252 100644 --- a/tests/Element/NodeElementTest.php +++ b/tests/Element/NodeElementTest.php @@ -9,7 +9,7 @@ class NodeElementTest extends ElementTestCase { public function testGetXpath() { - $node = new NodeElement('some custom xpath', $this->session); + $node = new NodeElement('some custom xpath', $this->driver, $this->elementFinder); $this->assertEquals('some custom xpath', $node->getXpath()); $this->assertNotEquals('not some custom xpath', $node->getXpath()); @@ -18,7 +18,7 @@ public function testGetXpath() public function testGetText() { $expected = 'val1'; - $node = new NodeElement('text_tag', $this->session); + $node = new NodeElement('text_tag', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -32,7 +32,7 @@ public function testGetText() public function testGetOuterHtml() { $expected = 'val1'; - $node = new NodeElement('text_tag', $this->session); + $node = new NodeElement('text_tag', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -46,7 +46,7 @@ public function testGetOuterHtml() public function testElementIsValid() { $elementXpath = 'some xpath'; - $node = new NodeElement($elementXpath, $this->session); + $node = new NodeElement($elementXpath, $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -59,7 +59,7 @@ public function testElementIsValid() public function testElementIsNotValid() { - $node = new NodeElement('some xpath', $this->session); + $node = new NodeElement('some xpath', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -72,7 +72,7 @@ public function testElementIsNotValid() public function testElementIsNotValidWithMultipleFound() { - $node = new NodeElement('some xpath', $this->session); + $node = new NodeElement('some xpath', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -86,7 +86,7 @@ public function testElementIsNotValidWithMultipleFound() public function testWaitForSuccess() { $callCounter = 0; - $node = new NodeElement('some xpath', $this->session); + $node = new NodeElement('some xpath', $this->driver, $this->elementFinder); $result = $node->waitFor(5, function ($givenNode) use (&$callCounter) { ++$callCounter; @@ -111,7 +111,7 @@ public function testWaitForSuccess() */ public function testWaitForTimeout() { - $node = new NodeElement('some xpath', $this->session); + $node = new NodeElement('some xpath', $this->driver, $this->elementFinder); $expectedTimeout = 2; $startTime = microtime(true); @@ -126,7 +126,7 @@ public function testWaitForTimeout() public function testHasAttribute() { - $node = new NodeElement('input_tag', $this->session); + $node = new NodeElement('input_tag', $this->driver, $this->elementFinder); $this->driver ->expects($this->exactly(2)) @@ -141,7 +141,7 @@ public function testHasAttribute() public function testGetAttribute() { $expected = 'http://...'; - $node = new NodeElement('input_tag', $this->session); + $node = new NodeElement('input_tag', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -154,7 +154,7 @@ public function testGetAttribute() public function testHasClass() { - $node = new NodeElement('input_tag', $this->session); + $node = new NodeElement('input_tag', $this->driver, $this->elementFinder); $this->driver ->expects($this->any()) @@ -171,7 +171,7 @@ class1 class2 public function testHasClassWithoutArgument() { - $node = new NodeElement('input_tag', $this->session); + $node = new NodeElement('input_tag', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -185,7 +185,7 @@ public function testHasClassWithoutArgument() public function testGetValue() { $expected = 'val1'; - $node = new NodeElement('input_tag', $this->session); + $node = new NodeElement('input_tag', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -199,7 +199,7 @@ public function testGetValue() public function testSetValue() { $expected = 'new_val'; - $node = new NodeElement('input_tag', $this->session); + $node = new NodeElement('input_tag', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -211,7 +211,7 @@ public function testSetValue() public function testClick() { - $node = new NodeElement('link_or_button', $this->session); + $node = new NodeElement('link_or_button', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -223,7 +223,7 @@ public function testClick() public function testPress() { - $node = new NodeElement('link_or_button', $this->session); + $node = new NodeElement('link_or_button', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -235,7 +235,7 @@ public function testPress() public function testRightClick() { - $node = new NodeElement('elem', $this->session); + $node = new NodeElement('elem', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -247,7 +247,7 @@ public function testRightClick() public function testDoubleClick() { - $node = new NodeElement('elem', $this->session); + $node = new NodeElement('elem', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -259,7 +259,7 @@ public function testDoubleClick() public function testCheck() { - $node = new NodeElement('checkbox_or_radio', $this->session); + $node = new NodeElement('checkbox_or_radio', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -271,7 +271,7 @@ public function testCheck() public function testUncheck() { - $node = new NodeElement('checkbox_or_radio', $this->session); + $node = new NodeElement('checkbox_or_radio', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -283,7 +283,7 @@ public function testUncheck() public function testSelectOption() { - $node = new NodeElement('select', $this->session); + $node = new NodeElement('select', $this->driver, $this->elementFinder); $option = $this->createMock(NodeElement::class); $option ->expects($this->once()) @@ -311,7 +311,7 @@ public function testSelectOption() public function testSelectOptionNotFound() { - $node = new NodeElement('select', $this->session); + $node = new NodeElement('select', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -330,7 +330,7 @@ public function testSelectOptionNotFound() public function testSelectOptionOtherTag() { - $node = new NodeElement('div', $this->session); + $node = new NodeElement('div', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -348,7 +348,7 @@ public function testSelectOptionOtherTag() public function testGetTagName() { - $node = new NodeElement('html//h3', $this->session); + $node = new NodeElement('html//h3', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -361,7 +361,7 @@ public function testGetTagName() public function testGetParent() { - $node = new NodeElement('elem', $this->session); + $node = new NodeElement('elem', $this->driver, $this->elementFinder); $parent = $this->getMockBuilder('Behat\Mink\Element\NodeElement') ->disableOriginalConstructor() ->getMock(); @@ -376,7 +376,7 @@ public function testGetParent() public function testGetParentNotFound() { - $node = new NodeElement('elem', $this->session); + $node = new NodeElement('elem', $this->driver, $this->elementFinder); $this->elementFinder->expects($this->once()) ->method('findAll') @@ -390,7 +390,7 @@ public function testGetParentNotFound() public function testAttachFile() { - $node = new NodeElement('elem', $this->session); + $node = new NodeElement('elem', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -402,7 +402,7 @@ public function testAttachFile() public function testIsVisible() { - $node = new NodeElement('some_xpath', $this->session); + $node = new NodeElement('some_xpath', $this->driver, $this->elementFinder); $this->driver ->expects($this->exactly(2)) @@ -416,7 +416,7 @@ public function testIsVisible() public function testIsChecked() { - $node = new NodeElement('some_xpath', $this->session); + $node = new NodeElement('some_xpath', $this->driver, $this->elementFinder); $this->driver ->expects($this->exactly(2)) @@ -430,7 +430,7 @@ public function testIsChecked() public function testIsSelected() { - $node = new NodeElement('some_xpath', $this->session); + $node = new NodeElement('some_xpath', $this->driver, $this->elementFinder); $this->driver ->expects($this->exactly(2)) @@ -444,7 +444,7 @@ public function testIsSelected() public function testFocus() { - $node = new NodeElement('some-element', $this->session); + $node = new NodeElement('some-element', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -456,7 +456,7 @@ public function testFocus() public function testBlur() { - $node = new NodeElement('some-element', $this->session); + $node = new NodeElement('some-element', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -468,7 +468,7 @@ public function testBlur() public function testMouseOver() { - $node = new NodeElement('some-element', $this->session); + $node = new NodeElement('some-element', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -480,7 +480,7 @@ public function testMouseOver() public function testDragTo() { - $node = new NodeElement('some_tag1', $this->session); + $node = new NodeElement('some_tag1', $this->driver, $this->elementFinder); $target = $this->getMockBuilder('Behat\Mink\Element\ElementInterface')->getMock(); $target->expects($this->any()) @@ -497,7 +497,7 @@ public function testDragTo() public function testKeyPress() { - $node = new NodeElement('elem', $this->session); + $node = new NodeElement('elem', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -509,7 +509,7 @@ public function testKeyPress() public function testKeyDown() { - $node = new NodeElement('elem', $this->session); + $node = new NodeElement('elem', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -521,7 +521,7 @@ public function testKeyDown() public function testKeyUp() { - $node = new NodeElement('elem', $this->session); + $node = new NodeElement('elem', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) @@ -533,7 +533,7 @@ public function testKeyUp() public function testSubmitForm() { - $node = new NodeElement('some_xpath', $this->session); + $node = new NodeElement('some_xpath', $this->driver, $this->elementFinder); $this->driver ->expects($this->once()) From 618c3d13cf71f522762f689fd0b7d36cf7dd4ebd Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 28 Dec 2013 11:32:39 +0100 Subject: [PATCH 4/5] Decoupled the DriverInterface from the NodeElement This avoids a circular dependency. The driver interface now returns an array of XPath for found elements, and Element::find() instantiates the NodeElement for them. The driver is now the low level API which does not depend on any other part of Mink (but used by other parts). The ElementFinder is responsible for instantiating the NodeElement. --- src/Driver/CoreDriver.php | 27 ++------------------------- src/Driver/DriverInterface.php | 13 +------------ src/Element/Element.php | 2 +- src/Element/ElementFinder.php | 12 +++++++++--- src/Element/NodeElement.php | 2 +- src/Session.php | 20 +++----------------- tests/Driver/CoreDriverTest.php | 16 ++-------------- tests/Element/ElementFinderTest.php | 24 +++--------------------- tests/Element/NodeElementTest.php | 4 ++-- tests/SessionTest.php | 7 +------ 10 files changed, 25 insertions(+), 102 deletions(-) diff --git a/src/Driver/CoreDriver.php b/src/Driver/CoreDriver.php index 4e05aa6ec..a15b54439 100644 --- a/src/Driver/CoreDriver.php +++ b/src/Driver/CoreDriver.php @@ -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; /** * Core driver. @@ -24,21 +22,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 * @@ -282,7 +265,7 @@ public function getWindowName() /** * @param string $xpath * - * @return NodeElement[] + * @return string[] * * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done @@ -291,13 +274,7 @@ public function getWindowName() */ public function find(string $xpath) { - $elements = array(); - - foreach ($this->findElementXpaths($xpath) as $xpath) { - $elements[] = new NodeElement($xpath, $this, $this->session->getElementFinder()); - } - - return $elements; + return $this->findElementXpaths($xpath); } /** diff --git a/src/Driver/DriverInterface.php b/src/Driver/DriverInterface.php index 9c40b4493..c8a3be527 100644 --- a/src/Driver/DriverInterface.php +++ b/src/Driver/DriverInterface.php @@ -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; use JetBrains\PhpStorm\Language; /** @@ -24,15 +22,6 @@ */ interface DriverInterface { - /** - * Sets driver's current session. - * - * @param Session $session - * - * @return void - */ - public function setSession(Session $session); - /** * Starts driver. * @@ -300,7 +289,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 diff --git a/src/Element/Element.php b/src/Element/Element.php index c49455d2f..52b9236e4 100644 --- a/src/Element/Element.php +++ b/src/Element/Element.php @@ -88,7 +88,7 @@ public function find(string $selector, $locator) { $items = $this->findAll($selector, $locator); - return count($items) ? current($items) : null; + return count($items) ? $items[0] : null; } /** diff --git a/src/Element/ElementFinder.php b/src/Element/ElementFinder.php index 98e0c9a95..e33c309ae 100644 --- a/src/Element/ElementFinder.php +++ b/src/Element/ElementFinder.php @@ -43,9 +43,9 @@ public function __construct(DriverInterface $driver, SelectorsHandler $selectors /** * @param string|array $locator * - * @return NodeElement[] + * @return list */ - 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); @@ -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; } } diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index 4f9588a7d..4d537f7df 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -30,7 +30,7 @@ class NodeElement extends TraversableElement /** * Initializes node element. * - * @param string $xpath element xpath + * @param string $xpath element xpath * @param DriverInterface $driver * @param ElementFinder $elementFinder */ diff --git a/src/Session.php b/src/Session.php index 2819b526d..2aa714849 100644 --- a/src/Session.php +++ b/src/Session.php @@ -12,8 +12,8 @@ use Behat\Mink\Driver\DriverInterface; use Behat\Mink\Element\ElementFinder; -use Behat\Mink\Selector\SelectorsHandler; use Behat\Mink\Element\DocumentElement; +use Behat\Mink\Selector\SelectorsHandler; /** * Mink session. @@ -30,18 +30,12 @@ class Session * @var DocumentElement */ private $page; - /** - * @var ElementFinder - */ - private $elementFinder; public function __construct(DriverInterface $driver, ?SelectorsHandler $selectorsHandler = null) { $this->driver = $driver; - $this->elementFinder = new ElementFinder($driver, $selectorsHandler ?? new SelectorsHandler()); - $this->page = new DocumentElement($driver, $this->elementFinder); - - $driver->setSession($this); + $elementFinder = new ElementFinder($driver, $selectorsHandler ?? new SelectorsHandler()); + $this->page = new DocumentElement($driver, $elementFinder); } /** @@ -131,14 +125,6 @@ public function getPage() return $this->page; } - /** - * @internal - */ - public function getElementFinder(): ElementFinder - { - return $this->elementFinder; - } - /** * Visit specified URL and automatically start session if not already running. * diff --git a/tests/Driver/CoreDriverTest.php b/tests/Driver/CoreDriverTest.php index b75dc4b82..1af510e3b 100644 --- a/tests/Driver/CoreDriverTest.php +++ b/tests/Driver/CoreDriverTest.php @@ -2,8 +2,6 @@ namespace Behat\Mink\Tests\Driver; -use Behat\Mink\Element\ElementFinder; -use Behat\Mink\Element\NodeElement; use PHPUnit\Framework\TestCase; class CoreDriverTest extends TestCase @@ -27,29 +25,19 @@ public function testCreateNodeElements() ->setMethods(array('findElementXpaths')) ->getMockForAbstractClass(); - $session = $this->getMockBuilder('Behat\Mink\Session') - ->disableOriginalConstructor() - ->getMock(); - - $session->method('getElementFinder')->willReturn($this->createMock(ElementFinder::class)); - - $driver->setSession($session); - $driver->expects($this->once()) ->method('findElementXpaths') ->with('xpath') ->willReturn(array('xpath1', 'xpath2')); - /** @var NodeElement[] $elements */ $elements = $driver->find('xpath'); $this->assertIsArray($elements); $this->assertCount(2, $elements); - $this->assertContainsOnlyInstancesOf('Behat\Mink\Element\NodeElement', $elements); - $this->assertSame('xpath1', $elements[0]->getXpath()); - $this->assertSame('xpath2', $elements[1]->getXpath()); + $this->assertSame('xpath1', $elements[0]); + $this->assertSame('xpath2', $elements[1]); } /** diff --git a/tests/Element/ElementFinderTest.php b/tests/Element/ElementFinderTest.php index 97c254403..b477a86e6 100644 --- a/tests/Element/ElementFinderTest.php +++ b/tests/Element/ElementFinderTest.php @@ -63,12 +63,6 @@ public function testNotFound() public function testFound() { - $element1 = $this->createStub(NodeElement::class); - $element1->method('getXpath')->willReturn('element1'); - - $element2 = $this->createStub(NodeElement::class); - $element2->method('getXpath')->willReturn('element2'); - $this->selectorsHandler->expects($this->once()) ->method('selectorToXpath') ->with('css', 'h3 > a') @@ -82,7 +76,7 @@ public function testFound() $this->driver->expects($this->once()) ->method('find') ->with('full_xpath') - ->will($this->returnValue(array($element1, $element2))); + ->will($this->returnValue(array('element1', 'element2'))); $results = $this->finder->findAll('css', 'h3 > a', 'parent_xpath'); @@ -94,12 +88,6 @@ public function testFound() public function testNamedFound() { - $element1 = $this->createStub(NodeElement::class); - $element1->method('getXpath')->willReturn('element1'); - - $element2 = $this->createStub(NodeElement::class); - $element2->method('getXpath')->willReturn('element2'); - $this->selectorsHandler->expects($this->once()) ->method('selectorToXpath') ->with('named_exact', 'test') @@ -113,7 +101,7 @@ public function testNamedFound() $this->driver->expects($this->once()) ->method('find') ->with('full_xpath') - ->will($this->returnValue(array($element1, $element2))); + ->will($this->returnValue(array('element1', 'element2'))); $results = $this->finder->findAll('named', 'test', 'parent_xpath'); @@ -125,12 +113,6 @@ public function testNamedFound() public function testNamedPartialFallback() { - $element1 = $this->createStub(NodeElement::class); - $element1->method('getXpath')->willReturn('element1'); - - $element2 = $this->createStub(NodeElement::class); - $element2->method('getXpath')->willReturn('element2'); - $this->selectorsHandler->expects($this->exactly(2)) ->method('selectorToXpath') ->will($this->returnValueMap(array( @@ -149,7 +131,7 @@ public function testNamedPartialFallback() ->method('find') ->willReturnMap(array( array('full_xpath', array()), - array('full_partial_xpath', array($element1, $element2)), + array('full_partial_xpath', array('element1', 'element2')), )); $results = $this->finder->findAll('named', 'test', 'parent_xpath'); diff --git a/tests/Element/NodeElementTest.php b/tests/Element/NodeElementTest.php index 4e51eb252..ed44f6ab1 100644 --- a/tests/Element/NodeElementTest.php +++ b/tests/Element/NodeElementTest.php @@ -52,7 +52,7 @@ public function testElementIsValid() ->expects($this->once()) ->method('find') ->with($elementXpath) - ->willReturn(array($this->createStub(NodeElement::class))); + ->willReturn(array($elementXpath)); $this->assertTrue($node->isValid()); } @@ -78,7 +78,7 @@ public function testElementIsNotValidWithMultipleFound() ->expects($this->once()) ->method('find') ->with('some xpath') - ->willReturn(array($this->createStub(NodeElement::class), $this->createStub(NodeElement::class))); + ->willReturn(array('some xpath', 'some other xpath')); $this->assertFalse($node->isValid(), 'more then 1 element found is invalid element'); } diff --git a/tests/SessionTest.php b/tests/SessionTest.php index 9be846a64..f18af7b2d 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -14,10 +14,6 @@ class SessionTest extends TestCase * @var DriverInterface&MockObject */ private $driver; - /** - * @var SelectorsHandler - */ - private $selectorsHandler; /** * Session. @@ -32,8 +28,7 @@ class SessionTest extends TestCase protected function prepareSession(): void { $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() From d8a44132902fd3b714f9fb4494ce1610d7a64dd2 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 30 Jan 2014 23:33:07 +0100 Subject: [PATCH 5/5] Disabled CI builds for the branch to avoid duplicated builds --- .github/workflows/tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 510efc177..b80f65d80 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,6 +2,8 @@ name: CI on: push: + branches-ignore: + - '2-architecture-changes' pull_request: defaults: