diff --git a/src/Symfony/Components/DomCrawler/Crawler.php b/src/Symfony/Components/DomCrawler/Crawler.php index 1f3abfe6c22c..9039801b996f 100644 --- a/src/Symfony/Components/DomCrawler/Crawler.php +++ b/src/Symfony/Components/DomCrawler/Crawler.php @@ -173,16 +173,6 @@ public function addNode(\DOMNode $node) } } - /** - * Returns true if the list of nodes is empty. - * - * @return Boolean true if the list of nodes is empty, false otherwise - */ - public function isEmpty() - { - return $this->count() < 1; - } - /** * Returns a node given its position in the node list. * @@ -265,7 +255,7 @@ public function first() */ public function last() { - return $this->eq($this->count() - 1); + return $this->eq(count($this) - 1); } /** diff --git a/tests/Symfony/Tests/Components/DomCrawler/CrawlerTest.php b/tests/Symfony/Tests/Components/DomCrawler/CrawlerTest.php index 76c70d6199aa..b633e8198f40 100644 --- a/tests/Symfony/Tests/Components/DomCrawler/CrawlerTest.php +++ b/tests/Symfony/Tests/Components/DomCrawler/CrawlerTest.php @@ -94,7 +94,7 @@ public function testAddContent() $crawler = new Crawler(); $crawler->addContent('foo bar', 'text/plain'); - $this->assertEquals(0, $crawler->count(), '->addContent() does nothing if the type is not (x|ht)ml'); + $this->assertEquals(0, count($crawler), '->addContent() does nothing if the type is not (x|ht)ml'); } /** @@ -152,14 +152,6 @@ public function testClear() $this->assertEquals(0, count($crawler), '->clear() removes all the nodes from the crawler'); } - public function testIsEmpty() - { - $crawler = new Crawler(new \DOMNode()); - $this->assertFalse($crawler->isEmpty(), '->isEmpty() returns false if the crawler node list is not empty'); - $crawler->clear(); - $this->assertTrue($crawler->isEmpty(), '->isEmpty() returns true if the crawler node list is empty'); - } - public function testEq() { $crawler = $this->createTestCrawler()->filter('li'); @@ -167,7 +159,7 @@ public function testEq() $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->eq() returns a new instance of a crawler'); $this->assertEquals('Two', $crawler->eq(1)->text(), '->eq() returns the nth node of the list'); - $this->assertTrue($crawler->eq(100)->isEmpty(), '->eq() returns an empty crawler if the nth node does not exist'); + $this->assertEquals(0, count($crawler->eq(100)), '->eq() returns an empty crawler if the nth node does not exist'); } public function testEach() @@ -238,7 +230,7 @@ public function testFilterXPath() $crawler = $this->createTestCrawler()->filter('ul'); - $this->assertEquals(6, $crawler->filterXPath('//li')->count(), '->filterXPath() filters the node list with the XPath expression'); + $this->assertEquals(6, count($crawler->filterXPath('//li')), '->filterXPath() filters the node list with the XPath expression'); } /** @@ -252,7 +244,7 @@ public function testFilter() $crawler = $this->createTestCrawler()->filter('ul'); - $this->assertEquals(6, $crawler->filter('li')->count(), '->filter() filters the node list with the CSS selector'); + $this->assertEquals(6, count($crawler->filter('li')), '->filter() filters the node list with the CSS selector'); } public function testSelectLink() @@ -261,17 +253,17 @@ public function testSelectLink() $this->assertNotSame($crawler, $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler'); $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->selectLink() returns a new instance of a crawler'); - $this->assertEquals(1, $crawler->selectLink('Fabien\'s Foo')->count(), '->selectLink() selects links by the node values'); - $this->assertEquals(1, $crawler->selectLink('Fabien\'s Bar')->count(), '->selectLink() selects links by the alt attribute of a clickable image'); + $this->assertEquals(1, count($crawler->selectLink('Fabien\'s Foo')), '->selectLink() selects links by the node values'); + $this->assertEquals(1, count($crawler->selectLink('Fabien\'s Bar')), '->selectLink() selects links by the alt attribute of a clickable image'); - $this->assertEquals(2, $crawler->selectLink('Fabien"s Foo')->count(), '->selectLink() selects links by the node values'); - $this->assertEquals(2, $crawler->selectLink('Fabien"s Bar')->count(), '->selectLink() selects links by the alt attribute of a clickable image'); + $this->assertEquals(2, count($crawler->selectLink('Fabien"s Foo')), '->selectLink() selects links by the node values'); + $this->assertEquals(2, count($crawler->selectLink('Fabien"s Bar')), '->selectLink() selects links by the alt attribute of a clickable image'); - $this->assertEquals(1, $crawler->selectLink('\' Fabien"s Foo')->count(), '->selectLink() selects links by the node values'); - $this->assertEquals(1, $crawler->selectLink('\' Fabien"s Bar')->count(), '->selectLink() selects links by the alt attribute of a clickable image'); + $this->assertEquals(1, count($crawler->selectLink('\' Fabien"s Foo')), '->selectLink() selects links by the node values'); + $this->assertEquals(1, count($crawler->selectLink('\' Fabien"s Bar')), '->selectLink() selects links by the alt attribute of a clickable image'); - $this->assertEquals(4, $crawler->selectLink('Foo')->count(), '->selectLink() selects links by the node values'); - $this->assertEquals(4, $crawler->selectLink('Bar')->count(), '->selectLink() selects links by the node values'); + $this->assertEquals(4, count($crawler->selectLink('Foo')), '->selectLink() selects links by the node values'); + $this->assertEquals(4, count($crawler->selectLink('Bar')), '->selectLink() selects links by the node values'); } public function testSelectButton()