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

Update .travis.yml to test under PHP 7+ #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sanmai
Copy link

@sanmai sanmai commented Sep 26, 2018

  • Add more recent versions of PHP to the build at Travis.
  • Fix build errors under PHP 7+. Example error.

Fixes #25

@sanmai sanmai changed the title Update .travis.yml Update .travis.yml to test under PHP 7+ Sep 26, 2018
@sanmai sanmai force-pushed the patch-2 branch 2 times, most recently from ee0a7e8 to 39742b6 Compare September 26, 2018 01:55
@sanmai
Copy link
Author

sanmai commented Sep 26, 2018

@schmittjoh would you have a minute to review this PR? Just a line of code changed, should be a piece of cake. Thank you.

@@ -178,7 +178,7 @@ public function testAdd()
return 1;
});

$this->assertSame(array(0, 0, 1, $this->a, $this->b), $this->seq->all());
$this->assertEquals(array(0, 0, 1, $this->a, $this->b), $this->seq->all());
Copy link
Owner

Choose a reason for hiding this comment

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

Could you tell me a bit more about this change? Looking at the failing test-case, it seems like the order of a and b changed which should not happen for a sequence type?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, these hex IDs confused me, but sure they changed places. Let me see if I can find a reason.

Copy link
Author

@sanmai sanmai Sep 26, 2018

Choose a reason for hiding this comment

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

So what I think is happening is that sortWith uses usort which does not guarantee that elements come in specific order. And there's this commit which specifically mentions that usort may be affected, which commit went into PHP 7.0 release.

And indeed if I swap $a and $b in the input data, this specific assertion checks out all right.

One way to tackle this is to rewrite that callback used for sortWith, which is, well, somewhat difficult to follow in the current form. What do you think?

@schmittjoh
Copy link
Owner

I prefer to keep the lock file. This is in particular useful for small libraries that do not see commits so that we have a known good state and reduce the risk of suddenly failing tests.

@sanmai
Copy link
Author

sanmai commented Sep 26, 2018

OK, I’ll get it back in a moment.

@sanmai
Copy link
Author

sanmai commented Sep 26, 2018

See, the problem with the commited lock file is that all packages in it have the very recent version you were able to install under currently used PHP version, which is 7.2 in my case. Hence you can see most builds on earlier versions are failing with "Your requirements could not be resolved to an installable set of packages".

Now we have two options:

  • We can add a platform requirement into composer.json, so it would always assume the code will only run under PHP 5.4, and select packages accordingly. This is a major drawback because there are backward-incompatible changes every versions of PHP, so packages that were working fine in PHP 5.4 could be suddenly failing under PHP 7.3. Also, you couldn't test with more recent versions, only with what you have locked to. If you depend on something and that thing breaks under you, you better know about it, right?
  • We can remove composer.lock, which I believe is the best practice for libraries these days.

What do you prefer?

(I went for the first option for now.)

@sanmai
Copy link
Author

sanmai commented Sep 26, 2018

The problem was in sortWith that uses usort which does not guarantee that elements come in specific order. And there's this commit which specifically mentions that usort may be affected, which commit went into PHP 7.0 release.

And indeed if I swap $a and $b in the input data, this specific assertion checks out all right. So now I changed them to be strings instead, and now we sort them explicitly. This way no matter in which order arguments are coming, output will be the same.

All tests are green.

Add more recent versions of PHP to the build at Travis.

Require a specific version of PHPUnit that's in use.

- Update .travis.yml to use a direct path to our vendored phpunit executable
Had this warning:

$ composer validate
./composer.json is valid, but with a few warnings
See https://getcomposer.org/doc/04-schema.md for details on the schema
License "Apache2" is not a valid SPDX license identifier, see https://spdx.org/licenses/ if you use an open license.
- Update SequenceTest to use strings, because they're not ints, just like objects
- A'n'B's are strings, let's sort them explicitly so that PHP's version differences won't come in our way
@sanmai
Copy link
Author

sanmai commented Oct 12, 2018

@schmittjoh is there anything else you'd like to change here?

@sanmai
Copy link
Author

sanmai commented Oct 28, 2018

@schmittjoh any chance this could be merged?

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