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

[Help/Contributor needed] Major release & refactoring for PHP8 support #41

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

samijnih
Copy link

@samijnih samijnih commented Mar 4, 2021

  • PHPUnit ^9.3 supports PHP 7.3, 7.4 and 8.0
  • PHPUnit ^8.5.12 supports PHP >=7.2

I can't figure how to add PHP 8 support alongside PHP 5 | 7.(0-2)

The idea is to make a new major release only for people using PHP >=7.3 by using PHPUnit ^9.3
But I imagine we can also use PHPUnit 8.5.12 for 7.2, 7.3, 7.4 and 8.0

People still using PHP 5.x should stay on the v1.x release

Changes

  • added return type on every test
  • replaced string FQCN in tests with import
  • refactored classes using the old validator to use the JsonSchema validator
  • removed some tests against PHP < 7.3
  • removed src/InvalidSchemaException.php
  • removed src/JsonValidator.php
  • replaced JsonValidator with JsonSchema\Validator

Need check

  • JsonSchema provides its own implementation for checking validation against a given schema. It also raises an exception called InvalidSchemaException
  • InvalidSchemaException seems not to be raised by default with JsonSchema\Validator. I think we must explicitly use the Constraint::CHECK_MODE_EXCEPTIONS for that (https://github.com/justinrainbow/json-schema#configuration-options)
  • I've removed tests against given invalid schema string path as it does not raise an exception on the third party validator by default
  • A question needs to be answered: who has the responsibility to convert a given string schema path to a compliant object for JsonSchema\Validator? I've dropped that responsibility in the package for now. You can check the example bellow from the JsonSchema README
// Validate
$validator = new JsonSchema\Validator;
$validator->validate($data, (object)['$ref' => 'file://' . realpath('schema.json')]);

https://github.com/justinrainbow/json-schema#basic-usage

Note

I stop working on this pull request.

I wanted to add support for PHP 8 as I've created an issue which has remained unanswered.

The thing is that this library is using a very old release of JsonSchema and it has not been upgraded since 2016. JsonSchema is now at its fifth major release.

Feel free to progress this work. I'm done for now and I'll stop be using this library in my projects.

@samijnih samijnih changed the title add PHP8 support DRAFT add PHP8 support Mar 4, 2021
@samijnih samijnih changed the title DRAFT add PHP8 support DRAFT WIP add PHP8 support Mar 4, 2021
@samijnih samijnih force-pushed the feat/php8 branch 5 times, most recently from be25d13 to 7f91825 Compare March 5, 2021 12:12
@samijnih samijnih changed the title DRAFT WIP add PHP8 support WIP major release for PHP8 support Mar 5, 2021
@samijnih samijnih force-pushed the feat/php8 branch 3 times, most recently from 536a9a6 to 8051011 Compare March 5, 2021 16:55
@samijnih samijnih marked this pull request as draft March 5, 2021 16:57
@samijnih samijnih changed the title WIP major release for PHP8 support Major release & refactoring for PHP8 support Mar 5, 2021
@samijnih samijnih force-pushed the feat/php8 branch 5 times, most recently from e7dadae to a3d9c65 Compare March 6, 2021 12:37
@samijnih samijnih changed the title Major release & refactoring for PHP8 support [Help/Contributor needed] Major release & refactoring for PHP8 support Mar 6, 2021
@samijnih samijnih mentioned this pull request Mar 6, 2021
Copy link

@machitgarha machitgarha left a comment

Choose a reason for hiding this comment

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

Thanks for all the hard work. Great work! :)

* dropped support for PHP ^5.2
* dropped support for PHP 7.0
* dropped support for PHP 7.1
* dropped support for PHP 7.2

Choose a reason for hiding this comment

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

I don't think breaking backward-compatibility in that regard is something reasonable.

The latest release is 1.2.2 in 2016, supporting the minimum PHP version 5.3. This means at least 8 years of BC. Your PR is trying to cut it down into 3 years, which IMO is not good.

Don't get me wrong, I don't say having 3-year compatibility is a bad idea. I mean, if we have something with 8-year compatibility and you want to make it 3, we should do it in many small steps, instead of one big step.

I think upgrading the minimum PHP version to 5.6 is a good idea. Or at the very least, we can make it 7.1.

Choose a reason for hiding this comment

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

Why support a version of PHP not supported by PHP itself? The minimum supported version should be PHP 7.4. Otherwise you're talking about supporting PHP versions that have been EOL for years, and this is going to cause dependency hell as other packages drop support.

Choose a reason for hiding this comment

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

Huge jumps could lag users behind. So instead of jumping to 7.4 in a sudden, we could move to 5.6, 7.2 and then 7.4, for example.

use Webmozart\Json\JsonDecoder;
use Webmozart\Json\ValidationFailedException;

Choose a reason for hiding this comment

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

Loving the import statements being ordered. :)

/**
* @expectedException \Webmozart\Json\ValidationFailedException
*/
public function testEncodeFailsIfValidationFailsWithSchemaFile()

Choose a reason for hiding this comment

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

Smart merging of these kinds of tests.

@machitgarha
Copy link

Personally, on the JsonSchema\Validator change, I think it should be made on a separated PR.

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.

None yet

3 participants