Add pear modules, mail and net_smtp via composer (#93)

Add pear modules, mail and net_smtp via composer, remove php 5.6 build due to phpunit 6
This commit is contained in:
Thilina Hasantha
2018-01-08 23:13:43 +01:00
committed by GitHub
parent 359e3f8382
commit e7792e7d79
2349 changed files with 117270 additions and 83170 deletions

View File

@@ -1,6 +1,4 @@
.idea
composer.lock
composer.phar
vendor/
cache.properties
phpunit.xml
/.idea
/.php_cs.cache
/composer.lock
/vendor

View File

@@ -0,0 +1,79 @@
<?php
$header = <<<'EOF'
This file is part of sebastian/global-state.
(c) Sebastian Bergmann <sebastian@phpunit.de>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules(
[
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'align_double_arrow' => true,
'align_equals' => true
],
'blank_line_after_namespace' => true,
'blank_line_before_return' => true,
'braces' => true,
'cast_spaces' => true,
'concat_space' => ['spacing' => 'one'],
'elseif' => true,
'encoding' => true,
'full_opening_tag' => true,
'function_declaration' => true,
#'header_comment' => ['header' => $header, 'separate' => 'none'],
'indentation_type' => true,
'line_ending' => true,
'lowercase_constants' => true,
'lowercase_keywords' => true,
'method_argument_space' => true,
'native_function_invocation' => true,
'no_alias_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_closing_tag' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => true,
'no_leading_namespace_whitespace' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_after_function_name' => true,
'no_spaces_inside_parenthesis' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_whitespace' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
'phpdoc_align' => true,
'phpdoc_indent' => true,
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'self_accessor' => true,
'simplified_null_return' => true,
'single_blank_line_at_eof' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'single_quote' => true,
'ternary_operator_spaces' => true,
'trim_array_spaces' => true,
'visibility_required' => true,
]
)
->setFinder(
PhpCsFixer\Finder::create()
->files()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->name('*.php')
);

View File

@@ -1,20 +1,26 @@
language: php
php:
- 5.3.3
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
- 7.0
- 7.0snapshot
- 7.1
- 7.1snapshot
- master
sudo: false
before_script:
before_install:
- composer self-update
- composer install --no-interaction --prefer-source --dev
- composer clear-cache
script: ./vendor/bin/phpunit
install:
- travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable
script:
- ./vendor/bin/phpunit --coverage-clover=coverage.xml
after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
email: false

View File

@@ -1,6 +1,6 @@
GlobalState
sebastian/global-state
Copyright (c) 2001-2015, Sebastian Bergmann <sebastian@phpunit.de>.
Copyright (c) 2001-2017, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -6,10 +6,11 @@ Snapshotting of global state, factored out of PHPUnit into a stand-alone compone
## Installation
To add this package as a local, per-project dependency to your project, simply add a dependency on `sebastian/global-state` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on GlobalState:
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
composer require sebastian/global-state
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
composer require --dev sebastian/global-state
{
"require": {
"sebastian/global-state": "1.0.*"
}
}

View File

@@ -1,33 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="global-state">
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/composer.lock"/>
</target>
<project name="global-state" default="setup">
<target name="setup" depends="clean,composer"/>
<target name="composer" depends="clean" description="Install dependencies with Composer">
<tstamp>
<format property="thirty.days.ago" pattern="MM/dd/yyyy hh:mm aa" offset="-30" unit="day"/>
</tstamp>
<delete>
<fileset dir="${basedir}">
<include name="composer.phar" />
<date datetime="${thirty.days.ago}" when="before"/>
</fileset>
</delete>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/composer.lock"/>
</target>
<get src="https://getcomposer.org/composer.phar" dest="${basedir}/composer.phar" skipexisting="true"/>
<exec executable="php">
<arg value="composer.phar"/>
<arg value="install"/>
</exec>
</target>
<target name="phpunit" description="Run unit tests with PHPUnit">
<exec executable="${basedir}/vendor/bin/phpunit" failonerror="true">
<arg value="--configuration"/>
<arg path="${basedir}/build/phpunit.xml"/>
</exec>
</target>
<target name="composer" depends="clean" description="Install dependencies with Composer">
<exec executable="composer" taskname="composer">
<env key="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
<arg value="update"/>
<arg value="--no-interaction"/>
<arg value="--no-progress"/>
<arg value="--no-ansi"/>
<arg value="--no-suggest"/>
<arg value="--optimize-autoloader"/>
<arg value="--prefer-stable"/>
</exec>
</target>
</project>

View File

@@ -11,10 +11,10 @@
}
],
"require": {
"php": ">=5.3.3"
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
"phpunit/phpunit": "^6.0"
},
"suggest": {
"ext-uopz": "*"
@@ -27,11 +27,14 @@
"autoload-dev": {
"classmap": [
"tests/_fixture/"
],
"files": [
"tests/_fixture/SnapshotFunctions.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "2.0-dev"
}
}
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuite>
<directory suffix="Test.php">tests</directory>
</testsuite>
<php>
<const name="GLOBALSTATE_TESTSUITE" value="true"/>
<ini name="date.timezone" value="Etc/UTC"/>
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
verbose="true">
<testsuite name="GlobalState">
<directory suffix="Test.php">tests</directory>
</testsuite>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<php>
<const name="GLOBALSTATE_TESTSUITE" value="true"/>
<ini name="date.timezone" value="Etc/UTC"/>
</php>
</phpunit>

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,6 +8,8 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use ReflectionClass;
@@ -20,108 +22,80 @@ class Blacklist
/**
* @var array
*/
private $globalVariables = array();
private $globalVariables = [];
/**
* @var string[]
*/
private $classes = [];
/**
* @var string[]
*/
private $classNamePrefixes = [];
/**
* @var string[]
*/
private $parentClasses = [];
/**
* @var string[]
*/
private $interfaces = [];
/**
* @var array
*/
private $classes = array();
private $staticAttributes = [];
/**
* @var array
*/
private $classNamePrefixes = array();
/**
* @var array
*/
private $parentClasses = array();
/**
* @var array
*/
private $interfaces = array();
/**
* @var array
*/
private $staticAttributes = array();
/**
* @param string $variableName
*/
public function addGlobalVariable($variableName)
public function addGlobalVariable(string $variableName)
{
$this->globalVariables[$variableName] = true;
}
/**
* @param string $className
*/
public function addClass($className)
public function addClass(string $className)
{
$this->classes[] = $className;
}
/**
* @param string $className
*/
public function addSubclassesOf($className)
public function addSubclassesOf(string $className)
{
$this->parentClasses[] = $className;
}
/**
* @param string $interfaceName
*/
public function addImplementorsOf($interfaceName)
public function addImplementorsOf(string $interfaceName)
{
$this->interfaces[] = $interfaceName;
}
/**
* @param string $classNamePrefix
*/
public function addClassNamePrefix($classNamePrefix)
public function addClassNamePrefix(string $classNamePrefix)
{
$this->classNamePrefixes[] = $classNamePrefix;
}
/**
* @param string $className
* @param string $attributeName
*/
public function addStaticAttribute($className, $attributeName)
public function addStaticAttribute(string $className, string $attributeName)
{
if (!isset($this->staticAttributes[$className])) {
$this->staticAttributes[$className] = array();
$this->staticAttributes[$className] = [];
}
$this->staticAttributes[$className][$attributeName] = true;
}
/**
* @param string $variableName
* @return bool
*/
public function isGlobalVariableBlacklisted($variableName)
public function isGlobalVariableBlacklisted(string $variableName): bool
{
return isset($this->globalVariables[$variableName]);
}
/**
* @param string $className
* @param string $attributeName
* @return bool
*/
public function isStaticAttributeBlacklisted($className, $attributeName)
public function isStaticAttributeBlacklisted(string $className, string $attributeName): bool
{
if (in_array($className, $this->classes)) {
if (\in_array($className, $this->classes)) {
return true;
}
foreach ($this->classNamePrefixes as $prefix) {
if (strpos($className, $prefix) === 0) {
if (\strpos($className, $prefix) === 0) {
return true;
}
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,6 +8,8 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
/**
@@ -15,16 +17,12 @@ namespace SebastianBergmann\GlobalState;
*/
class CodeExporter
{
/**
* @param Snapshot $snapshot
* @return string
*/
public function constants(Snapshot $snapshot)
public function constants(Snapshot $snapshot): string
{
$result = '';
foreach ($snapshot->constants() as $name => $value) {
$result .= sprintf(
$result .= \sprintf(
'if (!defined(\'%s\')) define(\'%s\', %s);' . "\n",
$name,
$name,
@@ -35,16 +33,27 @@ class CodeExporter
return $result;
}
/**
* @param Snapshot $snapshot
* @return string
*/
public function iniSettings(Snapshot $snapshot)
public function globalVariables(Snapshot $snapshot): string
{
$result = '$GLOBALS = [];' . PHP_EOL;
foreach ($snapshot->globalVariables() as $name => $value) {
$result .= \sprintf(
'$GLOBALS[%s] = %s;' . PHP_EOL,
$this->exportVariable($name),
$this->exportVariable($value)
);
}
return $result;
}
public function iniSettings(Snapshot $snapshot): string
{
$result = '';
foreach ($snapshot->iniSettings() as $key => $value) {
$result .= sprintf(
$result .= \sprintf(
'@ini_set(%s, %s);' . "\n",
$this->exportVariable($key),
$this->exportVariable($value)
@@ -54,32 +63,24 @@ class CodeExporter
return $result;
}
/**
* @param mixed $variable
* @return string
*/
private function exportVariable($variable)
private function exportVariable($variable): string
{
if (is_scalar($variable) || is_null($variable) ||
(is_array($variable) && $this->arrayOnlyContainsScalars($variable))) {
return var_export($variable, true);
if (\is_scalar($variable) || \is_null($variable) ||
(\is_array($variable) && $this->arrayOnlyContainsScalars($variable))) {
return \var_export($variable, true);
}
return 'unserialize(' . var_export(serialize($variable), true) . ')';
return 'unserialize(' . \var_export(\serialize($variable), true) . ')';
}
/**
* @param array $array
* @return bool
*/
private function arrayOnlyContainsScalars(array $array)
private function arrayOnlyContainsScalars(array $array): bool
{
$result = true;
foreach ($array as $element) {
if (is_array($element)) {
if (\is_array($element)) {
$result = self::arrayOnlyContainsScalars($element);
} elseif (!is_scalar($element) && !is_null($element)) {
} elseif (!\is_scalar($element) && !\is_null($element)) {
$result = false;
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,6 +8,8 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use ReflectionProperty;
@@ -20,27 +22,25 @@ class Restorer
/**
* Deletes function definitions that are not defined in a snapshot.
*
* @param Snapshot $snapshot
* @throws RuntimeException when the uopz_delete() function is not available
*
* @see https://github.com/krakjoe/uopz
*/
public function restoreFunctions(Snapshot $snapshot)
{
if (!function_exists('uopz_delete')) {
if (!\function_exists('uopz_delete')) {
throw new RuntimeException('The uopz_delete() function is required for this operation');
}
$functions = get_defined_functions();
$functions = \get_defined_functions();
foreach (array_diff($functions['user'], $snapshot->functions()) as $function) {
foreach (\array_diff($functions['user'], $snapshot->functions()) as $function) {
uopz_delete($function);
}
}
/**
* Restores all global and super-global variables from a snapshot.
*
* @param Snapshot $snapshot
*/
public function restoreGlobalVariables(Snapshot $snapshot)
{
@@ -52,11 +52,11 @@ class Restorer
$globalVariables = $snapshot->globalVariables();
foreach (array_keys($GLOBALS) as $key) {
foreach (\array_keys($GLOBALS) as $key) {
if ($key != 'GLOBALS' &&
!in_array($key, $superGlobalArrays) &&
!\in_array($key, $superGlobalArrays) &&
!$snapshot->blacklist()->isGlobalVariableBlacklisted($key)) {
if (isset($globalVariables[$key])) {
if (\array_key_exists($key, $globalVariables)) {
$GLOBALS[$key] = $globalVariables[$key];
} else {
unset($GLOBALS[$key]);
@@ -67,13 +67,12 @@ class Restorer
/**
* Restores all static attributes in user-defined classes from this snapshot.
*
* @param Snapshot $snapshot
*/
public function restoreStaticAttributes(Snapshot $snapshot)
{
$current = new Snapshot($snapshot->blacklist(), false, false, false, false, true, false, false, false, false);
$newClasses = array_diff($current->classes(), $snapshot->classes());
$newClasses = \array_diff($current->classes(), $snapshot->classes());
unset($current);
foreach ($snapshot->staticAttributes() as $className => $staticAttributes) {
@@ -111,19 +110,16 @@ class Restorer
/**
* Restores a super-global variable array from this snapshot.
*
* @param Snapshot $snapshot
* @param $superGlobalArray
*/
private function restoreSuperGlobalArray(Snapshot $snapshot, $superGlobalArray)
private function restoreSuperGlobalArray(Snapshot $snapshot, string $superGlobalArray)
{
$superGlobalVariables = $snapshot->superGlobalVariables();
if (isset($GLOBALS[$superGlobalArray]) &&
is_array($GLOBALS[$superGlobalArray]) &&
\is_array($GLOBALS[$superGlobalArray]) &&
isset($superGlobalVariables[$superGlobalArray])) {
$keys = array_keys(
array_merge(
$keys = \array_keys(
\array_merge(
$GLOBALS[$superGlobalArray],
$superGlobalVariables[$superGlobalArray]
)

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,6 +8,8 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use ReflectionClass;
@@ -26,73 +28,62 @@ class Snapshot
/**
* @var array
*/
private $globalVariables = array();
private $globalVariables = [];
/**
* @var array
*/
private $superGlobalArrays = array();
private $superGlobalArrays = [];
/**
* @var array
*/
private $superGlobalVariables = array();
private $superGlobalVariables = [];
/**
* @var array
*/
private $staticAttributes = array();
private $staticAttributes = [];
/**
* @var array
*/
private $iniSettings = array();
private $iniSettings = [];
/**
* @var array
*/
private $includedFiles = array();
private $includedFiles = [];
/**
* @var array
*/
private $constants = array();
private $constants = [];
/**
* @var array
*/
private $functions = array();
private $functions = [];
/**
* @var array
*/
private $interfaces = array();
private $interfaces = [];
/**
* @var array
*/
private $classes = array();
private $classes = [];
/**
* @var array
*/
private $traits = array();
private $traits = [];
/**
* Creates a snapshot of the current global state.
*
* @param Blacklist $blacklist
* @param bool $includeGlobalVariables
* @param bool $includeStaticAttributes
* @param bool $includeConstants
* @param bool $includeFunctions
* @param bool $includeClasses
* @param bool $includeInterfaces
* @param bool $includeTraits
* @param bool $includeIniSettings
* @param bool $includeIncludedFiles
*/
public function __construct(Blacklist $blacklist = null, $includeGlobalVariables = true, $includeStaticAttributes = true, $includeConstants = true, $includeFunctions = true, $includeClasses = true, $includeInterfaces = true, $includeTraits = true, $includeIniSettings = true, $includeIncludedFiles = true)
public function __construct(Blacklist $blacklist = null, bool $includeGlobalVariables = true, bool $includeStaticAttributes = true, bool $includeConstants = true, bool $includeFunctions = true, bool $includeClasses = true, bool $includeInterfaces = true, bool $includeTraits = true, bool $includeIniSettings = true, bool $includeIncludedFiles = true)
{
if ($blacklist === null) {
$blacklist = new Blacklist;
@@ -126,112 +117,72 @@ class Snapshot
}
if ($includeIniSettings) {
$this->iniSettings = ini_get_all(null, false);
$this->iniSettings = \ini_get_all(null, false);
}
if ($includeIncludedFiles) {
$this->includedFiles = get_included_files();
$this->includedFiles = \get_included_files();
}
if (function_exists('get_declared_traits')) {
$this->traits = get_declared_traits();
}
$this->traits = \get_declared_traits();
}
/**
* @return Blacklist
*/
public function blacklist()
public function blacklist(): Blacklist
{
return $this->blacklist;
}
/**
* @return array
*/
public function globalVariables()
public function globalVariables(): array
{
return $this->globalVariables;
}
/**
* @return array
*/
public function superGlobalVariables()
public function superGlobalVariables(): array
{
return $this->superGlobalVariables;
}
/**
* Returns a list of all super-global variable arrays.
*
* @return array
*/
public function superGlobalArrays()
public function superGlobalArrays(): array
{
return $this->superGlobalArrays;
}
/**
* @return array
*/
public function staticAttributes()
public function staticAttributes(): array
{
return $this->staticAttributes;
}
/**
* @return array
*/
public function iniSettings()
public function iniSettings(): array
{
return $this->iniSettings;
}
/**
* @return array
*/
public function includedFiles()
public function includedFiles(): array
{
return $this->includedFiles;
}
/**
* @return array
*/
public function constants()
public function constants(): array
{
return $this->constants;
}
/**
* @return array
*/
public function functions()
public function functions(): array
{
return $this->functions;
}
/**
* @return array
*/
public function interfaces()
public function interfaces(): array
{
return $this->interfaces;
}
/**
* @return array
*/
public function classes()
public function classes(): array
{
return $this->classes;
}
/**
* @return array
*/
public function traits()
public function traits(): array
{
return $this->traits;
}
@@ -241,7 +192,7 @@ class Snapshot
*/
private function snapshotConstants()
{
$constants = get_defined_constants(true);
$constants = \get_defined_constants(true);
if (isset($constants['user'])) {
$this->constants = $constants['user'];
@@ -253,7 +204,7 @@ class Snapshot
*/
private function snapshotFunctions()
{
$functions = get_defined_functions();
$functions = \get_defined_functions();
$this->functions = $functions['user'];
}
@@ -263,7 +214,7 @@ class Snapshot
*/
private function snapshotClasses()
{
foreach (array_reverse(get_declared_classes()) as $className) {
foreach (\array_reverse(\get_declared_classes()) as $className) {
$class = new ReflectionClass($className);
if (!$class->isUserDefined()) {
@@ -273,7 +224,7 @@ class Snapshot
$this->classes[] = $className;
}
$this->classes = array_reverse($this->classes);
$this->classes = \array_reverse($this->classes);
}
/**
@@ -281,7 +232,7 @@ class Snapshot
*/
private function snapshotInterfaces()
{
foreach (array_reverse(get_declared_interfaces()) as $interfaceName) {
foreach (\array_reverse(\get_declared_interfaces()) as $interfaceName) {
$class = new ReflectionClass($interfaceName);
if (!$class->isUserDefined()) {
@@ -291,7 +242,7 @@ class Snapshot
$this->interfaces[] = $interfaceName;
}
$this->interfaces = array_reverse($this->interfaces);
$this->interfaces = \array_reverse($this->interfaces);
}
/**
@@ -305,28 +256,26 @@ class Snapshot
$this->snapshotSuperGlobalArray($superGlobalArray);
}
foreach (array_keys($GLOBALS) as $key) {
foreach (\array_keys($GLOBALS) as $key) {
if ($key != 'GLOBALS' &&
!in_array($key, $superGlobalArrays) &&
!\in_array($key, $superGlobalArrays) &&
$this->canBeSerialized($GLOBALS[$key]) &&
!$this->blacklist->isGlobalVariableBlacklisted($key)) {
$this->globalVariables[$key] = unserialize(serialize($GLOBALS[$key]));
$this->globalVariables[$key] = \unserialize(\serialize($GLOBALS[$key]));
}
}
}
/**
* Creates a snapshot a super-global variable array.
*
* @param $superGlobalArray
*/
private function snapshotSuperGlobalArray($superGlobalArray)
private function snapshotSuperGlobalArray(string $superGlobalArray)
{
$this->superGlobalVariables[$superGlobalArray] = array();
$this->superGlobalVariables[$superGlobalArray] = [];
if (isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray])) {
if (isset($GLOBALS[$superGlobalArray]) && \is_array($GLOBALS[$superGlobalArray])) {
foreach ($GLOBALS[$superGlobalArray] as $key => $value) {
$this->superGlobalVariables[$superGlobalArray][$key] = unserialize(serialize($value));
$this->superGlobalVariables[$superGlobalArray][$key] = \unserialize(\serialize($value));
}
}
}
@@ -338,7 +287,7 @@ class Snapshot
{
foreach ($this->classes as $className) {
$class = new ReflectionClass($className);
$snapshot = array();
$snapshot = [];
foreach ($class->getProperties() as $attribute) {
if ($attribute->isStatic()) {
@@ -352,7 +301,7 @@ class Snapshot
$value = $attribute->getValue();
if ($this->canBeSerialized($value)) {
$snapshot[$name] = unserialize(serialize($value));
$snapshot[$name] = \unserialize(\serialize($value));
}
}
}
@@ -365,12 +314,10 @@ class Snapshot
/**
* Returns a list of all super-global variable arrays.
*
* @return array
*/
private function setupSuperGlobalArrays()
{
$this->superGlobalArrays = array(
$this->superGlobalArrays = [
'_ENV',
'_POST',
'_GET',
@@ -378,32 +325,30 @@ class Snapshot
'_SERVER',
'_FILES',
'_REQUEST'
);
];
if (ini_get('register_long_arrays') == '1') {
$this->superGlobalArrays = array_merge(
if (\ini_get('register_long_arrays') == '1') {
$this->superGlobalArrays = \array_merge(
$this->superGlobalArrays,
array(
[
'HTTP_ENV_VARS',
'HTTP_POST_VARS',
'HTTP_GET_VARS',
'HTTP_COOKIE_VARS',
'HTTP_SERVER_VARS',
'HTTP_POST_FILES'
)
]
);
}
}
/**
* @param mixed $variable
* @return bool
* @todo Implement this properly
* @todo Implement this properly
*/
private function canBeSerialized($variable)
private function canBeSerialized($variable): bool
{
if (!is_object($variable)) {
return !is_resource($variable);
if (!\is_object($variable)) {
return !\is_resource($variable);
}
if ($variable instanceof \stdClass) {

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,10 +8,10 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
/**
*/
interface Exception
{
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,10 +8,10 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
/**
*/
class RuntimeException extends \RuntimeException implements Exception
{
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,13 +8,20 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedChildClass;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedClass;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedImplementor;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface;
/**
* @covers \SebastianBergmann\GlobalState\Blacklist
*/
class BlacklistTest extends PHPUnit_Framework_TestCase
class BlacklistTest extends TestCase
{
/**
* @var \SebastianBergmann\GlobalState\Blacklist
@@ -42,7 +49,7 @@ class BlacklistTest extends PHPUnit_Framework_TestCase
{
$this->assertFalse(
$this->blacklist->isStaticAttributeBlacklisted(
'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
BlacklistedClass::class,
'attribute'
)
);
@@ -50,11 +57,11 @@ class BlacklistTest extends PHPUnit_Framework_TestCase
public function testClassCanBeBlacklisted()
{
$this->blacklist->addClass('SebastianBergmann\GlobalState\TestFixture\BlacklistedClass');
$this->blacklist->addClass(BlacklistedClass::class);
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
BlacklistedClass::class,
'attribute'
)
);
@@ -62,11 +69,11 @@ class BlacklistTest extends PHPUnit_Framework_TestCase
public function testSubclassesCanBeBlacklisted()
{
$this->blacklist->addSubclassesOf('SebastianBergmann\GlobalState\TestFixture\BlacklistedClass');
$this->blacklist->addSubclassesOf(BlacklistedClass::class);
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
'SebastianBergmann\GlobalState\TestFixture\BlacklistedChildClass',
BlacklistedChildClass::class,
'attribute'
)
);
@@ -74,11 +81,11 @@ class BlacklistTest extends PHPUnit_Framework_TestCase
public function testImplementorsCanBeBlacklisted()
{
$this->blacklist->addImplementorsOf('SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface');
$this->blacklist->addImplementorsOf(BlacklistedInterface::class);
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
'SebastianBergmann\GlobalState\TestFixture\BlacklistedImplementor',
BlacklistedImplementor::class,
'attribute'
)
);
@@ -90,7 +97,7 @@ class BlacklistTest extends PHPUnit_Framework_TestCase
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
BlacklistedClass::class,
'attribute'
)
);
@@ -99,13 +106,13 @@ class BlacklistTest extends PHPUnit_Framework_TestCase
public function testStaticAttributeCanBeBlacklisted()
{
$this->blacklist->addStaticAttribute(
'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
BlacklistedClass::class,
'attribute'
);
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
BlacklistedClass::class,
'attribute'
)
);

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\GlobalState\CodeExporter
*/
class CodeExporterTest extends TestCase
{
/**
* @runInSeparateProcess
*/
public function testCanExportGlobalVariablesToCode()
{
$GLOBALS = ['foo' => 'bar'];
$snapshot = new Snapshot(null, true, false, false, false, false, false, false, false, false);
$exporter = new CodeExporter;
$this->assertEquals(
'$GLOBALS = [];' . PHP_EOL . '$GLOBALS[\'foo\'] = \'bar\';' . PHP_EOL,
$exporter->globalVariables($snapshot)
);
}
}

View File

@@ -0,0 +1,105 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use PHPUnit\Framework\TestCase;
/**
* Class Restorer.
*/
class RestorerTest extends TestCase
{
public static function setUpBeforeClass()
{
$GLOBALS['varBool'] = false;
$GLOBALS['varNull'] = null;
$_GET['varGet'] = 0;
}
/**
* Check global variables are correctly backuped and restored (unit test).
*
* @covers \SebastianBergmann\GlobalState\Restorer::restoreGlobalVariables
* @covers \SebastianBergmann\GlobalState\Restorer::restoreSuperGlobalArray
*
* @uses \SebastianBergmann\GlobalState\Blacklist::isGlobalVariableBlacklisted
* @uses \SebastianBergmann\GlobalState\Snapshot::__construct
* @uses \SebastianBergmann\GlobalState\Snapshot::blacklist
* @uses \SebastianBergmann\GlobalState\Snapshot::canBeSerialized
* @uses \SebastianBergmann\GlobalState\Snapshot::globalVariables
* @uses \SebastianBergmann\GlobalState\Snapshot::setupSuperGlobalArrays
* @uses \SebastianBergmann\GlobalState\Snapshot::snapshotGlobals
* @uses \SebastianBergmann\GlobalState\Snapshot::snapshotSuperGlobalArray
* @uses \SebastianBergmann\GlobalState\Snapshot::superGlobalArrays
* @uses \SebastianBergmann\GlobalState\Snapshot::superGlobalVariables
*/
public function testRestorerGlobalVariable()
{
$snapshot = new Snapshot(null, true, false, false, false, false, false, false, false, false);
$restorer = new Restorer;
$restorer->restoreGlobalVariables($snapshot);
$this->assertArrayHasKey('varBool', $GLOBALS);
$this->assertEquals(false, $GLOBALS['varBool']);
$this->assertArrayHasKey('varNull', $GLOBALS);
$this->assertEquals(null, $GLOBALS['varNull']);
$this->assertArrayHasKey('varGet', $_GET);
$this->assertEquals(0, $_GET['varGet']);
}
/**
* Check global variables are correctly backuped and restored.
*
* The real test is the second, but the first has to be executed to backup the globals.
*
* @backupGlobals enabled
* @covers \SebastianBergmann\GlobalState\Restorer::restoreGlobalVariables
* @covers \SebastianBergmann\GlobalState\Restorer::restoreSuperGlobalArray
*
* @uses \SebastianBergmann\GlobalState\Blacklist::addClassNamePrefix
* @uses \SebastianBergmann\GlobalState\Blacklist::isGlobalVariableBlacklisted
* @uses \SebastianBergmann\GlobalState\Snapshot::__construct
* @uses \SebastianBergmann\GlobalState\Snapshot::blacklist
* @uses \SebastianBergmann\GlobalState\Snapshot::canBeSerialized
* @uses \SebastianBergmann\GlobalState\Snapshot::globalVariables
* @uses \SebastianBergmann\GlobalState\Snapshot::setupSuperGlobalArrays
* @uses \SebastianBergmann\GlobalState\Snapshot::snapshotGlobals
* @uses \SebastianBergmann\GlobalState\Snapshot::snapshotSuperGlobalArray
* @uses \SebastianBergmann\GlobalState\Snapshot::superGlobalArrays
* @uses \SebastianBergmann\GlobalState\Snapshot::superGlobalVariables
*/
public function testIntegrationRestorerGlobalVariables()
{
$this->assertArrayHasKey('varBool', $GLOBALS);
$this->assertEquals(false, $GLOBALS['varBool']);
$this->assertArrayHasKey('varNull', $GLOBALS);
$this->assertEquals(null, $GLOBALS['varNull']);
$this->assertArrayHasKey('varGet', $_GET);
$this->assertEquals(0, $_GET['varGet']);
}
/**
* Check global variables are correctly backuped and restored.
*
* @depends testIntegrationRestorerGlobalVariables
*/
public function testIntegrationRestorerGlobalVariables2()
{
$this->assertArrayHasKey('varBool', $GLOBALS);
$this->assertEquals(false, $GLOBALS['varBool']);
$this->assertArrayHasKey('varNull', $GLOBALS);
$this->assertEquals(null, $GLOBALS['varNull']);
$this->assertArrayHasKey('varGet', $_GET);
$this->assertEquals(0, $_GET['varGet']);
}
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,93 +8,100 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use ArrayObject;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface;
use SebastianBergmann\GlobalState\TestFixture\SnapshotClass;
use SebastianBergmann\GlobalState\TestFixture\SnapshotTrait;
/**
* @covers \SebastianBergmann\GlobalState\Snapshot
*/
class SnapshotTest extends PHPUnit_Framework_TestCase
class SnapshotTest extends TestCase
{
/**
* @var Blacklist
*/
private $blacklist;
protected function setUp()
{
$this->blacklist = $this->createMock(Blacklist::class);
}
public function testStaticAttributes()
{
$blacklist = $this->getBlacklist();
$blacklist->method('isStaticAttributeBlacklisted')->willReturnCallback(function ($class) {
return $class !== 'SebastianBergmann\GlobalState\TestFixture\SnapshotClass';
});
$this->blacklist->method('isStaticAttributeBlacklisted')->willReturnCallback(
function ($class) {
return $class !== SnapshotClass::class;
}
);
SnapshotClass::init();
$snapshot = new Snapshot($blacklist, false, true, false, false, false, false, false, false, false);
$expected = array('SebastianBergmann\GlobalState\TestFixture\SnapshotClass' => array(
'string' => 'snapshot',
'arrayObject' => new ArrayObject(array(1, 2, 3)),
'stdClass' => new \stdClass(),
));
$snapshot = new Snapshot($this->blacklist, false, true, false, false, false, false, false, false, false);
$expected = [
SnapshotClass::class => [
'string' => 'snapshot',
'arrayObject' => new ArrayObject([1, 2, 3]),
'stdClass' => new \stdClass(),
]
];
$this->assertEquals($expected, $snapshot->staticAttributes());
}
public function testConstants()
{
$snapshot = new Snapshot($this->getBlacklist(), false, false, true, false, false, false, false, false, false);
$snapshot = new Snapshot($this->blacklist, false, false, true, false, false, false, false, false, false);
$this->assertArrayHasKey('GLOBALSTATE_TESTSUITE', $snapshot->constants());
}
public function testFunctions()
{
require_once __DIR__.'/_fixture/SnapshotFunctions.php';
$snapshot = new Snapshot($this->getBlacklist(), false, false, false, true, false, false, false, false, false);
$snapshot = new Snapshot($this->blacklist, false, false, false, true, false, false, false, false, false);
$functions = $snapshot->functions();
$this->assertThat(
$functions,
$this->logicalOr(
// Zend
$this->contains('sebastianbergmann\globalstate\testfixture\snapshotfunction'),
// HHVM
$this->contains('SebastianBergmann\GlobalState\TestFixture\snapshotFunction')
)
);
$this->assertContains('sebastianbergmann\globalstate\testfixture\snapshotfunction', $functions);
$this->assertNotContains('assert', $functions);
}
public function testClasses()
{
$snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, true, false, false, false, false);
$classes = $snapshot->classes();
$snapshot = new Snapshot($this->blacklist, false, false, false, false, true, false, false, false, false);
$classes = $snapshot->classes();
$this->assertContains('PHPUnit_Framework_TestCase', $classes);
$this->assertNotContains('Exception', $classes);
$this->assertContains(TestCase::class, $classes);
$this->assertNotContains(Exception::class, $classes);
}
public function testInterfaces()
{
$snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, true, false, false, false);
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, true, false, false, false);
$interfaces = $snapshot->interfaces();
$this->assertContains('PHPUnit_Framework_Test', $interfaces);
$this->assertNotContains('Countable', $interfaces);
$this->assertContains(BlacklistedInterface::class, $interfaces);
$this->assertNotContains(\Countable::class, $interfaces);
}
/**
* @requires PHP 5.4
*/
public function testTraits()
{
spl_autoload_call('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait');
\spl_autoload_call('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait');
$snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, false, true, false, false);
$this->assertContains('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait', $snapshot->traits());
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, true, false, false);
$this->assertContains(SnapshotTrait::class, $snapshot->traits());
}
public function testIniSettings()
{
$snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, false, false, true, false);
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, false, true, false);
$iniSettings = $snapshot->iniSettings();
$this->assertArrayHasKey('date.timezone', $iniSettings);
@@ -103,17 +110,7 @@ class SnapshotTest extends PHPUnit_Framework_TestCase
public function testIncludedFiles()
{
$snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, false, false, false, true);
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, false, false, true);
$this->assertContains(__FILE__, $snapshot->includedFiles());
}
/**
* @return \SebastianBergmann\GlobalState\Blacklist
*/
private function getBlacklist()
{
return $this->getMockBuilder('SebastianBergmann\GlobalState\Blacklist')
->disableOriginalConstructor()
->getMock();
}
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,10 +8,10 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
/**
*/
class BlacklistedChildClass extends BlacklistedClass
{
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,10 +8,10 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
/**
*/
class BlacklistedClass
{
private static $attribute;

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,10 +8,10 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
/**
*/
class BlacklistedImplementor implements BlacklistedInterface
{
private static $attribute;

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,10 +8,10 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
/**
*/
interface BlacklistedInterface
{
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,13 +8,13 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
use DomDocument;
use ArrayObject;
/**
*/
class SnapshotClass
{
private static $string = 'snapshot';
@@ -27,11 +27,11 @@ class SnapshotClass
public static function init()
{
self::$dom = new DomDocument();
self::$closure = function () {};
self::$arrayObject = new ArrayObject(array(1, 2, 3));
self::$dom = new DomDocument();
self::$closure = function () {};
self::$arrayObject = new ArrayObject([1, 2, 3]);
self::$snapshotDomDocument = new SnapshotDomDocument();
self::$resource = fopen('php://memory', 'r');
self::$stdClass = new \stdClass();
self::$resource = \fopen('php://memory', 'r');
self::$stdClass = new \stdClass();
}
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,12 +8,12 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
use DomDocument;
/**
*/
class SnapshotDomDocument extends DomDocument
{
}

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,6 +8,8 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
function snapshotFunction()

View File

@@ -1,6 +1,6 @@
<?php
/*
* This file is part of the GlobalState package.
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
@@ -8,10 +8,10 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
/**
*/
trait SnapshotTrait
{
}