Skip to content

Commit 6a852f7

Browse files
Merge branch '4.4'
* 4.4: Fix tests Fix deprecated phpunit annotation
2 parents 5e54ee9 + 8742c0a commit 6a852f7

File tree

4 files changed

+28
-51
lines changed

4 files changed

+28
-51
lines changed

Tests/AbstractCrawlerTest.php

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,17 @@ public function testAdd()
7979
$this->assertEquals('Foo', $crawler->filterXPath('//body')->text(), '->add() adds nodes from a string');
8080
}
8181

82-
/**
83-
* @expectedException \InvalidArgumentException
84-
*/
8582
public function testAddInvalidType()
8683
{
84+
$this->expectException('InvalidArgumentException');
8785
$crawler = $this->createCrawler();
8886
$crawler->add(1);
8987
}
9088

91-
/**
92-
* @expectedException \InvalidArgumentException
93-
* @expectedExceptionMessage Attaching DOM nodes from multiple documents in the same crawler is forbidden.
94-
*/
9589
public function testAddMultipleDocumentNode()
9690
{
91+
$this->expectException('InvalidArgumentException');
92+
$this->expectExceptionMessage('Attaching DOM nodes from multiple documents in the same crawler is forbidden.');
9793
$crawler = $this->createTestCrawler();
9894
$crawler->addHtmlContent($this->getDoctype().'<html><div class="foo"></html>', 'UTF-8');
9995
}
@@ -725,22 +721,18 @@ public function testLink()
725721
}
726722
}
727723

728-
/**
729-
* @expectedException \InvalidArgumentException
730-
* @expectedExceptionMessage The selected node should be instance of DOMElement
731-
*/
732724
public function testInvalidLink()
733725
{
726+
$this->expectException('InvalidArgumentException');
727+
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
734728
$crawler = $this->createTestCrawler('http://example.com/bar/');
735729
$crawler->filterXPath('//li/text()')->link();
736730
}
737731

738-
/**
739-
* @expectedException \InvalidArgumentException
740-
* @expectedExceptionMessage The selected node should be instance of DOMElement
741-
*/
742732
public function testInvalidLinks()
743733
{
734+
$this->expectException('InvalidArgumentException');
735+
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
744736
$crawler = $this->createTestCrawler('http://example.com/bar/');
745737
$crawler->filterXPath('//li/text()')->link();
746738
}
@@ -841,12 +833,10 @@ public function testForm()
841833
}
842834
}
843835

844-
/**
845-
* @expectedException \InvalidArgumentException
846-
* @expectedExceptionMessage The selected node should be instance of DOMElement
847-
*/
848836
public function testInvalidForm()
849837
{
838+
$this->expectException('InvalidArgumentException');
839+
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
850840
$crawler = $this->createTestCrawler('http://example.com/bar/');
851841
$crawler->filterXPath('//li/text()')->form();
852842
}
@@ -954,7 +944,7 @@ public function testChildren()
954944
$this->assertTrue(true, '->children() does not trigger a notice if the node has no children');
955945
} catch (\PHPUnit\Framework\Error\Notice $e) {
956946
$this->fail('->children() does not trigger a notice if the node has no children');
957-
} catch (\PHPUnit_Framework_Error_Notice $e) {
947+
} catch (\PHPUnit\Framework\Error\Notice $e) {
958948
$this->fail('->children() does not trigger a notice if the node has no children');
959949
}
960950
}
@@ -1095,11 +1085,9 @@ public function testEvaluateReturnsACrawlerIfXPathExpressionEvaluatesToANode()
10951085
$this->assertSame('input', $crawler->first()->nodeName());
10961086
}
10971087

1098-
/**
1099-
* @expectedException \LogicException
1100-
*/
11011088
public function testEvaluateThrowsAnExceptionIfDocumentIsEmpty()
11021089
{
1090+
$this->expectException('LogicException');
11031091
$this->createCrawler()->evaluate('//form/input[1]');
11041092
}
11051093

Tests/FormTest.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ public function testConstructorThrowsExceptionIfTheNodeHasNoFormAncestor()
6767

6868
/**
6969
* __construct() should throw \\LogicException if the form attribute is invalid.
70-
*
71-
* @expectedException \LogicException
7270
*/
7371
public function testConstructorThrowsExceptionIfNoRelatedForm()
7472
{
73+
$this->expectException('LogicException');
7574
$dom = new \DOMDocument();
7675
$dom->loadHTML('
7776
<html>
@@ -729,20 +728,16 @@ public function testFormFieldRegistryAcceptAnyNames()
729728
$registry->remove('[t:dbt%3adate;]data_daterange_enddate_value');
730729
}
731730

732-
/**
733-
* @expectedException \InvalidArgumentException
734-
*/
735731
public function testFormFieldRegistryGetThrowAnExceptionWhenTheFieldDoesNotExist()
736732
{
733+
$this->expectException('InvalidArgumentException');
737734
$registry = new FormFieldRegistry();
738735
$registry->get('foo');
739736
}
740737

741-
/**
742-
* @expectedException \InvalidArgumentException
743-
*/
744738
public function testFormFieldRegistrySetThrowAnExceptionWhenTheFieldDoesNotExist()
745739
{
740+
$this->expectException('InvalidArgumentException');
746741
$registry = new FormFieldRegistry();
747742
$registry->set('foo', null);
748743
}
@@ -819,24 +814,20 @@ public function testFormRegistrySetValues()
819814
]);
820815
}
821816

822-
/**
823-
* @expectedException \InvalidArgumentException
824-
* @expectedExceptionMessage Cannot set value on a compound field "foo[bar]".
825-
*/
826817
public function testFormRegistrySetValueOnCompoundField()
827818
{
819+
$this->expectException('InvalidArgumentException');
820+
$this->expectExceptionMessage('Cannot set value on a compound field "foo[bar]".');
828821
$registry = new FormFieldRegistry();
829822
$registry->add($this->getFormFieldMock('foo[bar][baz]'));
830823

831824
$registry->set('foo[bar]', 'fbb');
832825
}
833826

834-
/**
835-
* @expectedException \InvalidArgumentException
836-
* @expectedExceptionMessage Unreachable field "0"
837-
*/
838827
public function testFormRegistrySetArrayOnNotCompoundField()
839828
{
829+
$this->expectException('InvalidArgumentException');
830+
$this->expectExceptionMessage('Unreachable field "0"');
840831
$registry = new FormFieldRegistry();
841832
$registry->add($this->getFormFieldMock('bar'));
842833

Tests/ImageTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
namespace Symfony\Component\DomCrawler\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\DomCrawler\Image;
1617

1718
class ImageTest extends TestCase
1819
{
19-
/**
20-
* @expectedException \LogicException
21-
*/
20+
use ForwardCompatTestTrait;
21+
2222
public function testConstructorWithANonImgTag()
2323
{
24+
$this->expectException('LogicException');
2425
$dom = new \DOMDocument();
2526
$dom->loadHTML('<html><div><div></html>');
2627

@@ -36,11 +37,9 @@ public function testBaseUriIsOptionalWhenImageUrlIsAbsolute()
3637
$this->assertSame('https://example.com/foo', $image->getUri());
3738
}
3839

39-
/**
40-
* @expectedException \InvalidArgumentException
41-
*/
4240
public function testAbsoluteBaseUriIsMandatoryWhenImageUrlIsRelative()
4341
{
42+
$this->expectException('InvalidArgumentException');
4443
$dom = new \DOMDocument();
4544
$dom->loadHTML('<html><img alt="foo" src="/foo" /></html>');
4645

Tests/LinkTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
namespace Symfony\Component\DomCrawler\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\DomCrawler\Link;
1617

1718
class LinkTest extends TestCase
1819
{
19-
/**
20-
* @expectedException \LogicException
21-
*/
20+
use ForwardCompatTestTrait;
21+
2222
public function testConstructorWithANonATag()
2323
{
24+
$this->expectException('LogicException');
2425
$dom = new \DOMDocument();
2526
$dom->loadHTML('<html><div><div></html>');
2627

@@ -36,11 +37,9 @@ public function testBaseUriIsOptionalWhenLinkUrlIsAbsolute()
3637
$this->assertSame('https://example.com/foo', $link->getUri());
3738
}
3839

39-
/**
40-
* @expectedException \InvalidArgumentException
41-
*/
4240
public function testAbsoluteBaseUriIsMandatoryWhenLinkUrlIsRelative()
4341
{
42+
$this->expectException('InvalidArgumentException');
4443
$dom = new \DOMDocument();
4544
$dom->loadHTML('<html><a href="/foo">foo</a></html>');
4645

0 commit comments

Comments
 (0)