Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/dom-crawler
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.4.48
Choose a base ref
...
head repository: symfony/dom-crawler
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.0.0
Choose a head ref

Commits on May 19, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    Josh-Cena Joshua Chen
    Copy the full SHA
    6de5fe2 View commit details
  2. Merge branch '5.4' into 6.0

    * 5.4:
      Allow Symfony 6
    derrabus committed May 19, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    Josh-Cena Joshua Chen
    Copy the full SHA
    32b6af4 View commit details

Commits on May 20, 2021

  1. Copy the full SHA
    10f1722 View commit details

Commits on May 22, 2021

  1. Copy the full SHA
    10d6d74 View commit details

Commits on May 26, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      Fix CS in README files
      Fix markdown
      [HttpKernel] Fixes tests for PHP7.4+
      fix test
      [HttpKernel] Throw when HttpKernel is created and the env is empty
      [FrameworkBundle] Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead
      [Filesystem] fix readlink for Windows
    nicolas-grekas committed May 26, 2021
    Copy the full SHA
    09e403d View commit details

Commits on Jun 2, 2021

  1. Copy the full SHA
    aee7c6a View commit details

Commits on Jun 21, 2021

  1. Remove code for old libxml versions

    Signed-off-by: Alexander M. Turek <me@derrabus.de>
    derrabus committed Jun 21, 2021
    Copy the full SHA
    ab4b299 View commit details

Commits on Jun 29, 2021

  1. Add union types

    nicolas-grekas committed Jun 29, 2021
    Copy the full SHA
    c055dcc View commit details

Commits on Jun 30, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      Fix tests
      CS fix
      CS fix
      CS fix
      CS fixes
      Bump Symfony version to 5.3.4
      Update VERSION for 5.3.3
      Update CHANGELOG for 5.3.3
      Bump Symfony version to 5.2.12
      Update VERSION for 5.2.11
      Update CHANGELOG for 5.2.11
      Bump Symfony version to 4.4.27
      Update VERSION for 4.4.26
      Update CONTRIBUTORS for 4.4.26
      Update CHANGELOG for 4.4.26
    nicolas-grekas committed Jun 30, 2021
    Copy the full SHA
    e0f6421 View commit details

Commits on Jul 7, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      [DomCrawler] Backport type fixes
      [FrameworkBundle] fix removing "action" from route names
    derrabus committed Jul 7, 2021
    Copy the full SHA
    57bcf7c View commit details
  2. Merge branch '5.4' into 6.0

    * 5.4:
      Fix CS
    derrabus committed Jul 7, 2021
    Copy the full SHA
    6d1375c View commit details
  3. Copy the full SHA
    7548764 View commit details

Commits on Jul 14, 2021

  1. Copy the full SHA
    8703e31 View commit details

Commits on Jul 21, 2021

  1. Copy the full SHA
    ea5b04f View commit details
  2. Merge branch '5.4' into 6.0

    * 5.4:
      Leverage str_contains/str_starts_with
      Leverage str_ends_with
    nicolas-grekas committed Jul 21, 2021
    Copy the full SHA
    6838e7c View commit details

Commits on Jul 23, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      [Cache] Add missing return type
      [5.2] Add missing `@return` annotations
      [4.4] Add missing `@return` annotations
      Handle lock with long key
      #42227 update phpdoc to recommend createIndex over ensureIndex
    nicolas-grekas committed Jul 23, 2021
    Copy the full SHA
    490fe1c View commit details

Commits on Aug 4, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      Fix return types for PHP 8.1
    derrabus committed Aug 4, 2021
    Copy the full SHA
    2da38bf View commit details

Commits on Aug 9, 2021

  1. Copy the full SHA
    fff99fd View commit details

Commits on Aug 10, 2021

  1. Remove ReturnTypeWillChange

    Signed-off-by: Alexander M. Turek <me@derrabus.de>
    derrabus committed Aug 10, 2021
    Copy the full SHA
    0542cbc View commit details

Commits on Aug 12, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      More return type fixes (bis)
      Cleanup `@return` annotations
    nicolas-grekas committed Aug 12, 2021
    Copy the full SHA
    9b2bc43 View commit details
  2. Copy the full SHA
    4c12f0d View commit details

Commits on Aug 17, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      [Serializer] cs fix
      Cleanup more `@return` annotations
      [Form] Fix phpdoc on FormBuilderInterface
    nicolas-grekas committed Aug 17, 2021
    Copy the full SHA
    392d486 View commit details

Commits on Aug 26, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      Fix skip condition for INTL
      [Messenger] Fix `ErrorDetailsStamp` denormalization
      [Translation] Extract translatable content on twig set
      Simplify code
      [FrameworkBundle] Add BrowserKitAssertionsTrait::assertThatForBrowser
      Fix composer.json versions
      [Ldap] Fixing the behaviour of getting LDAP Attributes
      Fix composer.json versions
      Remove redundant license info
      [HttpFoundation] Fix isNotModified determination logic
      Fix Url Validator false positives
      [Translation] Reverse fallback locales
      [Console] Backport minor refactorings
      [FrameworkBundle] Fall back to default configuration in debug:config and consistently resolve parameter values
      notifier smsapi - fixed checking whether message is sent
      allow null for framework.translator.default_path
      improve failure messages of the CrawlerSelectorTextContains constraint
    nicolas-grekas committed Aug 26, 2021
    Copy the full SHA
    19b541d View commit details

Commits on Aug 29, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      [Cache] Fix comment in MemcachedAdapter
      [SecurityBundle] Fix broken mock
      [DomCrawler] Don't pass null to trim()
    derrabus committed Aug 29, 2021
    Copy the full SHA
    e0f4d17 View commit details

Commits on Sep 7, 2021

  1. Copy the full SHA
    2794398 View commit details

Commits on Sep 9, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      [DoctrineBridge] Remove dead code
      [Lock] Remove unused variable
      [DoctrineBridge] Replace string with FQCN resolution in EntityType
      Add missing `@return $this` annotations
      [Notifier] Add missing types to SmscTransport
    nicolas-grekas committed Sep 9, 2021
    Copy the full SHA
    df890f9 View commit details

Commits on Sep 21, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      [Serializer] Save missing arguments in MissingConstructorArgumentsException
      remove support for deprecated "threadKey" parameter
      Remove useless comment in test
      [DomCrawler] Added Crawler::innerText() method
      [Form] Add the EnumType
      Fix iterrator in ServiceConfigurator
      [Console] Add support of RGB functional notation for output colors
      Add Slovak lang translation #41081
      [Validator] Add error's uid to `Count` and `Length` constraints with "exactly" option enabled
      [Validator] Add missing thai translation
      [Yaml] Add 0 to float repr
      [Translation] Add Burmese translation
      [Notifier] Update FirebaseTransport.php
      fix: #43086 remove shortcut e for option exclude of Yaml/LintCommand - solve conflict with --env -e
      Map `multipart/form-data` as `form` Content-Type
      [Serializer] Throw NotNormalizableValueException when type is not known or not in body in discriminator map
      [Yaml] Use more concise float representation in dump
      [FrameworkBundle] Remove translation data_collector BEFORE adding it to profiler
    derrabus committed Sep 21, 2021
    Copy the full SHA
    c878cb8 View commit details

Commits on Oct 5, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      fix SQLSRV throws for method_exists()
      [HttpKernel] Add basic support for language negotiation
      [Messenger] Add a middleware to log when transaction has been left open
      [HttpClient] Add method to set response factory in mock client
      Move array_merge calls out of loops to improve performance
      Remove references to DBALException
      [VarDumper] Fix handling of "new" in initializers on PHP 8.1
    derrabus committed Oct 5, 2021
    Copy the full SHA
    9c50d92 View commit details

Commits on Nov 3, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4:
      [Console] Restore psr/log >= 3.0 conflict
      [Security] Make the abstract Voter class implement CacheableVoterInterface
      Add generic types to traversable implementations
      [Security] Fix TypeError message
      [Security] Fix deprecation layer
      [FrameworkBundle] Add completion for workflow:dump
      Fix cancel button
      Fix misleading error on missing provider with authenticator manager
      Don't limit retries of toolbar loading
    derrabus committed Nov 3, 2021
    Copy the full SHA
    aa19861 View commit details

Commits on Nov 4, 2021

  1. Merge branch '5.4' into 6.0

    * 5.4: (27 commits)
      feat: add completion for DebugAutowiring search argument
      [Routing] Add support for aliasing routes
      [DependencyInjection] only allow `ReflectionNamedType` for `ServiceSubscriberTrait`
      Fix CS
      [Console] Open CompleteCommand for custom outputs
      [Intl] Update the ICU data to 70.1
      [Messenger] Add completion for failed messages commands.
      Fix tests
      Fixing missing full_stack variable that's needed by toolbar.html.twig
      [PropertyInfo] Bump phpstan/phpdoc-parser
      [Security] Backport type fixes
      [VarExporter] escape unicode chars involved in directionality
      [Framework] Add completion to debug:container
      [Messenger] Add completion to command messenger:consume
      [Intl] Update the ICU data to 70.1
      Fix more generic types
      Default access_decision_manager.strategy option with merge.
      Fix typos
      Update validators.ca.xlf
      Add missing Validator translations for Estonian
      ...
    
    Signed-off-by: Alexander M. Turek <me@derrabus.de>
    derrabus committed Nov 4, 2021
    Copy the full SHA
    e6f132c View commit details
20 changes: 5 additions & 15 deletions AbstractUriElement.php
Original file line number Diff line number Diff line change
@@ -55,49 +55,39 @@ public function __construct(\DOMElement $node, string $currentUri = null, ?strin

/**
* Gets the node associated with this link.
*
* @return \DOMElement
*/
public function getNode()
public function getNode(): \DOMElement
{
return $this->node;
}

/**
* Gets the method associated with this link.
*
* @return string
*/
public function getMethod()
public function getMethod(): string
{
return $this->method ?? 'GET';
}

/**
* Gets the URI associated with this link.
*
* @return string
*/
public function getUri()
public function getUri(): string
{
return UriResolver::resolve($this->getRawUri(), $this->currentUri);
}

/**
* Returns raw URI data.
*
* @return string
*/
abstract protected function getRawUri();
abstract protected function getRawUri(): string;

/**
* Returns the canonicalized URI path (see RFC 3986, section 5.2.4).
*
* @param string $path URI path
*
* @return string
*/
protected function canonicalizePath(string $path)
protected function canonicalizePath(string $path): string
{
if ('' === $path || '/' === $path) {
return $path;
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.0
---

* Remove `Crawler::parents()` method, use `ancestors()` instead

5.4
---

203 changes: 46 additions & 157 deletions Crawler.php

Large diffs are not rendered by default.

58 changes: 16 additions & 42 deletions Field/ChoiceFormField.php
Original file line number Diff line number Diff line change
@@ -20,29 +20,17 @@
*/
class ChoiceFormField extends FormField
{
/**
* @var string
*/
private $type;
/**
* @var bool
*/
private $multiple;
/**
* @var array
*/
private $options;
/**
* @var bool
*/
private $validationDisabled = false;
private string $type;
private bool $multiple;
private array $options;
private bool $validationDisabled = false;

/**
* Returns true if the field should be included in the submitted values.
*
* @return bool true if the field should be included in the submitted values, false otherwise
*/
public function hasValue()
public function hasValue(): bool
{
// don't send a value for unchecked checkboxes
if (\in_array($this->type, ['checkbox', 'radio']) && null === $this->value) {
@@ -54,10 +42,8 @@ public function hasValue()

/**
* Check if the current selected option is disabled.
*
* @return bool
*/
public function isDisabled()
public function isDisabled(): bool
{
if (parent::isDisabled() && 'select' === $this->type) {
return true;
@@ -74,10 +60,8 @@ public function isDisabled()

/**
* Sets the value of the field.
*
* @param string|array $value The value of the field
*/
public function select($value)
public function select(string|array|bool $value)
{
$this->setValue($value);
}
@@ -113,11 +97,9 @@ public function untick()
/**
* Sets the value of the field.
*
* @param string|array|bool|null $value The value of the field
*
* @throws \InvalidArgumentException When value type provided is not correct
*/
public function setValue($value)
public function setValue(string|array|bool|null $value)
{
if ('checkbox' === $this->type && false === $value) {
// uncheck
@@ -175,20 +157,16 @@ public function addChoice(\DOMElement $node)

/**
* Returns the type of the choice field (radio, select, or checkbox).
*
* @return string
*/
public function getType()
public function getType(): string
{
return $this->type;
}

/**
* Returns true if the field accepts multiple values.
*
* @return bool
*/
public function isMultiple()
public function isMultiple(): bool
{
return $this->multiple;
}
@@ -268,11 +246,9 @@ private function buildOptionValue(\DOMElement $node): array
/**
* Checks whether given value is in the existing options.
*
* @internal since Symfony 5.3
*
* @return bool
* @internal
*/
public function containsOption(string $optionValue, array $options)
public function containsOption(string $optionValue, array $options): bool
{
if ($this->validationDisabled) {
return true;
@@ -290,11 +266,9 @@ public function containsOption(string $optionValue, array $options)
/**
* Returns list of available field options.
*
* @internal since Symfony 5.3
*
* @return array
* @internal
*/
public function availableOptionValues()
public function availableOptionValues(): array
{
$values = [];

@@ -308,11 +282,11 @@ public function availableOptionValues()
/**
* Disables the internal validation of the field.
*
* @internal since Symfony 5.3
* @internal
*
* @return $this
*/
public function disableValidation()
public function disableValidation(): static
{
$this->validationDisabled = true;

20 changes: 5 additions & 15 deletions Field/FormField.php
Original file line number Diff line number Diff line change
@@ -57,10 +57,8 @@ public function __construct(\DOMElement $node)

/**
* Returns the label tag associated to the field or null if none.
*
* @return \DOMElement|null
*/
public function getLabel()
public function getLabel(): ?\DOMElement
{
$xpath = new \DOMXPath($this->node->ownerDocument);

@@ -78,20 +76,16 @@ public function getLabel()

/**
* Returns the name of the field.
*
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* Gets the value of the field.
*
* @return string|array|null
*/
public function getValue()
public function getValue(): string|array|null
{
return $this->value;
}
@@ -106,20 +100,16 @@ public function setValue(?string $value)

/**
* Returns true if the field should be included in the submitted values.
*
* @return bool
*/
public function hasValue()
public function hasValue(): bool
{
return true;
}

/**
* Check if the current field is disabled.
*
* @return bool
*/
public function isDisabled()
public function isDisabled(): bool
{
return $this->node->hasAttribute('disabled');
}
77 changes: 20 additions & 57 deletions Form.php
Original file line number Diff line number Diff line change
@@ -21,20 +21,9 @@
*/
class Form extends Link implements \ArrayAccess
{
/**
* @var \DOMElement
*/
private $button;

/**
* @var FormFieldRegistry
*/
private $fields;

/**
* @var string
*/
private $baseHref;
private \DOMElement $button;
private FormFieldRegistry $fields;
private ?string $baseHref;

/**
* @param \DOMElement $node A \DOMElement instance
@@ -54,10 +43,8 @@ public function __construct(\DOMElement $node, string $currentUri = null, string

/**
* Gets the form node associated with this form.
*
* @return \DOMElement
*/
public function getFormNode()
public function getFormNode(): \DOMElement
{
return $this->node;
}
@@ -69,7 +56,7 @@ public function getFormNode()
*
* @return $this
*/
public function setValues(array $values)
public function setValues(array $values): static
{
foreach ($values as $name => $value) {
$this->fields->set($name, $value);
@@ -82,10 +69,8 @@ public function setValues(array $values)
* Gets the field values.
*
* The returned array does not include file fields (@see getFiles).
*
* @return array
*/
public function getValues()
public function getValues(): array
{
$values = [];
foreach ($this->fields->all() as $name => $field) {
@@ -103,10 +88,8 @@ public function getValues()

/**
* Gets the file field values.
*
* @return array
*/
public function getFiles()
public function getFiles(): array
{
if (!\in_array($this->getMethod(), ['POST', 'PUT', 'DELETE', 'PATCH'])) {
return [];
@@ -132,10 +115,8 @@ public function getFiles()
*
* This method converts fields with the array notation
* (like foo[bar] to arrays) like PHP does.
*
* @return array
*/
public function getPhpValues()
public function getPhpValues(): array
{
$values = [];
foreach ($this->getValues() as $name => $value) {
@@ -159,10 +140,8 @@ public function getPhpValues()
* (@see getPhpValues), rather than uploaded files found in $_FILES.
* For a compound file field foo[bar] it will create foo[bar][name],
* instead of foo[name][bar] which would be found in $_FILES.
*
* @return array
*/
public function getPhpFiles()
public function getPhpFiles(): array
{
$values = [];
foreach ($this->getFiles() as $name => $value) {
@@ -195,10 +174,8 @@ function (&$value, $key) {
* The returned URI is not the same as the form "action" attribute.
* This method merges the value if the method is GET to mimics
* browser behavior.
*
* @return string
*/
public function getUri()
public function getUri(): string
{
$uri = parent::getUri();

@@ -219,7 +196,7 @@ public function getUri()
return $uri;
}

protected function getRawUri()
protected function getRawUri(): string
{
// If the form was created from a button rather than the form node, check for HTML5 action overrides
if ($this->button !== $this->node && $this->button->getAttribute('formaction')) {
@@ -233,10 +210,8 @@ protected function getRawUri()
* Gets the form method.
*
* If no method is defined in the form, GET is returned.
*
* @return string
*/
public function getMethod()
public function getMethod(): string
{
if (null !== $this->method) {
return $this->method;
@@ -262,10 +237,8 @@ public function getName(): string

/**
* Returns true if the named field exists.
*
* @return bool
*/
public function has(string $name)
public function has(string $name): bool
{
return $this->fields->has($name);
}
@@ -285,7 +258,7 @@ public function remove(string $name)
*
* @throws \InvalidArgumentException When field is not present in this form
*/
public function get(string $name)
public function get(string $name): FormField|array
{
return $this->fields->get($name);
}
@@ -303,7 +276,7 @@ public function set(FormField $field)
*
* @return FormField[]
*/
public function all()
public function all(): array
{
return $this->fields->all();
}
@@ -312,11 +285,8 @@ public function all()
* Returns true if the named field exists.
*
* @param string $name The field name
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($name)
public function offsetExists(mixed $name): bool
{
return $this->has($name);
}
@@ -330,8 +300,7 @@ public function offsetExists($name)
*
* @throws \InvalidArgumentException if the field does not exist
*/
#[\ReturnTypeWillChange]
public function offsetGet($name)
public function offsetGet(mixed $name): FormField|array
{
return $this->fields->get($name);
}
@@ -342,12 +311,9 @@ public function offsetGet($name)
* @param string $name The field name
* @param string|array $value The value of the field
*
* @return void
*
* @throws \InvalidArgumentException if the field does not exist
*/
#[\ReturnTypeWillChange]
public function offsetSet($name, $value)
public function offsetSet(mixed $name, mixed $value): void
{
$this->fields->set($name, $value);
}
@@ -356,11 +322,8 @@ public function offsetSet($name, $value)
* Removes a field from the form.
*
* @param string $name The field name
*
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($name)
public function offsetUnset(mixed $name): void
{
$this->fields->remove($name);
}
@@ -370,7 +333,7 @@ public function offsetUnset($name)
*
* @return $this
*/
public function disableValidation()
public function disableValidation(): static
{
foreach ($this->fields->all() as $field) {
if ($field instanceof Field\ChoiceFormField) {
13 changes: 4 additions & 9 deletions FormFieldRegistry.php
Original file line number Diff line number Diff line change
@@ -20,9 +20,8 @@
*/
class FormFieldRegistry
{
private $fields = [];

private $base = '';
private array $fields = [];
private string $base = '';

/**
* Adds a field to the registry.
@@ -70,7 +69,7 @@ public function remove(string $name)
*
* @throws \InvalidArgumentException if the field does not exist
*/
public function &get(string $name)
public function &get(string $name): FormField|array
{
$segments = $this->getSegments($name);
$target = &$this->fields;
@@ -87,8 +86,6 @@ public function &get(string $name)

/**
* Tests whether the form has the given field based on the fully qualified name.
*
* @return bool
*/
public function has(string $name): bool
{
@@ -104,11 +101,9 @@ public function has(string $name): bool
/**
* Set the value of a field based on the fully qualified name and its children.
*
* @param mixed $value The value
*
* @throws \InvalidArgumentException if the field does not exist
*/
public function set(string $name, $value)
public function set(string $name, mixed $value)
{
$target = &$this->get($name);
if ((!\is_array($value) && $target instanceof Field\FormField) || $target instanceof Field\ChoiceFormField) {
2 changes: 1 addition & 1 deletion Image.php
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ public function __construct(\DOMElement $node, string $currentUri = null)
parent::__construct($node, $currentUri, 'GET');
}

protected function getRawUri()
protected function getRawUri(): string
{
return $this->node->getAttribute('src');
}
2 changes: 1 addition & 1 deletion Link.php
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
*/
class Link extends AbstractUriElement
{
protected function getRawUri()
protected function getRawUri(): string
{
return $this->node->getAttribute('href');
}
6 changes: 3 additions & 3 deletions Test/Constraint/CrawlerSelectorAttributeValueSame.php
Original file line number Diff line number Diff line change
@@ -16,9 +16,9 @@

final class CrawlerSelectorAttributeValueSame extends Constraint
{
private $selector;
private $attribute;
private $expectedText;
private string $selector;
private string $attribute;
private string $expectedText;

public function __construct(string $selector, string $attribute, string $expectedText)
{
2 changes: 1 addition & 1 deletion Test/Constraint/CrawlerSelectorExists.php
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@

final class CrawlerSelectorExists extends Constraint
{
private $selector;
private string $selector;

public function __construct(string $selector)
{
8 changes: 4 additions & 4 deletions Test/Constraint/CrawlerSelectorTextContains.php
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@

final class CrawlerSelectorTextContains extends Constraint
{
private $selector;
private $expectedText;
private $hasNode = false;
private $nodeText;
private string $selector;
private string $expectedText;
private bool $hasNode = false;
private string $nodeText;

public function __construct(string $selector, string $expectedText)
{
4 changes: 2 additions & 2 deletions Test/Constraint/CrawlerSelectorTextSame.php
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@

final class CrawlerSelectorTextSame extends Constraint
{
private $selector;
private $expectedText;
private string $selector;
private string $expectedText;

public function __construct(string $selector, string $expectedText)
{
35 changes: 0 additions & 35 deletions Tests/AbstractCrawlerTest.php
Original file line number Diff line number Diff line change
@@ -12,16 +12,13 @@
namespace Symfony\Component\DomCrawler\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Form;
use Symfony\Component\DomCrawler\Image;
use Symfony\Component\DomCrawler\Link;

abstract class AbstractCrawlerTest extends TestCase
{
use ExpectDeprecationTrait;

abstract public function getDoctype(): string;

protected function createCrawler($node = null, string $uri = null, string $baseHref = null)
@@ -82,13 +79,6 @@ public function testAdd()
$this->assertEquals('Foo', $crawler->filterXPath('//body')->text(), '->add() adds nodes from a string');
}

public function testAddInvalidType()
{
$this->expectException(\InvalidArgumentException::class);
$crawler = $this->createCrawler();
$crawler->add(1);
}

public function testAddMultipleDocumentNode()
{
$this->expectException(\InvalidArgumentException::class);
@@ -1096,31 +1086,6 @@ public function testFilteredChildren()
$this->assertEquals(1, $foo->children('.ipsum')->count());
}

/**
* @group legacy
*/
public function testParents()
{
$this->expectDeprecation('Since symfony/dom-crawler 5.3: The Symfony\Component\DomCrawler\Crawler::parents() method is deprecated, use ancestors() instead.');

$crawler = $this->createTestCrawler()->filterXPath('//li[1]');
$this->assertNotSame($crawler, $crawler->parents(), '->parents() returns a new instance of a crawler');
$this->assertInstanceOf(Crawler::class, $crawler->parents(), '->parents() returns a new instance of a crawler');

$nodes = $crawler->parents();
$this->assertEquals(3, $nodes->count());

$nodes = $this->createTestCrawler()->filterXPath('//html')->parents();
$this->assertEquals(0, $nodes->count());

try {
$this->createTestCrawler()->filterXPath('//ol')->parents();
$this->fail('->parents() throws an \InvalidArgumentException if the node list is empty');
} catch (\InvalidArgumentException $e) {
$this->assertTrue(true, '->parents() throws an \InvalidArgumentException if the node list is empty');
}
}

public function testAncestors()
{
$crawler = $this->createTestCrawler()->filterXPath('//li[1]');
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -16,14 +16,12 @@
}
],
"require": {
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1",
"php": ">=8.0.2",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.16"
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
"symfony/css-selector": "^4.4|^5.0|^6.0",
"symfony/css-selector": "^5.4|^6.0",
"masterminds/html5": "^2.6"
},
"conflict": {
20 changes: 10 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
@@ -18,14 +18,14 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
</phpunit>