From 8069932716324ac7b7cde2f71c84e217751b1cb5 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Paixão Date: Mon, 19 Apr 2010 22:14:18 +0000 Subject: [PATCH] Aplicado patch da feature "cleanMock" disponível em http://github.com/eriksencosta/phpunit/tree/cleanMock --- ieducar/misc/patches/phpunit/cleanMock.README | 33 +++++++++++++++++++++++++++++++++ ieducar/misc/patches/phpunit/cleanMock.patch | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ieducar/phpunit.xml | 6 +++--- 3 files changed, 320 insertions(+), 3 deletions(-) create mode 100644 ieducar/misc/patches/phpunit/cleanMock.README create mode 100644 ieducar/misc/patches/phpunit/cleanMock.patch diff --git a/ieducar/misc/patches/phpunit/cleanMock.README b/ieducar/misc/patches/phpunit/cleanMock.README new file mode 100644 index 0000000..b5cbe05 --- /dev/null +++ b/ieducar/misc/patches/phpunit/cleanMock.README @@ -0,0 +1,33 @@ +-- +-- @author Eriksen Costa Paixão +-- @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL +-- @link http://phing.info/docs/guide/current/ Phing Documentation +-- + +Patch para o PHPUnit com a diretiva de configuração "cleanMock" para o arquivo +phpunit.xml + +Na release 3.4.7 do PHPUnit, foi corrigido o bug TRAC-986, reduzindo o consumo +de memória para testes que utilizam mock objects: + +http://github.com/sebastianbergmann/phpunit/commit/8b5044ff919f51e1da653e49bc7413f3e9f6dc29 + +O código simplesmente a desaloca o objeto na memória, disponibilizando-o ao GC +do PHP. + +No entanto, essa correção quebrou alguns testes do i-Educar que lidam com +classes legadas (namespace App). As instâncias dessas classes são mantidas no +registry da classe CoreExt_Entity para facilitar o setup dos testes. + +Para resolver esse problema, foi implementado uma nova opção de configuração no +PHPUnit chamada "cleanMock". Quando seu valor está "false", o PHPUnit não irá +desalocar o mock automaticamente. Caso "cleanMock" não seja configurado, o +comportamento default do PHPUnit é realizado. + +Todo o histórico de implementação dessa feature está disponível em: + +http://github.com/eriksencosta/phpunit/commit/ae26bcc3c3bc81321f741c6d99e8389b1b937fb4 + +Enquanto a feature não for incorporada por padrão no core do PHPUnit, esse +patch deverá ser mantido e a sua aplicação deverá ser estimulada através da +documentação oficial. \ No newline at end of file diff --git a/ieducar/misc/patches/phpunit/cleanMock.patch b/ieducar/misc/patches/phpunit/cleanMock.patch new file mode 100644 index 0000000..23f7737 --- /dev/null +++ b/ieducar/misc/patches/phpunit/cleanMock.patch @@ -0,0 +1,284 @@ +diff --git a/PHPUnit/Framework/TestCase.php b/PHPUnit/Framework/TestCase.php +index 1c52ccb..dc0002f 100644 +--- PHPUnit/Framework/TestCase.php ++++ PHPUnit/Framework/TestCase.php +@@ -116,6 +116,14 @@ PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert implements PHPUnit_Framework_Test, PHPUnit_Framework_SelfDescribing + { + /** ++ * Enable or disable the clean of mock objects to reduce the memory ++ * footprint. ++ * ++ * @var boolean ++ */ ++ protected $cleanMock = NULL; ++ ++ /** + * Enable or disable the backup and restoration of the $GLOBALS array. + * Overwrite this attribute in a child class of TestCase. + * Setting this attribute in setUp() has no effect! +@@ -726,7 +734,10 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple + foreach ($this->mockObjects as $mockObject) { + $this->numAssertions++; + $mockObject->__phpunit_verify(); +- $mockObject->__phpunit_cleanup(); ++ ++ if ($this->cleanMock === TRUE || $this->cleanMock === NULL) { ++ $mockObject->__phpunit_cleanup(); ++ } + } + + $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; +@@ -906,6 +917,17 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple + } + + /** ++ * @param boolean $cleanMock ++ * @since Method available since Release 3.4.X ++ */ ++ public function setCleanMock($cleanMock) ++ { ++ if (is_null($this->cleanMock) && is_bool($cleanMock)) { ++ $this->cleanMock = $cleanMock; ++ } ++ } ++ ++ /** + * Calling this method in setUp() has no effect! + * + * @param boolean $backupGlobals +diff --git a/PHPUnit/Framework/TestSuite.php b/PHPUnit/Framework/TestSuite.php +index aed6726..e365412 100644 +--- PHPUnit/Framework/TestSuite.php ++++ PHPUnit/Framework/TestSuite.php +@@ -94,6 +94,14 @@ PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + class PHPUnit_Framework_TestSuite implements PHPUnit_Framework_Test, PHPUnit_Framework_SelfDescribing, IteratorAggregate + { + /** ++ * Enable or disable the clean of mock objects to reduce the memory ++ * footprint. ++ * ++ * @var boolean ++ */ ++ protected $cleanMock = NULL; ++ ++ /** + * Enable or disable the backup and restoration of the $GLOBALS array. + * + * @var boolean +@@ -679,6 +687,7 @@ class PHPUnit_Framework_TestSuite implements PHPUnit_Framework_Test, PHPUnit_Fra + } + + if ($test instanceof PHPUnit_Framework_TestSuite) { ++ $test->setCleanMock($this->cleanMock); + $test->setBackupGlobals($this->backupGlobals); + $test->setBackupStaticAttributes($this->backupStaticAttributes); + $test->setSharedFixture($this->sharedFixture); +@@ -718,6 +727,7 @@ class PHPUnit_Framework_TestSuite implements PHPUnit_Framework_Test, PHPUnit_Fra + + if ($runTest) { + if ($test instanceof PHPUnit_Framework_TestCase) { ++ $test->setCleanMock($this->cleanMock); + $test->setBackupGlobals($this->backupGlobals); + $test->setBackupStaticAttributes( + $this->backupStaticAttributes +@@ -878,6 +888,17 @@ class PHPUnit_Framework_TestSuite implements PHPUnit_Framework_Test, PHPUnit_Fra + } + + /** ++ * @param boolean $cleanMock ++ * @since Method available since Release 3.4.X ++ */ ++ public function setCleanMock($cleanMock) ++ { ++ if (is_null($this->cleanMock) && is_bool($cleanMock)) { ++ $this->cleanMock = $cleanMock; ++ } ++ } ++ ++ /** + * @param boolean $backupGlobals + * @since Method available since Release 3.3.0 + */ +diff --git a/PHPUnit/Tests/Framework/TestCaseTest.php b/PHPUnit/Tests/Framework/TestCaseTest.php +index e1bcf59..f8c7581 100644 +--- PHPUnit/Tests/Framework/TestCaseTest.php ++++ PHPUnit/Tests/Framework/TestCaseTest.php +@@ -52,6 +52,7 @@ require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIREC + require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ExceptionInTearDownTest.php'; + require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ExceptionInTest.php'; + require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Failure.php'; ++require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'MockCleaned.php'; + require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'NoArgTestCaseTest.php'; + require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Singleton.php'; + require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Success.php'; +@@ -322,5 +323,35 @@ class Framework_TestCaseTest extends PHPUnit_Framework_TestCase + + $this->assertNotSame($GLOBALS['singleton'], Singleton::getInstance()); + } ++ ++ public function testMockInvocationMockerCleaned() ++ { ++ $test = new MockCleaned(); ++ $mock = $test->getMock('StdClass'); ++ ++ $mock->expects($this->any()) ++ ->method('__toString') ++ ->will($this->returnValue('foo')); ++ ++ $test->run(); ++ ++ $this->assertNull($this->readAttribute($mock, 'invocationMocker')); ++ } ++ ++ public function testMockInvocationMockerNotCleaned() ++ { ++ $test = new MockCleaned(); ++ $test->setCleanMock(FALSE); ++ ++ $mock = $test->getMock('StdClass'); ++ ++ $mock->expects($this->any()) ++ ->method('__toString') ++ ->will($this->returnValue('foo')); ++ ++ $test->run(); ++ ++ $this->assertNotNull($this->readAttribute($mock, 'invocationMocker')); ++ } + } + ?> +diff --git a/PHPUnit/Tests/Util/ConfigurationTest.php b/PHPUnit/Tests/Util/ConfigurationTest.php +index e341cb5..ff6aaf2 100644 +--- PHPUnit/Tests/Util/ConfigurationTest.php ++++ PHPUnit/Tests/Util/ConfigurationTest.php +@@ -257,6 +257,7 @@ class Util_ConfigurationTest extends PHPUnit_Framework_TestCase + 'backupGlobals' => TRUE, + 'backupStaticAttributes' => FALSE, + 'bootstrap' => '/path/to/bootstrap.php', ++ 'cleanMock' => TRUE, + 'colors' => FALSE, + 'convertErrorsToExceptions' => TRUE, + 'convertNoticesToExceptions' => TRUE, +diff --git a/PHPUnit/Tests/_files/MockCleaned.php b/PHPUnit/Tests/_files/MockCleaned.php +new file mode 100644 +index 0000000..4540972 +--- /dev/null ++++ PHPUnit/Tests/_files/MockCleaned.php +@@ -0,0 +1,8 @@ ++ +diff --git a/PHPUnit/Tests/_files/configuration.xml b/PHPUnit/Tests/_files/configuration.xml +index fbca0c6..bf862db 100644 +--- PHPUnit/Tests/_files/configuration.xml ++++ PHPUnit/Tests/_files/configuration.xml +@@ -3,6 +3,7 @@ + setCleanMock(FALSE); ++ } ++ + if ($arguments['backupGlobals'] === FALSE) { + $suite->setBackupGlobals(FALSE); + } +@@ -660,6 +664,11 @@ class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner + $arguments['bootstrap'] = $phpunitConfiguration['bootstrap']; + } + ++ if (isset($phpunitConfiguration['cleanMock']) && ++ !isset($arguments['cleanMock'])) { ++ $arguments['cleanMock'] = $phpunitConfiguration['cleanMock']; ++ } ++ + if (isset($phpunitConfiguration['colors']) && + !isset($arguments['colors'])) { + $arguments['colors'] = $phpunitConfiguration['colors']; +@@ -852,6 +861,7 @@ class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner + $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : NULL; + $arguments['cpdMinLines'] = isset($arguments['cpdMinLines']) ? $arguments['cpdMinLines'] : 5; + $arguments['cpdMinMatches'] = isset($arguments['cpdMinMatches']) ? $arguments['cpdMinMatches'] : 70; ++ $arguments['cleanMock'] = isset($arguments['cleanMock']) ? $arguments['cleanMock'] : TRUE; + $arguments['colors'] = isset($arguments['colors']) ? $arguments['colors'] : FALSE; + $arguments['convertErrorsToExceptions'] = isset($arguments['convertErrorsToExceptions']) ? $arguments['convertErrorsToExceptions'] : TRUE; + $arguments['convertNoticesToExceptions'] = isset($arguments['convertNoticesToExceptions']) ? $arguments['convertNoticesToExceptions'] : TRUE; +diff --git a/PHPUnit/Util/Configuration.php b/PHPUnit/Util/Configuration.php +index 39d749b..4c64aea 100644 +--- PHPUnit/Util/Configuration.php ++++ PHPUnit/Util/Configuration.php +@@ -59,6 +59,7 @@ PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + * document->documentElement->hasAttribute('colors')) { +- $result['colors'] = $this->getBoolean( +- (string)$this->document->documentElement->getAttribute('colors'), +- FALSE +- ); +- } +- +- else if ($this->document->documentElement->hasAttribute('ansi')) { +- $result['colors'] = $this->getBoolean( +- (string)$this->document->documentElement->getAttribute('ansi'), +- FALSE +- ); +- } +- + if ($this->document->documentElement->hasAttribute('backupGlobals')) { + $result['backupGlobals'] = $this->getBoolean( + (string)$this->document->documentElement->getAttribute('backupGlobals'), +@@ -558,6 +545,27 @@ class PHPUnit_Util_Configuration + $result['bootstrap'] = (string)$this->document->documentElement->getAttribute('bootstrap'); + } + ++ if ($this->document->documentElement->hasAttribute('cleanMock')) { ++ $result['cleanMock'] = $this->getBoolean( ++ (string)$this->document->documentElement->getAttribute('cleanMock'), ++ TRUE ++ ); ++ } ++ ++ if ($this->document->documentElement->hasAttribute('colors')) { ++ $result['colors'] = $this->getBoolean( ++ (string)$this->document->documentElement->getAttribute('colors'), ++ FALSE ++ ); ++ } ++ ++ else if ($this->document->documentElement->hasAttribute('ansi')) { ++ $result['colors'] = $this->getBoolean( ++ (string)$this->document->documentElement->getAttribute('ansi'), ++ FALSE ++ ); ++ } ++ + if ($this->document->documentElement->hasAttribute('convertErrorsToExceptions')) { + $result['convertErrorsToExceptions'] = $this->getBoolean( + (string)$this->document->documentElement->getAttribute('convertErrorsToExceptions'), diff --git a/ieducar/phpunit.xml b/ieducar/phpunit.xml index 13ce578..fb3677a 100644 --- a/ieducar/phpunit.xml +++ b/ieducar/phpunit.xml @@ -4,10 +4,10 @@ - Configurações do PHPUnit. --> - + - ../tests + ../tests - \ No newline at end of file + -- libgit2 0.21.2