diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 47565d27..f154ce92 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -9,7 +9,7 @@ build: # to not enough memory. # @https://github.com/smalot/pdfparser/issues/410 # @https://github.com/smalot/pdfparser/pull/412 - command: make prepare-for-scrutinizer && make install-dev-tools && make run-phpunit ARGS="--coverage-clover coverage/clover.xml" + command: make prepare-for-scrutinizer && make install-dev-tools && make run-phpunit ARGS="--exclude-group memory-heavy --coverage-clover coverage/clover.xml" coverage: file: coverage/clover.xml format: clover diff --git a/tests/Integration/ParserTest.php b/tests/Integration/ParserTest.php index 13298f8e..5228cf99 100644 --- a/tests/Integration/ParserTest.php +++ b/tests/Integration/ParserTest.php @@ -48,6 +48,11 @@ protected function setUp(): void $this->fixture = new Parser(); } + /** + * Notice: it may fail to run in Scrutinizer because of memory limitations. + * + * @group memory-heavy + */ public function testParseFile() { $directory = $this->rootDir.'/samples/bugs'; @@ -305,6 +310,8 @@ public function testUsageOfConfigObject() /** * Tests the impact of the retainImageContent config setting on memory usage * + * @group memory-heavy + * * @see https://github.com/smalot/pdfparser/issues/104#issuecomment-883422508 */ public function testRetainImageContentImpact() @@ -314,29 +321,46 @@ public function testRetainImageContentImpact() } $filename = $this->rootDir.'/samples/bugs/Issue104a.pdf'; - $iterations = 2; + $iterations = 1; - // check default (= true) + /* + * check default (= true) + */ $this->fixture = new Parser([]); $this->assertTrue($this->fixture->getConfig()->getRetainImageContent()); + $document = null; for ($i = 0; $i < $iterations; ++$i) { $document = $this->fixture->parseFile($filename); } - $this->assertTrue(memory_get_usage() > 200000000); + $usedMemory = memory_get_usage(true); + $this->assertTrue($usedMemory > 100000000, 'Memory is only '.$usedMemory); + $this->assertTrue(null != $document && 0 < \strlen($document->getText())); // force garbage collection $this->fixture = $document = null; gc_collect_cycles(); - // check false + /* + * check false + */ $config = new Config(); $config->setRetainImageContent(false); $this->fixture = new Parser([], $config); $this->assertEquals($config, $this->fixture->getConfig()); - $this->assertTrue(memory_get_usage() < 200000000); + for ($i = 0; $i < $iterations; ++$i) { + $document = $this->fixture->parseFile($filename); + } + + $usedMemory = memory_get_usage(true); + /* + * note: the following memory value is set manually and may differ from system to system. + * it must be high enough to not produce a false negative though. + */ + $this->assertTrue($usedMemory < 106000000, 'Memory is '.$usedMemory); + $this->assertTrue(0 < \strlen($document->getText())); } }