Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[VarDumper] Ingore PHPUnit and Prophecy object when they are nested #15175

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

Merged
merged 1 commit into from
Jul 2, 2015

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Jul 2, 2015

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

The purpose of this PR is to ignore nested PHPUnit/Prophecy object when dumping.

Reproducer:

$a = $this->getMock('Datetime');
$b = $this->prophesize('Datetime')->reveal();
$std = new \stdClass;
$std->my = 'property';
$std->a = $a;
$std->b = $b;

die(dump($a, $b, $std));

=>

{#86
  +"my": "property"
  +"a": Mock_Datetime_8ba7f351 {#22 …5}
  +"b": Double\DateTime\P1 {#90 …1}
}

@@ -69,6 +69,10 @@
'Symfony\Component\DependencyInjection\ContainerInterface' => 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castThrowingCasterException',

'PHPUnit_Framework_MockObject_MockObject' => 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',
'PHPUnit_Framework_MockObject_Stub' => 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',
'Prophecy\Prophecy\ProphecyInterface' => 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',
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 this should be applied on ProphecySubjectInterface, not on ProphecyInterface. Prophecy\Prophecy\ProphecyInterface is the object used to configure the mock. If you are dumping this one, you probably want to see the internals. The test double will implement Prophecy\Prophecy\ProphecySubjectInterface

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 does not work, did I miss something?

Copy link
Member

Choose a reason for hiding this comment

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

well, it depends where you are trying to dump things actually. Can you show a snippet of your code to see where you used dumping together with Prophecy ?
but in any case, Prophecy\Prophecy\ProphecyInterface is only implemented on pure Prophecy objects (i.e. not extending your code at all). I'm not sure it makes sense to cut all internals there.
Maybe we would only need to cut only the circular reference between the ObjectProphecy (implementing this interface) and the MethodProphecy when dumping.

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 put a snippet in the PR description.

@stof
Copy link
Member

stof commented Jul 2, 2015

should we also cut internals for Mockery mocks ?

@lyrixx
Copy link
Member Author

lyrixx commented Jul 2, 2015

should we also cut internals for Mockery mocks ?

I don't use Mockery... So no ? ;)

@stof
Copy link
Member

stof commented Jul 2, 2015

@lyrixx Mockery\MockInterface is the mockery mock interface.

@lyrixx lyrixx force-pushed the var-dump-ignore-testing-tools branch 2 times, most recently from 64fe225 to b24992d Compare July 2, 2015 13:34
@lyrixx
Copy link
Member Author

lyrixx commented Jul 2, 2015

I added support for Mockery

@stof
Copy link
Member

stof commented Jul 2, 2015

@lyrixx In the case of Prophecy, $this->prophesize('Datetime') does not give you a test double. It is the Prophecy\Prophecy\ObjectProphecy instance used to configure your test double. You will only get the test double after calling ->reveal() on it. this is why I said that the interface for which cutting internals makes sense is Prophecy\Prophecy\ProphecySubjectInterface

@lyrixx lyrixx force-pushed the var-dump-ignore-testing-tools branch from b24992d to df8bd14 Compare July 2, 2015 14:20
@lyrixx
Copy link
Member Author

lyrixx commented Jul 2, 2015

@stof Ah, Got it ;)Thanks. Fixed.

@lyrixx lyrixx force-pushed the var-dump-ignore-testing-tools branch from df8bd14 to 2bea373 Compare July 2, 2015 14:25
@nicolas-grekas
Copy link
Member

👍

@stof
Copy link
Member

stof commented Jul 2, 2015

👍

@nicolas-grekas
Copy link
Member

Thank you @lyrixx.

@nicolas-grekas nicolas-grekas merged commit 2bea373 into symfony:2.8 Jul 2, 2015
nicolas-grekas added a commit that referenced this pull request Jul 2, 2015
…ey are nested (lyrixx)

This PR was merged into the 2.8 branch.

Discussion
----------

[VarDumper] Ingore PHPUnit and Prophecy object when they are nested

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

The purpose of this PR is to ignore nested PHPUnit/Prophecy object when `dump`ing.

Reproducer:

```php
$a = $this->getMock('Datetime');
$b = $this->prophesize('Datetime')->reveal();
$std = new \stdClass;
$std->my = 'property';
$std->a = $a;
$std->b = $b;

die(dump($a, $b, $std));
```

=>

```
{#86
  +"my": "property"
  +"a": Mock_Datetime_8ba7f351 {#22 …5}
  +"b": Double\DateTime\P1 {#90 …1}
}
```

Commits
-------

2bea373 [VarDumper] Ingore PHPUnit and Prophecy object when they are nested
@lyrixx lyrixx deleted the var-dump-ignore-testing-tools branch July 2, 2015 17:30
@fabpot fabpot mentioned this pull request Nov 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants