diff --git a/composer.json b/composer.json index e73d8ba..910c1eb 100644 --- a/composer.json +++ b/composer.json @@ -41,8 +41,7 @@ "autoload-dev": { "psr-4": { "Typhoon\\Reflection\\": [ - "tests/unit", - "tests/memory" + "tests/unit" ] } }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 520cf57..ea85503 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -17,9 +17,6 @@ tests/unit - - tests/memory - diff --git a/tests/memory/MemoryLeakTest.php b/tests/memory/MemoryLeakTest.php deleted file mode 100644 index 511e0b0..0000000 --- a/tests/memory/MemoryLeakTest.php +++ /dev/null @@ -1,91 +0,0 @@ -in(self::DIRECTORIES_TO_LOAD)->name('*.php') as $file) { - /** @psalm-suppress UnresolvableInclude */ - require_once $file->getPathname(); - } - - self::$phpParser = (new ParserFactory())->createForHostVersion(); - self::cleanUpParser(); - } - - private static function cleanUpParser(): void - { - self::$phpParser->parse(''); - } - - private static function assertMemoryIsConstant(\Closure $action): void - { - $memory = memory_get_usage(); - - $action(); - self::cleanUpParser(); - - self::assertLessThanOrEqual($memory, memory_get_usage()); - } - - public function testTyphoonReflectorClassExistsIsNotLeaking(): void - { - // warm up - TyphoonReflector::build(phpParser: self::$phpParser)->classExists(Type\NamedObjectType::class); - self::cleanUpParser(); - - foreach (self::CLASSES as $class) { - self::assertMemoryIsConstant(static function () use ($class): void { - TyphoonReflector::build(phpParser: self::$phpParser)->classExists($class); - }); - } - } - - public function testTyphoonReflectorReflectIsNotLeaking(): void - { - // warm up - TyphoonReflector::build(phpParser: self::$phpParser)->reflectClass(Type\NamedObjectType::class); - TyphoonReflector::build(phpParser: self::$phpParser)->reflectClass(Type\TemplateType::class); - self::cleanUpParser(); - - foreach (self::CLASSES as $class) { - self::assertMemoryIsConstant(static function () use ($class): void { - TyphoonReflector::build(phpParser: self::$phpParser)->reflectClass($class); - }); - } - } -} diff --git a/tests/unit/ReflectorMemoryTest.php b/tests/unit/ReflectorMemoryTest.php new file mode 100644 index 0000000..579d22d --- /dev/null +++ b/tests/unit/ReflectorMemoryTest.php @@ -0,0 +1,28 @@ +reflectClass(\AppendIterator::class); + $weakReflector = \WeakReference::create($reflector); + $weakReflection = \WeakReference::create($reflection); + + unset($reflector, $reflection); + + self::assertNull($weakReflector->get()); + self::assertNull($weakReflection->get()); + } +}