Skip to content

Commit 0ebb8d7

Browse files
committed
Merge branch '5.2' into 5.x
* 5.2: Use ::class keyword when possible
2 parents a777d47 + a9dab73 commit 0ebb8d7

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

Tests/AbstractCrawlerTest.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ public function testAdd()
8181

8282
public function testAddInvalidType()
8383
{
84-
$this->expectException('InvalidArgumentException');
84+
$this->expectException(\InvalidArgumentException::class);
8585
$crawler = $this->createCrawler();
8686
$crawler->add(1);
8787
}
8888

8989
public function testAddMultipleDocumentNode()
9090
{
91-
$this->expectException('InvalidArgumentException');
91+
$this->expectException(\InvalidArgumentException::class);
9292
$this->expectExceptionMessage('Attaching DOM nodes from multiple documents in the same crawler is forbidden.');
9393
$crawler = $this->createTestCrawler();
9494
$crawler->addHtmlContent($this->getDoctype().'<html><div class="foo"></html>', 'UTF-8');
@@ -250,7 +250,7 @@ public function testEq()
250250
{
251251
$crawler = $this->createTestCrawler()->filterXPath('//li');
252252
$this->assertNotSame($crawler, $crawler->eq(0), '->eq() returns a new instance of a crawler');
253-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->eq(0), '->eq() returns a new instance of a crawler');
253+
$this->assertInstanceOf(Crawler::class, $crawler->eq(0), '->eq() returns a new instance of a crawler');
254254

255255
$this->assertEquals('Two', $crawler->eq(1)->text(), '->eq() returns the nth node of the list');
256256
$this->assertCount(0, $crawler->eq(100), '->eq() returns an empty crawler if the nth node does not exist');
@@ -276,15 +276,15 @@ public function testIteration()
276276
{
277277
$crawler = $this->createTestCrawler()->filterXPath('//li');
278278

279-
$this->assertInstanceOf('Traversable', $crawler);
279+
$this->assertInstanceOf(\Traversable::class, $crawler);
280280
$this->assertContainsOnlyInstancesOf('DOMElement', iterator_to_array($crawler), 'Iterating a Crawler gives DOMElement instances');
281281
}
282282

283283
public function testSlice()
284284
{
285285
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');
286286
$this->assertNotSame($crawler->slice(), $crawler, '->slice() returns a new instance of a crawler');
287-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->slice(), '->slice() returns a new instance of a crawler');
287+
$this->assertInstanceOf(Crawler::class, $crawler->slice(), '->slice() returns a new instance of a crawler');
288288

289289
$this->assertCount(3, $crawler->slice(), '->slice() does not slice the nodes in the list if any param is entered');
290290
$this->assertCount(1, $crawler->slice(1, 1), '->slice() slices the nodes in the list');
@@ -297,7 +297,7 @@ public function testReduce()
297297
return 1 !== $i;
298298
});
299299
$this->assertNotSame($nodes, $crawler, '->reduce() returns a new instance of a crawler');
300-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $nodes, '->reduce() returns a new instance of a crawler');
300+
$this->assertInstanceOf(Crawler::class, $nodes, '->reduce() returns a new instance of a crawler');
301301

302302
$this->assertCount(2, $nodes, '->reduce() filters the nodes in the list');
303303
}
@@ -406,7 +406,7 @@ public function testFilterXPath()
406406
{
407407
$crawler = $this->createTestCrawler();
408408
$this->assertNotSame($crawler, $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
409-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
409+
$this->assertInstanceOf(Crawler::class, $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
410410

411411
$crawler = $this->createTestCrawler()->filterXPath('//ul');
412412
$this->assertCount(6, $crawler->filterXPath('//li'), '->filterXPath() filters the node list with the XPath expression');
@@ -573,7 +573,7 @@ public function testFilter()
573573
{
574574
$crawler = $this->createTestCrawler();
575575
$this->assertNotSame($crawler, $crawler->filter('li'), '->filter() returns a new instance of a crawler');
576-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->filter('li'), '->filter() returns a new instance of a crawler');
576+
$this->assertInstanceOf(Crawler::class, $crawler->filter('li'), '->filter() returns a new instance of a crawler');
577577

578578
$crawler = $this->createTestCrawler()->filter('ul');
579579

@@ -626,7 +626,7 @@ public function testSelectLink()
626626
{
627627
$crawler = $this->createTestCrawler();
628628
$this->assertNotSame($crawler, $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
629-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
629+
$this->assertInstanceOf(Crawler::class, $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
630630

631631
$this->assertCount(1, $crawler->selectLink('Fabien\'s Foo'), '->selectLink() selects links by the node values');
632632
$this->assertCount(1, $crawler->selectLink('Fabien\'s Bar'), '->selectLink() selects links by the alt attribute of a clickable image');
@@ -645,7 +645,7 @@ public function testSelectImage()
645645
{
646646
$crawler = $this->createTestCrawler();
647647
$this->assertNotSame($crawler, $crawler->selectImage('Bar'), '->selectImage() returns a new instance of a crawler');
648-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->selectImage('Bar'), '->selectImage() returns a new instance of a crawler');
648+
$this->assertInstanceOf(Crawler::class, $crawler->selectImage('Bar'), '->selectImage() returns a new instance of a crawler');
649649

650650
$this->assertCount(1, $crawler->selectImage('Fabien\'s Bar'), '->selectImage() selects images by alt attribute');
651651
$this->assertCount(2, $crawler->selectImage('Fabien"s Bar'), '->selectImage() selects images by alt attribute');
@@ -656,7 +656,7 @@ public function testSelectButton()
656656
{
657657
$crawler = $this->createTestCrawler();
658658
$this->assertNotSame($crawler, $crawler->selectButton('FooValue'), '->selectButton() returns a new instance of a crawler');
659-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->selectButton('FooValue'), '->selectButton() returns a new instance of a crawler');
659+
$this->assertInstanceOf(Crawler::class, $crawler->selectButton('FooValue'), '->selectButton() returns a new instance of a crawler');
660660

661661
$this->assertEquals(1, $crawler->selectButton('FooValue')->count(), '->selectButton() selects buttons');
662662
$this->assertEquals(1, $crawler->selectButton('FooName')->count(), '->selectButton() selects buttons');
@@ -713,7 +713,7 @@ public function testSelectButtonWithDoubleQuotesInNameAttribute()
713713
public function testLink()
714714
{
715715
$crawler = $this->createTestCrawler('http://example.com/bar/')->selectLink('Foo');
716-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Link', $crawler->link(), '->link() returns a Link instance');
716+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Link::class, $crawler->link(), '->link() returns a Link instance');
717717

718718
$this->assertEquals('POST', $crawler->link('post')->getMethod(), '->link() takes a method as its argument');
719719

@@ -730,15 +730,15 @@ public function testLink()
730730

731731
public function testInvalidLink()
732732
{
733-
$this->expectException('InvalidArgumentException');
733+
$this->expectException(\InvalidArgumentException::class);
734734
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
735735
$crawler = $this->createTestCrawler('http://example.com/bar/');
736736
$crawler->filterXPath('//li/text()')->link();
737737
}
738738

739739
public function testInvalidLinks()
740740
{
741-
$this->expectException('InvalidArgumentException');
741+
$this->expectException(\InvalidArgumentException::class);
742742
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
743743
$crawler = $this->createTestCrawler('http://example.com/bar/');
744744
$crawler->filterXPath('//li/text()')->link();
@@ -747,7 +747,7 @@ public function testInvalidLinks()
747747
public function testImage()
748748
{
749749
$crawler = $this->createTestCrawler('http://example.com/bar/')->selectImage('Bar');
750-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Image', $crawler->image(), '->image() returns an Image instance');
750+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Image::class, $crawler->image(), '->image() returns an Image instance');
751751

752752
try {
753753
$this->createTestCrawler()->filterXPath('//ol')->image();
@@ -823,8 +823,8 @@ public function testForm()
823823
$testCrawler = $this->createTestCrawler('http://example.com/bar/');
824824
$crawler = $testCrawler->selectButton('FooValue');
825825
$crawler2 = $testCrawler->selectButton('FooBarValue');
826-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Form', $crawler->form(), '->form() returns a Form instance');
827-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Form', $crawler2->form(), '->form() returns a Form instance');
826+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Form::class, $crawler->form(), '->form() returns a Form instance');
827+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Form::class, $crawler2->form(), '->form() returns a Form instance');
828828

829829
$this->assertEquals($crawler->form()->getFormNode()->getAttribute('id'), $crawler2->form()->getFormNode()->getAttribute('id'), '->form() works on elements with form attribute');
830830

@@ -842,7 +842,7 @@ public function testForm()
842842

843843
public function testInvalidForm()
844844
{
845-
$this->expectException('InvalidArgumentException');
845+
$this->expectException(\InvalidArgumentException::class);
846846
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
847847
$crawler = $this->createTestCrawler('http://example.com/bar/');
848848
$crawler->filterXPath('//li/text()')->form();
@@ -852,7 +852,7 @@ public function testLast()
852852
{
853853
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');
854854
$this->assertNotSame($crawler, $crawler->last(), '->last() returns a new instance of a crawler');
855-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->last(), '->last() returns a new instance of a crawler');
855+
$this->assertInstanceOf(Crawler::class, $crawler->last(), '->last() returns a new instance of a crawler');
856856

857857
$this->assertEquals('Three', $crawler->last()->text());
858858
}
@@ -861,7 +861,7 @@ public function testFirst()
861861
{
862862
$crawler = $this->createTestCrawler()->filterXPath('//li');
863863
$this->assertNotSame($crawler, $crawler->first(), '->first() returns a new instance of a crawler');
864-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->first(), '->first() returns a new instance of a crawler');
864+
$this->assertInstanceOf(Crawler::class, $crawler->first(), '->first() returns a new instance of a crawler');
865865

866866
$this->assertEquals('One', $crawler->first()->text());
867867
}
@@ -870,7 +870,7 @@ public function testSiblings()
870870
{
871871
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(1);
872872
$this->assertNotSame($crawler, $crawler->siblings(), '->siblings() returns a new instance of a crawler');
873-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->siblings(), '->siblings() returns a new instance of a crawler');
873+
$this->assertInstanceOf(Crawler::class, $crawler->siblings(), '->siblings() returns a new instance of a crawler');
874874

875875
$nodes = $crawler->siblings();
876876
$this->assertEquals(2, $nodes->count());
@@ -993,7 +993,7 @@ public function testNextAll()
993993
{
994994
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(1);
995995
$this->assertNotSame($crawler, $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
996-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
996+
$this->assertInstanceOf(Crawler::class, $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
997997

998998
$nodes = $crawler->nextAll();
999999
$this->assertEquals(1, $nodes->count());
@@ -1011,7 +1011,7 @@ public function testPreviousAll()
10111011
{
10121012
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(2);
10131013
$this->assertNotSame($crawler, $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
1014-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
1014+
$this->assertInstanceOf(Crawler::class, $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
10151015

10161016
$nodes = $crawler->previousAll();
10171017
$this->assertEquals(2, $nodes->count());
@@ -1029,7 +1029,7 @@ public function testChildren()
10291029
{
10301030
$crawler = $this->createTestCrawler()->filterXPath('//ul');
10311031
$this->assertNotSame($crawler, $crawler->children(), '->children() returns a new instance of a crawler');
1032-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->children(), '->children() returns a new instance of a crawler');
1032+
$this->assertInstanceOf(Crawler::class, $crawler->children(), '->children() returns a new instance of a crawler');
10331033

10341034
$nodes = $crawler->children();
10351035
$this->assertEquals(3, $nodes->count());
@@ -1094,7 +1094,7 @@ public function testParents()
10941094

10951095
$crawler = $this->createTestCrawler()->filterXPath('//li[1]');
10961096
$this->assertNotSame($crawler, $crawler->parents(), '->parents() returns a new instance of a crawler');
1097-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->parents(), '->parents() returns a new instance of a crawler');
1097+
$this->assertInstanceOf(Crawler::class, $crawler->parents(), '->parents() returns a new instance of a crawler');
10981098

10991099
$nodes = $crawler->parents();
11001100
$this->assertEquals(3, $nodes->count());
@@ -1219,7 +1219,7 @@ public function testEvaluateReturnsACrawlerIfXPathExpressionEvaluatesToANode()
12191219

12201220
public function testEvaluateThrowsAnExceptionIfDocumentIsEmpty()
12211221
{
1222-
$this->expectException('LogicException');
1222+
$this->expectException(\LogicException::class);
12231223
$this->createCrawler()->evaluate('//form/input[1]');
12241224
}
12251225

Tests/FormTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FormTest extends TestCase
2121
public static function setUpBeforeClass(): void
2222
{
2323
// Ensure that the private helper class FormFieldRegistry is loaded
24-
class_exists('Symfony\\Component\\DomCrawler\\Form');
24+
class_exists(Form::class);
2525
}
2626

2727
public function testConstructorThrowsExceptionIfTheNodeHasNoFormAncestor()
@@ -70,7 +70,7 @@ public function testConstructorThrowsExceptionIfTheNodeHasNoFormAncestor()
7070
*/
7171
public function testConstructorThrowsExceptionIfNoRelatedForm(\DOMElement $node)
7272
{
73-
$this->expectException('LogicException');
73+
$this->expectException(\LogicException::class);
7474

7575
new Form($node, 'http://example.com');
7676
}
@@ -682,7 +682,7 @@ public function testGet()
682682
{
683683
$form = $this->createForm('<form method="post"><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
684684

685-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Field\\InputFormField', $form->get('bar'), '->get() returns the field object associated with the given name');
685+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Field\InputFormField::class, $form->get('bar'), '->get() returns the field object associated with the given name');
686686

687687
try {
688688
$form->get('foo');
@@ -698,7 +698,7 @@ public function testAll()
698698

699699
$fields = $form->all();
700700
$this->assertCount(1, $fields, '->all() return an array of form field objects');
701-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Field\\InputFormField', $fields['bar'], '->all() return an array of form field objects');
701+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Field\InputFormField::class, $fields['bar'], '->all() return an array of form field objects');
702702
}
703703

704704
public function testSubmitWithoutAFormButton()
@@ -741,14 +741,14 @@ public function testFormFieldRegistryAcceptAnyNames()
741741

742742
public function testFormFieldRegistryGetThrowAnExceptionWhenTheFieldDoesNotExist()
743743
{
744-
$this->expectException('InvalidArgumentException');
744+
$this->expectException(\InvalidArgumentException::class);
745745
$registry = new FormFieldRegistry();
746746
$registry->get('foo');
747747
}
748748

749749
public function testFormFieldRegistrySetThrowAnExceptionWhenTheFieldDoesNotExist()
750750
{
751-
$this->expectException('InvalidArgumentException');
751+
$this->expectException(\InvalidArgumentException::class);
752752
$registry = new FormFieldRegistry();
753753
$registry->set('foo', null);
754754
}
@@ -827,7 +827,7 @@ public function testFormRegistrySetValues()
827827

828828
public function testFormRegistrySetValueOnCompoundField()
829829
{
830-
$this->expectException('InvalidArgumentException');
830+
$this->expectException(\InvalidArgumentException::class);
831831
$this->expectExceptionMessage('Cannot set value on a compound field "foo[bar]".');
832832
$registry = new FormFieldRegistry();
833833
$registry->add($this->getFormFieldMock('foo[bar][baz]'));
@@ -837,7 +837,7 @@ public function testFormRegistrySetValueOnCompoundField()
837837

838838
public function testFormRegistrySetArrayOnNotCompoundField()
839839
{
840-
$this->expectException('InvalidArgumentException');
840+
$this->expectException(\InvalidArgumentException::class);
841841
$this->expectExceptionMessage('Unreachable field "0"');
842842
$registry = new FormFieldRegistry();
843843
$registry->add($this->getFormFieldMock('bar'));
@@ -864,13 +864,13 @@ public function testDifferentFieldTypesWithSameName()
864864
');
865865
$form = new Form($dom->getElementsByTagName('form')->item(0), 'http://example.com');
866866

867-
$this->assertInstanceOf('Symfony\Component\DomCrawler\Field\ChoiceFormField', $form->get('option'));
867+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Field\ChoiceFormField::class, $form->get('option'));
868868
}
869869

870870
protected function getFormFieldMock($name, $value = null)
871871
{
872872
$field = $this
873-
->getMockBuilder('Symfony\\Component\\DomCrawler\\Field\\FormField')
873+
->getMockBuilder(\Symfony\Component\DomCrawler\Field\FormField::class)
874874
->setMethods(['getName', 'getValue', 'setValue', 'initialize'])
875875
->disableOriginalConstructor()
876876
->getMock()

Tests/ImageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ImageTest extends TestCase
1818
{
1919
public function testConstructorWithANonImgTag()
2020
{
21-
$this->expectException('LogicException');
21+
$this->expectException(\LogicException::class);
2222
$dom = new \DOMDocument();
2323
$dom->loadHTML('<html><div><div></html>');
2424

@@ -36,7 +36,7 @@ public function testBaseUriIsOptionalWhenImageUrlIsAbsolute()
3636

3737
public function testAbsoluteBaseUriIsMandatoryWhenImageUrlIsRelative()
3838
{
39-
$this->expectException('InvalidArgumentException');
39+
$this->expectException(\InvalidArgumentException::class);
4040
$dom = new \DOMDocument();
4141
$dom->loadHTML('<html><img alt="foo" src="/foo" /></html>');
4242

Tests/LinkTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LinkTest extends TestCase
1818
{
1919
public function testConstructorWithANonATag()
2020
{
21-
$this->expectException('LogicException');
21+
$this->expectException(\LogicException::class);
2222
$dom = new \DOMDocument();
2323
$dom->loadHTML('<html><div><div></html>');
2424

@@ -36,7 +36,7 @@ public function testBaseUriIsOptionalWhenLinkUrlIsAbsolute()
3636

3737
public function testAbsoluteBaseUriIsMandatoryWhenLinkUrlIsRelative()
3838
{
39-
$this->expectException('InvalidArgumentException');
39+
$this->expectException(\InvalidArgumentException::class);
4040
$dom = new \DOMDocument();
4141
$dom->loadHTML('<html><a href="/foo">foo</a></html>');
4242

0 commit comments

Comments
 (0)