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

Tests: introduce namespaces #503

Merged
merged 19 commits into from
Jul 30, 2021
Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 29, 2021

This introduces namespaces to all test related classes. As this commit only affects the tests, this is not a breaking change.

👉🏻 This PR will be easiest to review by checking through the individual commits.

Fixes #459
Related to #460 and partially addressees action point 5 from that issue.

Commit details

Tests: allow for namespacing the tests

This is a preliminary commit to set up the basics to allow for namespacing the tests.

It:

  • Adds an entry for the namespaced variants of the tests to the PHPUnit config file, so those tests will be found and run.
  • Adds a custom autoloader for PSR4-based namespaced test classes to the test bootstrap.

The old setup is - for now - still left in place to allow for testing each individual step in the transformation.

Once the transformation has been completed, the old setup will be removed.

Note: the testsuite cannot be named Requests as older PHPUnit versions, in that case, would confuse it with the Requests class and expect that class to extend the PHPUnit_Framework_TestCase class. With that in mind, the testsuite is called RequestsTests.

Tests: namespace the base TestCase class

... and add use statements for it and adjust the extends in all the test classes which extend from it.

Tests: namespace the Transport base TestCase class

... and add use statements for it and adjust the extends in all the test classes which extend from it.

Tests: namespace the ChunkedDecoding test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_ChunkedDecoding class to ChunkedDecodingTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file.

Tests: namespace the Cookies test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_Cookies class to CookiesTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file.

Tests: namespace the Encoding test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTests_Encoding class to EncodingTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file.

Tests: namespace the IDNAEncoder test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_IDNAEncoder class to IDNAEncoderTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file.

Tests: namespace the IRI test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_IRI class to IRITest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file.
  • Adjusts the reference to the file in the PHPCS config file.

Tests: namespace the Requests test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_Requests class to RequestsTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file.

Tests: namespace the Session test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_Session class to SessionTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file.

Tests: namespace the SSL test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_SSL class to SSLTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file.

Tests: namespace the Response_Headers test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_Response_Headers class to HeadersTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file.

Tests: namespace the Utility_FilteredIterator test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_Utility_FilteredIterator class to FilteredIteratorTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the named reference to the old test class file from the PHPUnit config file and removes the now empty testsuite "General".

Tests: namespace the Auth_Basic test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_Auth_Basic class to BasicTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the testsuite which previously contained the old test class file from the PHPUnit config file in favour of letting the generic testsuite handle this.

Tests: namespace the Proxy_HTTP test class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_Proxy_HTTP class to HTTPTest.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Removes the testsuite which previously contained the old test class file from the PHPUnit config file in favour of letting the generic testsuite handle this.

Tests: namespace the Transport_* test classes

This commit:

  • Namespaces the classes.
  • Renames the RequestsTest_Transport_cURL class to CurlTest.
  • Renames the RequestsTest_Transport_fsockopen class to FsockopenTest.
  • Renames the class files to match the new class names.
  • Add use statements for all used classes.
  • Removes the testsuite which previously contained the old test class files from the PHPUnit config file in favour of letting the generic testsuite handle this.

Tests: namespace the Transport mock class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_Mock_Transport class to TransportMock.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Adjusts all references to this Mock class in other test files.

Tests: namespace the RawTransport mock class

This commit:

  • Namespaces the class.
  • Renames the RequestsTest_Mock_Transport class to TransportMock.
  • Renames the class file to match the new class name.
  • Add use statements for all used classes.
  • Adjusts all references to this Mock class in other test files.

Tests: finish off namespacing

Now all test classes are namespaced, the old autoloader in the test bootstrap is no longer necessary.

Additionally, as long as Composer knows about the namespaced test classes. the (new) custom autoloader is only really needed when PHPUnit is run via a PHAR file.

To this end, this commit:

  • Adds a autoload-dev section to the composer.json configuration file.
  • Removes the old autoloader.
  • And places the "manual" loading of the PHPUnit polyfills autoloader and the custom autoloader in a condition, so they only get used when the tests are run via a PHAR file.

jrfnl added 19 commits June 29, 2021 22:35
This is a preliminary commit to set up the basics to allow for namespacing the tests.

It:
* Adds an entry for the namespaced variants of the tests to the PHPUnit config file, so those tests will be found and run.
* Adds a custom autoloader for PSR4-based namespaced test classes to the test bootstrap.

The old setup is - for now - still left in place to allow for testing each individual step in the transformation.

Once the transformation has been completed, the old setup will be removed.

**Note**: _the testsuite cannot be named `Requests` as older PHPUnit versions, in that case, would confuse it with the `Requests` class and expect that class to extend the `PHPUnit_Framework_TestCase` class. With that in mind, the testsuite is called `RequestsTests`._
... and add use statements for it and adjust the `extends` in all the test classes which extend from it.
... and add use statements for it and adjust the `extends` in all the test classes which extend from it.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_ChunkedDecoding` class to `ChunkedDecodingTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_Cookies` class to `CookiesTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file.
This commit:
* Namespaces the class.
* Renames the `RequestsTests_Encoding` class to `EncodingTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_IDNAEncoder` class to `IDNAEncoderTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_IRI` class to `IRITest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file.
* Adjusts the reference to the file in the PHPCS config file.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_Requests` class to `RequestsTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_Session` class to `SessionTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_SSL` class to `SSLTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_Response_Headers` class to `HeadersTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_Utility_FilteredIterator` class to `FilteredIteratorTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the named reference to the old test class file from the PHPUnit config file and removes the now empty `testsuite` "General".
This commit:
* Namespaces the class.
* Renames the `RequestsTest_Auth_Basic` class to `BasicTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the testsuite which previously contained the old test class file from the PHPUnit config file in favour of letting the generic testsuite handle this.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_Proxy_HTTP` class to `HTTPTest`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Removes the testsuite which previously contained the old test class file from the PHPUnit config file in favour of letting the generic testsuite handle this.
This commit:
* Namespaces the classes.
* Renames the `RequestsTest_Transport_cURL` class to `CurlTest`.
* Renames the `RequestsTest_Transport_fsockopen` class to `FsockopenTest`.
* Renames the class files to match the new class names.
* Add `use` statements for all used classes.
* Removes the testsuite which previously contained the old test class files from the PHPUnit config file in favour of letting the generic testsuite handle this.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_Mock_Transport` class to `TransportMock`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Adjusts all references to this Mock class in other test files.
This commit:
* Namespaces the class.
* Renames the `RequestsTest_Mock_Transport` class to `TransportMock`.
* Renames the class file to match the new class name.
* Add `use` statements for all used classes.
* Adjusts all references to this Mock class in other test files.
Now all test classes are namespaced, the old autoloader in the test bootstrap is no longer necessary.

Additionally, as long as Composer knows about the namespaced test classes. the (new) custom autoloader is only really needed when PHPUnit is run via a PHAR file.

To this end, this commit:
* Adds a `autoload-dev` section to the `composer.json` configuration file.
* Removes the old autoloader.
* And places the "manual" loading of the PHPUnit polyfills autoloader and the custom autoloader in a condition, so they only get used when the tests are run via a PHAR file.
@jrfnl jrfnl added this to the 2.0.0 milestone Jun 29, 2021
@jrfnl jrfnl mentioned this pull request Jun 29, 2021
14 tasks
@schlessera schlessera merged commit 02fd0da into develop Jul 30, 2021
@schlessera schlessera deleted the feature/tests-introduce-namespaces branch July 30, 2021 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests configuration setup
2 participants