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

add simple CI pipeline with basic PHP test runner #823

Merged
merged 10 commits into from
Feb 20, 2024

Conversation

mmitch
Copy link
Contributor

@mmitch mmitch commented Feb 18, 2024

(ping @garvinhicking ref. https://www.onli-blogging.de/2323/15-Jahre-Serendipity-als-Entwickler-ein-Rueckblick-und-ein-Ausblick.html#c10436)

I have prepared a simple GitHub Action CI pipeline that runs the basic PHP tests on every push and will annotate commits and Pull Requests with the build status.

The tests run for all current PHP versions (that means 8.1, 8.2 and 8.3). The matrix can be expanded to other versions as well, but I don't know if we need to test against deprecated PHP versions without security support. On the other hand, nightly builds of PHP 8.4 could also be used as a test target.

To make the tests pass I had to update them to make them work with a current version of PHPUnit.

Things currently not included:

  • There is no build status badge for README.markdown yet. If you like to have one, I'll add it :-)
  • Code coverage is not computed yet. With the low count of test cases this does not seem too useful at the moment.
  • FrontendTest.php is not included yet. The test framework Selenium RC is triple-deprecated (Selenium RC is Selenium 1; Selenium 1, 2 and 3 are already deprecated; Selenium 4 is current) and I can't even find downloads of the mentioned selenium-server.jar (Selenium homepage and GitHub project offer Selenium 2.39.0 as oldest download). I'll see if I can update the tests to work with a current version somehow or if it is feasible to switch to another test framework (any wishes?) - but not as part of this PR ;-)

test matrix contains all currently released and supported PHP versions
```
2 tests triggered 2 PHPUnit deprecations:

1) functionsTest::test_serendipity_serverOffsetHour
Data Provider method functionsTest::serverOffsetHourDataProvider() is not static

/home/runner/work/Serendipity/Serendipity/tests/include/functionsTest.php:17

2) functionsTest::test_serendipity_serverOffsetHourWithTimestampNull
Data Provider method functionsTest::serverOffsetHourWithTimestampNullDataProvider() is not static

/home/runner/work/Serendipity/Serendipity/tests/include/functionsTest.php:46
```
```
There was 1 PHPUnit test runner deprecation:

1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
```
```
There were 3 PHPUnit test runner deprecations:

1) Metadata found in doc-comment for method functionsConfigTest::test_serendipity_getTemplateFile(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

2) Metadata found in doc-comment for method functionsTest::test_serendipity_serverOffsetHour(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

3) Metadata found in doc-comment for method functionsTest::test_serendipity_serverOffsetHourWithTimestampNull(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

```
`assertContains()` is used for arrays etc., but we only have a string.
Use `assertStringEndsWith()` instead, the _ends with_ also makes the
test more robust.
@garvinhicking
Copy link
Member

Wow, that's pretty cool. I wasn't aware the tests we have are really anything at this point, but happy to see the can still act as a foundation.

Have you by chance seen the "feature/composer" branch and #821 (comment)?

Would you be interested in aligning this PR with that branch and maybe work on it together?

(Otherwise I'd happily merge this PR into main, it's an improvement either way. If we could add PHP 7.4 into the matrix mix, I'm sure @onli would be happy, because that's still used in some Linux distro LTS's)

Many, many, many thanks for getting involved, this puts a smile to my face.

@onli
Copy link
Member

onli commented Feb 19, 2024

(Otherwise I'd happily merge this PR into main, it's an improvement either way. If we could add PHP 7.4 into the matrix mix, I'm sure @onli would be happy, because that's still used in some Linux distro LTS's)

Exactly right :)

@mmitch
Copy link
Contributor Author

mmitch commented Feb 19, 2024

The tests run under PHP 7.4 , too, I've just added it to the build matrix.

I think I'll first try to tackle the frontend testsuite before looking at #821 in depth – I've never worked with composer (and I don't want to use Docker 😉), so I'll have to dive a bit deeper before doing anything.
With regard to my first glance at https://github.com/s9y/Serendipity/blob/feature/composer/README.markdown#concept

  • Linting and static code analysis should be possible if there are any PHP Actions available (GitHub CodeQL does not seem to support PHP, or I would already have added it here)
  • Dependency checks should also be possible if there are any Actions for that. Perhaps it is already covered by GitHub itself (there is a dependency management, but the languages that I typically use aren't supported).
  • Release and asset building might be hardest because I've never really done that and I don't know anything about PHP release artefacts and packaging.

Feel free to merge this in the meantime, I can use it as a foundation if I take a look at the composer-feature.

@garvinhicking garvinhicking merged commit 78d4d10 into s9y:master Feb 20, 2024
garvinhicking pushed a commit that referenced this pull request Feb 20, 2024
* add initial PHP test workflow

test matrix contains all currently released and supported PHP versions

* actually run the tests as described in tests/README

* tests: fix PHPUnit imports

* tests: fix missing constant S9Y_INCLUDE_PATH

* tests: fix PHPUnit deprecation warning: DataProviders must be static

```
2 tests triggered 2 PHPUnit deprecations:

1) functionsTest::test_serendipity_serverOffsetHour
Data Provider method functionsTest::serverOffsetHourDataProvider() is not static

/home/runner/work/Serendipity/Serendipity/tests/include/functionsTest.php:17

2) functionsTest::test_serendipity_serverOffsetHourWithTimestampNull
Data Provider method functionsTest::serverOffsetHourWithTimestampNullDataProvider() is not static

/home/runner/work/Serendipity/Serendipity/tests/include/functionsTest.php:46
```

* tests: migrate PHPUnit XML configuration to version 11.0

```
There was 1 PHPUnit test runner deprecation:

1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
```

* tests: disable code coverage for now

* tests: migrate doc-comments to Attributes

```
There were 3 PHPUnit test runner deprecations:

1) Metadata found in doc-comment for method functionsConfigTest::test_serendipity_getTemplateFile(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

2) Metadata found in doc-comment for method functionsTest::test_serendipity_serverOffsetHour(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

3) Metadata found in doc-comment for method functionsTest::test_serendipity_serverOffsetHourWithTimestampNull(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

```

* tests: fix assertions

`assertContains()` is used for arrays etc., but we only have a string.
Use `assertStringEndsWith()` instead, the _ends with_ also makes the
test more robust.

* tests: also run on PHP 7.4
@garvinhicking
Copy link
Member

Hi!

Thanks a lot, I just merged your PR into both branches (main and feature/composer).

I think I'll first try to tackle the frontend testsuite before looking at #821 in depth – I've never worked with composer (and I don't want to use Docker 😉), so I'll have to dive a bit deeper before doing anything. With regard to my first glance at https://github.com/s9y/Serendipity/blob/feature/composer/README.markdown#concept

You should be able to help with the "composer move" effort even without too much composer knowledge I hope.

With Docker and ddev you would be setup in a minute, just git clone the feature/composer directory, then ddev start, ddev composer install and then ddev launch and you would be good to go with a completely distinct webserver environment with PHP+MySQL.

Without that, it's a lot more configuration of course:

  • Create a directory like /var/www/html/serendipity (where you store your webserver files)
  • GIT clone the feature/composer branch into that directory
  • Setup your webserver for a distinct virtualhost, map the DocumentRoot to /var/www/html/serendipity/public
  • Inside the /var/www/html/serendipity directory, do a composer install
  • Then you should be able to point your browser to your virtualhost and see the output

Of course currently the branch is non-functional, it throws errors because the PHP include directories and paths are not referenced properly, because I moved around directories but did not change the code for it. That's the "busywork" we need to work on :-D

  • Linting and static code analysis should be possible if there are any PHP Actions available (GitHub CodeQL does not seem to support PHP, or I would already have added it here)

I'd do that with phpstan and php-cs-fixer, there are .github workflows out there I utilize, e.g. https://github.com/TYPO3-Documentation/render-guides/blob/main/.github/workflows/main.yaml - it should be straight-forward to port that to serendipity, once we use composer.

  • Dependency checks should also be possible if there are any Actions for that. Perhaps it is already covered by GitHub itself (there is a dependency management, but the languages that I typically use aren't supported).

There's some GitHub action workflows available that use dependabot, I do have some bootstrap code for that (https://github.com/TYPO3-Documentation/render-guides/blob/main/.github/dependabot.yml) which should also be easy to port to Serendipity, again - once composer is properly utilized :-)

  • Release and asset building might be hardest because I've never really done that and I don't know anything about PHP release artefacts and packaging.

I've got some experience with that too, steps would be similar to something like https://github.com/sergeyklay/gh-actions-php-phar-create-release-example/blob/master/.github/workflows/release.yml

Also the creation of a docker container shouldn't be hard, with something like https://github.com/garvinhicking/typo3-documentation-browsersync/blob/main/.github/workflows/docker.yaml

Crossing my fingers I can get you hooked 👯‍♂️

@onli
Copy link
Member

onli commented Feb 20, 2024

I'd do that with phpstan and php-cs-fixer

Just to note, IIRC I did have no luck with phpstan, it was not compatible with the oldschool serendipity PHP code. That is why I set on phan instead, at #758 is still the config.

So if you get phpstan to work we can close #758, otherwise maybe the config there can be re-used :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants