Skip to content

Commit 2b078cc

Browse files
committed
Use ::class keyword when possible
1 parent ebcfbb5 commit 2b078cc

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');
@@ -282,15 +282,15 @@ public function testIteration()
282282
{
283283
$crawler = $this->createTestCrawler()->filterXPath('//li');
284284

285-
$this->assertInstanceOf('Traversable', $crawler);
285+
$this->assertInstanceOf(\Traversable::class, $crawler);
286286
$this->assertContainsOnlyInstancesOf('DOMElement', iterator_to_array($crawler), 'Iterating a Crawler gives DOMElement instances');
287287
}
288288

289289
public function testSlice()
290290
{
291291
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');
292292
$this->assertNotSame($crawler->slice(), $crawler, '->slice() returns a new instance of a crawler');
293-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->slice(), '->slice() returns a new instance of a crawler');
293+
$this->assertInstanceOf(Crawler::class, $crawler->slice(), '->slice() returns a new instance of a crawler');
294294

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

308308
$this->assertCount(2, $nodes, '->reduce() filters the nodes in the list');
309309
}
@@ -412,7 +412,7 @@ public function testFilterXPath()
412412
{
413413
$crawler = $this->createTestCrawler();
414414
$this->assertNotSame($crawler, $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
415-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
415+
$this->assertInstanceOf(Crawler::class, $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
416416

417417
$crawler = $this->createTestCrawler()->filterXPath('//ul');
418418
$this->assertCount(6, $crawler->filterXPath('//li'), '->filterXPath() filters the node list with the XPath expression');
@@ -579,7 +579,7 @@ public function testFilter()
579579
{
580580
$crawler = $this->createTestCrawler();
581581
$this->assertNotSame($crawler, $crawler->filter('li'), '->filter() returns a new instance of a crawler');
582-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->filter('li'), '->filter() returns a new instance of a crawler');
582+
$this->assertInstanceOf(Crawler::class, $crawler->filter('li'), '->filter() returns a new instance of a crawler');
583583

584584
$crawler = $this->createTestCrawler()->filter('ul');
585585

@@ -632,7 +632,7 @@ public function testSelectLink()
632632
{
633633
$crawler = $this->createTestCrawler();
634634
$this->assertNotSame($crawler, $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
635-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
635+
$this->assertInstanceOf(Crawler::class, $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
636636

637637
$this->assertCount(1, $crawler->selectLink('Fabien\'s Foo'), '->selectLink() selects links by the node values');
638638
$this->assertCount(1, $crawler->selectLink('Fabien\'s Bar'), '->selectLink() selects links by the alt attribute of a clickable image');
@@ -651,7 +651,7 @@ public function testSelectImage()
651651
{
652652
$crawler = $this->createTestCrawler();
653653
$this->assertNotSame($crawler, $crawler->selectImage('Bar'), '->selectImage() returns a new instance of a crawler');
654-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->selectImage('Bar'), '->selectImage() returns a new instance of a crawler');
654+
$this->assertInstanceOf(Crawler::class, $crawler->selectImage('Bar'), '->selectImage() returns a new instance of a crawler');
655655

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

667667
$this->assertEquals(1, $crawler->selectButton('FooValue')->count(), '->selectButton() selects buttons');
668668
$this->assertEquals(1, $crawler->selectButton('FooName')->count(), '->selectButton() selects buttons');
@@ -719,7 +719,7 @@ public function testSelectButtonWithDoubleQuotesInNameAttribute()
719719
public function testLink()
720720
{
721721
$crawler = $this->createTestCrawler('http://example.com/bar/')->selectLink('Foo');
722-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Link', $crawler->link(), '->link() returns a Link instance');
722+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Link::class, $crawler->link(), '->link() returns a Link instance');
723723

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

@@ -736,15 +736,15 @@ public function testLink()
736736

737737
public function testInvalidLink()
738738
{
739-
$this->expectException('InvalidArgumentException');
739+
$this->expectException(\InvalidArgumentException::class);
740740
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
741741
$crawler = $this->createTestCrawler('http://example.com/bar/');
742742
$crawler->filterXPath('//li/text()')->link();
743743
}
744744

745745
public function testInvalidLinks()
746746
{
747-
$this->expectException('InvalidArgumentException');
747+
$this->expectException(\InvalidArgumentException::class);
748748
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
749749
$crawler = $this->createTestCrawler('http://example.com/bar/');
750750
$crawler->filterXPath('//li/text()')->link();
@@ -753,7 +753,7 @@ public function testInvalidLinks()
753753
public function testImage()
754754
{
755755
$crawler = $this->createTestCrawler('http://example.com/bar/')->selectImage('Bar');
756-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Image', $crawler->image(), '->image() returns an Image instance');
756+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Image::class, $crawler->image(), '->image() returns an Image instance');
757757

758758
try {
759759
$this->createTestCrawler()->filterXPath('//ol')->image();
@@ -829,8 +829,8 @@ public function testForm()
829829
$testCrawler = $this->createTestCrawler('http://example.com/bar/');
830830
$crawler = $testCrawler->selectButton('FooValue');
831831
$crawler2 = $testCrawler->selectButton('FooBarValue');
832-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Form', $crawler->form(), '->form() returns a Form instance');
833-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Form', $crawler2->form(), '->form() returns a Form instance');
832+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Form::class, $crawler->form(), '->form() returns a Form instance');
833+
$this->assertInstanceOf(\Symfony\Component\DomCrawler\Form::class, $crawler2->form(), '->form() returns a Form instance');
834834

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

@@ -848,7 +848,7 @@ public function testForm()
848848

849849
public function testInvalidForm()
850850
{
851-
$this->expectException('InvalidArgumentException');
851+
$this->expectException(\InvalidArgumentException::class);
852852
$this->expectExceptionMessage('The selected node should be instance of DOMElement');
853853
$crawler = $this->createTestCrawler('http://example.com/bar/');
854854
$crawler->filterXPath('//li/text()')->form();
@@ -858,7 +858,7 @@ public function testLast()
858858
{
859859
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');
860860
$this->assertNotSame($crawler, $crawler->last(), '->last() returns a new instance of a crawler');
861-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->last(), '->last() returns a new instance of a crawler');
861+
$this->assertInstanceOf(Crawler::class, $crawler->last(), '->last() returns a new instance of a crawler');
862862

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

872872
$this->assertEquals('One', $crawler->first()->text());
873873
}
@@ -876,7 +876,7 @@ public function testSiblings()
876876
{
877877
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(1);
878878
$this->assertNotSame($crawler, $crawler->siblings(), '->siblings() returns a new instance of a crawler');
879-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->siblings(), '->siblings() returns a new instance of a crawler');
879+
$this->assertInstanceOf(Crawler::class, $crawler->siblings(), '->siblings() returns a new instance of a crawler');
880880

881881
$nodes = $crawler->siblings();
882882
$this->assertEquals(2, $nodes->count());
@@ -999,7 +999,7 @@ public function testNextAll()
999999
{
10001000
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(1);
10011001
$this->assertNotSame($crawler, $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
1002-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
1002+
$this->assertInstanceOf(Crawler::class, $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
10031003

10041004
$nodes = $crawler->nextAll();
10051005
$this->assertEquals(1, $nodes->count());
@@ -1017,7 +1017,7 @@ public function testPreviousAll()
10171017
{
10181018
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(2);
10191019
$this->assertNotSame($crawler, $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
1020-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
1020+
$this->assertInstanceOf(Crawler::class, $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
10211021

10221022
$nodes = $crawler->previousAll();
10231023
$this->assertEquals(2, $nodes->count());
@@ -1035,7 +1035,7 @@ public function testChildren()
10351035
{
10361036
$crawler = $this->createTestCrawler()->filterXPath('//ul');
10371037
$this->assertNotSame($crawler, $crawler->children(), '->children() returns a new instance of a crawler');
1038-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->children(), '->children() returns a new instance of a crawler');
1038+
$this->assertInstanceOf(Crawler::class, $crawler->children(), '->children() returns a new instance of a crawler');
10391039

10401040
$nodes = $crawler->children();
10411041
$this->assertEquals(3, $nodes->count());
@@ -1095,7 +1095,7 @@ public function testParents()
10951095
{
10961096
$crawler = $this->createTestCrawler()->filterXPath('//li[1]');
10971097
$this->assertNotSame($crawler, $crawler->parents(), '->parents() returns a new instance of a crawler');
1098-
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->parents(), '->parents() returns a new instance of a crawler');
1098+
$this->assertInstanceOf(Crawler::class, $crawler->parents(), '->parents() returns a new instance of a crawler');
10991099

11001100
$nodes = $crawler->parents();
11011101
$this->assertEquals(3, $nodes->count());
@@ -1199,7 +1199,7 @@ public function testEvaluateReturnsACrawlerIfXPathExpressionEvaluatesToANode()
11991199

12001200
public function testEvaluateThrowsAnExceptionIfDocumentIsEmpty()
12011201
{
1202-
$this->expectException('LogicException');
1202+
$this->expectException(\LogicException::class);
12031203
$this->createCrawler()->evaluate('//form/input[1]');
12041204
}
12051205

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)