Skip to content

fix tests - #2521

Merged
dantleech merged 2 commits into
phpactor:masterfrom
gerardroche:fix-tests
Jan 25, 2024
Merged

dantleech merged 2 commits into
phpactor:masterfrom
gerardroche:fix-tests

Conversation

@gerardroche

Copy link
Copy Markdown
Contributor
  • fix(tests): ansi output causes test failures

    On some terminals, e.g. gnome-terminal, kitty (ubuntu), some tests fail
    because the output of process contain color codes. For example in
    the following assertion:

    $this->assertStringContainsString('class ⟶Badger⟵', $process->getOutput());
    

    The characters surrounding "Badger" will be in color and so the
    assertion fails because there are color codes in the string.

    This patch adds --no-ansi to the -php-cs-fixer test command so that
    the output never has color codes.

  • fix(test): passing null to type string is deprecated

    When error reporting includes deprecations, the follow notice is emitted
    when running the tests:

    Deprecated: SplFileInfo::__construct(): Passing null to parameter #1 ($filename) of type string is deprecated in vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(44) : eval()'d code on line 6
    

    The test has been updated to use Symfony's SplFileInfo class which
    Prophecy has an internal patch to help avoid the deprecations.

On some terminals, e.g. gnome-terminal, kitty (ubuntu), some tests fail
because the output of process contain color codes. For example in
the following assertion:

    $this->assertStringContainsString('class ⟶Badger⟵', $process->getOutput());

The characters surrounding "Badger" will be in color and so the
assertion fails because there are color codes in the string.

This patch adds `--no-ansi` to the `-php-cs-fixer` test command so that
the output never has color codes.
When error reporting includes deprecations, the follow notice is emitted
when running the tests:

```
Deprecated: SplFileInfo::__construct(): Passing null to parameter #1 ($filename) of type string is deprecated in vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(44) : eval()'d code on line 6
```

The test has been updated to use Symfony's SplFileInfo class which
Prophecy has an internal patch to help avoid the deprecations.
private function createFakeSplFileInfo(string $filename, bool $isDir = false): SplFileInfo
{
$file = $this->prophesize(SplFileInfo::class);
$file = $this->prophesize(\Symfony\Component\Finder\SplFileInfo::class);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not sure why this change? it should not be the FQN - should it be the Symfony SPL info?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the class that the Prophecy spltfileinfo patch checks against here: https://github.com/phpspec/prophecy/blob/master/src/Prophecy/Doubler/ClassPatch/SplFileInfoPatch.php#L119

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Notice that the return type is still \SplFileInfo because we're only using the symfony one to avoid the deprecation. Apparently there is an internal implementation detail about \SplFileInfo that makes it difficult for Prophecy to prophesize it without arguments.

@dantleech
dantleech merged commit e337744 into phpactor:master Jan 25, 2024
@dantleech

Copy link
Copy Markdown
Collaborator

all clear, thanks :) we should probably import the class rather than using the FQN but CS fixer should take care of that so not important.

@gerardroche
gerardroche deleted the fix-tests branch January 25, 2024 13: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