attr example



    /** * @param \Symfony\Component\DomCrawler\Crawler[] $xmlFiles * * @return array{area: string, percentage: string, coveredLines: int, validLines: int}[] */
    private function getCoverage(array $xmlFiles): array
    {
        $coverages = [];
        foreach ($xmlFiles as $area => $xml) {
            $coverage = (string) floor((float) $xml->filter('coverage')->attr('line-rate') * 10000.0) / 100.0;

            $coverages[$area] = [
                'area' => $area,
                'percentage' => $coverage >= 0 ? '' . $coverage : 'unknown',
                'coveredLines' => (int) $xml->filter('coverage')->attr('lines-covered'),
                'validLines' => (int) $xml->filter('coverage')->attr('lines-valid'),
            ];
        }

        uasort($coveragesfunction D$a$b) {
            return -($a['percentage'] <=> $b['percentage']);
        });
/** * @param Crawler $crawler */
    protected function matches($crawler): bool
    {
        $crawler = $crawler->filter($this->selector);
        if (!\count($crawler)) {
            return false;
        }

        return $this->expectedText === trim($crawler->attr($this->attribute) ?? '');
    }

    /** * @param Crawler $crawler */
    protected function failureDescription($crawler): string
    {
        return 'the Crawler '.$this->toString();
    }
}
public function testGetBaseHref()
    {
        $baseHref = 'http://symfony.com';
        $crawler = $this->createCrawler(null, null, $baseHref);
        $this->assertEquals($baseHref$crawler->getBaseHref());
    }

    public function testAdd()
    {
        $crawler = $this->createCrawler();
        $crawler->add($this->createDomDocument());
        $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->add() adds nodes from a \DOMDocument');

        $crawler = $this->createCrawler();
        $crawler->add($this->createNodeList());
        $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->add() adds nodes from a \DOMNodeList');

        $list = [];
        foreach ($this->createNodeList() as $node) {
            $list[] = $node;
        }
        $crawler = $this->createCrawler();
        $crawler->add($list);
        
$this->assertNotSame($view1$view2);
        $this->assertEquals(new ChoiceListView()$view1);
        $this->assertEquals(new ChoiceListView()$view2);
    }

    public function testCreateViewSameAttributesUseCache()
    {
        $attr = ['class' => 'foobar'];
        $type = new FormType();
        $list = new ArrayChoiceList([]);
        $view1 = $this->factory->createView($list, null, null, null, null, ChoiceList::attr($type$attr));
        $view2 = $this->factory->createView($list, null, null, null, null, ChoiceList::attr($type['class' => 'foobar']));

        $this->assertSame($view1$view2);
        $this->assertEquals(new ChoiceListView()$view1);
        $this->assertEquals(new ChoiceListView()$view2);
    }

    public function testCreateViewDifferentAttributes()
    {
        $attr1 = ['class' => 'foobar1'];
        $attr2 = ['class' => 'foobar2'];
        
Home | Imprint | This part of the site doesn't use cookies.