Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "property" instead of "attribute" for configuring the backup of static fields #4603

Closed
sebastianbergmann opened this issue Feb 9, 2021 · 4 comments
Assignees
Labels
feature/test-runner CLI test runner type/backward-compatibility Something will be/is intentionally broken
Milestone

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Feb 9, 2021

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).

Wikipedia

PHPUnit currently refers to "fields" (see above) as "attributes". This is (or will become) confusing considering the introduction of attributes in PHP 8 and their support in PHPUnit.

PHPUnit will be changed to use the term "property" instead of "attribute" where "field" is meant.

PHPUnit can optionally create a backup of static fields before each test and restore these fields from that backup after each test. This functionality is controlled by

  • the backupStaticAttributes attribute on the <phpunit> root element of PHPUnit's XML configuration file
  • the --static-backup CLI option
  • the @backupStaticAttributes annotation
  • the BackupStaticProperties attribute (as of PHP 8 and PHPUnit 10)

The backupStaticAttributes attribute will be deprecated in PHPUnit 10. It will be removed in PHPUnit 11. A new backupStaticProperties attribute will implemented to replace it. The XML configuration file migrator will be expanded to handle this change.

The --static-backup CLI option does not need to be renamed, only its help text will be updated to use "properties" instead of "attributes".

Support for metadata in comments (using the the @backupStaticAttributes annotation, for example) will be deprecated in PHPUnit 11 (February 2022) and removed in PHPUnit 12 (February 2023). Therefore, I do not think it's sensible to deprecate @backupStaticAttributes now and introduce a @backupStaticProperties replacement that will itself be deprecated within a year.

@lolli42
Copy link
Contributor

lolli42 commented Feb 5, 2023

backupStaticAttributes is still mentioned on https://phpunit.readthedocs.io/en/10.0/configuration.html and backupStaticProperties is missing.

@MichaelRushton
Copy link

MichaelRushton commented Feb 5, 2023

After upgrading to 10.0.3, using either @backupStaticProperties or @backupStaticAttributes at the class level triggers this error:

An error occurred inside PHPUnit.

Message:  assert($metadata instanceof BackupStaticProperties)
Location: /var/www/html/framework/vendor/phpunit/phpunit/src/Framework/TestBuilder.php:189

#0 /var/www/html/framework/vendor/phpunit/phpunit/src/Framework/TestBuilder.php(189): assert(false, 'assert($metadat...')
#1 /var/www/html/framework/vendor/phpunit/phpunit/src/Framework/TestBuilder.php(63): PHPUnit\Framework\TestBuilder->backupSettings('ConfigTest', 'testCanSet')
#2 /var/www/html/framework/vendor/phpunit/phpunit/src/Framework/TestSuite.php(491): PHPUnit\Framework\TestBuilder->build(Object(ReflectionClass), 'testCanSet')
#3 /var/www/html/framework/vendor/phpunit/phpunit/src/Framework/TestSuite.php(132): PHPUnit\Framework\TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod))
#4 /var/www/html/framework/vendor/phpunit/phpunit/src/Framework/TestSuite.php(229): PHPUnit\Framework\TestSuite::fromClassReflector(Object(ReflectionClass))
#5 /var/www/html/framework/vendor/phpunit/phpunit/src/Framework/TestSuite.php(257): PHPUnit\Framework\TestSuite->addTestSuite(Object(ReflectionClass))
#6 /var/www/html/framework/vendor/phpunit/phpunit/src/Framework/TestSuite.php(275): PHPUnit\Framework\TestSuite->addTestFile('/var/www/html/f...')
#7 /var/www/html/framework/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(76): PHPUnit\Framework\TestSuite->addTestFiles(Array)
#8 /var/www/html/framework/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(46): PHPUnit\TextUI\Configuration\TestSuiteBuilder->testSuiteFromPath('/var/www/html/f...', Array)
#9 /var/www/html/framework/vendor/phpunit/phpunit/src/TextUI/Application.php(285): PHPUnit\TextUI\Configuration\TestSuiteBuilder->build(Object(PHPUnit\TextUI\Configuration\Configuration))
#10 /var/www/html/framework/vendor/phpunit/phpunit/src/TextUI/Application.php(97): PHPUnit\TextUI\Application->buildTestSuite(Object(PHPUnit\TextUI\Configuration\Configuration))
#11 /var/www/html/framework/vendor/phpunit/phpunit/phpunit(90): PHPUnit\TextUI\Application->run(Array)
#12 /var/www/html/framework/vendor/bin/phpunit(123): include('/var/www/html/f...')
#13 {main}

It works as expected when added at the method level.

Also, #[BackupStaticProperties] does nothing.

@sebastianbergmann
Copy link
Owner Author

backupStaticAttributes is still mentioned on https://phpunit.readthedocs.io/en/10.0/configuration.html and backupStaticProperties is missing.

Yes, the documentation still needs to be updated.

@sebastianbergmann
Copy link
Owner Author

Also, #[BackupStaticProperties] does nothing.

I cannot reproduce this. If you still experience this issue after 1bd8f24 then please open a new ticket.

andygrunwald added a commit to lansuite/lansuite that referenced this issue Jul 4, 2023
…cause backupStaticAttributes is deprecated

Error Message: Element 'phpunit', attribute 'backupStaticAttributes': The attribute 'backupStaticAttributes' is not allowed.

See:
- sebastianbergmann/phpunit#4604
- sebastianbergmann/phpunit#4603
- sebastianbergmann/phpunit@642ca8b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/backward-compatibility Something will be/is intentionally broken
Projects
None yet
Development

No branches or pull requests

3 participants