Skip to content

Commit

Permalink
Closes #2496
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 13, 2017
1 parent c8745d3 commit 0efe9f6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ChangeLog-6.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ All notable changes of the PHPUnit 6.5 release series are documented in this fil

## [6.5.0] - 2017-12-01

* Implemented [#2496](https://github.com/sebastianbergmann/phpunit/issues/2496): Allow shallow copy of dependencies

[6.5.0]: https://github.com/sebastianbergmann/phpunit/compare/6.4...6.5.0

19 changes: 15 additions & 4 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2023,16 +2023,25 @@ protected function handleDependencies()
$passedKeys = \array_flip(\array_unique($passedKeys));

foreach ($this->dependencies as $dependency) {
$clone = false;
$deepClone = false;
$shallowClone = false;

if (\strpos($dependency, 'clone ') === 0) {
$clone = true;
$deepClone = true;
$dependency = \substr($dependency, \strlen('clone '));
} elseif (\strpos($dependency, '!clone ') === 0) {
$clone = false;
$deepClone = false;
$dependency = \substr($dependency, \strlen('!clone '));
}

if (\strpos($dependency, 'shallowClone ') === 0) {
$shallowClone = true;
$dependency = \substr($dependency, \strlen('shallowClone '));
} elseif (\strpos($dependency, '!shallowClone ') === 0) {
$shallowClone = false;
$dependency = \substr($dependency, \strlen('!shallowClone '));
}

if (\strpos($dependency, '::') === false) {
$dependency = $className . '::' . $dependency;
}
Expand Down Expand Up @@ -2069,11 +2078,13 @@ protected function handleDependencies()
return false;
}

if ($clone) {
if ($deepClone) {
$deepCopy = new DeepCopy;
$deepCopy->skipUncloneable(false);

$this->dependencyInput[$dependency] = $deepCopy->copy($passed[$dependency]['result']);
} elseif ($shallowClone) {
$this->dependencyInput[$dependency] = clone $passed[$dependency]['result'];
} else {
$this->dependencyInput[$dependency] = $passed[$dependency]['result'];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TextUI/dependencies-clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

.... 4 / 4 (100%)
...... 6 / 6 (100%)

Time: %s, Memory: %s

OK (4 tests, 4 assertions)
OK (6 tests, 6 assertions)

16 changes: 16 additions & 0 deletions tests/_files/ClonedDependencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@ public function testFour($dependency)
{
$this->assertNotSame(self::$dependency, $dependency);
}

/**
* @depends !shallowClone testOne
*/
public function testFive($dependency)
{
$this->assertSame(self::$dependency, $dependency);
}

/**
* @depends shallowClone testOne
*/
public function testSix($dependency)
{
$this->assertNotSame(self::$dependency, $dependency);
}
}

0 comments on commit 0efe9f6

Please sign in to comment.