laravel-6 support

This commit is contained in:
RafficMohammed
2023-01-08 01:17:22 +05:30
parent 1a5c16ae4b
commit 774eed8b0e
4962 changed files with 279380 additions and 297961 deletions

View File

@@ -0,0 +1,40 @@
# Configuration for probot-stale - https://github.com/probot/stale
# Number of days of inactivity before an Issue or Pull Request becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale Issue or Pull Request is closed.
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
daysUntilClose: 7
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
exemptLabels:
- enhancement
# Set to true to ignore issues in a project (defaults to false)
exemptProjects: false
# Set to true to ignore issues in a milestone (defaults to false)
exemptMilestones: false
# Label to use when marking as stale
staleLabel: stale
# Comment to post when marking as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions.
# Comment to post when removing the stale label.
# unmarkComment: >
# Your comment here.
# Comment to post when closing a stale Issue or Pull Request.
closeComment: >
This issue has been automatically closed because it has not had activity since it was marked as stale. Thank you for your contributions.
# Limit the number of actions per hour, from 1-30. Default is 30
limitPerRun: 30
# Limit to only `issues` or `pulls`
only: issues

View File

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

View File

@@ -1,79 +0,0 @@
<?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

@@ -0,0 +1,197 @@
<?php declare(strict_types=1);
$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(
[
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'operators' => [
'=' => 'align',
'=>' => 'align',
],
],
'blank_line_after_namespace' => true,
'blank_line_before_statement' => [
'statements' => [
'break',
'continue',
'declare',
'do',
'for',
'foreach',
'if',
'include',
'include_once',
'require',
'require_once',
'return',
'switch',
'throw',
'try',
'while',
'yield',
],
],
'braces' => true,
'cast_spaces' => true,
'class_attributes_separation' => ['elements' => ['const', 'method', 'property']],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'declare_strict_types' => true,
'dir_constant' => true,
'elseif' => true,
'encoding' => true,
'full_opening_tag' => true,
'function_declaration' => true,
'header_comment' => ['header' => $header, 'separate' => 'none'],
'indentation_type' => true,
'is_null' => true,
'line_ending' => true,
'list_syntax' => ['syntax' => 'short'],
'logical_operators' => true,
'lowercase_cast' => true,
'lowercase_constants' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'method_argument_space' => ['ensure_fully_multiline' => true],
'modernize_types_casting' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => true,
'native_constant_invocation' => true,
'native_function_casing' => true,
'native_function_invocation' => true,
'new_with_braces' => false,
'no_alias_functions' => true,
'no_alternative_syntax' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_blank_lines_before_namespace' => true,
'no_closing_tag' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_homoglyph_names' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => ['use' => 'print'],
'no_multiline_whitespace_around_double_arrow' => true,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_short_bool_cast' => true,
'no_short_echo_tag' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_after_function_name' => true,
'no_spaces_inside_parenthesis' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_unset_on_property' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'non_printable_character' => true,
'normalize_index_brace' => true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => [
'order' => [
'use_trait',
'constant_public',
'constant_protected',
'constant_private',
'property_public_static',
'property_protected_static',
'property_private_static',
'property_public',
'property_protected',
'property_private',
'method_public_static',
'construct',
'destruct',
'magic',
'phpunit',
'method_public',
'method_protected',
'method_private',
'method_protected_static',
'method_private_static',
],
],
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => true,
'phpdoc_annotation_without_dot' => true,
'phpdoc_indent' => true,
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types' => ['groups' => ['simple', 'meta']],
'phpdoc_types_order' => true,
'phpdoc_var_without_name' => true,
'pow_to_exponentiation' => true,
'protected_to_private' => true,
'return_assignment' => true,
'return_type_declaration' => ['space_before' => 'none'],
'self_accessor' => true,
'semicolon_after_instruction' => true,
'set_type_to_cast' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true,
'single_blank_line_at_eof' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'single_quote' => true,
'standardize_not_equals' => true,
'ternary_to_null_coalescing' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => [
'elements' => [
'const',
'method',
'property',
],
],
'void_return' => true,
'whitespace_after_comma_in_array' => true,
]
)
->setFinder(
PhpCsFixer\Finder::create()
->files()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
);

View File

@@ -1,10 +1,8 @@
language: php
php:
- 7.0
- 7.0snapshot
- 7.1
- 7.1snapshot
- 7.2
- 7.3
- master
sudo: false
@@ -14,7 +12,7 @@ before_install:
- composer clear-cache
install:
- travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable
- travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest
script:
- ./vendor/bin/phpunit --coverage-clover=coverage.xml

View File

@@ -0,0 +1,30 @@
# Changes in sebastian/global-state
All notable changes in `sebastian/global-state` are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [3.0.2] - 2022-02-10
### Fixed
* The `$includeTraits` parameter of `SebastianBergmann\GlobalState\Snapshot::__construct()` is not respected
## [3.0.1] - 2020-11-30
### Changed
* Changed PHP version constraint in `composer.json` from `^7.2` to `>=7.2`
## [3.0.0] - 2019-02-01
### Changed
* `Snapshot::canBeSerialized()` now recursively checks arrays and object graphs for variables that cannot be serialized
### Removed
* This component is no longer supported on PHP 7.0 and PHP 7.1
[3.0.2]: https://github.com/sebastianbergmann/phpunit/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/sebastianbergmann/phpunit/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/phpunit/compare/2.0.0...3.0.0

View File

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

View File

@@ -1,4 +1,4 @@
# GlobalState
# global-state
Snapshotting of global state, factored out of PHPUnit into a stand-alone component.

View File

@@ -9,14 +9,11 @@
<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

@@ -10,11 +10,19 @@
"email": "sebastian@phpunit.de"
}
],
"prefer-stable": true,
"config": {
"optimize-autoloader": true,
"sort-packages": true
},
"require": {
"php": "^7.0"
"php": ">=7.2",
"sebastian/object-reflector": "^1.1.1",
"sebastian/recursion-context": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
"ext-dom": "*",
"phpunit/phpunit": "^8.0"
},
"suggest": {
"ext-uopz": "*"
@@ -34,7 +42,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
"dev-master": "3.0-dev"
}
}
}

View File

@@ -1,15 +1,18 @@
<?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"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuite>
<directory suffix="Test.php">tests</directory>
</testsuite>
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<php>
<const name="GLOBALSTATE_TESTSUITE" value="true"/>

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,17 +7,12 @@
* 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 ReflectionClass;
/**
* A blacklist for global state elements that should not be snapshotted.
*/
class Blacklist
final class Blacklist
{
/**
* @var array
@@ -49,32 +44,32 @@ class Blacklist
*/
private $staticAttributes = [];
public function addGlobalVariable(string $variableName)
public function addGlobalVariable(string $variableName): void
{
$this->globalVariables[$variableName] = true;
}
public function addClass(string $className)
public function addClass(string $className): void
{
$this->classes[] = $className;
}
public function addSubclassesOf(string $className)
public function addSubclassesOf(string $className): void
{
$this->parentClasses[] = $className;
}
public function addImplementorsOf(string $interfaceName)
public function addImplementorsOf(string $interfaceName): void
{
$this->interfaces[] = $interfaceName;
}
public function addClassNamePrefix(string $classNamePrefix)
public function addClassNamePrefix(string $classNamePrefix): void
{
$this->classNamePrefixes[] = $classNamePrefix;
}
public function addStaticAttribute(string $className, string $attributeName)
public function addStaticAttribute(string $className, string $attributeName): void
{
if (!isset($this->staticAttributes[$className])) {
$this->staticAttributes[$className] = [];
@@ -100,7 +95,7 @@ class Blacklist
}
}
$class = new ReflectionClass($className);
$class = new \ReflectionClass($className);
foreach ($this->parentClasses as $type) {
if ($class->isSubclassOf($type)) {

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,15 +7,12 @@
* 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;
/**
* Exports parts of a Snapshot as PHP code.
*/
class CodeExporter
final class CodeExporter
{
public function constants(Snapshot $snapshot): string
{
@@ -35,11 +32,11 @@ class CodeExporter
public function globalVariables(Snapshot $snapshot): string
{
$result = '$GLOBALS = [];' . PHP_EOL;
$result = '$GLOBALS = [];' . \PHP_EOL;
foreach ($snapshot->globalVariables() as $name => $value) {
$result .= \sprintf(
'$GLOBALS[%s] = %s;' . PHP_EOL,
'$GLOBALS[%s] = %s;' . \PHP_EOL,
$this->exportVariable($name),
$this->exportVariable($value)
);
@@ -65,7 +62,7 @@ class CodeExporter
private function exportVariable($variable): string
{
if (\is_scalar($variable) || \is_null($variable) ||
if (\is_scalar($variable) || null === $variable ||
(\is_array($variable) && $this->arrayOnlyContainsScalars($variable))) {
return \var_export($variable, true);
}
@@ -79,8 +76,8 @@ class CodeExporter
foreach ($array as $element) {
if (\is_array($element)) {
$result = self::arrayOnlyContainsScalars($element);
} elseif (!\is_scalar($element) && !\is_null($element)) {
$result = $this->arrayOnlyContainsScalars($element);
} elseif (!\is_scalar($element) && null !== $element) {
$result = false;
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,13 +7,8 @@
* 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 ReflectionProperty;
/**
* Restorer of snapshots of global state.
*/
@@ -24,9 +19,9 @@ class Restorer
*
* @throws RuntimeException when the uopz_delete() function is not available
*
* @see https://github.com/krakjoe/uopz
* @see https://github.com/krakjoe/uopz
*/
public function restoreFunctions(Snapshot $snapshot)
public function restoreFunctions(Snapshot $snapshot): void
{
if (!\function_exists('uopz_delete')) {
throw new RuntimeException('The uopz_delete() function is required for this operation');
@@ -42,7 +37,7 @@ class Restorer
/**
* Restores all global and super-global variables from a snapshot.
*/
public function restoreGlobalVariables(Snapshot $snapshot)
public function restoreGlobalVariables(Snapshot $snapshot): void
{
$superGlobalArrays = $snapshot->superGlobalArrays();
@@ -53,7 +48,7 @@ class Restorer
$globalVariables = $snapshot->globalVariables();
foreach (\array_keys($GLOBALS) as $key) {
if ($key != 'GLOBALS' &&
if ($key !== 'GLOBALS' &&
!\in_array($key, $superGlobalArrays) &&
!$snapshot->blacklist()->isGlobalVariableBlacklisted($key)) {
if (\array_key_exists($key, $globalVariables)) {
@@ -68,7 +63,7 @@ class Restorer
/**
* Restores all static attributes in user-defined classes from this snapshot.
*/
public function restoreStaticAttributes(Snapshot $snapshot)
public function restoreStaticAttributes(Snapshot $snapshot): void
{
$current = new Snapshot($snapshot->blacklist(), false, false, false, false, true, false, false, false, false);
$newClasses = \array_diff($current->classes(), $snapshot->classes());
@@ -77,7 +72,7 @@ class Restorer
foreach ($snapshot->staticAttributes() as $className => $staticAttributes) {
foreach ($staticAttributes as $name => $value) {
$reflector = new ReflectionProperty($className, $name);
$reflector = new \ReflectionProperty($className, $name);
$reflector->setAccessible(true);
$reflector->setValue($value);
}
@@ -111,7 +106,7 @@ class Restorer
/**
* Restores a super-global variable array from this snapshot.
*/
private function restoreSuperGlobalArray(Snapshot $snapshot, string $superGlobalArray)
private function restoreSuperGlobalArray(Snapshot $snapshot, string $superGlobalArray): void
{
$superGlobalVariables = $snapshot->superGlobalVariables();

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,13 +7,10 @@
* 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 ReflectionClass;
use Serializable;
use SebastianBergmann\ObjectReflector\ObjectReflector;
use SebastianBergmann\RecursionContext\Context;
/**
* A snapshot of global state.
@@ -124,7 +121,9 @@ class Snapshot
$this->includedFiles = \get_included_files();
}
$this->traits = \get_declared_traits();
if ($includeTraits) {
$this->traits = \get_declared_traits();
}
}
public function blacklist(): Blacklist
@@ -190,7 +189,7 @@ class Snapshot
/**
* Creates a snapshot user-defined constants.
*/
private function snapshotConstants()
private function snapshotConstants(): void
{
$constants = \get_defined_constants(true);
@@ -202,7 +201,7 @@ class Snapshot
/**
* Creates a snapshot user-defined functions.
*/
private function snapshotFunctions()
private function snapshotFunctions(): void
{
$functions = \get_defined_functions();
@@ -212,10 +211,10 @@ class Snapshot
/**
* Creates a snapshot user-defined classes.
*/
private function snapshotClasses()
private function snapshotClasses(): void
{
foreach (\array_reverse(\get_declared_classes()) as $className) {
$class = new ReflectionClass($className);
$class = new \ReflectionClass($className);
if (!$class->isUserDefined()) {
break;
@@ -230,10 +229,10 @@ class Snapshot
/**
* Creates a snapshot user-defined interfaces.
*/
private function snapshotInterfaces()
private function snapshotInterfaces(): void
{
foreach (\array_reverse(\get_declared_interfaces()) as $interfaceName) {
$class = new ReflectionClass($interfaceName);
$class = new \ReflectionClass($interfaceName);
if (!$class->isUserDefined()) {
break;
@@ -248,7 +247,7 @@ class Snapshot
/**
* Creates a snapshot of all global and super-global variables.
*/
private function snapshotGlobals()
private function snapshotGlobals(): void
{
$superGlobalArrays = $this->superGlobalArrays();
@@ -257,10 +256,11 @@ class Snapshot
}
foreach (\array_keys($GLOBALS) as $key) {
if ($key != 'GLOBALS' &&
if ($key !== 'GLOBALS' &&
!\in_array($key, $superGlobalArrays) &&
$this->canBeSerialized($GLOBALS[$key]) &&
!$this->blacklist->isGlobalVariableBlacklisted($key)) {
/* @noinspection UnserializeExploitsInspection */
$this->globalVariables[$key] = \unserialize(\serialize($GLOBALS[$key]));
}
}
@@ -269,12 +269,13 @@ class Snapshot
/**
* Creates a snapshot a super-global variable array.
*/
private function snapshotSuperGlobalArray(string $superGlobalArray)
private function snapshotSuperGlobalArray(string $superGlobalArray): void
{
$this->superGlobalVariables[$superGlobalArray] = [];
if (isset($GLOBALS[$superGlobalArray]) && \is_array($GLOBALS[$superGlobalArray])) {
foreach ($GLOBALS[$superGlobalArray] as $key => $value) {
/* @noinspection UnserializeExploitsInspection */
$this->superGlobalVariables[$superGlobalArray][$key] = \unserialize(\serialize($value));
}
}
@@ -283,10 +284,10 @@ class Snapshot
/**
* Creates a snapshot of all static attributes in user-defined classes.
*/
private function snapshotStaticAttributes()
private function snapshotStaticAttributes(): void
{
foreach ($this->classes as $className) {
$class = new ReflectionClass($className);
$class = new \ReflectionClass($className);
$snapshot = [];
foreach ($class->getProperties() as $attribute) {
@@ -301,6 +302,7 @@ class Snapshot
$value = $attribute->getValue();
if ($this->canBeSerialized($value)) {
/* @noinspection UnserializeExploitsInspection */
$snapshot[$name] = \unserialize(\serialize($value));
}
}
@@ -315,7 +317,7 @@ class Snapshot
/**
* Returns a list of all super-global variable arrays.
*/
private function setupSuperGlobalArrays()
private function setupSuperGlobalArrays(): void
{
$this->superGlobalArrays = [
'_ENV',
@@ -324,45 +326,96 @@ class Snapshot
'_COOKIE',
'_SERVER',
'_FILES',
'_REQUEST'
'_REQUEST',
];
if (\ini_get('register_long_arrays') == '1') {
$this->superGlobalArrays = \array_merge(
$this->superGlobalArrays,
[
'HTTP_ENV_VARS',
'HTTP_POST_VARS',
'HTTP_GET_VARS',
'HTTP_COOKIE_VARS',
'HTTP_SERVER_VARS',
'HTTP_POST_FILES'
]
);
}
}
/**
* @todo Implement this properly
*/
private function canBeSerialized($variable): bool
{
if (!\is_object($variable)) {
return !\is_resource($variable);
}
if ($variable instanceof \stdClass) {
if (\is_scalar($variable) || $variable === null) {
return true;
}
$class = new ReflectionClass($variable);
if (\is_resource($variable)) {
return false;
}
do {
if ($class->isInternal()) {
return $variable instanceof Serializable;
foreach ($this->enumerateObjectsAndResources($variable) as $value) {
if (\is_resource($value)) {
return false;
}
} while ($class = $class->getParentClass());
if (\is_object($value)) {
$class = new \ReflectionClass($value);
if ($class->isAnonymous()) {
return false;
}
try {
@\serialize($value);
} catch (\Throwable $t) {
return false;
}
}
}
return true;
}
private function enumerateObjectsAndResources($variable): array
{
if (isset(\func_get_args()[1])) {
$processed = \func_get_args()[1];
} else {
$processed = new Context;
}
$result = [];
if ($processed->contains($variable)) {
return $result;
}
$array = $variable;
$processed->add($variable);
if (\is_array($variable)) {
foreach ($array as $element) {
if (!\is_array($element) && !\is_object($element) && !\is_resource($element)) {
continue;
}
if (!\is_resource($element)) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$result = \array_merge(
$result,
$this->enumerateObjectsAndResources($element, $processed)
);
} else {
$result[] = $element;
}
}
} else {
$result[] = $variable;
foreach ((new ObjectReflector)->getAttributes($variable) as $value) {
if (!\is_array($value) && !\is_object($value) && !\is_resource($value)) {
continue;
}
if (!\is_resource($value)) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$result = \array_merge(
$result,
$this->enumerateObjectsAndResources($value, $processed)
);
} else {
$result[] = $value;
}
}
}
return $result;
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,9 +7,6 @@
* 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;
interface Exception

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,11 +7,8 @@
* 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;
class RuntimeException extends \RuntimeException implements Exception
final class RuntimeException extends \RuntimeException implements Exception
{
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,9 +7,6 @@
* 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;
@@ -21,31 +18,31 @@ use SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface;
/**
* @covers \SebastianBergmann\GlobalState\Blacklist
*/
class BlacklistTest extends TestCase
final class BlacklistTest extends TestCase
{
/**
* @var \SebastianBergmann\GlobalState\Blacklist
*/
private $blacklist;
protected function setUp()
protected function setUp(): void
{
$this->blacklist = new Blacklist;
}
public function testGlobalVariableThatIsNotBlacklistedIsNotTreatedAsBlacklisted()
public function testGlobalVariableThatIsNotBlacklistedIsNotTreatedAsBlacklisted(): void
{
$this->assertFalse($this->blacklist->isGlobalVariableBlacklisted('variable'));
}
public function testGlobalVariableCanBeBlacklisted()
public function testGlobalVariableCanBeBlacklisted(): void
{
$this->blacklist->addGlobalVariable('variable');
$this->assertTrue($this->blacklist->isGlobalVariableBlacklisted('variable'));
}
public function testStaticAttributeThatIsNotBlacklistedIsNotTreatedAsBlacklisted()
public function testStaticAttributeThatIsNotBlacklistedIsNotTreatedAsBlacklisted(): void
{
$this->assertFalse(
$this->blacklist->isStaticAttributeBlacklisted(
@@ -55,7 +52,7 @@ class BlacklistTest extends TestCase
);
}
public function testClassCanBeBlacklisted()
public function testClassCanBeBlacklisted(): void
{
$this->blacklist->addClass(BlacklistedClass::class);
@@ -67,7 +64,7 @@ class BlacklistTest extends TestCase
);
}
public function testSubclassesCanBeBlacklisted()
public function testSubclassesCanBeBlacklisted(): void
{
$this->blacklist->addSubclassesOf(BlacklistedClass::class);
@@ -79,7 +76,7 @@ class BlacklistTest extends TestCase
);
}
public function testImplementorsCanBeBlacklisted()
public function testImplementorsCanBeBlacklisted(): void
{
$this->blacklist->addImplementorsOf(BlacklistedInterface::class);
@@ -91,7 +88,7 @@ class BlacklistTest extends TestCase
);
}
public function testClassNamePrefixesCanBeBlacklisted()
public function testClassNamePrefixesCanBeBlacklisted(): void
{
$this->blacklist->addClassNamePrefix('SebastianBergmann\GlobalState');
@@ -103,7 +100,7 @@ class BlacklistTest extends TestCase
);
}
public function testStaticAttributeCanBeBlacklisted()
public function testStaticAttributeCanBeBlacklisted(): void
{
$this->blacklist->addStaticAttribute(
BlacklistedClass::class,

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,9 +7,6 @@
* 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;
@@ -17,12 +14,12 @@ use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\GlobalState\CodeExporter
*/
class CodeExporterTest extends TestCase
final class CodeExporterTest extends TestCase
{
/**
* @runInSeparateProcess
*/
public function testCanExportGlobalVariablesToCode()
public function testCanExportGlobalVariablesToCode(): void
{
$GLOBALS = ['foo' => 'bar'];
@@ -31,7 +28,7 @@ class CodeExporterTest extends TestCase
$exporter = new CodeExporter;
$this->assertEquals(
'$GLOBALS = [];' . PHP_EOL . '$GLOBALS[\'foo\'] = \'bar\';' . PHP_EOL,
'$GLOBALS = [];' . \PHP_EOL . '$GLOBALS[\'foo\'] = \'bar\';' . \PHP_EOL,
$exporter->globalVariables($snapshot)
);
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,43 +7,26 @@
* 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.
* @covers \SebastianBergmann\GlobalState\Restorer
*
* @uses \SebastianBergmann\GlobalState\Blacklist
* @uses \SebastianBergmann\GlobalState\Snapshot
*/
class RestorerTest extends TestCase
final class RestorerTest extends TestCase
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
$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()
public function testRestorerGlobalVariable(): void
{
$snapshot = new Snapshot(null, true, false, false, false, false, false, false, false, false);
$restorer = new Restorer;
@@ -58,27 +41,9 @@ class RestorerTest extends TestCase
}
/**
* 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()
public function testIntegrationRestorerGlobalVariables(): void
{
$this->assertArrayHasKey('varBool', $GLOBALS);
$this->assertEquals(false, $GLOBALS['varBool']);
@@ -89,11 +54,9 @@ class RestorerTest extends TestCase
}
/**
* Check global variables are correctly backuped and restored.
*
* @depends testIntegrationRestorerGlobalVariables
*/
public function testIntegrationRestorerGlobalVariables2()
public function testIntegrationRestorerGlobalVariables2(): void
{
$this->assertArrayHasKey('varBool', $GLOBALS);
$this->assertEquals(false, $GLOBALS['varBool']);

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,12 +7,8 @@
* 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 ArrayObject;
use PHPUnit\Framework\TestCase;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface;
use SebastianBergmann\GlobalState\TestFixture\SnapshotClass;
@@ -20,50 +16,47 @@ use SebastianBergmann\GlobalState\TestFixture\SnapshotTrait;
/**
* @covers \SebastianBergmann\GlobalState\Snapshot
*
* @uses \SebastianBergmann\GlobalState\Blacklist
*/
class SnapshotTest extends TestCase
final class SnapshotTest extends TestCase
{
/**
* @var Blacklist
*/
private $blacklist;
protected function setUp()
protected function setUp(): void
{
$this->blacklist = $this->createMock(Blacklist::class);
$this->blacklist = new Blacklist;
}
public function testStaticAttributes()
public function testStaticAttributes(): void
{
$this->blacklist->method('isStaticAttributeBlacklisted')->willReturnCallback(
function ($class) {
return $class !== SnapshotClass::class;
}
);
SnapshotClass::init();
$this->blacklistAllLoadedClassesExceptSnapshotClass();
$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(),
]
'string' => 'string',
'objects' => [new \stdClass],
],
];
$this->assertEquals($expected, $snapshot->staticAttributes());
}
public function testConstants()
public function testConstants(): void
{
$snapshot = new Snapshot($this->blacklist, false, false, true, false, false, false, false, false, false);
$this->assertArrayHasKey('GLOBALSTATE_TESTSUITE', $snapshot->constants());
}
public function testFunctions()
public function testFunctions(): void
{
$snapshot = new Snapshot($this->blacklist, false, false, false, true, false, false, false, false, false);
$functions = $snapshot->functions();
@@ -72,7 +65,7 @@ class SnapshotTest extends TestCase
$this->assertNotContains('assert', $functions);
}
public function testClasses()
public function testClasses(): void
{
$snapshot = new Snapshot($this->blacklist, false, false, false, false, true, false, false, false, false);
$classes = $snapshot->classes();
@@ -81,7 +74,7 @@ class SnapshotTest extends TestCase
$this->assertNotContains(Exception::class, $classes);
}
public function testInterfaces()
public function testInterfaces(): void
{
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, true, false, false, false);
$interfaces = $snapshot->interfaces();
@@ -90,7 +83,7 @@ class SnapshotTest extends TestCase
$this->assertNotContains(\Countable::class, $interfaces);
}
public function testTraits()
public function testTraits(): void
{
\spl_autoload_call('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait');
@@ -99,7 +92,7 @@ class SnapshotTest extends TestCase
$this->assertContains(SnapshotTrait::class, $snapshot->traits());
}
public function testIniSettings()
public function testIniSettings(): void
{
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, false, true, false);
$iniSettings = $snapshot->iniSettings();
@@ -108,9 +101,20 @@ class SnapshotTest extends TestCase
$this->assertEquals('Etc/UTC', $iniSettings['date.timezone']);
}
public function testIncludedFiles()
public function testIncludedFiles(): void
{
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, false, false, true);
$this->assertContains(__FILE__, $snapshot->includedFiles());
}
private function blacklistAllLoadedClassesExceptSnapshotClass(): void
{
foreach (\get_declared_classes() as $class) {
if ($class === SnapshotClass::class) {
continue;
}
$this->blacklist->addClass($class);
}
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,9 +7,6 @@
* 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\TestFixture;
class BlacklistedChildClass extends BlacklistedClass

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,9 +7,6 @@
* 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\TestFixture;
class BlacklistedClass

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,9 +7,6 @@
* 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\TestFixture;
class BlacklistedImplementor implements BlacklistedInterface

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,9 +7,6 @@
* 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\TestFixture;
interface BlacklistedInterface

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,31 +7,29 @@
* 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\TestFixture;
use DomDocument;
use ArrayObject;
class SnapshotClass
{
private static $string = 'snapshot';
private static $dom;
private static $closure;
private static $arrayObject;
private static $snapshotDomDocument;
private static $resource;
private static $stdClass;
private static $string = 'string';
public static function init()
private static $closures = [];
private static $files = [];
private static $resources = [];
private static $objects = [];
public static function init(): void
{
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::$closures[] = function (): void {
};
self::$files[] = new \SplFileInfo(__FILE__);
self::$resources[] = \fopen('php://memory', 'r');
self::$objects[] = new \stdClass;
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,9 +7,6 @@
* 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\TestFixture;
use DomDocument;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,11 +7,8 @@
* 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\TestFixture;
function snapshotFunction()
function snapshotFunction(): void
{
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of sebastian/global-state.
*
@@ -7,9 +7,6 @@
* 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\TestFixture;
trait SnapshotTrait