Skip to content

Commit

Permalink
Merge pull request #22 from wick-ed/master
Browse files Browse the repository at this point in the history
usage of custom assertions
  • Loading branch information
wick-ed committed Feb 19, 2015
2 parents 180eace + fb93fb0 commit 7bd926a
Show file tree
Hide file tree
Showing 19 changed files with 1,088 additions and 505 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Version 1.1.0

## Bugfixes

* None

## Features

* Allows for the usage of custom assertions by specifying a type property within the annotation (see class \AppserverIo\Doppelgaenger\Tests\Data\AssertionTest\RespectValidationTestClass for example)
* Added a semantic versioning declaration of the public API

# Version 1.0.0

## Bugfixes
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Make PHP structure definition clones which look the same but behave differently
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/appserver-io/doppelgaenger/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/appserver-io/doppelgaenger/?branch=master)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/appserver-io/doppelgaenger/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/appserver-io/doppelgaenger/?branch=master)


# Introduction

Doppelgaenger is created for tampering with PHP structure definitions such as classes before they get loaded and known to the code which uses them.
Expand All @@ -34,6 +33,16 @@ Just include the following code into your composer.json` and you are good to go.
}
```

# Semantic versioning

This library follows semantic versioning and its public API defines as follows:

* The public API of [its related appserver.io PSR](https://github.com/appserver-io-psr/mop)
* The public interface of the `\AppserverIo\Doppelgaenger\AutoLoader` class
* The public interface of the `\AppserverIo\Doppelgaenger\Config` class
* The syntax and amount of usable annotations (NOT including common annotations such as `@param` and `@return`)
* The format of its configuration files

# External Links

* Documentation at [appserver.io](http://docs.appserver.io) (have a look at `AOP` and `Design by Contract` section)
* Documentation at [appserver.io](http://docs.appserver.io) (have a look at [`AOP`](http://appserver.io/get-started/documentation/aop.html) and [`Design by Contract`](http://appserver.io/get-started/documentation/design-by-contract.html) section)
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"require-dev": {
"appserver-io/build": "~1.0",
"respect/validation": "0.8.*",
"squizlabs/php_codesniffer" : "dev-master as 2.1.0"
},
"autoload": {
Expand Down
7 changes: 7 additions & 0 deletions src/Dictionaries/ReservedKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ class ReservedKeywords
*/
const ORIGINAL_FUNCTION_SUFFIX = 'DOPPELGAENGEROriginal';

/**
* Variable locally used as a flag for handling assertion flow
*
* @var string PASSED_ASSERTION_FLAG
*/
const PASSED_ASSERTION_FLAG = '$doppelgaengerPassedBlock';

/**
* Reserved local variable containing the result of the actual function execution
*
Expand Down
23 changes: 20 additions & 3 deletions src/Entities/Assertions/AbstractAssertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

namespace AppserverIo\Doppelgaenger\Entities\Assertions;

use AppserverIo\Doppelgaenger\Dictionaries\ReservedKeywords;
use AppserverIo\Doppelgaenger\Exceptions\ParserException;
use AppserverIo\Doppelgaenger\Interfaces\AssertionInterface;
use AppserverIo\Doppelgaenger\Interfaces\CodifyableInterface;
use AppserverIo\Doppelgaenger\Utils\PhpLint;

/**
Expand All @@ -33,7 +35,7 @@
* @link https://github.com/appserver-io/doppelgaenger
* @link http://www.appserver.io/
*/
abstract class AbstractAssertion implements AssertionInterface
abstract class AbstractAssertion implements AssertionInterface, CodifyableInterface
{
/**
* Minimal scope is "function" per default as we don't have DbC checks right know (would be body)
Expand Down Expand Up @@ -86,8 +88,8 @@ public function __construct()
*/
public function getInvertString()
{
// Invert this instance
$self = $this;
// Invert a copy of this instance
$self = clone $this;

$self->invert();

Expand Down Expand Up @@ -173,4 +175,19 @@ public function setPrivateContext($privateContext)
{
$this->privateContext = $privateContext;
}

/**
* Return a string representation of the classes logic as a piece of PHP code.
* Used to transfer important logic into generated code
*
* @return string
*/
public function toCode()
{
$code = 'if ('. $this->getInvertString() .') {
' . ReservedKeywords::FAILURE_VARIABLE . '[] = \'The assertion (' . str_replace('\'', '"', $this->getString()) . ') must hold\';
}';

return $code;
}
}

0 comments on commit 7bd926a

Please sign in to comment.