Skip to content

Commit

Permalink
Merge pull request #4 from jakzal/php-5.3
Browse files Browse the repository at this point in the history
PHP 5.3 & 5.4 support
  • Loading branch information
jakzal committed Aug 2, 2018
2 parents 31a1368 + c565893 commit fea7bf1
Show file tree
Hide file tree
Showing 55 changed files with 269 additions and 575 deletions.
12 changes: 4 additions & 8 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(['src', 'tests'])
->in(array('src', 'tests'))
;

return PhpCsFixer\Config::create()
->setRules([
->setRules(array(
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_before_statement' => true,
'declare_strict_types' => true,
'native_function_invocation' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_extra_consecutive_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
'phpdoc_add_missing_param_annotation' => array('only_untyped' => true),
'protected_to_private' => true,
'strict_comparison' => true,
'ternary_operator_spaces' => true,
'ternary_to_null_coalescing' => true,
'yoda_style' => true,
])
))
->setFinder($finder)
;

2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ inherit: true
build:
environment:
php:
version: 7.2
version: 5.4
tests:
override:
- make test
Expand Down
18 changes: 4 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
dist: precise
language: php
matrix:
include:
- php: 7.1
env: EXECUTE_DEPLOYMENT=true
- php: 7.2
- php: 5.4
env: deps=low
- php: 5.3
env: deps=high
fast_finish: true
before_install:
- phpenv config-rm xdebug.ini
install:
- if [[ $deps = low ]]; then make update-min; else make install; fi
script:
- if [[ $deps = low ]]; then make test-min; else make test; fi
- make package test-package
deploy:
provider: releases
api_key:
secure: SSjBKEch3qcKlWVEb5DbXDFUvdnLTV03e82OryeNIYPD7pWhjoxdOWicB/od9b39/YD/LR1lxMt9+fHRseCrwo1FOUZmnMgzphr0MiF2RZUF4CpWFJXL+EbxQ/GbKVv+hQhDwyBDwlNchPzrVM3tRe/llt0Xg8A7NGQI0UBdZZFJKWgydoSYN4VSias8FTBMS0Nvi/D4cE2iHDJE1bDpx+Fm1w9LP/DfvnSMcQwJ1mwTNiIRO0/vH5OWlkwWjT2UDEP3TOe9sj6XfYHpU9nuaCEGTiL3XUnfWyNP8hk5Fq8wsN0vBSvW66kmz2uDnN7vZPm7b7YUXfTHJW7M78DzWmfSjaiNFx35yjgJ34tIDxfv00BOh5t2OGXEt4qX8Si0oDkFpotnCk+zdQM8IaCYyITRa1/gtjyAZLW8yvBE9l5ZW51mEURCK94Gm22T+wo4srLtZqqho0yzaFVKxGzQ11HC0KskoMR4zE9P3C9p2PDQO+o2GFSr9o8hlj0QvYVpyyfBG95y8fUyIddJropfkyXuR1Ze4clmNJN/PmKG6pzSZzOM2gBIXUNlZ1BZcPo4J1QvWsvqkkYLH908VOWShrPQlSGUmtS+FSfO4zDFwnNmtScd/WHqZmSZi2ZA/dvJXhAB3sb4QBmbKqcQArUPvBiasrFCqhn/uenrQMKNudg=
file: build/zalas-phpunit-doubles-extension.phar
skip_cleanup: true
on:
tags: true
repo: jakzal/phpunit-doubles
condition: "$EXECUTE_DEPLOYMENT"
61 changes: 4 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ update-no-dev:
composer update --prefer-stable --no-dev
.PHONY: update-no-dev

test: vendor cs deptrac phpunit infection
test: vendor cs phpunit
.PHONY: test

test-min: update-min cs deptrac phpunit infection
test-min: update-min cs phpunit
.PHONY: test-min

test-package: package test-package-tools
cd tests/phar && ./tools/phpunit
.PHONY: test-package

cs: tools/php-cs-fixer
tools/php-cs-fixer --dry-run --allow-risky=yes --no-interaction --ansi fix
.PHONY: cs
Expand All @@ -37,14 +33,6 @@ cs-fix: tools/php-cs-fixer
tools/php-cs-fixer --allow-risky=yes --no-interaction --ansi fix
.PHONY: cs-fix

deptrac: tools/deptrac
tools/deptrac --no-interaction --ansi --formatter-graphviz-display=0
.PHONY: deptrac

infection: tools/infection tools/infection.pubkey
phpdbg -qrr ./tools/infection --no-interaction --formatter=progress --min-msi=100 --min-covered-msi=100 --only-covered --ansi
.PHONY: infection

phpunit: tools/phpunit
tools/phpunit
.PHONY: phpunit
Expand All @@ -53,36 +41,15 @@ phpunit-coverage: tools/phpunit
phpdbg -qrr tools/phpunit
.PHONY: phpunit

tools: tools/php-cs-fixer tools/deptrac tools/infection tools/box
tools: tools/php-cs-fixer
.PHONY: tools

test-package-tools: tests/phar/tools/phpunit tests/phar/tools/phpunit.d/zalas-phpunit-doubles-extension.phar
.PHONY: test-package-tools

clean:
rm -rf build
rm -rf vendor
find tools -not -path '*/\.*' -type f -delete
find tests/phar/tools -not -path '*/\.*' -type f -delete
.PHONY: clean

package: tools/box
$(eval VERSION=$(shell (git describe --abbrev=0 --tags 2>/dev/null || echo "0.1-dev") | sed -e 's/^v//'))
@rm -rf build/phar && mkdir -p build/phar

cp -r src LICENSE composer.json scoper.inc.php build/phar
sed -e 's/@@version@@/$(VERSION)/g' manifest.xml.in > build/phar/manifest.xml

cd build/phar && \
composer remove phpunit/phpunit --no-update && \
composer config platform.php 7.1 && \
composer update --no-dev -o -a

tools/box compile

@rm -rf build/phar
.PHONY: package

vendor: install

vendor/bin/phpunit: install
Expand All @@ -91,24 +58,4 @@ tools/phpunit: vendor/bin/phpunit
ln -sf ../vendor/bin/phpunit tools/phpunit

tools/php-cs-fixer:
curl -Ls http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -o tools/php-cs-fixer && chmod +x tools/php-cs-fixer

tools/deptrac:
curl -Ls http://get.sensiolabs.de/deptrac.phar -o tools/deptrac && chmod +x tools/deptrac

tools/infection: tools/infection.pubkey
curl -Ls https://github.com/infection/infection/releases/download/0.9.0/infection.phar -o tools/infection && chmod +x tools/infection

tools/infection.pubkey:
curl -Ls https://github.com/infection/infection/releases/download/0.9.0/infection.phar.pubkey -o tools/infection.pubkey

tools/box:
curl -Ls https://github.com/humbug/box/releases/download/3.0.0-beta.4/box.phar -o tools/box && chmod +x tools/box

tests/phar/tools/phpunit:
curl -Ls https://phar.phpunit.de/phpunit-7.phar -o tests/phar/tools/phpunit && chmod +x tests/phar/tools/phpunit

tests/phar/tools/phpunit.d/zalas-phpunit-doubles-extension.phar: build/zalas-phpunit-doubles-extension.phar
cp build/zalas-phpunit-doubles-extension.phar tests/phar/tools/phpunit.d/zalas-phpunit-doubles-extension.phar

build/zalas-phpunit-doubles-extension.phar: package
curl -Ls https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.2.20/php-cs-fixer.phar -o tools/php-cs-fixer && chmod +x tools/php-cs-fixer
35 changes: 9 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

Initialises test doubles in PHPUnit test cases for you.

**Warning**: Note this is a backport of the library originally written for PHP >=7.1.
Things might not work as expected and they definitely work a lot slower than the original version.
If you're interested in optimising this branch, look into the `ReflectionExtractor` class.

## Installation

### Composer
Expand All @@ -13,24 +17,9 @@ Initialises test doubles in PHPUnit test cases for you.
composer require --dev zalas/phpunit-doubles
```

### Phar

The extension is also distributed as a PHAR, which can be downloaded from the most recent
[Github Release](https://github.com/jakzal/phpunit-doubles/releases).

Put the extension in your PHPUnit extensions directory.
Remember to instruct PHPUnit to load extensions in your `phpunit.xml`:

```xml
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.0/phpunit.xsd"
extensionsDirectory="tools/phpunit.d"
>
</phpunit>
```

## Usage

Include the `Zalas\PHPUnit\Doubles\TestCase\TestDoubles` trait to have your test doubles initialised
Extend the `Zalas\PHPUnit\Doubles\TestCase\TestDoublesTestCase` to have your test doubles initialised
in one of the supported test doubling frameworks.

Both the type of test double and the kind of test doubling framework are taken from the property type:
Expand All @@ -52,14 +41,11 @@ Currently, two test doubling frameworks are supported:
```php
<?php

use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Zalas\PHPUnit\Doubles\TestCase\TestDoubles;
use Zalas\PHPUnit\Doubles\TestCase\TestDoublesTestCase;

class DiscworldTest extends TestCase
class DiscworldTest extends TestDoublesTestCase
{
use TestDoubles;

/**
* @var Vimes|ObjectProphecy
*/
Expand Down Expand Up @@ -88,13 +74,10 @@ class DiscworldTest extends TestCase
<?php

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Zalas\PHPUnit\Doubles\TestCase\TestDoubles;
use Zalas\PHPUnit\Doubles\TestCase\TestDoublesTestCase;

class DiscworldTest extends TestCase
class DiscworldTest extends TestDoublesTestCase
{
use TestDoubles;

/**
* @var Vimes|MockObject
*/
Expand Down
18 changes: 0 additions & 18 deletions box.json.dist

This file was deleted.

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"description": "Initialises test doubles in PHPUnit test cases for you",
"type": "library",
"require": {
"php": "^7.1",
"phpunit/phpunit": "^7.0",
"phpdocumentor/reflection-docblock": "^4.0.1"
"php": "~5.3.0||~5.4.0",
"phpunit/phpunit": "^4.8.36",
"phpdocumentor/reflection-docblock": "^2.0",
"php-di/phpdoc-reader": "^2.0"
},
"require-dev": {
},
Expand Down
67 changes: 0 additions & 67 deletions depfile.yml

This file was deleted.

15 changes: 0 additions & 15 deletions manifest.xml.in

This file was deleted.

2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
Expand Down
9 changes: 0 additions & 9 deletions scoper.inc.php

This file was deleted.

3 changes: 1 addition & 2 deletions src/Extractor/Extractor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
declare(strict_types=1);

namespace Zalas\PHPUnit\Doubles\Extractor;

Expand All @@ -15,5 +14,5 @@ interface Extractor
*
* @return Property[]
*/
public function extract(/*object */$object, callable $filter): array;
public function extract(/*object */$object, /*callable */$filter)/*: array*/;
}
Loading

0 comments on commit fea7bf1

Please sign in to comment.