diff --git a/composer.json b/composer.json index 2ad526e..abcb1fc 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "dragon-code/benchmark": "^2.6", "ergebnis/composer-normalize": "^2.44.0", "friendsofphp/php-cs-fixer": "^3.64.0", + "php-defer/php-defer": "^5.0", "phpstan/phpstan": "^1.12.6", "phpunit/phpunit": "^10.5.36", "phpyh/coding-standard": "^2.6.2", diff --git a/composer.lock b/composer.lock index 5dbd04e..ccea8bb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c1d9a7109f30053b5f9b13d5bef79d82", + "content-hash": "6e87d49fba51ad37732d79e631352694", "packages": [ { "name": "nikic/php-parser", @@ -1993,6 +1993,53 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "php-defer/php-defer", + "version": "v5.0.7", + "source": { + "type": "git", + "url": "https://github.com/php-defer/php-defer.git", + "reference": "9f4183d6039e8337fefc3b5e73ed4ede58ee0bf7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-defer/php-defer/zipball/9f4183d6039e8337fefc3b5e73ed4ede58ee0bf7", + "reference": "9f4183d6039e8337fefc3b5e73ed4ede58ee0bf7", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions.inc.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bartłomiej Krukowski", + "email": "bartlomiej@krukowski.me" + } + ], + "description": "Golang's defer statement for PHP", + "keywords": [ + "defer", + "golang" + ], + "support": { + "issues": "https://github.com/php-defer/php-defer/issues", + "source": "https://github.com/php-defer/php-defer/tree/v5.0.7" + }, + "time": "2023-09-21T16:38:54+00:00" + }, { "name": "phpstan/phpstan", "version": "1.12.6", @@ -6238,14 +6285,14 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { "php": "^8.1", "ext-tokenizer": "*" }, - "platform-dev": {}, + "platform-dev": [], "platform-overrides": { "php": "8.1" }, diff --git a/tests/TyphoonReflectorMemoryTest.php b/tests/TyphoonReflectorMemoryTest.php index c887237..3d791dc 100644 --- a/tests/TyphoonReflectorMemoryTest.php +++ b/tests/TyphoonReflectorMemoryTest.php @@ -12,24 +12,20 @@ final class TyphoonReflectorMemoryTest extends TestCase { public function testItIsGarbageCollected(): void { - $gcWasEnabled = gc_enabled(); - gc_disable(); + if (gc_enabled()) { + gc_disable(); + defer($_, gc_enable(...)); + } - try { - $reflector = TyphoonReflector::build(); - $reflection = $reflector->reflectClass(\AppendIterator::class); - $weakReflector = \WeakReference::create($reflector); - $weakReflection = \WeakReference::create($reflection); + $reflector = TyphoonReflector::build(); + $reflection = $reflector->reflectClass(\AppendIterator::class); + $weakReflector = \WeakReference::create($reflector); + $weakReflection = \WeakReference::create($reflection); - unset($reflection, $reflector); + unset($reflection, $reflector); - // assertTrue() is used instead of assertNull() to avoid huge reflector dump in the diff - self::assertTrue($weakReflector->get() === null, 'Reflector is not garbage collected.'); - self::assertTrue($weakReflection->get() === null, 'ClassReflection is not garbage collected.'); - } finally { - if ($gcWasEnabled) { - gc_enable(); - } - } + // assertTrue() is used instead of assertNull() to avoid huge reflector dump in the diff + self::assertTrue($weakReflector->get() === null, 'Reflector is not garbage collected.'); + self::assertTrue($weakReflection->get() === null, 'ClassReflection is not garbage collected.'); } }