Skip to content

Rename AtkPhpunit NS and zero memory leaks testing #323

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
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan --dev ; fi
composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader
if [ "${{ matrix.type }}" == "Phpunit Lowest" ]; then composer update --ansi --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress --optimize-autoloader ; fi
if [ "${{ matrix.type }}" == "Phpunit Burn" ]; then sed -i 's/ *public function runBare(): void/public function runBare(): void { gc_collect_cycles(); $mem0 = memory_get_usage(); for ($i = 0; $i < '"$(if [ \"$GITHUB_EVENT_NAME\" == \"schedule\" ]; then echo 5000; else echo 500; fi)"'; ++$i) { $this->_runBare(); if ($i === 0) { gc_collect_cycles(); $mem1 = memory_get_usage(); } } gc_collect_cycles(); $mem2 = memory_get_usage(); if ($mem2 - 1536 * 1024 > $mem0 || $mem2 - 128 * 1024 > $mem1) { $this->onNotSuccessfulTest(new AssertionFailedError("Memory leak detected! (" . round($mem0 \/ (1024 * 1024), 3) . " + " . round(($mem1 - $mem0) \/ (1024 * 1024), 3) . " + " . round(($mem2 - $mem1) \/ (1024 * 1024), 3) . " MB, " . $i . " iterations)")); } } private function _runBare(): void/' vendor/phpunit/phpunit/src/Framework/TestCase.php && cat vendor/phpunit/phpunit/src/Framework/TestCase.php | grep '_runBare(' ; fi
if [ "${{ matrix.type }}" == "Phpunit Burn" ]; then sed -i 's/ *public function runBare(): void/public function runBare(): void { gc_collect_cycles(); gc_collect_cycles(); $mem0 = memory_get_usage(); for ($i = 0; $i < '"$(if [ \"$GITHUB_EVENT_NAME\" == \"schedule\" ]; then echo 5000; else echo 500; fi)"'; ++$i) { $this->_runBare(); gc_collect_cycles(); gc_collect_cycles(); if ($i === 0) { $mem1 = memory_get_usage(); } } $mem2 = memory_get_usage(); if ($mem2 - 1536 * 1024 > $mem0 || $mem2 > $mem1) { $this->onNotSuccessfulTest(new AssertionFailedError("Memory leak detected! (" . round($mem0 \/ (1024 * 1024), 3) . " MB + " . round(($mem1 - $mem0) \/ (1024 * 1024), 3) . " MB + " . round(($mem2 - $mem1) \/ 1024, 3) . " KB, " . $i . " iterations)")); } } private function _runBare(): void/' vendor/phpunit/phpunit/src/Framework/TestCase.php && cat vendor/phpunit/phpunit/src/Framework/TestCase.php | grep '_runBare(' ; fi

- name: Init
run: |
Expand Down
5 changes: 2 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
<directory suffix=".php">src</directory>
</include>
<exclude>
<file>src/AtkPhpunit/ResultPrinter.php</file>
<file>src/AtkPhpunit/ExceptionWrapper.php</file>
<file>src/AtkPhpunit/TestCase.php</file>
<file>src/Phpunit/ResultPrinter.php</file>
<file>src/Phpunit/TestCase.php</file>
</exclude>
<report>
<clover outputFile="build/logs/clover.xml" />
Expand Down
2 changes: 1 addition & 1 deletion src/AppScopeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ trait AppScopeTrait
protected function assertInstanceOfApp(object $app): void
{
// called from phpunit, allow to use/test this trait without \Atk4\Ui\App class
if (class_exists(\PHPUnit\Framework\TestCase::class, false)) {
if (class_exists(\PHPUnit\Framework\TestCase::class, false) && !class_exists(\Atk4\Ui\App::class)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Atk4\Core\AtkPhpunit;
namespace Atk4\Core\Phpunit;

use Atk4\Core\Exception;
use PHPUnit\Framework\ExceptionWrapper;
Expand Down
17 changes: 16 additions & 1 deletion src/AtkPhpunit/TestCase.php → src/Phpunit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@

declare(strict_types=1);

namespace Atk4\Core\AtkPhpunit;
namespace Atk4\Core\Phpunit;

/**
* Generic TestCase for PHPUnit tests for ATK4 repos.
*/
class TestCase extends \PHPUnit\Framework\TestCase
{
protected function tearDown(): void
{
// remove once https://github.com/sebastianbergmann/phpunit/issues/4705 is fixed
foreach (array_keys(array_diff_key(get_object_vars($this), get_class_vars(\PHPUnit\Framework\TestCase::class))) as $k) {
if (!is_scalar($this->{$k})) {
$this->{$k} = null;
}
}

// once PHP 8.0 support is dropped, needed only once, see:
// https://github.com/php/php-src/commit/b58d74547f7700526b2d7e632032ed808abab442
gc_collect_cycles();
gc_collect_cycles();
}

/**
* Calls protected method.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/AppScopeTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Atk4\Core\Tests;

use Atk4\Core\AppScopeTrait;
use Atk4\Core\AtkPhpunit;
use Atk4\Core\ContainerTrait;
use Atk4\Core\NameTrait;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Core\TrackableTrait;

/**
* @coversDefaultClass \Atk4\Core\AppScopeTrait
*/
class AppScopeTraitTest extends AtkPhpunit\TestCase
class AppScopeTraitTest extends TestCase
{
public function testConstruct(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/CollectionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Atk4\Core\Tests;

use Atk4\Core;
use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;

/**
* @coversDefaultClass \Atk4\Core\ContainerTrait
*/
class CollectionTraitTest extends AtkPhpunit\TestCase
class CollectionTraitTest extends TestCase
{
public function testBasic(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ConfigTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\ConfigTrait;
use Atk4\Core\Phpunit\TestCase;

/**
* @coversDefaultClass \Atk4\Core\ConfigTrait
*/
class ConfigTraitTest extends AtkPhpunit\TestCase
class ConfigTraitTest extends TestCase
{
/** @var string */
public $dir = __DIR__ . '/config_test';
Expand Down
4 changes: 2 additions & 2 deletions tests/ContainerTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Atk4\Core\Tests;

use Atk4\Core;
use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;

/**
* @coversDefaultClass \Atk4\Core\ContainerTrait
*/
class ContainerTraitTest extends AtkPhpunit\TestCase
class ContainerTraitTest extends TestCase
{
public function testBasic(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/DebugTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace Atk4\Core\Tests;

use Atk4\Core\AppScopeTrait;
use Atk4\Core\AtkPhpunit;
use Atk4\Core\DebugTrait;
use Atk4\Core\Phpunit\TestCase;

/**
* @coversDefaultClass \Atk4\Core\DebugTrait
*/
class DebugTraitTest extends AtkPhpunit\TestCase
class DebugTraitTest extends TestCase
{
/**
* Test debug().
Expand Down
4 changes: 2 additions & 2 deletions tests/DiContainerTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\DiContainerTrait;
use Atk4\Core\Exception;
use Atk4\Core\Phpunit\TestCase;

/**
* @coversDefaultClass \Atk4\Core\DiContainerTrait
*/
class DiContainerTraitTest extends AtkPhpunit\TestCase
class DiContainerTraitTest extends TestCase
{
public function testFromSeed(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/DynamicMethodTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Atk4\Core\Tests;

use Atk4\Core\AppScopeTrait;
use Atk4\Core\AtkPhpunit;
use Atk4\Core\DynamicMethodTrait;
use Atk4\Core\Exception;
use Atk4\Core\HookTrait;
use Atk4\Core\Phpunit\TestCase;

/**
* @coversDefaultClass \Atk4\Core\DynamicMethodTrait
*/
class DynamicMethodTraitTest extends AtkPhpunit\TestCase
class DynamicMethodTraitTest extends TestCase
{
public function testConstruct(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Exception;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Core\TrackableTrait;

/**
* @coversDefaultClass \Atk4\Core\Exception
*/
class ExceptionTest extends AtkPhpunit\TestCase
class ExceptionTest extends TestCase
{
public function testBasic(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\DiContainerTrait;
use Atk4\Core\Exception;
use Atk4\Core\Factory;
use Atk4\Core\HookBreaker;
use Atk4\Core\Phpunit\TestCase;

/**
* @coversDefaultClass \Atk4\Core\Factory
*/
class FactoryTest extends AtkPhpunit\TestCase
class FactoryTest extends TestCase
{
public function testMerge1(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/HookTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Exception;
use Atk4\Core\HookBreaker;
use Atk4\Core\HookTrait;
use Atk4\Core\Phpunit\TestCase;

/**
* @coversDefaultClass \Atk4\Core\HookTrait
*/
class HookTraitTest extends AtkPhpunit\TestCase
class HookTraitTest extends TestCase
{
public function testArguments(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/InitializerTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace Atk4\Core\Tests;

use Atk4\Core;
use Atk4\Core\AtkPhpunit;
use Atk4\Core\Exception;
use Atk4\Core\Phpunit\TestCase;

/**
* @coversDefaultClass \Atk4\Core\InitializerTrait
*/
class InitializerTraitTest extends AtkPhpunit\TestCase
class InitializerTraitTest extends TestCase
{
public function testBasic(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/LocalizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Exception;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Core\Translator\Adapter\Generic;
use Atk4\Core\Translator\ITranslatorAdapter;
use Atk4\Core\Translator\Translator;
use Atk4\Data\Persistence;

class LocalizationTest extends AtkPhpunit\TestCase
class LocalizationTest extends TestCase
{
public function testTranslatableTrait(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ReadableCaptionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Core\ReadableCaptionTrait;

/**
* @coversDefaultClass \Atk4\Core\ReadableCaptionTrait
*/
class ReadableCaptionTraitTest extends AtkPhpunit\TestCase
class ReadableCaptionTraitTest extends TestCase
{
/**
* Test readableCaption method.
Expand Down
4 changes: 2 additions & 2 deletions tests/SessionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Exception;
use Atk4\Core\NameTrait;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Core\SessionTrait;

/**
* @coversDefaultClass \Atk4\Core\SessionTrait
*/
class SessionTraitTest extends AtkPhpunit\TestCase
class SessionTraitTest extends TestCase
{
public static function setUpBeforeClass(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/StaticAddToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\ContainerTrait;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Core\StaticAddToTrait;
use Atk4\Core\TrackableTrait;

Expand Down Expand Up @@ -60,7 +60,7 @@ public function __construct(string $name)
/**
* @coversDefaultClass \Atk4\Core\StaticAddToTrait
*/
class StaticAddToTest extends AtkPhpunit\TestCase
class StaticAddToTest extends TestCase
{
public function testBasic(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/TraitUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Atk4\Core\tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\HookTrait;
use Atk4\Core\NameTrait;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Core\TraitUtil;

/**
* @coversDefaultClass \Atk4\Core\TraitUtil
*/
class TraitUtilTest extends AtkPhpunit\TestCase
class TraitUtilTest extends TestCase
{
public function testHasTrait(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/TranslatorAdapterBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Atk4\Core\Tests;

use Atk4\Core\AtkPhpunit;
use Atk4\Core\Phpunit\TestCase;

abstract class TranslatorAdapterBase extends AtkPhpunit\TestCase
abstract class TranslatorAdapterBase extends TestCase
{
abstract public function getTranslatableMock(): object;

Expand Down