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 jest and a simple test example #136

Closed

Conversation

internalsystemerror
Copy link
Member

Q A
Documentation no
Bugfix no
BC Break no
New Feature yes
RFC no
QA yes

Description

In order to investigate laminas/automatic-releases#212, and as previously requested by @boesing we need to add unit tests.

In adding a simple example for config/app.ts#createConfig() it appears that the stableVersion for 8.1 is actually 7.4 which may be the cause of the issue above.

Signed-off-by: Gary Lockett <gary@creativecow.uk>
@internalsystemerror internalsystemerror marked this pull request as draft October 29, 2022 17:03
@internalsystemerror
Copy link
Member Author

internalsystemerror commented Oct 29, 2022

@Ocramius I think we have possibly found the cause of the issue on automatic-releases (see https://github.com/laminas/laminas-ci-matrix-action/actions/runs/3352246718/jobs/5554266299).

@boesing I know you've done a lot of work on this, so I wanted to set up unit testing and ping you so you're kept in the loop.

Signed-off-by: Gary Lockett <gary@creativecow.uk>
@internalsystemerror internalsystemerror marked this pull request as ready for review October 29, 2022 17:11
Dockerfile Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
const phpIniFromConfigurationPath: PathLike = 'tests/php-ini-from-configuration';

it('should return valid config', () => {
expect(createConfig(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall okay with this testing approach, but note that we could've caught this with the previous testing approach too 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think of the current approach as higher up the pyramid. Unit testing will give us quicker clarity as to what the issue is, so the more the better I say.

codeChecks : true,
docLinting : true,
},
`${phpIniFromConfigurationPath}/composer.json`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we testing here? 🤔

Would probably make sense to have these files readable inside the test?

Copy link
Member Author

@internalsystemerror internalsystemerror Oct 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was more just a quick example, but it makes sense to have distinct tests. Ideally I'd have passed in the configurations themselves, but these needed filenames so I used existing ones.

)).toEqual({
codeChecks : true,
docLinting : true,
versions : [ '8.1' ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I realized: ~8.1.2 will, for example, never match 8.1 🤔

Copy link
Member Author

@internalsystemerror internalsystemerror Oct 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's normalizing all the versions to these minor version numbers beforehand, so it should in theory:

return INSTALLABLE_VERSIONS
.filter((version) => semver.satisfies(`${version}.0`, composerPhpVersion));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an existing test for that scenario?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I'm not even sure what's supposed to be returned here, I'm taking the code at face value. Could do with waiting for @boesing (time permitting obviously) to have a look over this, and I can add more tests after that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I associated many PRs that are affected by this specific problem: they can be seen on the PR overview.

The problem is that a dependency range like "php": "~8.1.12" will produce a matrix containing PHP 7.4, 8.0, 8.1, for some reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was the line mentioned above after all. composerPhpVersion is the constraint pulled straight from require.php in composer.json.

Signed-off-by: Gary Lockett <gary@creativecow.uk>
Signed-off-by: Gary Lockett <gary@creativecow.uk>
Signed-off-by: Gary Lockett <gary@creativecow.uk>
@internalsystemerror
Copy link
Member Author

Closing in favour of #139

@internalsystemerror internalsystemerror deleted the add-unit-testing branch November 2, 2022 14:42
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.

2 participants