Skip to content

Commit

Permalink
Fixes code review issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasd committed May 3, 2019
1 parent b1bf5ca commit 3cd36f0
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 45 deletions.
40 changes: 40 additions & 0 deletions tests/Helper/Stringer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Behat\Mink\Tests\Helper;

/**
* A container class to hold a string.
*
* @package Behat\Mink\Tests\helpers
*/
class Stringer
{

/**
* Internal storage.
*
* @var string
*/
private $content;

/**
* Stringer constructor.
*
* @param string $content
*/
public function __construct($content)
{
$this->content = $content;
}

/**
* Returns the wrapped string.
*
* @return string
*/
public function __toString()
{
return $this->content;
}

}
106 changes: 103 additions & 3 deletions tests/WebAssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Behat\Mink\Tests;

use Behat\Mink\Exception\ExpectationException;
use Behat\Mink\Tests\helpers\Stringer;
use Behat\Mink\Tests\Helper\Stringer;
use Behat\Mink\WebAssert;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -256,7 +256,7 @@ public function testResponseHeaderContains()
)
));

$this->assertCorrectAssertion('responseHeaderContains', array('foo', new Stringer('ba')));
$this->assertCorrectAssertion('responseHeaderContains', array('foo', 'ba'));
$this->assertWrongAssertion(
'responseHeaderContains',
array('bar', 'bz'),
Expand All @@ -277,6 +277,50 @@ public function testResponseHeaderNotContains()
)
));

$this->assertCorrectAssertion('responseHeaderNotContains', array('foo', 'bz'));
$this->assertWrongAssertion(
'responseHeaderNotContains',
array('bar', 'ba'),
'Behat\\Mink\\Exception\\ExpectationException',
'The text "ba" was found in the "bar" response header, but it should not.'
);
}

public function testResponseHeaderContainsObjectWithToString()
{
$this->session
->expects($this->any())
->method('getResponseHeader')
->will($this->returnValueMap(
array(
array('foo', 'bar'),
array('bar', 'baz'),
)
));

$this->assertCorrectAssertion('responseHeaderContains', array('foo', new Stringer('ba')));
$this->assertWrongAssertion(
'responseHeaderContains',
array('bar', 'bz'),
'Behat\\Mink\\Exception\\ExpectationException',
'The text "bz" was not found anywhere in the "bar" response header.'
);
}

public function testResponseHeaderNotContainsObjectWithToString()
{
$this->session
->expects($this->any())
->method('getResponseHeader')
->will(
$this->returnValueMap(
array(
array('foo', 'bar'),
array('bar', 'baz'),
)
)
);

$this->assertCorrectAssertion('responseHeaderNotContains', array('foo', new Stringer('bz')));
$this->assertWrongAssertion(
'responseHeaderNotContains',
Expand Down Expand Up @@ -459,7 +503,7 @@ public function testResponseContains()
->will($this->returnValue('Some page text'))
;

$this->assertCorrectAssertion('responseContains', array(new Stringer('PAGE text')));
$this->assertCorrectAssertion('responseContains', array('PAGE text'));
$this->assertWrongAssertion(
'responseContains',
array('html text'),
Expand Down Expand Up @@ -487,6 +531,62 @@ public function testResponseNotContains()
->will($this->returnValue('Some html text'))
;

$this->assertCorrectAssertion('responseNotContains', array('PAGE text'));
$this->assertWrongAssertion(
'responseNotContains',
array('HTML text'),
'Behat\\Mink\\Exception\\ExpectationException',
'The string "HTML text" appears in the HTML response of this page, but it should not.'
);
}

public function testResponseContainsObjectWithToString()
{
$page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')
->disableOriginalConstructor()
->getMock()
;

$this->session
->expects($this->exactly(2))
->method('getPage')
->will($this->returnValue($page))
;

$page
->expects($this->exactly(2))
->method('getContent')
->will($this->returnValue('Some page text'))
;

$this->assertCorrectAssertion('responseContains', array(new Stringer('PAGE text')));
$this->assertWrongAssertion(
'responseContains',
array('html text'),
'Behat\\Mink\\Exception\\ExpectationException',
'The string "html text" was not found anywhere in the HTML response of the current page.'
);
}

public function testResponseNotContainsObjectWithToString()
{
$page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')
->disableOriginalConstructor()
->getMock()
;

$this->session
->expects($this->exactly(2))
->method('getPage')
->will($this->returnValue($page))
;

$page
->expects($this->exactly(2))
->method('getContent')
->will($this->returnValue('Some html text'))
;

$this->assertCorrectAssertion('responseNotContains', array(new Stringer('PAGE text')));
$this->assertWrongAssertion(
'responseNotContains',
Expand Down
42 changes: 0 additions & 42 deletions tests/helpers/Stringer.php

This file was deleted.

0 comments on commit 3cd36f0

Please sign in to comment.