Skip to content

Commit

Permalink
Clean up MVP a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
epdenouden committed Jun 24, 2019
1 parent 227c492 commit a5a0372
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Framework/DataProviderTestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ final class DataProviderTestSuite extends TestSuite
*/
private $isLoaded = false;

public function __construct($theClass = '', $name = '')
{
parent::__construct($theClass, $name);

$this->loadData();
}

/**
* @param string[] $dependencies
*/
Expand Down Expand Up @@ -59,7 +66,6 @@ public function injectFilter(Factory $filter): void
{
$this->iteratorFilter = $filter;

// print "%%% load() in injectFilter()\n";
$this->loadData();
}

Expand Down Expand Up @@ -106,7 +112,7 @@ public function loadData(): void
$message .= "\n" . $_message;
}

$this->addTest(new IncompleteTestCase($message));
$this->addTest(new IncompleteTestCase($className, $name, $message));
} catch (SkippedTestError $e) {
$message = \sprintf(
'Test for %s::%s skipped by data provider',
Expand All @@ -120,7 +126,7 @@ public function loadData(): void
$message .= "\n" . $_message;
}

$this->addTest(new SkippedTestCase($message));
$this->addTest(new SkippedTestCase($className, $name, $message));
} catch (Exception $e) {
$message = \sprintf(
'The data provider specified for %s::%s is invalid.',
Expand Down
11 changes: 11 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2210,4 +2210,15 @@ private function recordDoubledType($originalClassName): void
}
}
}

public function unloadData(): void
{
if (empty($this->data)) {
return;
}

// MVP unloading: this needs a deeper look
$this->data = [];
$this->dataName = "__UNLOADED__";
}
}
6 changes: 6 additions & 0 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ public function run(TestResult $result = null): TestResult
}

$test->run($result);

if ($test instanceof TestCase and $test->usesDataProvider()) {
$test->unloadData();
}
}

try {
Expand Down Expand Up @@ -710,6 +714,8 @@ public function testAt(int $index)

/**
* Returns the tests as an enumeration.
*
* @return TestCase[]
*/
public function tests(): array
{
Expand Down

0 comments on commit a5a0372

Please sign in to comment.