Skip to content

Commit a9dab73

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: Use ::class keyword when possible
2 parents 1b61da4 + 2b078cc commit a9dab73

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
@@ -78,14 +78,14 @@ public function testAdd()
7878

7979
public function testAddInvalidType()
8080
{
81-
$this->expectException('InvalidArgumentException');
81+
$this->expectException(\InvalidArgumentException::class);
8282
$crawler = $this->createCrawler();
8383
$crawler->add(1);
8484
}
8585

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

252252
$this->assertEquals('Two', $crawler->eq(1)->text(), '->eq() returns the nth node of the list');
253253
$this->assertCount(0, $crawler->eq(100), '->eq() returns an empty crawler if the nth node does not exist');
@@ -273,15 +273,15 @@ public function testIteration()
273273
{
274274
$crawler = $this->createTestCrawler()->filterXPath('//li');
275275

276-
$this->assertInstanceOf('Traversable', $crawler);
276+
$this->assertInstanceOf(\Traversable::class, $crawler);
277277
$this->assertContainsOnlyInstancesOf('DOMElement', iterator_to_array($crawler), 'Iterating a Crawler gives DOMElement instances');
278278
}
279279

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

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

299299
$this->assertCount(2, $nodes, '->reduce() filters the nodes in the list');
300300
}
@@ -403,7 +403,7 @@ public function testFilterXPath()
403403
{
404404
$crawler = $this->createTestCrawler();
405405
$this->assertNotSame($crawler, $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
406-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
406+
$this->assertInstanceOf(Crawler::class, $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
407407

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

575575
$crawler = $this->createTestCrawler()->filter('ul');
576576

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

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

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

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

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

@@ -727,15 +727,15 @@ public function testLink()
727727

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

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

749749
try {
750750
$this->createTestCrawler()->filterXPath('//ol')->image();
@@ -820,8 +820,8 @@ public function testForm()
820820
$testCrawler = $this->createTestCrawler('http://example.com/bar/');
821821
$crawler = $testCrawler->selectButton('FooValue');
822822
$crawler2 = $testCrawler->selectButton('FooBarValue');
823-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Form', $crawler->form(), '->form() returns a Form instance');
824-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Form', $crawler2->form(), '->form() returns a Form instance');
823+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Form::class, $crawler->form(), '->form() returns a Form instance');
824+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Form::class, $crawler2->form(), '->form() returns a Form instance');
825825

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

@@ -839,7 +839,7 @@ public function testForm()
839839

840840
public function testInvalidForm()
841841
{
842-
$this->expectException('InvalidArgumentException');
842+
$this->expectException(\InvalidArgumentException::class);
843843
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
844844
$crawler = $this->createTestCrawler('http://example.com/bar/');
845845
$crawler->filterXPath('//li/text()')->form();
@@ -849,7 +849,7 @@ public function testLast()
849849
{
850850
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');
851851
$this->assertNotSame($crawler, $crawler->last(), '->last() returns a new instance of a crawler');
852-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->last(), '->last() returns a new instance of a crawler');
852+
$this->assertInstanceOf(Crawler::class, $crawler->last(), '->last() returns a new instance of a crawler');
853853

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

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

872872
$nodes = $crawler->siblings();
873873
$this->assertEquals(2, $nodes->count());
@@ -990,7 +990,7 @@ public function testNextAll()
990990
{
991991
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(1);
992992
$this->assertNotSame($crawler, $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
993-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
993+
$this->assertInstanceOf(Crawler::class, $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
994994

995995
$nodes = $crawler->nextAll();
996996
$this->assertEquals(1, $nodes->count());
@@ -1008,7 +1008,7 @@ public function testPreviousAll()
10081008
{
10091009
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(2);
10101010
$this->assertNotSame($crawler, $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
1011-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
1011+
$this->assertInstanceOf(Crawler::class, $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
10121012

10131013
$nodes = $crawler->previousAll();
10141014
$this->assertEquals(2, $nodes->count());
@@ -1026,7 +1026,7 @@ public function testChildren()
10261026
{
10271027
$crawler = $this->createTestCrawler()->filterXPath('//ul');
10281028
$this->assertNotSame($crawler, $crawler->children(), '->children() returns a new instance of a crawler');
1029-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->children(), '->children() returns a new instance of a crawler');
1029+
$this->assertInstanceOf(Crawler::class, $crawler->children(), '->children() returns a new instance of a crawler');
10301030

10311031
$nodes = $crawler->children();
10321032
$this->assertEquals(3, $nodes->count());
@@ -1086,7 +1086,7 @@ public function testParents()
10861086
{
10871087
$crawler = $this->createTestCrawler()->filterXPath('//li[1]');
10881088
$this->assertNotSame($crawler, $crawler->parents(), '->parents() returns a new instance of a crawler');
1089-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->parents(), '->parents() returns a new instance of a crawler');
1089+
$this->assertInstanceOf(Crawler::class, $crawler->parents(), '->parents() returns a new instance of a crawler');
10901090

10911091
$nodes = $crawler->parents();
10921092
$this->assertEquals(3, $nodes->count());
@@ -1190,7 +1190,7 @@ public function testEvaluateReturnsACrawlerIfXPathExpressionEvaluatesToANode()
11901190

11911191
public function testEvaluateThrowsAnExceptionIfDocumentIsEmpty()
11921192
{
1193-
$this->expectException('LogicException');
1193+
$this->expectException(\LogicException::class);
11941194
$this->createCrawler()->evaluate('//form/input[1]');
11951195
}
11961196

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)