Skip to content

Commit

Permalink
sandbox for xdebug_trace of different data provider implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
epdenouden committed Jun 24, 2019
1 parent a5a0372 commit 3b70a64
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 14 deletions.
4 changes: 4 additions & 0 deletions phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define('DEBUG_DP_JIT', getenv('DP_JIT') ? true : false);
define('DEBUG_DP_UNLOAD', getenv('DP_UNLOAD') ? true : false);
xdebug_enable();
xdebug_start_trace('/tmp/phpunit.xt', XDEBUG_TRACE_NAKED_FILENAME | XDEBUG_TRACE_COMPUTERIZED);

if (version_compare('7.2.0', PHP_VERSION, '>')) {
fwrite(
Expand Down
5 changes: 3 additions & 2 deletions src/Framework/DataProviderTestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function __construct($theClass = '', $name = '')
{
parent::__construct($theClass, $name);

$this->loadData();
if (!\DEBUG_DP_JIT) {
$this->loadData();
}
}

/**
Expand Down Expand Up @@ -98,7 +100,6 @@ public function loadData(): void
);

$this->createTestsFromData($className, $name, $data);

} catch (IncompleteTestError $e) {
$message = \sprintf(
'Test for %s::%s marked incomplete by data provider',
Expand Down
26 changes: 15 additions & 11 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,21 @@ public function addWarning(string $warning): void
$this->warnings[] = $warning;
}

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

if (!\DEBUG_DP_UNLOAD) {
return;
}

// MVP unloading: this needs a deeper look
$this->data = [];
$this->dataName = '__UNLOADED__';
}

/**
* Override to run the test and assert its state.
*
Expand Down Expand Up @@ -2210,15 +2225,4 @@ 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__";
}
}
2 changes: 1 addition & 1 deletion src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public function run(TestResult $result = null): TestResult

$test->run($result);

if ($test instanceof TestCase and $test->usesDataProvider()) {
if ($test instanceof TestCase && $test->usesDataProvider()) {
$test->unloadData();
}
}
Expand Down
191 changes: 191 additions & 0 deletions tests/sandbox/DummyGeneratorDataprovidersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class DummyGeneratorDataProviderLoadingTest extends \PHPUnit\Framework\TestCase
{
const SIZE_SMALL = 10000;
const SIZE_MEDIUM = 50000;
const SIZE_LARGE = 100000;

public function testFirst(): void
{
$this->assertTrue(true);
}

/**
* @dataProvider smallProvider
*/
public function testSmall1 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider smallProvider
*/
public function testSmall2 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider smallProvider
*/
public function testSmall3 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider mediumProvider
*/
public function testMedium1 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider mediumProvider
*/
public function testMedium2 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider mediumProvider
*/
public function testMedium3 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider mediumProvider
*/
public function testMedium4 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider mediumProvider
*/
public function testMedium5 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge1 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge2 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge3 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge4 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge5 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge6 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge7 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge8 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge9 (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge10 (string $text): void
{
$this->assertIsString($text);
}

public function testLast(): void
{
$this->assertTrue(true);
}

public function smallProvider(): array
{
return [
"small 1" => [str_repeat("some string", self::SIZE_SMALL)],
];
}

public function mediumProvider(): array
{
return [
"medium 1" => [str_repeat("some string", self::SIZE_MEDIUM)],
];
}

public function largeProvider(): array
{
return [
"large 1" => [str_repeat("some string", self::SIZE_LARGE)],
];
}

}
86 changes: 86 additions & 0 deletions tests/sandbox/SyntheticDataprovidersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class SyntheticDataProviderLoadingTest extends \PHPUnit\Framework\TestCase
{
const SIZE_SMALL = 10000;
const SIZE_MEDIUM = 50000;
const SIZE_LARGE = 100000;

public function testFirst(): void
{
$this->assertTrue(true);
}

/**
* @dataProvider smallProvider
*/
public function testSmall (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider mediumProvider
*/
public function testMedium (string $text): void
{
$this->assertIsString($text);
}

/**
* @dataProvider largeProvider
*/
public function testLarge (string $text): void
{
$this->assertIsString($text);
}

public function testLast(): void
{
$this->assertTrue(true);
}

public function smallProvider(): array
{
return [
"small 1" => [str_repeat("some string", self::SIZE_SMALL)],
"small 2" => [str_repeat("some string", self::SIZE_SMALL)],
"small 3" => [str_repeat("some string", self::SIZE_SMALL)],
];
}

public function mediumProvider(): array
{
return [
"medium 1" => [str_repeat("some string", self::SIZE_MEDIUM)],
"medium 2" => [str_repeat("some string", self::SIZE_MEDIUM)],
"medium 3" => [str_repeat("some string", self::SIZE_MEDIUM)],
"medium 4" => [str_repeat("some string", self::SIZE_MEDIUM)],
"medium 5" => [str_repeat("some string", self::SIZE_MEDIUM)],
];
}

public function largeProvider(): array
{
return [
"large 1" => [str_repeat("some string", self::SIZE_LARGE)],
"large 2" => [str_repeat("some string", self::SIZE_LARGE)],
"large 3" => [str_repeat("some string", self::SIZE_LARGE)],
"large 4" => [str_repeat("some string", self::SIZE_LARGE)],
"large 5" => [str_repeat("some string", self::SIZE_LARGE)],
"large 6" => [str_repeat("some string", self::SIZE_LARGE)],
"large 7" => [str_repeat("some string", self::SIZE_LARGE)],
"large 8" => [str_repeat("some string", self::SIZE_LARGE)],
"large 9" => [str_repeat("some string", self::SIZE_LARGE)],
"large 10" => [str_repeat("some string", self::SIZE_LARGE)],
];
}

}
31 changes: 31 additions & 0 deletions tests/sandbox/trace_jit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

rm -f data_*.txt

# Prefetch
DP_JIT=0 \
DP_UNLOAD=0 \
./phpunit tests/sandbox/SyntheticDataprovidersTest.php

awk '/TestResult->startTest[[:space:]]/{print $5}' /tmp/phpunit.xt > data_prefetch.txt

# JIT only
DP_JIT=1 \
DP_UNLOAD=0 \
./phpunit tests/sandbox/SyntheticDataprovidersTest.php

awk '/TestResult->startTest[[:space:]]/{print $5}' /tmp/phpunit.xt > data_jit.txt

# JIT with unload
DP_JIT=1 \
DP_UNLOAD=1 \
./phpunit tests/sandbox/SyntheticDataprovidersTest.php

awk '/TestResult->startTest[[:space:]]/{print $5}' /tmp/phpunit.xt > data_unload.txt

# Simulate resource consumption of a Generator driven data provider
DP_JIT=1 \
DP_UNLOAD=1 \
./phpunit tests/sandbox/DummyGeneratorDataprovidersTest.php

awk '/TestResult->startTest[[:space:]]/{print $5}' /tmp/phpunit.xt > data_generator.txt

0 comments on commit 3b70a64

Please sign in to comment.