Skip to content

Add logic to new stream functions on Windows #105

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

Closed
wants to merge 4 commits into from

Conversation

johnstevenson
Copy link
Contributor

The tests are pretty useless, but it is impossible to guarantee what the descriptors are pointing to in all test environments.

*/
public function testSapiWindowsVt100Support()
{
if ('\\' !== DIRECTORY_SEPARATOR) {
Copy link
Member

Choose a reason for hiding this comment

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

@requires OSFAMILY ... instead

Copy link
Member

Choose a reason for hiding this comment

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

The current code matches the convention we're following, LGTM as is.

Copy link
Member

Choose a reason for hiding this comment

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

what's behind that convention? looks pretty weird to me to not use solution provided by test runner but do it manually

Copy link
Member

Choose a reason for hiding this comment

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

Dunno exactly, maybe just discoverability is better, so more commonly used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do it whatever way you chaps want.

Copy link
Member

Choose a reason for hiding this comment

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

let's keep it this way, that's consistent with the code base

Copy link
Member

Choose a reason for hiding this comment

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

I think the reason is support for older PHPUnit versions (IIRC, OSFAMILY was added later)

{
// We cannot actually enable vt100 support
if (true === $enable || !self::stream_isatty($stream)) {
return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just wondering if I have got the logic right here, in automatically returning false if the enable param is true. It makes sense in the strictest way, in that you cannot actually enable the setting without using the native function. But in terms of how the polyfill will used, it may be better to remove this bit (because an application would probably always set the enable param to true). Thoughts please.

Also, I haven't covered the case where enable = false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps if (false === $enable ... would be better, in that one would simply not apply the vt100 formatting sequences, regardless of what the native function would return.

@johnstevenson
Copy link
Contributor Author

I've changed the logic in sapi_windows_vt100_support, based on the following:

The only way to enable support for vt100 sequences in modern Windows consoles is to use the SetConsoleMode API function and PHP now provides a way to do this with sapi_windows_vt100_support. This is a multi-purpose function that can enable support, disable support or return whether support is enabled. Note that on cli start-up support will not be enabled.

So in userland, an app that outputs vt100 sequences will either enable it early on, or on-demand in an output handler. It would unnecessary to disable it, because an app would simply omit vt100 sequences if they were inappropriate.

@nicolas-grekas
Copy link
Member

I would trust you on this one, looks 👍 to me.

@johnstevenson
Copy link
Contributor Author

@nicolas-grekas Thanks. I reviewed the PR that added this to php-src and contributed some mods and stuff (like the stream_isatty function), which might or might not set your mind at rest.

@johnstevenson
Copy link
Contributor Author

@nicolas-grekas Apologies, but I found some Git Bash weirdness happening when testing composer/xdebug-handler

In addition, if you invoke git-bash.exe then TERM=xterm, but if you use Git\bin\bash.exe then TERM=cygwin and color output is not supported (although it was on older versions of Git for Windows).

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Sorry for the late review, LGTM, except the tests, which need to be enhanced.
Right now, our CI doesn't use PHP 7.2, I'll do it in another PR.
For now, can you ensure this passes on PHP 7.2 on your Windows machine once comments are addressed?

*/
public function testSapiWindowsVt100Support()
{
if ('\\' !== DIRECTORY_SEPARATOR) {
Copy link
Member

Choose a reason for hiding this comment

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

let's keep it this way, that's consistent with the code base

$this->markTestSkipped('Windows only test');
}

$this->assertFalse(p::sapi_windows_vt100_support(STDOUT, false));
Copy link
Member

Choose a reason for hiding this comment

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

we should make the test pass without the p:: prefix: the testing framework will ensure the test is run twice: with and without the polyfill when possible, so that behavior parity is "proven" on 7.2

Copy link
Member

Choose a reason for hiding this comment

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

we do know it, but as you see it's not obvious, maybe it worth to put that knowledge somewhere? (contributing file perhaps?)

Copy link
Member

Choose a reason for hiding this comment

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

@keradus Why not :) The readme has this sentence on the topic:

Polyfills are unit-tested alongside their native implementation so that feature and behavior parity can be proven and enforced in the long run.

Feel free to submit a PR to amend the README.md, or another file that could be a better fit to you.

public function testStreamIsatty()
{
$fp = fopen('php://temp', 'r+');
$this->assertFalse(p::stream_isatty($fp));
Copy link
Member

Choose a reason for hiding this comment

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

no p::, see above

@johnstevenson
Copy link
Contributor Author

@nicolas-grekas To confirm: The tests pass on PHP-7.2 on Windows

@nicolas-grekas
Copy link
Member

Thank you @johnstevenson.

@johnstevenson johnstevenson deleted the php-win7.2 branch January 31, 2018 19:57
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.

4 participants