-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Clone test arguments #1060
Clone test arguments #1060
Conversation
If a test uses @depenends, clone the objects that are passed into functions that use that argument. This prevents unintended modification of the objects value by other functions. Fixes #1057
This would need to be enabled somehow as it breaks backwards compatibility and not all objects are cloneable. |
Also, don't worry about the travis failure (it's related to #1052). |
@whatthejeff I was thinking about how to implement this so that it wouldn't be BC and would correctly handle cases where objects weren't cloneable. I was wondering if you had any feedback on these suggestions.
class Issue1075test extends PHPUnit_Framework_TestCase
{
public function testStackInitiallyEmpty()
{
$stack = new SomeStack();
$this->assertEmpty($stack->getItems());
return $stack;
}
/**
* @depends testStackInitiallyEmpty
*/
public function testAddItem($stack)
{
$stack->addItem('SomeItem');
$this->assertNotEmpty($stack->getItems());
}
/**
* @depends testStackInitiallyEmpty SideEffectSafe
*/
public function testSomethingElseThatWantsAnEmptyStack($stack)
{
$this->assertEmpty($stack->getItems());
}
} Since the object is already mutated prior to the third test running, it would clone the mutated value. As for the case of non cloneable objects:
My last thought, is this some functionality that needs to be in PHPUnit. There are ways to write tests which would prevent this issue from occurring. |
Have you looked at #11? IIRC, JExample (http://scg.unibe.ch/research/jexample), where the idea behind |
@sebastianbergmann–it looks like JExample uses the
|
Implements a policy system for defining how variables are injected using into tests when using @Depends. - Adds doc block parser for policies to Util_Test - Adds function to TestCase to manage the passing in of dependencies - TestSuite now checks for dependency policy
I started implementing multiple injection policies but ran into some issues with rerun. I'm not sure if there is a good way to rerun a "sibling" test. In the TestCase you can use My commit can be found on my local repo: baileylo/PHPUnit@b0fa94964854b09d0ce7ff557cf7f04e97805ce8. Brief over view of what I've done:
Issues I've run into:
|
@whatthejeff Do you know if there is a good way to re-run tests with in a given test suite? For more context you can see my previous comment. |
Dear contributor, let me start by apologizing for not commenting and/or working on the issue you have reported or merging the pull request you have sent sooner. PHPUnit 5.0 was released today. And today I am closing all open bug reports and pull requests for PHPUnit and its dependencies that I maintain. Please do not interpret the closing of this ticket as an insult or a lack of interest in your problem. I am sorry for any inconvenience this may cause. If the topic of this ticket is still relevant then please open a new ticket or send a new pull request. If your ticket or pull request is about a defect then please check whether the issue still exists in PHPUnit 4.8 (which will received bug fixes until August 2016). If your ticket or pull request is about a new feature then please port your patch PHPUnit 5.0 before sending a new pull request. I hope that today's extreme backlog grooming will allow me to respond to bug reports and pull requests in a more timely manner in the future. Thank you for your understanding, |
If a test uses
@depenends
, clone the arguments that are objects to prevent unintended modification of the objects by other functions.My biggest fear here is an bump in memory usage by phpunit, as we now duplicate multiple objects.
Fixes #1057