Download the PHP package mazer/rewrite-dagger without Composer

On this page you can find all versions of the php package mazer/rewrite-dagger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package rewrite-dagger

RewriteDagger

tests coding-style PHP Version Requires Latest Stable Version License

A php test tool that mock anything without using any extensions.

Table of content

Install

Features

RewriteDagger can mock anything that test target dependened. No matter those function and class is from PHP buildin, third party or your project. By rewriting the test target code before including and evaluating it, RewriteDagger can replace any words and content present in the test target without any extension.

Usage

Quick start

There is a PHP function that needs to be tested as follows

This function is difficult to test because it has a built-in PHP function (header) that is difficult to sense input and a PHP language construct (exit) that terminates the script execution.

To solve this problem, we test it by PHPUnit and RewriteDagger.

With RewriteDagger, we can easily replace header and exit with other class that can sense input and will not terminate script execution.

How it works

As Features say, RewriteDagger rewrite the test target code before include and evaluate it.

To achieve this function, it has three core parts:

Dagger mainly focuses on various rewriting rule itself, and uses the CodeRepository injected by DaggerFactory to operate, include and evaluate the code.

RewriteDagger (Drawing by skanaar/nomnoml)

Next, we explain the usage of these three components separately.

Dagger

__construct(CodeRepositoryInterface $codeRepository)

Dagger dependents on any implementation of CodeRepositoryInterface to help it evaluate the rewritten code.


includeCode(String $path): void

Include, rewrite, evaluate code file corresponding to $path.

Dagger can have multiple rewriting rules. When includeCode is called, Dagger executes all these rules on the code before evaluating it.


addDeleteRule(String $from): void

before after
42 is a number. 42


testAddRegexDeleteRule(String $from): void

before after
42 is a number. is a number.


addReplaceRule(String $from, String $to): void

before after
42 is a number. 42 : Answer to the Ultimate Question of Everything.


addRegexReplaceRule(String $from, String $to): void

before after
42 is a number. Number is a number.


addInsertBeforeRule(String $from, String $to): void

before after
42 is a number. 42 is a answer and number.


addRegexInsertBeforeRule(String $from, String $to): void

before after
42 is a number. (Number) 42 is a number.


addInsertAfterRule(String $from, String $to): void

before after
42 is a number. 42 is a number and answer.


addRegexInsertAfterRule(String $from, String $to): void

before after
42 is a number. 42 (Number) is a number.


addRegexReplaceCallbackRule(String $from, callable $callback): void

before after
42 is a number. [42] is a (number).


testRemoveAllRules(): void

Remove all rules set before.


CodeRepository

All codeRepository is the implementation of CodeRepositoryInterface which provide

In PHP, there are two ways to evaluate a string as code. One is to write the string as a real file then include() or require() it, the other is to use eval() function. RewriteDagger implements them in FileCodeRepository and EvalCodeRepository respectively.

RewriteDagger (Drawing by skanaar/nomnoml)


FileCodeRepository

__construct(string $tempPath = null)

FileCodeRepository writes a string to a temporary file in $tempPath with a unique name, then includes and evaluates it. If $tempPath is null, FileCodeRepository automatically generated it by sys_get_temp_dir().


EvalCodeRepository

__construct()

EvalCodeRepository is much simpler than FileCodeRepository, it eval() the input string directly.


DaggerFactory

Generally, unless you want to use a custom CodeRepository in Dagger, Dagger and CodeRepository are usually created by DaggerFactory instead of manually.

getDagger(array $config = []): Dagger

config key description
codeRepositoryType enum {include, require, eval}
tempPath temp path for FileCodeRepository


initDagger(Dagger $dagger): Dagger

initDagger is a protected function that allows you to customize DaggerFactory, which can operate on Dagger before return it (mainly adding default rules).

Testing

All the commands for testing are defined in composer.json.

The only thing you need to notice is that phpunit varsion in composer.lock is 9, which don't support php 7.2. But RewriteDagger does support php 7.2, so if you are using php 7.2, make sure to run compoesr update to change phpunit varsion to 8 before testing.

test without coverage

test with coverage

check coding style

Disadvantage

The two biggest disadvantages of using RewriteDagger are reduced test coverage and readability.

Inspire

RewriteDagger is inspired by the book 《Working Effectively with Legacy Code》 ( ISBN 13: 978-0131177055). Hope to provide Link Seams in PHP to make legacy PHP code easier to test.

Related repo

badoo/soft-mocks

License

MIT License


All versions of rewrite-dagger with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mazer/rewrite-dagger contains the following files

Loading the files please wait ....