Skip to content

Commit

Permalink
Add compatibility with PHPUnit 6
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Jan 7, 2018
1 parent 808702d commit e5338f0
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 42 deletions.
11 changes: 9 additions & 2 deletions tests/Driver/CoreDriverTest.php
Expand Up @@ -3,8 +3,9 @@
namespace Behat\Mink\Tests\Driver;

use Behat\Mink\Element\NodeElement;
use PHPUnit\Framework\TestCase;

class CoreDriverTest extends \PHPUnit_Framework_TestCase
class CoreDriverTest extends TestCase
{
public function testNoExtraMethods()
{
Expand Down Expand Up @@ -65,7 +66,13 @@ public function testInterfaceMethods(\ReflectionMethod $method)

$driver = $this->getMockForAbstractClass('Behat\Mink\Driver\CoreDriver');

$this->setExpectedException('Behat\Mink\Exception\UnsupportedDriverActionException');
if (method_exists($this, 'expectException')) {
$this->expectException('Behat\Mink\Exception\UnsupportedDriverActionException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('Behat\Mink\Exception\UnsupportedDriverActionException');
}

call_user_func_array(array($driver, $method->getName()), $this->getArguments($method));
}

Expand Down
63 changes: 56 additions & 7 deletions tests/Element/DocumentElementTest.php
Expand Up @@ -273,7 +273,14 @@ public function testClickLink()
);

$this->document->clickLink('some link');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');

if (method_exists($this, 'expectException')) {
$this->expectException('Behat\Mink\Exception\ElementNotFoundException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
}

$this->document->clickLink('some link');
}

Expand All @@ -293,7 +300,14 @@ public function testClickButton()
);

$this->document->pressButton('some button');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');

if (method_exists($this, 'expectException')) {
$this->expectException('Behat\Mink\Exception\ElementNotFoundException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
}

$this->document->pressButton('some button');
}

Expand All @@ -314,7 +328,14 @@ public function testFillField()
);

$this->document->fillField('some field', 'some val');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');

if (method_exists($this, 'expectException')) {
$this->expectException('Behat\Mink\Exception\ElementNotFoundException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
}

$this->document->fillField('some field', 'some val');
}

Expand All @@ -334,7 +355,14 @@ public function testCheckField()
);

$this->document->checkField('some field');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');

if (method_exists($this, 'expectException')) {
$this->expectException('Behat\Mink\Exception\ElementNotFoundException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
}

$this->document->checkField('some field');
}

Expand All @@ -354,7 +382,14 @@ public function testUncheckField()
);

$this->document->uncheckField('some field');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');

if (method_exists($this, 'expectException')) {
$this->expectException('Behat\Mink\Exception\ElementNotFoundException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
}

$this->document->uncheckField('some field');
}

Expand All @@ -375,7 +410,14 @@ public function testSelectField()
);

$this->document->selectFieldOption('some field', 'option2');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');

if (method_exists($this, 'expectException')) {
$this->expectException('Behat\Mink\Exception\ElementNotFoundException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
}

$this->document->selectFieldOption('some field', 'option2');
}

Expand All @@ -396,7 +438,14 @@ public function testAttachFileToField()
);

$this->document->attachFileToField('some field', '/path/to/file');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');

if (method_exists($this, 'expectException')) {
$this->expectException('Behat\Mink\Exception\ElementNotFoundException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
}

$this->document->attachFileToField('some field', '/path/to/file');
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Element/ElementTest.php
Expand Up @@ -5,8 +5,9 @@
use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Session;
use Behat\Mink\Selector\SelectorsHandler;
use PHPUnit\Framework\TestCase;

abstract class ElementTest extends \PHPUnit_Framework_TestCase
abstract class ElementTest extends TestCase
{
/**
* Session.
Expand Down
2 changes: 1 addition & 1 deletion tests/Element/NodeElementTest.php
Expand Up @@ -489,7 +489,7 @@ public function testDragTo()
{
$node = new NodeElement('some_tag1', $this->session);

$target = $this->getMock('Behat\Mink\Element\ElementInterface');
$target = $this->getMockBuilder('Behat\Mink\Element\ElementInterface')->getMock();
$target->expects($this->any())
->method('getXPath')
->will($this->returnValue('some_tag2'));
Expand Down
3 changes: 2 additions & 1 deletion tests/Exception/ElementExceptionTest.php
Expand Up @@ -3,11 +3,12 @@
namespace Behat\Mink\Tests\Exception;

use Behat\Mink\Exception\ElementException;
use PHPUnit\Framework\TestCase;

/**
* @group legacy
*/
class ElementExceptionTest extends \PHPUnit_Framework_TestCase
class ElementExceptionTest extends TestCase
{
public function testMessage()
{
Expand Down
5 changes: 3 additions & 2 deletions tests/Exception/ElementHtmlExceptionTest.php
Expand Up @@ -3,12 +3,13 @@
namespace Behat\Mink\Tests\Exception;

use Behat\Mink\Exception\ElementHtmlException;
use PHPUnit\Framework\TestCase;

class ElementHtmlExceptionTest extends \PHPUnit_Framework_TestCase
class ElementHtmlExceptionTest extends TestCase
{
public function testExceptionToString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();
$element = $this->getElementMock();

$driver->expects($this->any())
Expand Down
7 changes: 4 additions & 3 deletions tests/Exception/ElementNotFoundExceptionTest.php
Expand Up @@ -3,15 +3,16 @@
namespace Behat\Mink\Tests\Exception;

use Behat\Mink\Exception\ElementNotFoundException;
use PHPUnit\Framework\TestCase;

class ElementNotFoundExceptionTest extends \PHPUnit_Framework_TestCase
class ElementNotFoundExceptionTest extends TestCase
{
/**
* @dataProvider provideExceptionMessage
*/
public function testBuildMessage($message, $type, $selector = null, $locator = null)
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();

$exception = new ElementNotFoundException($driver, $type, $selector, $locator);

Expand All @@ -35,7 +36,7 @@ public function provideExceptionMessage()
*/
public function testConstructWithSession()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();
$session = $this->getMockBuilder('Behat\Mink\Session')
->disableOriginalConstructor()
->getMock();
Expand Down
5 changes: 3 additions & 2 deletions tests/Exception/ElementTextExceptionTest.php
Expand Up @@ -3,12 +3,13 @@
namespace Behat\Mink\Tests\Exception;

use Behat\Mink\Exception\ElementTextException;
use PHPUnit\Framework\TestCase;

class ElementTextExceptionTest extends \PHPUnit_Framework_TestCase
class ElementTextExceptionTest extends TestCase
{
public function testExceptionToString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();
$element = $this->getElementMock();

$driver->expects($this->any())
Expand Down
13 changes: 7 additions & 6 deletions tests/Exception/ExpectationExceptionTest.php
Expand Up @@ -3,19 +3,20 @@
namespace Behat\Mink\Tests\Exception;

use Behat\Mink\Exception\ExpectationException;
use PHPUnit\Framework\TestCase;

class ExpectationExceptionTest extends \PHPUnit_Framework_TestCase
class ExpectationExceptionTest extends TestCase
{
public function testEmptyMessageAndPreviousException()
{
$exception = new ExpectationException('', $this->getMock('Behat\Mink\Driver\DriverInterface'), new \Exception('Something failed'));
$exception = new ExpectationException('', $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock(), new \Exception('Something failed'));

$this->assertEquals('Something failed', $exception->getMessage());
}

public function testExceptionToString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();

$driver->expects($this->any())
->method('getStatusCode')
Expand Down Expand Up @@ -50,7 +51,7 @@ public function testExceptionToString()

public function testBigContent()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();

$driver->expects($this->any())
->method('getStatusCode')
Expand Down Expand Up @@ -84,7 +85,7 @@ public function testBigContent()

public function testExceptionWhileRenderingString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();
$driver->expects($this->any())
->method('getContent')
->will($this->throwException(new \Exception('Broken page')));
Expand All @@ -99,7 +100,7 @@ public function testExceptionWhileRenderingString()
*/
public function testConstructWithSession()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();
$session = $this->getMockBuilder('Behat\Mink\Session')
->disableOriginalConstructor()
->getMock();
Expand Down
5 changes: 3 additions & 2 deletions tests/Exception/ResponseTextExceptionTest.php
Expand Up @@ -3,12 +3,13 @@
namespace Behat\Mink\Tests\Exception;

use Behat\Mink\Exception\ResponseTextException;
use PHPUnit\Framework\TestCase;

class ResponseTextExceptionTest extends \PHPUnit_Framework_TestCase
class ResponseTextExceptionTest extends TestCase
{
public function testExceptionToString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();

$driver->expects($this->any())
->method('getStatusCode')
Expand Down
31 changes: 26 additions & 5 deletions tests/MinkTest.php
Expand Up @@ -3,8 +3,9 @@
namespace Behat\Mink\Tests;

use Behat\Mink\Mink;
use PHPUnit\Framework\TestCase;

class MinkTest extends \PHPUnit_Framework_TestCase
class MinkTest extends TestCase
{
/**
* @var Mink
Expand Down Expand Up @@ -70,7 +71,12 @@ public function testNotStartedSession()
$this->mink->registerSession('mock_session', $session);
$this->assertSame($session, $this->mink->getSession('mock_session'));

$this->setExpectedException('InvalidArgumentException');
if (method_exists($this, 'expectException')) {
$this->expectException('InvalidArgumentException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('InvalidArgumentException');
}

$this->mink->getSession('not_registered');
}
Expand All @@ -85,7 +91,12 @@ public function testSetDefaultSessionName()

$this->assertEquals('session_name', $this->mink->getDefaultSessionName());

$this->setExpectedException('InvalidArgumentException');
if (method_exists($this, 'expectException')) {
$this->expectException('InvalidArgumentException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('InvalidArgumentException');
}

$this->mink->setDefaultSessionName('not_registered');
}
Expand Down Expand Up @@ -116,7 +127,12 @@ public function testGetNoDefaultSession()

$this->mink->registerSession('session_1', $session1);

$this->setExpectedException('InvalidArgumentException');
if (method_exists($this, 'expectException')) {
$this->expectException('InvalidArgumentException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('InvalidArgumentException');
}

$this->mink->getSession();
}
Expand Down Expand Up @@ -148,7 +164,12 @@ public function testIsSessionStarted()
$this->mink->registerSession('started', $session_2);
$this->assertTrue($this->mink->isSessionStarted('started'));

$this->setExpectedException('InvalidArgumentException');
if (method_exists($this, 'expectException')) {
$this->expectException('InvalidArgumentException');
} else {
// BC with PHPUnit 4 used for PHP 5.5 and older
$this->setExpectedException('InvalidArgumentException');
}

$this->mink->getSession('not_registered');
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Selector/CssSelectorTest.php
Expand Up @@ -3,8 +3,9 @@
namespace Behat\Mink\Tests\Selector;

use Behat\Mink\Selector\CssSelector;
use PHPUnit\Framework\TestCase;

class CssSelectorTest extends \PHPUnit_Framework_TestCase
class CssSelectorTest extends TestCase
{
protected function setUp()
{
Expand Down

0 comments on commit e5338f0

Please sign in to comment.