Skip to content

Commit dd19ac3

Browse files
committed
Fixes code review issues.
1 parent 34f39d8 commit dd19ac3

File tree

3 files changed

+143
-45
lines changed

3 files changed

+143
-45
lines changed

tests/Helper/Stringer.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Behat\Mink\Tests\Helper;
4+
5+
/**
6+
* A container class to hold a string.
7+
*
8+
* @package Behat\Mink\Tests\helpers
9+
*/
10+
class Stringer
11+
{
12+
13+
/**
14+
* Internal storage.
15+
*
16+
* @var string
17+
*/
18+
private $content;
19+
20+
/**
21+
* Stringer constructor.
22+
*
23+
* @param string $content
24+
*/
25+
public function __construct($content)
26+
{
27+
$this->content = $content;
28+
}
29+
30+
/**
31+
* Returns the wrapped string.
32+
*
33+
* @return string
34+
*/
35+
public function __toString()
36+
{
37+
return $this->content;
38+
}
39+
40+
}

tests/WebAssertTest.php

+103-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Behat\Mink\Tests;
44

55
use Behat\Mink\Exception\ExpectationException;
6-
use Behat\Mink\Tests\helpers\Stringer;
6+
use Behat\Mink\Tests\Helper\Stringer;
77
use Behat\Mink\WebAssert;
88
use PHPUnit\Framework\TestCase;
99

@@ -256,7 +256,7 @@ public function testResponseHeaderContains()
256256
)
257257
));
258258

259-
$this->assertCorrectAssertion('responseHeaderContains', array('foo', new Stringer('ba')));
259+
$this->assertCorrectAssertion('responseHeaderContains', array('foo', 'ba'));
260260
$this->assertWrongAssertion(
261261
'responseHeaderContains',
262262
array('bar', 'bz'),
@@ -277,6 +277,50 @@ public function testResponseHeaderNotContains()
277277
)
278278
));
279279

280+
$this->assertCorrectAssertion('responseHeaderNotContains', array('foo', 'bz'));
281+
$this->assertWrongAssertion(
282+
'responseHeaderNotContains',
283+
array('bar', 'ba'),
284+
'Behat\\Mink\\Exception\\ExpectationException',
285+
'The text "ba" was found in the "bar" response header, but it should not.'
286+
);
287+
}
288+
289+
public function testResponseHeaderContainsObjectWithToString()
290+
{
291+
$this->session
292+
->expects($this->any())
293+
->method('getResponseHeader')
294+
->will($this->returnValueMap(
295+
array(
296+
array('foo', 'bar'),
297+
array('bar', 'baz'),
298+
)
299+
));
300+
301+
$this->assertCorrectAssertion('responseHeaderContains', array('foo', new Stringer('ba')));
302+
$this->assertWrongAssertion(
303+
'responseHeaderContains',
304+
array('bar', 'bz'),
305+
'Behat\\Mink\\Exception\\ExpectationException',
306+
'The text "bz" was not found anywhere in the "bar" response header.'
307+
);
308+
}
309+
310+
public function testResponseHeaderNotContainsObjectWithToString()
311+
{
312+
$this->session
313+
->expects($this->any())
314+
->method('getResponseHeader')
315+
->will(
316+
$this->returnValueMap(
317+
array(
318+
array('foo', 'bar'),
319+
array('bar', 'baz'),
320+
)
321+
)
322+
);
323+
280324
$this->assertCorrectAssertion('responseHeaderNotContains', array('foo', new Stringer('bz')));
281325
$this->assertWrongAssertion(
282326
'responseHeaderNotContains',
@@ -459,7 +503,7 @@ public function testResponseContains()
459503
->will($this->returnValue('Some page text'))
460504
;
461505

462-
$this->assertCorrectAssertion('responseContains', array(new Stringer('PAGE text')));
506+
$this->assertCorrectAssertion('responseContains', array('PAGE text'));
463507
$this->assertWrongAssertion(
464508
'responseContains',
465509
array('html text'),
@@ -487,6 +531,62 @@ public function testResponseNotContains()
487531
->will($this->returnValue('Some html text'))
488532
;
489533

534+
$this->assertCorrectAssertion('responseNotContains', array('PAGE text'));
535+
$this->assertWrongAssertion(
536+
'responseNotContains',
537+
array('HTML text'),
538+
'Behat\\Mink\\Exception\\ExpectationException',
539+
'The string "HTML text" appears in the HTML response of this page, but it should not.'
540+
);
541+
}
542+
543+
public function testResponseContainsObjectWithToString()
544+
{
545+
$page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')
546+
->disableOriginalConstructor()
547+
->getMock()
548+
;
549+
550+
$this->session
551+
->expects($this->exactly(2))
552+
->method('getPage')
553+
->will($this->returnValue($page))
554+
;
555+
556+
$page
557+
->expects($this->exactly(2))
558+
->method('getContent')
559+
->will($this->returnValue('Some page text'))
560+
;
561+
562+
$this->assertCorrectAssertion('responseContains', array(new Stringer('PAGE text')));
563+
$this->assertWrongAssertion(
564+
'responseContains',
565+
array('html text'),
566+
'Behat\\Mink\\Exception\\ExpectationException',
567+
'The string "html text" was not found anywhere in the HTML response of the current page.'
568+
);
569+
}
570+
571+
public function testResponseNotContainsObjectWithToString()
572+
{
573+
$page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')
574+
->disableOriginalConstructor()
575+
->getMock()
576+
;
577+
578+
$this->session
579+
->expects($this->exactly(2))
580+
->method('getPage')
581+
->will($this->returnValue($page))
582+
;
583+
584+
$page
585+
->expects($this->exactly(2))
586+
->method('getContent')
587+
->will($this->returnValue('Some html text'))
588+
;
589+
490590
$this->assertCorrectAssertion('responseNotContains', array(new Stringer('PAGE text')));
491591
$this->assertWrongAssertion(
492592
'responseNotContains',

tests/helpers/Stringer.php

-42
This file was deleted.

0 commit comments

Comments
 (0)