Skip to content

Commit

Permalink
Merge pull request #27 from wick-ed/patch#811
Browse files Browse the repository at this point in the history
Allow for forced static calls to original method
  • Loading branch information
wick-ed committed May 15, 2015
2 parents 5ac717b + 34e8d95 commit 78f14a3
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 24 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Version 1.3.3

## Bugfixes

* Fixed [#811](https://github.com/appserver-io/appserver/issues/811) - Endless recursion on parent::<METHOD> call

## Features

* None

# Version 1.3.2

## Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion build.default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#--------------------------------------------------------------------------------

# ---- Module Release Settings --------------------------------------------------
release.version = 1.3.2
release.version = 1.3.3

# ---- PHPCPD Settings ----------------------------------------------------------
# Directories
Expand Down
11 changes: 6 additions & 5 deletions src/Entities/Definitions/FunctionDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,14 @@ public function getAllPostconditions($nonPrivateOnly = false)
* Will return the header of this function either in calling or in defining manner.
* String will stop after the closing ")" bracket, so the string can be used for interfaces as well.
*
* @param string $type Can be either "call" or "definition"
* @param string $suffix Suffix for the function name
* @param boolean $showMe Will mark a method as original by extending it with a suffix
* @param string $type Can be either "call" or "definition"
* @param string $suffix Suffix for the function name
* @param boolean $showMe Will mark a method as original by extending it with a suffix
* @param boolean $forceStatic Will force static call for call type headers
*
* @return string
*/
public function getHeader($type, $suffix = '', $showMe = false)
public function getHeader($type, $suffix = '', $showMe = false, $forceStatic = false)
{
$header = '';

Expand Down Expand Up @@ -395,7 +396,7 @@ public function getHeader($type, $suffix = '', $showMe = false)

// If we have to generate code for a call we have to check for either static or normal access
if ($type === 'call') {
if ($this->isStatic === true) {
if ($this->isStatic === true || $forceStatic) {
$header .= 'self::';
} else {
$header .= '$this->';
Expand Down
2 changes: 1 addition & 1 deletion src/StreamFilters/ProcessingFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ public function filter($in, $out, &$consumed, $closing)
protected function generateCode(FunctionDefinition $functionDefinition)
{
// Build up the call to the original function
return ReservedKeywords::RESULT . ' = ' . $functionDefinition->getHeader('call', ReservedKeywords::ORIGINAL_FUNCTION_SUFFIX) . ';';
return ReservedKeywords::RESULT . ' = ' . $functionDefinition->getHeader('call', ReservedKeywords::ORIGINAL_FUNCTION_SUFFIX, false, true) . ';';
}
}
44 changes: 44 additions & 0 deletions tests/Tests/Data/GeneratorTest/RecursionTestClass1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* \AppserverIo\Doppelgaenger\Tests\Data\GeneratorTest\RecursionTestClass1
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* PHP version 5
*
* @author Bernhard Wick <bw@appserver.io>
* @copyright 2015 TechDivision GmbH - <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io/doppelgaenger
* @link http://www.appserver.io/
*/

namespace AppserverIo\Doppelgaenger\Tests\Data\GeneratorTest;

/**
* Class used to test the safety against an endless recursion introduced by the usage of parent::-calls
* in a direct child/parent relationship
*
* @author Bernhard Wick <bw@appserver.io>
* @copyright 2015 TechDivision GmbH - <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io/doppelgaenger
* @link http://www.appserver.io/
*/
class RecursionTestClass1
{

/**
* Method which should not be called recursively more than once
*
* @return void
*/
public function iDontWantToBeRecursive()
{
}
}
58 changes: 58 additions & 0 deletions tests/Tests/Data/GeneratorTest/RecursionTestClass2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* \AppserverIo\Doppelgaenger\Tests\Data\GeneratorTest\RecursionTestClass2
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* PHP version 5
*
* @author Bernhard Wick <bw@appserver.io>
* @copyright 2015 TechDivision GmbH - <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io/doppelgaenger
* @link http://www.appserver.io/
*/

namespace AppserverIo\Doppelgaenger\Tests\Data\GeneratorTest;

/**
* Class used to test the safety against an endless recursion introduced by the usage of parent::-calls
* in a direct child/parent relationship
*
* @author Bernhard Wick <bw@appserver.io>
* @copyright 2015 TechDivision GmbH - <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io/doppelgaenger
* @link http://www.appserver.io/
*/
class RecursionTestClass2 extends RecursionTestClass1
{

/**
* Counter to measure calls
*
* @var integer $recursionCounter
*/
public $recursionCounter = 0;

/**
* Method which should not be called recursively more than once
*
* @return void
*/
public function iDontWantToBeRecursive()
{
// increment the counter
$this->recursionCounter ++;

// stop execution at a point which MUST have been an unwanted recursion
if ($this->recursionCounter < 10) {
parent::iDontWantToBeRecursive();
}
}
}
48 changes: 31 additions & 17 deletions tests/Tests/Functional/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use AppserverIo\Doppelgaenger\Tests\Data\GeneratorTest\CustomProcessingTestClass;
use AppserverIo\Doppelgaenger\Tests\Data\GeneratorTest\LocalCustomProcessingTestClass;
use AppserverIo\Doppelgaenger\Tests\Data\TagPlacementTestClass;
use AppserverIo\Doppelgaenger\Tests\Data\GeneratorTest\RecursionTestClass2;

/**
* This test covers known generator problems
Expand All @@ -40,7 +41,7 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase
/**
* Will test if a randomly placed php tag will throw of the generator
*
* @return null
* @return void
*/
public function testPhpTag()
{
Expand All @@ -50,7 +51,7 @@ public function testPhpTag()
/**
* Method to test if an around advice is able to proceed the initially called method
*
* @return null
* @return void
*/
public function testProceededMethod()
{
Expand All @@ -68,7 +69,7 @@ public function testProceededMethod()
/**
* Method to test if an around advice is able to block the initially called method
*
* @return null
* @return void
*/
public function testBlockedMethod()
{
Expand All @@ -86,7 +87,7 @@ public function testBlockedMethod()
/**
* Method to test if an around advice can proceed the advised method AFTER the own logic
*
* @return null
* @return void
*/
public function testAdviceAfterAdvisedOrder()
{
Expand All @@ -104,7 +105,7 @@ public function testAdviceAfterAdvisedOrder()
/**
* Method to test if an around advice can proceed the advised method BEFORE the own logic
*
* @return null
* @return void
*/
public function testAdviceBeforeAdvisedOrder()
{
Expand All @@ -122,54 +123,67 @@ public function testAdviceBeforeAdvisedOrder()
/**
* Will test if we can enable custom enforcement processing on class level using the @Processing annotation
*
* @return null
* @return void
*
* @expectedException \AppserverIo\Doppelgaenger\Tests\TestLoggerUsedException
*/
public function testCustomClassProcessing()
{
$testCase = new CustomProcessingTestClass();
$testCase->iHaveNoCustomProcessing();
$testClass = new CustomProcessingTestClass();
$testClass->iHaveNoCustomProcessing();
}

/**
* Will test if we can enable custom enforcement processing on method level using the @Processing annotation
*
* @return null
* @return void
*
* @expectedException \AppserverIo\Psr\MetaobjectProtocol\Dbc\BrokenPostconditionException
*/
public function testCustomMethodProcessing()
{
$testCase = new CustomProcessingTestClass();
$testCase->iHaveACustomExceptionProcessing();
$testClass = new CustomProcessingTestClass();
$testClass->iHaveACustomExceptionProcessing();
}

/**
* Will test if we can enable custom enforcement processing on method level using the @Processing annotation
* without any annotation within the class doc block
*
* @return null
* @return void
*
* @expectedException \AppserverIo\Doppelgaenger\Tests\TestLoggerUsedException
*/
public function testCustomMethodOnlyProcessing1()
{
$testCase = new LocalCustomProcessingTestClass();
$testCase->iHaveACustomLoggingProcessing();
$testClass = new LocalCustomProcessingTestClass();
$testClass->iHaveACustomLoggingProcessing();
}

/**
* Will test if we can enable custom enforcement processing on method level using the @Processing annotation
* without any annotation within the class doc block
*
* @return null
* @return void
*
* @expectedException \AppserverIo\Psr\MetaobjectProtocol\Dbc\BrokenPostconditionException
*/
public function testCustomMethodOnlyProcessing2()
{
$testCase = new LocalCustomProcessingTestClass();
$testCase->iHaveACustomExceptionProcessing();
$testClass = new LocalCustomProcessingTestClass();
$testClass->iHaveACustomExceptionProcessing();
}

/**
* Tests if we can catch potential endless recursions based on a call like parent::<METHOD_NAME>
*
* @return void
*/
public function testEndlessRecursionSafety()
{
$testClass = new RecursionTestClass2();
$testClass->iDontWantToBeRecursive();

$this->assertEquals(1, $testClass->recursionCounter);
}
}

0 comments on commit 78f14a3

Please sign in to comment.