Skip to content

Commit 76b6838

Browse files
committed
initial commit
0 parents  commit 76b6838

13 files changed

+448
-0
lines changed

.coveralls.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage_clover: build/logs/clover.xml
2+
json_path: build/logs/coveralls-upload.json

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
/vendor/
3+
.phpunit.result.cache

.scrutinizer.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
checks:
2+
php:
3+
code_rating: true
4+
5+
filter:
6+
excluded_paths:
7+
- tests/*
8+
- vendor/*
9+
10+
build:
11+
12+
environment:
13+
php: '7.4'
14+
15+
dependencies:
16+
before:
17+
- composer require phpunit/phpunit --dev --no-update
18+
- composer update --prefer-stable
19+
- composer show | grep -E '^(phpunit/phpunit|sebastian/comparator)'
20+
- mkdir -p build/logs
21+
22+
tests:
23+
override:
24+
-
25+
command: 'phpdbg -qrr vendor/bin/phpunit --coverage-clover build/logs/clover.xml'
26+
coverage:
27+
file: 'build/logs/clover.xml'
28+
format: 'clover'

.travis.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
language: php
2+
3+
matrix:
4+
include:
5+
- dist: precise
6+
php: 5.3
7+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" DISABLE_TLS="1"
8+
- dist: precise
9+
php: 5.3
10+
env: COMPOSER_FLAGS="--prefer-stable" DISABLE_TLS="1"
11+
- dist: trusty
12+
php: 5.4
13+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
14+
- dist: trusty
15+
php: 5.4
16+
env: COMPOSER_FLAGS="--prefer-stable"
17+
- dist: trusty
18+
php: 5.5
19+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
20+
- dist: trusty
21+
php: 5.5
22+
env: COMPOSER_FLAGS="--prefer-stable"
23+
- php: 5.6.0
24+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
25+
- php: 5.6
26+
env: COMPOSER_FLAGS="--prefer-stable"
27+
- php: 7.0.0
28+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
29+
- php: 7.0
30+
env: COMPOSER_FLAGS="--prefer-stable"
31+
- php: 7.1.0
32+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
33+
- php: 7.1
34+
env: COMPOSER_FLAGS="--prefer-stable"
35+
- php: 7.2.0
36+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
37+
- php: 7.2
38+
env: COMPOSER_FLAGS="--prefer-stable"
39+
- php: 7.3.0
40+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
41+
- php: 7.3
42+
env: COMPOSER_FLAGS="--prefer-stable"
43+
- php: 7.4.0
44+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
45+
- php: 7.4
46+
env: COMPOSER_FLAGS="--prefer-stable"
47+
- php: 8.0.0
48+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
49+
- php: 8.0
50+
env: COMPOSER_FLAGS="--prefer-stable"
51+
52+
cache:
53+
directories:
54+
- ./vendor
55+
- $HOME/.composer/cache
56+
57+
before_script:
58+
- '[ $DISABLE_TLS -eq 1 ] && composer config --global -- disable-tls true || :'
59+
- '[ $DISABLE_TLS -eq 1 ] && composer config --global -- secure-http false || :'
60+
- composer self-update
61+
- composer require phpunit/phpunit --dev --no-update $COMPOSER_FLAGS
62+
- composer update $COMPOSER_FLAGS
63+
- composer show | grep -E '^(phpunit/phpunit|sebastian/comparator)'
64+
- composer json:polyfill
65+
66+
script:
67+
- vendor/bin/phpunit

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 mpyw
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# PHPUnit Patch Serializable Comparison [![Build Status](https://travis-ci.com/mpyw/phpunit-patch-serializable-comparison.svg?branch=master)](https://travis-ci.com/mpyw/phpunit-patch-serializable-comparison)
2+
3+
Fixes `assertSame()`/`assertEquals()` serialization errors running in separate processes.
4+
5+
## Requirements
6+
7+
- php: `>=5.3.3`
8+
- [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit): `>=4.8.0`
9+
- [sebastianbergmann/comparator](https://github.com/sebastianbergmann/comparator): `^1.0 || ^2.0 || ^3.0 || ^4.0`
10+
11+
## Installing
12+
13+
```bash
14+
composer require --dev mpyw/phpunit-patch-serializable-comparison
15+
```
16+
17+
## Example
18+
19+
```php
20+
class AssertionTest extends TestCase
21+
{
22+
protected function callAssertSameInClosure(\Closure $closure)
23+
{
24+
static::assertSame('aaa', 'bbb');
25+
}
26+
27+
/**
28+
* @runInSeparateProcess
29+
* @preserveGlobalState disabled
30+
*/
31+
public function testAssertionIncludingUnserializableTrace()
32+
{
33+
static::callAssertSameInClosure(function () {});
34+
}
35+
}
36+
```
37+
38+
### Before Patching
39+
40+
```
41+
PHPUnit\Framework\Exception: PHP Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in Standard input code:XX
42+
Stack trace:
43+
#0 Standard input code(XX): serialize(Array)
44+
#1 Standard input code(XX): __phpunit_run_isolated_test()
45+
#2 {main}
46+
thrown in Standard input code on line XX
47+
```
48+
49+
### After Patching
50+
51+
```diff
52+
Failed asserting that two strings are identical.
53+
--- Expected
54+
+++ Actual
55+
@@ @@
56+
-'aaa'
57+
+'bbb'
58+
```

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "mpyw/phpunit-patch-serializable-comparison",
3+
"description": "Fixes assertSame/assertEquals serialization errors running in separate processes.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "mpyw",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"keywords": ["phpunit", "isolation", "serialization", "separate", "process", "processes", "patch", "fix", "bug"],
13+
"autoload": {
14+
"files": [
15+
"./files/ComparisonFailure.php"
16+
]
17+
},
18+
"autoload-dev": {
19+
"psr-4": {
20+
"Mpyw\\PHPUnitPatchSerializableComparison\\Tests\\": "tests/"
21+
}
22+
},
23+
"require": {
24+
"php": ">=5.3.3",
25+
"sebastian/comparator": "^1.0 || ^2.0 || ^3.0 || ^4.0"
26+
},
27+
"scripts": {
28+
"json:restore": "git checkout composer.json",
29+
"json:polyfill": "./polyfill && composer dump-autoload"
30+
}
31+
}

files/ComparisonFailure.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
3+
namespace SebastianBergmann\Comparator;
4+
5+
use RuntimeException;
6+
use SebastianBergmann\Diff\Differ;
7+
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
8+
9+
/**
10+
* Thrown when an assertion for string equality failed.
11+
*/
12+
final class ComparisonFailure extends RuntimeException
13+
{
14+
/**
15+
* Expected value of the retrieval which does not match $actual.
16+
*
17+
* @var mixed
18+
*/
19+
protected $expected;
20+
21+
/**
22+
* Actually retrieved value which does not match $expected.
23+
*
24+
* @var mixed
25+
*/
26+
protected $actual;
27+
28+
/**
29+
* The string representation of the expected value.
30+
*
31+
* @var string
32+
*/
33+
protected $expectedAsString;
34+
35+
/**
36+
* The string representation of the actual value.
37+
*
38+
* @var string
39+
*/
40+
protected $actualAsString;
41+
42+
/**
43+
* @var bool
44+
*/
45+
protected $identical;
46+
47+
/**
48+
* Optional message which is placed in front of the first line
49+
* returned by toString().
50+
*
51+
* @var string
52+
*/
53+
protected $message;
54+
55+
/**
56+
* Initialises with the expected value and the actual value.
57+
*
58+
* @param mixed $expected expected value retrieved
59+
* @param mixed $actual actual value retrieved
60+
* @param string $expectedAsString
61+
* @param string $actualAsString
62+
* @param bool $identical
63+
* @param string $message a string which is prefixed on all returned lines
64+
* in the difference output
65+
*
66+
* @noinspection PhpMissingParentConstructorInspection
67+
*/
68+
public function __construct($expected, $actual, $expectedAsString, $actualAsString, $identical = false, $message = '')
69+
{
70+
$this->expected = $expected;
71+
$this->actual = $actual;
72+
$this->expectedAsString = $expectedAsString;
73+
$this->actualAsString = $actualAsString;
74+
$this->message = $message;
75+
}
76+
77+
public function getActual()
78+
{
79+
return $this->actual;
80+
}
81+
82+
public function getExpected()
83+
{
84+
return $this->expected;
85+
}
86+
87+
/**
88+
* @return string
89+
*/
90+
public function getActualAsString()
91+
{
92+
return $this->actualAsString;
93+
}
94+
95+
/**
96+
* @return string
97+
*/
98+
public function getExpectedAsString()
99+
{
100+
return $this->expectedAsString;
101+
}
102+
103+
/**
104+
* @return string
105+
*/
106+
public function getDiff()
107+
{
108+
if (!$this->actualAsString && !$this->expectedAsString) {
109+
return '';
110+
}
111+
112+
$header = "\n--- Expected\n+++ Actual\n";
113+
if (\class_exists('SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder')) {
114+
$header = new UnifiedDiffOutputBuilder($header);
115+
}
116+
$differ = new Differ($header);
117+
118+
return $differ->diff($this->expectedAsString, $this->actualAsString);
119+
}
120+
121+
/**
122+
* @return string
123+
*/
124+
public function toString()
125+
{
126+
return $this->message . $this->getDiff();
127+
}
128+
129+
/**
130+
* Make the class serializable.
131+
*
132+
* @return string[]
133+
*/
134+
public function __sleep()
135+
{
136+
return \array_keys(\get_object_vars($this));
137+
}
138+
}

phpunit.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
bootstrap="vendor/autoload.php"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
>
12+
<testsuites>
13+
<testsuite name="Package Test Suite">
14+
<directory suffix="TestTest.php">./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist processUncoveredFilesFromWhitelist="true">
19+
<directory suffix=".php">classmap</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

polyfill

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__ . '/vendor/autoload.php';
5+
6+
if (class_exists('PHPUnit_Framework_TestCase') && !class_exists('PHPUnit\Framework\TestCase')) {
7+
fwrite(STDERR, "Editing composer.json");
8+
9+
$json = \json_decode(\file_get_contents($filename = __DIR__ . '/composer.json'), true);
10+
$json['autoload-dev']['files'][] = './test-polyfill/TestCase.php';
11+
\file_put_contents($filename, \json_encode($json));
12+
}

0 commit comments

Comments
 (0)