Skip to content
ElementTextExceptionTest.php 1.23 KiB
Newer Older
<?php

namespace Behat\Mink\Tests\Exception;

use Behat\Mink\Exception\ElementTextException;

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

            ->method('getStatusCode')
            ->will($this->returnValue(200));
            ->method('getCurrentUrl')
            ->will($this->returnValue('http://localhost/test'));

        $element->expects($this->any())
            ->method('getText')
            ->will($this->returnValue("Hello world\nTest\n"));

        $expected = <<<'TXT'
Text error

+--[ HTTP/1.1 200 | http://localhost/test | %s ]
|
|  Hello world
|  Test
|
TXT;

        $expected = sprintf($expected.'  ', get_class($driver));

        $exception = new ElementTextException('Text error', $driver, $element);

        $this->assertEquals($expected, $exception->__toString());
    }

    private function getElementMock()
    {
        return $this->getMockBuilder('Behat\Mink\Element\NodeElement')
            ->disableOriginalConstructor()
            ->getMock();
    }
}