initial commit
This commit is contained in:
67
vendor/symfony/dom-crawler/Test/Constraint/CrawlerAnySelectorTextContains.php
vendored
Normal file
67
vendor/symfony/dom-crawler/Test/Constraint/CrawlerAnySelectorTextContains.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DomCrawler\Test\Constraint;
|
||||
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
final class CrawlerAnySelectorTextContains extends Constraint
|
||||
{
|
||||
private bool $hasNode = false;
|
||||
|
||||
public function __construct(
|
||||
private string $selector,
|
||||
private string $expectedText,
|
||||
) {
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
if ($this->hasNode) {
|
||||
return \sprintf('the text of any node matching selector "%s" contains "%s"', $this->selector, $this->expectedText);
|
||||
}
|
||||
|
||||
return \sprintf('the Crawler has a node matching selector "%s"', $this->selector);
|
||||
}
|
||||
|
||||
protected function matches($other): bool
|
||||
{
|
||||
if (!$other instanceof Crawler) {
|
||||
throw new \InvalidArgumentException(\sprintf('"%s" constraint expected an argument of type "%s", got "%s".', self::class, Crawler::class, get_debug_type($other)));
|
||||
}
|
||||
|
||||
$other = $other->filter($this->selector);
|
||||
if (!\count($other)) {
|
||||
$this->hasNode = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->hasNode = true;
|
||||
|
||||
$nodes = $other->each(fn (Crawler $node) => $node->text(null, true));
|
||||
$matches = array_filter($nodes, function (string $node): bool {
|
||||
return str_contains($node, $this->expectedText);
|
||||
});
|
||||
|
||||
return 0 < \count($matches);
|
||||
}
|
||||
|
||||
protected function failureDescription($other): string
|
||||
{
|
||||
if (!$other instanceof Crawler) {
|
||||
throw new \InvalidArgumentException(\sprintf('"%s" constraint expected an argument of type "%s", got "%s".', self::class, Crawler::class, get_debug_type($other)));
|
||||
}
|
||||
|
||||
return $this->toString();
|
||||
}
|
||||
}
|
||||
54
vendor/symfony/dom-crawler/Test/Constraint/CrawlerAnySelectorTextSame.php
vendored
Normal file
54
vendor/symfony/dom-crawler/Test/Constraint/CrawlerAnySelectorTextSame.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DomCrawler\Test\Constraint;
|
||||
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
final class CrawlerAnySelectorTextSame extends Constraint
|
||||
{
|
||||
public function __construct(
|
||||
private string $selector,
|
||||
private string $expectedText,
|
||||
) {
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return \sprintf('has at least a node matching selector "%s" with content "%s"', $this->selector, $this->expectedText);
|
||||
}
|
||||
|
||||
protected function matches($other): bool
|
||||
{
|
||||
if (!$other instanceof Crawler) {
|
||||
throw new \InvalidArgumentException(\sprintf('"%s" constraint expected an argument of type "%s", got "%s".', self::class, Crawler::class, get_debug_type($other)));
|
||||
}
|
||||
|
||||
$other = $other->filter($this->selector);
|
||||
if (!\count($other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$nodes = $other->each(fn (Crawler $node) => trim($node->text(null, true)));
|
||||
|
||||
return \in_array($this->expectedText, $nodes, true);
|
||||
}
|
||||
|
||||
protected function failureDescription($other): string
|
||||
{
|
||||
if (!$other instanceof Crawler) {
|
||||
throw new \InvalidArgumentException(\sprintf('"%s" constraint expected an argument of type "%s", got "%s".', self::class, Crawler::class, get_debug_type($other)));
|
||||
}
|
||||
|
||||
return 'the Crawler '.$this->toString();
|
||||
}
|
||||
}
|
||||
51
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorAttributeValueSame.php
vendored
Normal file
51
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorAttributeValueSame.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DomCrawler\Test\Constraint;
|
||||
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
final class CrawlerSelectorAttributeValueSame extends Constraint
|
||||
{
|
||||
public function __construct(
|
||||
private string $selector,
|
||||
private string $attribute,
|
||||
private string $expectedText,
|
||||
) {
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return \sprintf('has a node matching selector "%s" with attribute "%s" of value "%s"', $this->selector, $this->attribute, $this->expectedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
45
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorCount.php
vendored
Normal file
45
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorCount.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DomCrawler\Test\Constraint;
|
||||
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
final class CrawlerSelectorCount extends Constraint
|
||||
{
|
||||
public function __construct(
|
||||
private readonly int $count,
|
||||
private readonly string $selector,
|
||||
) {
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return \sprintf('selector "%s" count is "%d"', $this->selector, $this->count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Crawler $crawler
|
||||
*/
|
||||
protected function matches($crawler): bool
|
||||
{
|
||||
return $this->count === \count($crawler->filter($this->selector));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Crawler $crawler
|
||||
*/
|
||||
protected function failureDescription($crawler): string
|
||||
{
|
||||
return \sprintf('the Crawler selector "%s" was expected to be found %d time(s) but was found %d time(s)', $this->selector, $this->count, \count($crawler->filter($this->selector)));
|
||||
}
|
||||
}
|
||||
44
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorExists.php
vendored
Normal file
44
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorExists.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DomCrawler\Test\Constraint;
|
||||
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
final class CrawlerSelectorExists extends Constraint
|
||||
{
|
||||
public function __construct(
|
||||
private string $selector,
|
||||
) {
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return \sprintf('matches selector "%s"', $this->selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Crawler $crawler
|
||||
*/
|
||||
protected function matches($crawler): bool
|
||||
{
|
||||
return 0 < \count($crawler->filter($this->selector));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Crawler $crawler
|
||||
*/
|
||||
protected function failureDescription($crawler): string
|
||||
{
|
||||
return 'the Crawler '.$this->toString();
|
||||
}
|
||||
}
|
||||
62
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorTextContains.php
vendored
Normal file
62
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorTextContains.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DomCrawler\Test\Constraint;
|
||||
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
final class CrawlerSelectorTextContains extends Constraint
|
||||
{
|
||||
private bool $hasNode = false;
|
||||
private string $nodeText;
|
||||
|
||||
public function __construct(
|
||||
private string $selector,
|
||||
private string $expectedText,
|
||||
) {
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
if ($this->hasNode) {
|
||||
return \sprintf('the text "%s" of the node matching selector "%s" contains "%s"', $this->nodeText, $this->selector, $this->expectedText);
|
||||
}
|
||||
|
||||
return \sprintf('the Crawler has a node matching selector "%s"', $this->selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Crawler $crawler
|
||||
*/
|
||||
protected function matches($crawler): bool
|
||||
{
|
||||
$crawler = $crawler->filter($this->selector);
|
||||
if (!\count($crawler)) {
|
||||
$this->hasNode = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->hasNode = true;
|
||||
$this->nodeText = $crawler->text(null, true);
|
||||
|
||||
return str_contains($this->nodeText, $this->expectedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Crawler $crawler
|
||||
*/
|
||||
protected function failureDescription($crawler): string
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
}
|
||||
50
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorTextSame.php
vendored
Normal file
50
vendor/symfony/dom-crawler/Test/Constraint/CrawlerSelectorTextSame.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DomCrawler\Test\Constraint;
|
||||
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
final class CrawlerSelectorTextSame extends Constraint
|
||||
{
|
||||
public function __construct(
|
||||
private string $selector,
|
||||
private string $expectedText,
|
||||
) {
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return \sprintf('has a node matching selector "%s" with content "%s"', $this->selector, $this->expectedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Crawler $crawler
|
||||
*/
|
||||
protected function matches($crawler): bool
|
||||
{
|
||||
$crawler = $crawler->filter($this->selector);
|
||||
if (!\count($crawler)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->expectedText === trim($crawler->text(null, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Crawler $crawler
|
||||
*/
|
||||
protected function failureDescription($crawler): string
|
||||
{
|
||||
return 'the Crawler '.$this->toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user