updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -2,9 +2,14 @@
All notable changes to `sebastianbergmann/code-unit-reverse-lookup` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## 1.0.0 - 2016-02-13
## [1.0.2] - 2020-11-30
### Added
### Changed
* Changed PHP version constraint in `composer.json` from `^5.6 || ^7.0` to `>=5.6`
## 1.0.0 - 2016-02-13
* Initial release
[1.0.2]: https://github.com/sebastianbergmann/code-unit-reverse-lookup/compare/1.0.1...1.0.2

View File

@@ -10,10 +10,10 @@
}
],
"require": {
"php": "^5.6 || ^7.0"
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "^5.7 || ^6.0"
"phpunit/phpunit": "^8.5"
},
"autoload": {
"classmap": [

View File

@@ -22,7 +22,7 @@ class WizardTest extends TestCase
*/
private $wizard;
protected function setUp()
protected function setUp(): void
{
$this->wizard = new Wizard;
}

View File

@@ -1,40 +0,0 @@
# 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 +0,0 @@
/.idea
/.php_cs.cache
/composer.lock
/vendor

View File

@@ -1,189 +0,0 @@
<?php
$header = <<<'EOF'
This file is part of sebastian/comparator.
(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'],
'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' => true,
'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,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => true,
//'void_return' => true,
'whitespace_after_comma_in_array' => true,
]
)
->setFinder(
PhpCsFixer\Finder::create()
->files()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
);

View File

@@ -1,33 +0,0 @@
language: php
sudo: false
php:
- 7.1
- 7.2
- master
env:
matrix:
- DEPENDENCIES="high"
- DEPENDENCIES="low"
global:
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest"
before_install:
- composer self-update
- composer clear-cache
install:
- if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi
- if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi
script:
- ./vendor/bin/phpunit --coverage-clover=coverage.xml
after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
email: false

View File

@@ -2,6 +2,24 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [3.0.5] - 2022-09-14
### Fixed
* [#102](https://github.com/sebastianbergmann/comparator/pull/102): Fix `float` comparison precision
## [3.0.4] - 2022-09-14
### Fixed
* [#99](https://github.com/sebastianbergmann/comparator/pull/99): Fix weak comparison between `'0'` and `false`
## [3.0.3] - 2020-11-30
### Changed
* Changed PHP version constraint in `composer.json` from `^7.1` to `>=7.1`
## [3.0.2] - 2018-07-12
### Changed
@@ -12,14 +30,14 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
### Fixed
* Fixed [#53](https://github.com/sebastianbergmann/comparator/pull/53): `DOMNodeComparator` ignores `$ignoreCase` parameter
* Fixed [#58](https://github.com/sebastianbergmann/comparator/pull/58): `ScalarComparator` does not handle extremely ugly string comparison edge cases
* [#53](https://github.com/sebastianbergmann/comparator/pull/53): `DOMNodeComparator` ignores `$ignoreCase` parameter
* [#58](https://github.com/sebastianbergmann/comparator/pull/58): `ScalarComparator` does not handle extremely ugly string comparison edge cases
## [3.0.0] - 2018-04-18
### Fixed
* Fixed [#48](https://github.com/sebastianbergmann/comparator/issues/48): `DateTimeComparator` does not support fractional second deltas
* [#48](https://github.com/sebastianbergmann/comparator/issues/48): `DateTimeComparator` does not support fractional second deltas
### Removed
@@ -41,7 +59,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
### Fixed
* Fixed [phpunit/#2923](https://github.com/sebastianbergmann/phpunit/issues/2923): Unexpected failed date matching
* [phpunit/#2923](https://github.com/sebastianbergmann/phpunit/issues/2923): Unexpected failed date matching
## [2.1.0] - 2017-11-03
@@ -50,6 +68,9 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Added `SebastianBergmann\Comparator\Factory::reset()` to unregister all non-default comparators
* Added support for `phpunit/phpunit-mock-objects` version `^5.0`
[3.0.5]: https://github.com/sebastianbergmann/comparator/compare/3.0.4...3.0.5
[3.0.4]: https://github.com/sebastianbergmann/comparator/compare/3.0.3...3.0.4
[3.0.3]: https://github.com/sebastianbergmann/comparator/compare/3.0.2...3.0.3
[3.0.2]: https://github.com/sebastianbergmann/comparator/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/sebastianbergmann/comparator/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/comparator/compare/2.1.3...3.0.0

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="comparator" default="setup">
<target name="setup" depends="clean,composer"/>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/composer.lock"/>
</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"/>
</exec>
</target>
</project>

View File

@@ -24,12 +24,12 @@
],
"prefer-stable": true,
"require": {
"php": "^7.1",
"php": ">=7.1",
"sebastian/diff": "^3.0",
"sebastian/exporter": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "^7.1"
"phpunit/phpunit": "^8.5"
},
"config": {
"optimize-autoloader": true,

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="https://schema.phpunit.de/7.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -11,6 +11,8 @@ namespace SebastianBergmann\Comparator;
/**
* Compares doubles for equality.
*
* @deprecated since v3.0.5 and v4.0.8
*/
class DoubleComparator extends NumericComparator
{

View File

@@ -123,7 +123,6 @@ class Factory
$this->registerDefaultComparator(new ObjectComparator);
$this->registerDefaultComparator(new ResourceComparator);
$this->registerDefaultComparator(new ArrayComparator);
$this->registerDefaultComparator(new DoubleComparator);
$this->registerDefaultComparator(new NumericComparator);
$this->registerDefaultComparator(new ScalarComparator);
$this->registerDefaultComparator(new TypeComparator);

View File

@@ -24,10 +24,8 @@ class NumericComparator extends ScalarComparator
*/
public function accepts($expected, $actual)
{
// all numerical values, but not if one of them is a double
// or both of them are strings
// all numerical values, but not if both of them are strings
return \is_numeric($expected) && \is_numeric($actual) &&
!(\is_float($expected) || \is_float($actual)) &&
!(\is_string($expected) && \is_string($actual));
}

View File

@@ -51,7 +51,7 @@ class ScalarComparator extends Comparator
// always compare as strings to avoid strange behaviour
// otherwise 0 == 'Foobar'
if (\is_string($expected) || \is_string($actual)) {
if ((\is_string($expected) && !\is_bool($actual)) || (\is_string($actual) && !\is_bool($expected))) {
$expectedToCompare = (string) $expectedToCompare;
$actualToCompare = (string) $actualToCompare;

View File

@@ -1,161 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\Comparator\ArrayComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class ArrayComparatorTest extends TestCase
{
/**
* @var ArrayComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new ArrayComparator;
$this->comparator->setFactory(new Factory);
}
public function acceptsFailsProvider()
{
return [
[[], null],
[null, []],
[null, null]
];
}
public function assertEqualsSucceedsProvider()
{
return [
[
['a' => 1, 'b' => 2],
['b' => 2, 'a' => 1]
],
[
[1],
['1']
],
[
[3, 2, 1],
[2, 3, 1],
0,
true
],
[
[2.3],
[2.5],
0.5
],
[
[[2.3]],
[[2.5]],
0.5
],
[
[new Struct(2.3)],
[new Struct(2.5)],
0.5
],
];
}
public function assertEqualsFailsProvider()
{
return [
[
[],
[0 => 1]
],
[
[0 => 1],
[]
],
[
[0 => null],
[]
],
[
[0 => 1, 1 => 2],
[0 => 1, 1 => 3]
],
[
['a', 'b' => [1, 2]],
['a', 'b' => [2, 1]]
],
[
[2.3],
[4.2],
0.5
],
[
[[2.3]],
[[4.2]],
0.5
],
[
[new Struct(2.3)],
[new Struct(4.2)],
0.5
]
];
}
public function testAcceptsSucceeds(): void
{
$this->assertTrue(
$this->comparator->accepts([], [])
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0, $canonicalize = false): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual, $delta, $canonicalize);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual, $delta = 0.0, $canonicalize = false): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage('Failed asserting that two arrays are equal');
$this->comparator->assertEquals($expected, $actual, $delta, $canonicalize);
}
}

View File

@@ -1,59 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\Comparator\ComparisonFailure
*
* @uses \SebastianBergmann\Comparator\Factory
*/
final class ComparisonFailureTest extends TestCase
{
public function testComparisonFailure(): void
{
$actual = "\nB\n";
$expected = "\nA\n";
$message = 'Test message';
$failure = new ComparisonFailure(
$expected,
$actual,
'|' . $expected,
'|' . $actual,
false,
$message
);
$this->assertSame($actual, $failure->getActual());
$this->assertSame($expected, $failure->getExpected());
$this->assertSame('|' . $actual, $failure->getActualAsString());
$this->assertSame('|' . $expected, $failure->getExpectedAsString());
$diff = '
--- Expected
+++ Actual
@@ @@
|
-A
+B
';
$this->assertSame($diff, $failure->getDiff());
$this->assertSame($message . $diff, $failure->toString());
}
public function testDiffNotPossible(): void
{
$failure = new ComparisonFailure('a', 'b', false, false, true, 'test');
$this->assertSame('', $failure->getDiff());
$this->assertSame('test', $failure->toString());
}
}

View File

@@ -1,180 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use DOMDocument;
use DOMNode;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\Comparator\DOMNodeComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class DOMNodeComparatorTest extends TestCase
{
/**
* @var DOMNodeComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new DOMNodeComparator;
}
public function acceptsSucceedsProvider()
{
$document = new DOMDocument;
$node = new DOMNode;
return [
[$document, $document],
[$node, $node],
[$document, $node],
[$node, $document]
];
}
public function acceptsFailsProvider()
{
$document = new DOMDocument;
return [
[$document, null],
[null, $document],
[null, null]
];
}
public function assertEqualsSucceedsProvider()
{
return [
[
$this->createDOMDocument('<root></root>'),
$this->createDOMDocument('<root/>')
],
[
$this->createDOMDocument('<root attr="bar"></root>'),
$this->createDOMDocument('<root attr="bar"/>')
],
[
$this->createDOMDocument('<root><foo attr="bar"></foo></root>'),
$this->createDOMDocument('<root><foo attr="bar"/></root>')
],
[
$this->createDOMDocument("<root>\n <child/>\n</root>"),
$this->createDOMDocument('<root><child/></root>')
],
[
$this->createDOMDocument('<Root></Root>'),
$this->createDOMDocument('<root></root>'),
$ignoreCase = true
],
[
$this->createDOMDocument("<a x='' a=''/>"),
$this->createDOMDocument("<a a='' x=''/>"),
],
];
}
public function assertEqualsFailsProvider()
{
return [
[
$this->createDOMDocument('<root></root>'),
$this->createDOMDocument('<bar/>')
],
[
$this->createDOMDocument('<foo attr1="bar"/>'),
$this->createDOMDocument('<foo attr1="foobar"/>')
],
[
$this->createDOMDocument('<foo> bar </foo>'),
$this->createDOMDocument('<foo />')
],
[
$this->createDOMDocument('<foo xmlns="urn:myns:bar"/>'),
$this->createDOMDocument('<foo xmlns="urn:notmyns:bar"/>')
],
[
$this->createDOMDocument('<foo> bar </foo>'),
$this->createDOMDocument('<foo> bir </foo>')
],
[
$this->createDOMDocument('<Root></Root>'),
$this->createDOMDocument('<root></root>')
],
[
$this->createDOMDocument('<root> bar </root>'),
$this->createDOMDocument('<root> BAR </root>')
]
];
}
/**
* @dataProvider acceptsSucceedsProvider
*/
public function testAcceptsSucceeds($expected, $actual): void
{
$this->assertTrue(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual, $ignoreCase = false): void
{
$exception = null;
try {
$delta = 0.0;
$canonicalize = false;
$this->comparator->assertEquals($expected, $actual, $delta, $canonicalize, $ignoreCase);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage('Failed asserting that two DOM');
$this->comparator->assertEquals($expected, $actual);
}
private function createDOMDocument($content)
{
$document = new DOMDocument;
$document->preserveWhiteSpace = false;
$document->loadXML($content);
return $document;
}
}

View File

@@ -1,213 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use DateTime;
use DateTimeImmutable;
use DateTimeZone;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\Comparator\DateTimeComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class DateTimeComparatorTest extends TestCase
{
/**
* @var DateTimeComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new DateTimeComparator;
}
public function acceptsFailsProvider()
{
$datetime = new DateTime;
return [
[$datetime, null],
[null, $datetime],
[null, null]
];
}
public function assertEqualsSucceedsProvider()
{
return [
[
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 04:13:25', new DateTimeZone('America/New_York')),
10
],
[
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 04:14:40', new DateTimeZone('America/New_York')),
65
],
[
new DateTime('2013-03-29', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29', new DateTimeZone('America/New_York'))
],
[
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/Chicago'))
],
[
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 03:13:49', new DateTimeZone('America/Chicago')),
15
],
[
new DateTime('2013-03-30', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 23:00:00', new DateTimeZone('America/Chicago'))
],
[
new DateTime('2013-03-30', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 23:01:30', new DateTimeZone('America/Chicago')),
100
],
[
new DateTime('@1364616000'),
new DateTime('2013-03-29 23:00:00', new DateTimeZone('America/Chicago'))
],
[
new DateTime('2013-03-29T05:13:35-0500'),
new DateTime('2013-03-29T04:13:35-0600')
],
[
new DateTimeImmutable('2013-03-30', new DateTimeZone('America/New_York')),
new DateTimeImmutable('2013-03-29 23:01:30', new DateTimeZone('America/Chicago')),
100
],
[
new DateTimeImmutable('2013-03-30 12:00:00', new DateTimeZone('UTC')),
new DateTimeImmutable('2013-03-30 12:00:00.5', new DateTimeZone('UTC')),
0.5
],
];
}
public function assertEqualsFailsProvider()
{
return [
[
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/New_York'))
],
[
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/New_York')),
3500
],
[
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 05:13:35', new DateTimeZone('America/New_York')),
3500
],
[
new DateTime('2013-03-29', new DateTimeZone('America/New_York')),
new DateTime('2013-03-30', new DateTimeZone('America/New_York'))
],
[
new DateTime('2013-03-29', new DateTimeZone('America/New_York')),
new DateTime('2013-03-30', new DateTimeZone('America/New_York')),
43200
],
[
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago')),
],
[
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago')),
3500
],
[
new DateTime('2013-03-30', new DateTimeZone('America/New_York')),
new DateTime('2013-03-30', new DateTimeZone('America/Chicago'))
],
[
new DateTime('2013-03-29T05:13:35-0600'),
new DateTime('2013-03-29T04:13:35-0600')
],
[
new DateTime('2013-03-29T05:13:35-0600'),
new DateTime('2013-03-29T05:13:35-0500')
],
];
}
public function testAcceptsSucceeds(): void
{
$this->assertTrue(
$this->comparator->accepts(
new DateTime,
new DateTime
)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual, $delta);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual, $delta = 0.0): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage('Failed asserting that two DateTime objects are equal.');
$this->comparator->assertEquals($expected, $actual, $delta);
}
public function testAcceptsDateTimeInterface(): void
{
$this->assertTrue($this->comparator->accepts(new DateTime, new DateTimeImmutable));
}
public function testSupportsDateTimeInterface(): void
{
$this->assertNull(
$this->comparator->assertEquals(
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTimeImmutable('2013-03-29 04:13:35', new DateTimeZone('America/New_York'))
)
);
}
}

View File

@@ -1,135 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\Comparator\DoubleComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class DoubleComparatorTest extends TestCase
{
/**
* @var DoubleComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new DoubleComparator;
}
public function acceptsSucceedsProvider()
{
return [
[0, 5.0],
[5.0, 0],
['5', 4.5],
[1.2e3, 7E-10],
[3, \acos(8)],
[\acos(8), 3],
[\acos(8), \acos(8)]
];
}
public function acceptsFailsProvider()
{
return [
[5, 5],
['4.5', 5],
[0x539, 02471],
[5.0, false],
[null, 5.0]
];
}
public function assertEqualsSucceedsProvider()
{
return [
[2.3, 2.3],
['2.3', 2.3],
[5.0, 5],
[5, 5.0],
[5.0, '5'],
[1.2e3, 1200],
[2.3, 2.5, 0.5],
[3, 3.05, 0.05],
[1.2e3, 1201, 1],
[(string) (1 / 3), 1 - 2 / 3],
[1 / 3, (string) (1 - 2 / 3)]
];
}
public function assertEqualsFailsProvider()
{
return [
[2.3, 4.2],
['2.3', 4.2],
[5.0, '4'],
[5.0, 6],
[1.2e3, 1201],
[2.3, 2.5, 0.2],
[3, 3.05, 0.04],
[3, \acos(8)],
[\acos(8), 3],
[\acos(8), \acos(8)]
];
}
/**
* @dataProvider acceptsSucceedsProvider
*/
public function testAcceptsSucceeds($expected, $actual): void
{
$this->assertTrue(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual, $delta);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual, $delta = 0.0): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage('matches expected');
$this->comparator->assertEquals($expected, $actual, $delta);
}
}

View File

@@ -1,136 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use Exception;
use PHPUnit\Framework\TestCase;
use RuntimeException;
/**
* @covers \SebastianBergmann\Comparator\ExceptionComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class ExceptionComparatorTest extends TestCase
{
/**
* @var ExceptionComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new ExceptionComparator;
$this->comparator->setFactory(new Factory);
}
public function acceptsSucceedsProvider()
{
return [
[new Exception, new Exception],
[new RuntimeException, new RuntimeException],
[new Exception, new RuntimeException]
];
}
public function acceptsFailsProvider()
{
return [
[new Exception, null],
[null, new Exception],
[null, null]
];
}
public function assertEqualsSucceedsProvider()
{
$exception1 = new Exception;
$exception2 = new Exception;
$exception3 = new RuntimeException('Error', 100);
$exception4 = new RuntimeException('Error', 100);
return [
[$exception1, $exception1],
[$exception1, $exception2],
[$exception3, $exception3],
[$exception3, $exception4]
];
}
public function assertEqualsFailsProvider()
{
$typeMessage = 'not instance of expected class';
$equalMessage = 'Failed asserting that two objects are equal.';
$exception1 = new Exception('Error', 100);
$exception2 = new Exception('Error', 101);
$exception3 = new Exception('Errors', 101);
$exception4 = new RuntimeException('Error', 100);
$exception5 = new RuntimeException('Error', 101);
return [
[$exception1, $exception2, $equalMessage],
[$exception1, $exception3, $equalMessage],
[$exception1, $exception4, $typeMessage],
[$exception2, $exception3, $equalMessage],
[$exception4, $exception5, $equalMessage]
];
}
/**
* @dataProvider acceptsSucceedsProvider
*/
public function testAcceptsSucceeds($expected, $actual): void
{
$this->assertTrue(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual, $message): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage($message);
$this->comparator->assertEquals($expected, $actual);
}
}

View File

@@ -1,117 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\Comparator\Factory
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class FactoryTest extends TestCase
{
public function instanceProvider()
{
$tmpfile = \tmpfile();
return [
[null, null, 'SebastianBergmann\\Comparator\\ScalarComparator'],
[null, true, 'SebastianBergmann\\Comparator\\ScalarComparator'],
[true, null, 'SebastianBergmann\\Comparator\\ScalarComparator'],
[true, true, 'SebastianBergmann\\Comparator\\ScalarComparator'],
[false, false, 'SebastianBergmann\\Comparator\\ScalarComparator'],
[true, false, 'SebastianBergmann\\Comparator\\ScalarComparator'],
[false, true, 'SebastianBergmann\\Comparator\\ScalarComparator'],
['', '', 'SebastianBergmann\\Comparator\\ScalarComparator'],
['0', '0', 'SebastianBergmann\\Comparator\\ScalarComparator'],
['0', 0, 'SebastianBergmann\\Comparator\\NumericComparator'],
[0, '0', 'SebastianBergmann\\Comparator\\NumericComparator'],
[0, 0, 'SebastianBergmann\\Comparator\\NumericComparator'],
[1.0, 0, 'SebastianBergmann\\Comparator\\DoubleComparator'],
[0, 1.0, 'SebastianBergmann\\Comparator\\DoubleComparator'],
[1.0, 1.0, 'SebastianBergmann\\Comparator\\DoubleComparator'],
[[1], [1], 'SebastianBergmann\\Comparator\\ArrayComparator'],
[$tmpfile, $tmpfile, 'SebastianBergmann\\Comparator\\ResourceComparator'],
[new \stdClass, new \stdClass, 'SebastianBergmann\\Comparator\\ObjectComparator'],
[new \DateTime, new \DateTime, 'SebastianBergmann\\Comparator\\DateTimeComparator'],
[new \SplObjectStorage, new \SplObjectStorage, 'SebastianBergmann\\Comparator\\SplObjectStorageComparator'],
[new \Exception, new \Exception, 'SebastianBergmann\\Comparator\\ExceptionComparator'],
[new \DOMDocument, new \DOMDocument, 'SebastianBergmann\\Comparator\\DOMNodeComparator'],
// mixed types
[$tmpfile, [1], 'SebastianBergmann\\Comparator\\TypeComparator'],
[[1], $tmpfile, 'SebastianBergmann\\Comparator\\TypeComparator'],
[$tmpfile, '1', 'SebastianBergmann\\Comparator\\TypeComparator'],
['1', $tmpfile, 'SebastianBergmann\\Comparator\\TypeComparator'],
[$tmpfile, new \stdClass, 'SebastianBergmann\\Comparator\\TypeComparator'],
[new \stdClass, $tmpfile, 'SebastianBergmann\\Comparator\\TypeComparator'],
[new \stdClass, [1], 'SebastianBergmann\\Comparator\\TypeComparator'],
[[1], new \stdClass, 'SebastianBergmann\\Comparator\\TypeComparator'],
[new \stdClass, '1', 'SebastianBergmann\\Comparator\\TypeComparator'],
['1', new \stdClass, 'SebastianBergmann\\Comparator\\TypeComparator'],
[new ClassWithToString, '1', 'SebastianBergmann\\Comparator\\ScalarComparator'],
['1', new ClassWithToString, 'SebastianBergmann\\Comparator\\ScalarComparator'],
[1.0, new \stdClass, 'SebastianBergmann\\Comparator\\TypeComparator'],
[new \stdClass, 1.0, 'SebastianBergmann\\Comparator\\TypeComparator'],
[1.0, [1], 'SebastianBergmann\\Comparator\\TypeComparator'],
[[1], 1.0, 'SebastianBergmann\\Comparator\\TypeComparator'],
];
}
/**
* @dataProvider instanceProvider
*/
public function testGetComparatorFor($a, $b, $expected): void
{
$factory = new Factory;
$actual = $factory->getComparatorFor($a, $b);
$this->assertInstanceOf($expected, $actual);
}
public function testRegister(): void
{
$comparator = new TestClassComparator;
$factory = new Factory;
$factory->register($comparator);
$a = new TestClass;
$b = new TestClass;
$expected = 'SebastianBergmann\\Comparator\\TestClassComparator';
$actual = $factory->getComparatorFor($a, $b);
$factory->unregister($comparator);
$this->assertInstanceOf($expected, $actual);
}
public function testUnregister(): void
{
$comparator = new TestClassComparator;
$factory = new Factory;
$factory->register($comparator);
$factory->unregister($comparator);
$a = new TestClass;
$b = new TestClass;
$expected = 'SebastianBergmann\\Comparator\\ObjectComparator';
$actual = $factory->getComparatorFor($a, $b);
$this->assertInstanceOf($expected, $actual);
}
public function testIsSingleton(): void
{
$f = Factory::getInstance();
$this->assertSame($f, Factory::getInstance());
}
}

View File

@@ -1,168 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
use stdClass;
/**
* @covers \SebastianBergmann\Comparator\MockObjectComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class MockObjectComparatorTest extends TestCase
{
/**
* @var MockObjectComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new MockObjectComparator;
$this->comparator->setFactory(new Factory);
}
public function acceptsSucceedsProvider()
{
$testmock = $this->createMock(TestClass::class);
$stdmock = $this->createMock(stdClass::class);
return [
[$testmock, $testmock],
[$stdmock, $stdmock],
[$stdmock, $testmock]
];
}
public function acceptsFailsProvider()
{
$stdmock = $this->createMock(stdClass::class);
return [
[$stdmock, null],
[null, $stdmock],
[null, null]
];
}
public function assertEqualsSucceedsProvider()
{
// cyclic dependencies
$book1 = $this->getMockBuilder(Book::class)->setMethods(null)->getMock();
$book1->author = $this->getMockBuilder(Author::class)->setMethods(null)->setConstructorArgs(['Terry Pratchett'])->getMock();
$book1->author->books[] = $book1;
$book2 = $this->getMockBuilder(Book::class)->setMethods(null)->getMock();
$book2->author = $this->getMockBuilder(Author::class)->setMethods(null)->setConstructorArgs(['Terry Pratchett'])->getMock();
$book2->author->books[] = $book2;
$object1 = $this->getMockBuilder(SampleClass::class)->setMethods(null)->setConstructorArgs([4, 8, 15])->getMock();
$object2 = $this->getMockBuilder(SampleClass::class)->setMethods(null)->setConstructorArgs([4, 8, 15])->getMock();
return [
[$object1, $object1],
[$object1, $object2],
[$book1, $book1],
[$book1, $book2],
[
$this->getMockBuilder(Struct::class)->setMethods(null)->setConstructorArgs([2.3])->getMock(),
$this->getMockBuilder(Struct::class)->setMethods(null)->setConstructorArgs([2.5])->getMock(),
0.5
]
];
}
public function assertEqualsFailsProvider()
{
$typeMessage = 'is not instance of expected class';
$equalMessage = 'Failed asserting that two objects are equal.';
// cyclic dependencies
$book1 = $this->getMockBuilder(Book::class)->setMethods(null)->getMock();
$book1->author = $this->getMockBuilder(Author::class)->setMethods(null)->setConstructorArgs(['Terry Pratchett'])->getMock();
$book1->author->books[] = $book1;
$book2 = $this->getMockBuilder(Book::class)->setMethods(null)->getMock();
$book1->author = $this->getMockBuilder(Author::class)->setMethods(null)->setConstructorArgs(['Terry Pratch'])->getMock();
$book2->author->books[] = $book2;
$book3 = $this->getMockBuilder(Book::class)->setMethods(null)->getMock();
$book3->author = 'Terry Pratchett';
$book4 = $this->createMock(stdClass::class);
$book4->author = 'Terry Pratchett';
$object1 = $this->getMockBuilder(SampleClass::class)->setMethods(null)->setConstructorArgs([4, 8, 15])->getMock();
$object2 = $this->getMockBuilder(SampleClass::class)->setMethods(null)->setConstructorArgs([16, 23, 42])->getMock();
return [
[
$this->getMockBuilder(SampleClass::class)->setMethods(null)->setConstructorArgs([4, 8, 15])->getMock(),
$this->getMockBuilder(SampleClass::class)->setMethods(null)->setConstructorArgs([16, 23, 42])->getMock(),
$equalMessage
],
[$object1, $object2, $equalMessage],
[$book1, $book2, $equalMessage],
[$book3, $book4, $typeMessage],
[
$this->getMockBuilder(Struct::class)->setMethods(null)->setConstructorArgs([2.3])->getMock(),
$this->getMockBuilder(Struct::class)->setMethods(null)->setConstructorArgs([4.2])->getMock(),
$equalMessage,
0.5
]
];
}
/**
* @dataProvider acceptsSucceedsProvider
*/
public function testAcceptsSucceeds($expected, $actual): void
{
$this->assertTrue(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual, $delta);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual, $message, $delta = 0.0): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage($message);
$this->comparator->assertEquals($expected, $actual, $delta);
}
}

View File

@@ -1,123 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\Comparator\NumericComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class NumericComparatorTest extends TestCase
{
/**
* @var NumericComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new NumericComparator;
}
public function acceptsSucceedsProvider()
{
return [
[5, 10],
[8, '0'],
['10', 0],
[0x74c3b00c, 42],
[0755, 0777]
];
}
public function acceptsFailsProvider()
{
return [
['5', '10'],
[8, 5.0],
[5.0, 8],
[10, null],
[false, 12]
];
}
public function assertEqualsSucceedsProvider()
{
return [
[1337, 1337],
['1337', 1337],
[0x539, 1337],
[02471, 1337],
[1337, 1338, 1],
['1337', 1340, 5],
];
}
public function assertEqualsFailsProvider()
{
return [
[1337, 1338],
['1338', 1337],
[0x539, 1338],
[1337, 1339, 1],
['1337', 1340, 2],
];
}
/**
* @dataProvider acceptsSucceedsProvider
*/
public function testAcceptsSucceeds($expected, $actual): void
{
$this->assertTrue(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual, $delta);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual, $delta = 0.0): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage('matches expected');
$this->comparator->assertEquals($expected, $actual, $delta);
}
}

View File

@@ -1,150 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
use stdClass;
/**
* @covers \SebastianBergmann\Comparator\ObjectComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class ObjectComparatorTest extends TestCase
{
/**
* @var ObjectComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new ObjectComparator;
$this->comparator->setFactory(new Factory);
}
public function acceptsSucceedsProvider()
{
return [
[new TestClass, new TestClass],
[new stdClass, new stdClass],
[new stdClass, new TestClass]
];
}
public function acceptsFailsProvider()
{
return [
[new stdClass, null],
[null, new stdClass],
[null, null]
];
}
public function assertEqualsSucceedsProvider()
{
// cyclic dependencies
$book1 = new Book;
$book1->author = new Author('Terry Pratchett');
$book1->author->books[] = $book1;
$book2 = new Book;
$book2->author = new Author('Terry Pratchett');
$book2->author->books[] = $book2;
$object1 = new SampleClass(4, 8, 15);
$object2 = new SampleClass(4, 8, 15);
return [
[$object1, $object1],
[$object1, $object2],
[$book1, $book1],
[$book1, $book2],
[new Struct(2.3), new Struct(2.5), 0.5]
];
}
public function assertEqualsFailsProvider()
{
$typeMessage = 'is not instance of expected class';
$equalMessage = 'Failed asserting that two objects are equal.';
// cyclic dependencies
$book1 = new Book;
$book1->author = new Author('Terry Pratchett');
$book1->author->books[] = $book1;
$book2 = new Book;
$book2->author = new Author('Terry Pratch');
$book2->author->books[] = $book2;
$book3 = new Book;
$book3->author = 'Terry Pratchett';
$book4 = new stdClass;
$book4->author = 'Terry Pratchett';
$object1 = new SampleClass(4, 8, 15);
$object2 = new SampleClass(16, 23, 42);
return [
[new SampleClass(4, 8, 15), new SampleClass(16, 23, 42), $equalMessage],
[$object1, $object2, $equalMessage],
[$book1, $book2, $equalMessage],
[$book3, $book4, $typeMessage],
[new Struct(2.3), new Struct(4.2), $equalMessage, 0.5]
];
}
/**
* @dataProvider acceptsSucceedsProvider
*/
public function testAcceptsSucceeds($expected, $actual): void
{
$this->assertTrue(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual, $delta);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual, $message, $delta = 0.0): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage($message);
$this->comparator->assertEquals($expected, $actual, $delta);
}
}

View File

@@ -1,122 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\Comparator\ResourceComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class ResourceComparatorTest extends TestCase
{
/**
* @var ResourceComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new ResourceComparator;
}
public function acceptsSucceedsProvider()
{
$tmpfile1 = \tmpfile();
$tmpfile2 = \tmpfile();
return [
[$tmpfile1, $tmpfile1],
[$tmpfile2, $tmpfile2],
[$tmpfile1, $tmpfile2]
];
}
public function acceptsFailsProvider()
{
$tmpfile1 = \tmpfile();
return [
[$tmpfile1, null],
[null, $tmpfile1],
[null, null]
];
}
public function assertEqualsSucceedsProvider()
{
$tmpfile1 = \tmpfile();
$tmpfile2 = \tmpfile();
return [
[$tmpfile1, $tmpfile1],
[$tmpfile2, $tmpfile2]
];
}
public function assertEqualsFailsProvider()
{
$tmpfile1 = \tmpfile();
$tmpfile2 = \tmpfile();
return [
[$tmpfile1, $tmpfile2],
[$tmpfile2, $tmpfile1]
];
}
/**
* @dataProvider acceptsSucceedsProvider
*/
public function testAcceptsSucceeds($expected, $actual): void
{
$this->assertTrue(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual): void
{
$this->expectException(ComparisonFailure::class);
$this->comparator->assertEquals($expected, $actual);
}
}

View File

@@ -1,164 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\Comparator\ScalarComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class ScalarComparatorTest extends TestCase
{
/**
* @var ScalarComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new ScalarComparator;
}
public function acceptsSucceedsProvider()
{
return [
['string', 'string'],
[new ClassWithToString, 'string'],
['string', new ClassWithToString],
['string', null],
[false, 'string'],
[false, true],
[null, false],
[null, null],
['10', 10],
['', false],
['1', true],
[1, true],
[0, false],
[0.1, '0.1']
];
}
public function acceptsFailsProvider()
{
return [
[[], []],
['string', []],
[new ClassWithToString, new ClassWithToString],
[false, new ClassWithToString],
[\tmpfile(), \tmpfile()]
];
}
public function assertEqualsSucceedsProvider()
{
return [
['string', 'string'],
[new ClassWithToString, new ClassWithToString],
['string representation', new ClassWithToString],
[new ClassWithToString, 'string representation'],
['string', 'STRING', true],
['STRING', 'string', true],
['String Representation', new ClassWithToString, true],
[new ClassWithToString, 'String Representation', true],
['10', 10],
['', false],
['1', true],
[1, true],
[0, false],
[0.1, '0.1'],
[false, null],
[false, false],
[true, true],
[null, null]
];
}
public function assertEqualsFailsProvider()
{
$stringException = 'Failed asserting that two strings are equal.';
$otherException = 'matches expected';
return [
['string', 'other string', $stringException],
['string', 'STRING', $stringException],
['STRING', 'string', $stringException],
['string', 'other string', $stringException],
// https://github.com/sebastianbergmann/phpunit/issues/1023
['9E6666666', '9E7777777', $stringException],
[new ClassWithToString, 'does not match', $otherException],
['does not match', new ClassWithToString, $otherException],
[0, 'Foobar', $otherException],
['Foobar', 0, $otherException],
['10', 25, $otherException],
['1', false, $otherException],
['', true, $otherException],
[false, true, $otherException],
[true, false, $otherException],
[null, true, $otherException],
[0, true, $otherException],
['0', '0.0', $stringException],
['0.', '0.0', $stringException],
['0e1', '0e2', $stringException],
["\n\n\n0.0", ' 0.', $stringException],
['0.0', '25e-10000', $stringException],
];
}
/**
* @dataProvider acceptsSucceedsProvider
*/
public function testAcceptsSucceeds($expected, $actual): void
{
$this->assertTrue(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual, $ignoreCase = false): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual, 0.0, false, $ignoreCase);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual, $message): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage($message);
$this->comparator->assertEquals($expected, $actual);
}
}

View File

@@ -1,145 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
use SplObjectStorage;
use stdClass;
/**
* @covers \SebastianBergmann\Comparator\SplObjectStorageComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class SplObjectStorageComparatorTest extends TestCase
{
/**
* @var SplObjectStorageComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new SplObjectStorageComparator;
}
public function acceptsFailsProvider()
{
return [
[new SplObjectStorage, new stdClass],
[new stdClass, new SplObjectStorage],
[new stdClass, new stdClass]
];
}
public function assertEqualsSucceedsProvider()
{
$object1 = new stdClass();
$object2 = new stdClass();
$storage1 = new SplObjectStorage();
$storage2 = new SplObjectStorage();
$storage3 = new SplObjectStorage();
$storage3->attach($object1);
$storage3->attach($object2);
$storage4 = new SplObjectStorage();
$storage4->attach($object2);
$storage4->attach($object1);
return [
[$storage1, $storage1],
[$storage1, $storage2],
[$storage3, $storage3],
[$storage3, $storage4]
];
}
public function assertEqualsFailsProvider()
{
$object1 = new stdClass;
$object2 = new stdClass;
$storage1 = new SplObjectStorage;
$storage2 = new SplObjectStorage;
$storage2->attach($object1);
$storage3 = new SplObjectStorage;
$storage3->attach($object2);
$storage3->attach($object1);
return [
[$storage1, $storage2],
[$storage1, $storage3],
[$storage2, $storage3],
];
}
public function testAcceptsSucceeds(): void
{
$this->assertTrue(
$this->comparator->accepts(
new SplObjectStorage,
new SplObjectStorage
)
);
}
/**
* @dataProvider acceptsFailsProvider
*/
public function testAcceptsFails($expected, $actual): void
{
$this->assertFalse(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage('Failed asserting that two objects are equal.');
$this->comparator->assertEquals($expected, $actual);
}
public function testAssertEqualsFails2(): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage('Failed asserting that two objects are equal.');
$t = new SplObjectStorage();
$t->attach(new \stdClass());
$this->comparator->assertEquals($t, new \SplObjectStorage());
}
}

View File

@@ -1,107 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
use PHPUnit\Framework\TestCase;
use stdClass;
/**
* @covers \SebastianBergmann\Comparator\TypeComparator<extended>
*
* @uses \SebastianBergmann\Comparator\Comparator
* @uses \SebastianBergmann\Comparator\Factory
* @uses \SebastianBergmann\Comparator\ComparisonFailure
*/
final class TypeComparatorTest extends TestCase
{
/**
* @var TypeComparator
*/
private $comparator;
protected function setUp(): void
{
$this->comparator = new TypeComparator;
}
public function acceptsSucceedsProvider()
{
return [
[true, 1],
[false, [1]],
[null, new stdClass],
[1.0, 5],
['', '']
];
}
public function assertEqualsSucceedsProvider()
{
return [
[true, true],
[true, false],
[false, false],
[null, null],
[new stdClass, new stdClass],
[0, 0],
[1.0, 2.0],
['hello', 'world'],
['', ''],
[[], [1, 2, 3]]
];
}
public function assertEqualsFailsProvider()
{
return [
[true, null],
[null, false],
[1.0, 0],
[new stdClass, []],
['1', 1]
];
}
/**
* @dataProvider acceptsSucceedsProvider
*/
public function testAcceptsSucceeds($expected, $actual): void
{
$this->assertTrue(
$this->comparator->accepts($expected, $actual)
);
}
/**
* @dataProvider assertEqualsSucceedsProvider
*/
public function testAssertEqualsSucceeds($expected, $actual): void
{
$exception = null;
try {
$this->comparator->assertEquals($expected, $actual);
} catch (ComparisonFailure $exception) {
}
$this->assertNull($exception, 'Unexpected ComparisonFailure');
}
/**
* @dataProvider assertEqualsFailsProvider
*/
public function testAssertEqualsFails($expected, $actual): void
{
$this->expectException(ComparisonFailure::class);
$this->expectExceptionMessage('does not match expected type');
$this->comparator->assertEquals($expected, $actual);
}
}

View File

@@ -1,26 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
/**
* An author.
*/
class Author
{
// the order of properties is important for testing the cycle!
public $books = [];
private $name = '';
public function __construct($name)
{
$this->name = $name;
}
}

View File

@@ -1,19 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
/**
* A book.
*/
class Book
{
// the order of properties is important for testing the cycle!
public $author;
}

View File

@@ -1,18 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
class ClassWithToString
{
public function __toString()
{
return 'string representation';
}
}

View File

@@ -1,29 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
/**
* A sample class.
*/
class SampleClass
{
public $a;
protected $b;
protected $c;
public function __construct($a, $b, $c)
{
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
}

View File

@@ -1,23 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
/**
* A struct.
*/
class Struct
{
public $var;
public function __construct($var)
{
$this->var = $var;
}
}

View File

@@ -1,14 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
class TestClass
{
}

View File

@@ -1,14 +0,0 @@
<?php
/*
* This file is part of sebastian/comparator.
*
* (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.
*/
namespace SebastianBergmann\Comparator;
class TestClassComparator extends ObjectComparator
{
}

View File

@@ -2,4 +2,5 @@
/composer.lock
/vendor
/.php_cs.cache
/.phpunit.result.cache
/from.txt.orig

View File

@@ -3,6 +3,7 @@ language: php
php:
- 7.1
- 7.2
- 7.3
- master
sudo: false

View File

@@ -2,6 +2,18 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [3.0.3] - 2020-11-30
### Changed
* Changed PHP version constraint in `composer.json` from `^7.1` to `>=7.1`
## [3.0.2] - 2019-02-04
### Changed
* `Chunk::setLines()` now ensures that the `$lines` array only contains `Line` objects
## [3.0.1] - 2018-06-10
### Fixed
@@ -40,6 +52,8 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* This component is no longer supported on PHP 5.6
[3.0.3]: https://github.com/sebastianbergmann/diff/compare/3.0.2...3.0.3
[3.0.2]: https://github.com/sebastianbergmann/diff/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/sebastianbergmann/diff/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/diff/compare/2.0...3.0.0
[2.0.1]: https://github.com/sebastianbergmann/diff/compare/c341c98ce083db77f896a0aa64f5ee7652915970...2.0.1

View File

@@ -1,6 +1,6 @@
sebastian/diff
Copyright (c) 2002-2018, Sebastian Bergmann <sebastian@phpunit.de>.
Copyright (c) 2002-2019, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -15,10 +15,10 @@
}
],
"require": {
"php": "^7.1"
"php": ">=7.1"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"phpunit/phpunit": "^7.5 || ^8.0",
"symfony/process": "^2 || ^3.3 || ^4"
},
"autoload": {

View File

@@ -33,7 +33,7 @@ final class Chunk
private $endRange;
/**
* @var array
* @var Line[]
*/
private $lines;
@@ -66,13 +66,25 @@ final class Chunk
return $this->endRange;
}
/**
* @return Line[]
*/
public function getLines(): array
{
return $this->lines;
}
/**
* @param Line[] $lines
*/
public function setLines(array $lines): void
{
foreach ($lines as $line) {
if (!$line instanceof Line) {
throw new InvalidArgumentException;
}
}
$this->lines = $lines;
}
}

View File

@@ -27,6 +27,11 @@ final class ChunkTest extends TestCase
$this->chunk = new Chunk;
}
public function testHasInitiallyNoLines(): void
{
$this->assertSame([], $this->chunk->getLines());
}
public function testCanBeCreatedWithoutArguments(): void
{
$this->assertInstanceOf(Chunk::class, $this->chunk);
@@ -59,10 +64,10 @@ final class ChunkTest extends TestCase
public function testLinesCanBeSet(): void
{
$this->assertSame([], $this->chunk->getLines());
$lines = [new Line(Line::ADDED, 'added'), new Line(Line::REMOVED, 'removed')];
$testValue = ['line0', 'line1'];
$this->chunk->setLines($testValue);
$this->assertSame($testValue, $this->chunk->getLines());
$this->chunk->setLines($lines);
$this->assertSame($lines, $this->chunk->getLines());
}
}

View File

@@ -426,24 +426,6 @@ EOF
];
}
public function testConstructorNull(): void
{
$this->assertAttributeInstanceOf(
UnifiedDiffOutputBuilder::class,
'outputBuilder',
new Differ(null)
);
}
public function testConstructorString(): void
{
$this->assertAttributeInstanceOf(
UnifiedDiffOutputBuilder::class,
'outputBuilder',
new Differ("--- Original\n+++ New\n")
);
}
public function testConstructorInvalidArgInt(): void
{
$this->expectException(InvalidArgumentException::class);

View File

@@ -190,7 +190,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
{
$diff = $this->implementation->calculate(['5'], ['05']);
$this->assertInternalType('array', $diff);
$this->assertIsArray($diff);
$this->assertCount(0, $diff);
}

View File

@@ -38,12 +38,10 @@ final class ParserTest extends TestCase
$diffs = $this->parser->parse($content);
$this->assertInternalType('array', $diffs);
$this->assertContainsOnlyInstancesOf(Diff::class, $diffs);
$this->assertCount(1, $diffs);
$chunks = $diffs[0]->getChunks();
$this->assertInternalType('array', $chunks);
$this->assertContainsOnlyInstancesOf(Chunk::class, $chunks);
$this->assertCount(1, $chunks);
@@ -85,13 +83,11 @@ index abcdefg..abcdefh 100644
-B
END;
$diffs = $this->parser->parse($content);
$this->assertInternalType('array', $diffs);
$this->assertContainsOnlyInstancesOf(Diff::class, $diffs);
$this->assertCount(1, $diffs);
$chunks = $diffs[0]->getChunks();
$this->assertInternalType('array', $chunks);
$this->assertContainsOnlyInstancesOf(Chunk::class, $chunks);
$this->assertCount(1, $chunks);
@@ -102,7 +98,6 @@ END;
$this->assertSame(8, $chunk->getEndRange());
$lines = $chunk->getLines();
$this->assertInternalType('array', $lines);
$this->assertContainsOnlyInstancesOf(Line::class, $lines);
$this->assertCount(2, $lines);

View File

@@ -0,0 +1 @@
github: sebastianbergmann

View File

@@ -1,40 +0,0 @@
# 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

@@ -3,3 +3,4 @@
/composer.lock
/composer.phar
/.php_cs.cache
/.phpunit.result.cache

View File

@@ -4,19 +4,22 @@ php:
- 7.1
- 7.2
- 7.3
- master
- 7.4snapshot
sudo: false
env:
matrix:
- DRIVER="phpdbg"
- DRIVER="xdebug"
before_install:
- composer self-update
- composer clear-cache
install:
- travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest
script:
- ./vendor/bin/phpunit --coverage-clover=coverage.xml
- if [[ "$DRIVER" = 'phpdbg' ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ "$DRIVER" != 'phpdbg' ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml; fi
after_success:
- bash <(curl -s https://codecov.io/bash)

View File

@@ -2,6 +2,57 @@
All notable changes in `sebastianbergmann/environment` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [4.2.4] - 2020-11-30
### Changed
* Changed PHP version constraint in `composer.json` from `^7.1` to `>=7.1`
## [4.2.3] - 2019-11-20
### Changed
* Implemented [#50](https://github.com/sebastianbergmann/environment/pull/50): Windows improvements to console capabilities
### Fixed
* Fixed [#49](https://github.com/sebastianbergmann/environment/issues/49): Detection how OpCache handles docblocks does not work correctly when PHPDBG is used
## [4.2.2] - 2019-05-05
### Fixed
* Fixed [#44](https://github.com/sebastianbergmann/environment/pull/44): `TypeError` in `Console::getNumberOfColumnsInteractive()`
## [4.2.1] - 2019-04-25
### Fixed
* Fixed an issue in `Runtime::getCurrentSettings()`
## [4.2.0] - 2019-04-25
### Added
* Implemented [#36](https://github.com/sebastianbergmann/environment/pull/36): `Runtime::getCurrentSettings()`
## [4.1.0] - 2019-02-01
### Added
* Implemented `Runtime::getNameWithVersionAndCodeCoverageDriver()` method
* Implemented [#34](https://github.com/sebastianbergmann/environment/pull/34): Support for PCOV extension
## [4.0.2] - 2019-01-28
### Fixed
* Fixed [#33](https://github.com/sebastianbergmann/environment/issues/33): `Runtime::discardsComments()` returns true too eagerly
### Removed
* Removed support for Zend Optimizer+ in `Runtime::discardsComments()`
## [4.0.1] - 2018-11-25
### Fixed
@@ -58,6 +109,13 @@ All notable changes in `sebastianbergmann/environment` are documented in this fi
* This component is no longer supported on PHP 5.6
[4.2.4]: https://github.com/sebastianbergmann/phpunit/compare/4.2.3...4.2.4
[4.2.3]: https://github.com/sebastianbergmann/phpunit/compare/4.2.2...4.2.3
[4.2.2]: https://github.com/sebastianbergmann/phpunit/compare/4.2.1...4.2.2
[4.2.1]: https://github.com/sebastianbergmann/phpunit/compare/4.2.0...4.2.1
[4.2.0]: https://github.com/sebastianbergmann/phpunit/compare/4.1.0...4.2.0
[4.1.0]: https://github.com/sebastianbergmann/phpunit/compare/4.0.2...4.1.0
[4.0.2]: https://github.com/sebastianbergmann/phpunit/compare/4.0.1...4.0.2
[4.0.1]: https://github.com/sebastianbergmann/phpunit/compare/66691f8e2dc4641909166b275a9a4f45c0e89092...4.0.1
[4.0.0]: https://github.com/sebastianbergmann/phpunit/compare/3.1.0...66691f8e2dc4641909166b275a9a4f45c0e89092
[3.1.0]: https://github.com/sebastianbergmann/phpunit/compare/3.0...3.1.0

View File

@@ -1,6 +1,6 @@
sebastian/environment
Copyright (c) 2014-2018, Sebastian Bergmann <sebastian@phpunit.de>.
Copyright (c) 2014-2019, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -16,10 +16,13 @@
},
"prefer-stable": true,
"require": {
"php": "^7.1"
"php": ">=7.1"
},
"require-dev": {
"phpunit/phpunit": "^7.4"
"phpunit/phpunit": "^7.5"
},
"suggest": {
"ext-posix": "*"
},
"autoload": {
"classmap": [
@@ -28,7 +31,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "4.2-dev"
}
}
}

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.4/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"

View File

@@ -40,7 +40,7 @@ final class Console
if ($this->isWindows()) {
// @codeCoverageIgnoreStart
return (\defined('STDOUT') && \function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(\STDOUT))
return (\defined('STDOUT') && \function_exists('sapi_windows_vt100_support') && @\sapi_windows_vt100_support(\STDOUT))
|| false !== \getenv('ANSICON')
|| 'ON' === \getenv('ConEmuANSI')
|| 'xterm' === \getenv('TERM');
@@ -53,13 +53,7 @@ final class Console
// @codeCoverageIgnoreEnd
}
if ($this->isInteractive(\STDOUT)) {
return true;
}
$stat = @\fstat(\STDOUT);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
return $this->isInteractive(\STDOUT);
}
/**
@@ -69,14 +63,14 @@ final class Console
*/
public function getNumberOfColumns(): int
{
if ($this->isWindows()) {
return $this->getNumberOfColumnsWindows();
}
if (!$this->isInteractive(\defined('STDIN') ? \STDIN : self::STDIN)) {
return 80;
}
if ($this->isWindows()) {
return $this->getNumberOfColumnsWindows();
}
return $this->getNumberOfColumnsInteractive();
}
@@ -90,8 +84,18 @@ final class Console
*/
public function isInteractive($fileDescriptor = self::STDOUT): bool
{
return (\is_resource($fileDescriptor) && \function_exists('stream_isatty') && @\stream_isatty($fileDescriptor)) // stream_isatty requires that descriptor is a real resource, not numeric ID of it
|| (\function_exists('posix_isatty') && @\posix_isatty($fileDescriptor));
if (\is_resource($fileDescriptor)) {
// These functions require a descriptor that is a real resource, not a numeric ID of it
if (\function_exists('stream_isatty') && @\stream_isatty($fileDescriptor)) {
return true;
}
$stat = @\fstat(\STDOUT);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
}
return \function_exists('posix_isatty') && @\posix_isatty($fileDescriptor);
}
private function isWindows(): bool
@@ -104,13 +108,13 @@ final class Console
*/
private function getNumberOfColumnsInteractive(): int
{
if (\function_exists('shell_exec') && \preg_match('#\d+ (\d+)#', \shell_exec('stty size') ?? '', $match) === 1) {
if (\function_exists('shell_exec') && \preg_match('#\d+ (\d+)#', \shell_exec('stty size') ?: '', $match) === 1) {
if ((int) $match[1] > 0) {
return (int) $match[1];
}
}
if (\function_exists('shell_exec') && \preg_match('#columns = (\d+);#', \shell_exec('stty') ?? '', $match) === 1) {
if (\function_exists('shell_exec') && \preg_match('#columns = (\d+);#', \shell_exec('stty') ?: '', $match) === 1) {
if ((int) $match[1] > 0) {
return (int) $match[1];
}

View File

@@ -20,26 +20,32 @@ final class Runtime
private static $binary;
/**
* Returns true when Xdebug is supported or
* Returns true when Xdebug or PCOV is available or
* the runtime used is PHPDBG.
*/
public function canCollectCodeCoverage(): bool
{
return $this->hasXdebug() || $this->hasPHPDBGCodeCoverage();
return $this->hasXdebug() || $this->hasPCOV() || $this->hasPHPDBGCodeCoverage();
}
/**
* Returns true when OPcache is loaded and opcache.save_comments=0 is set.
*
* Code taken from Doctrine\Common\Annotations\AnnotationReader::__construct().
* Returns true when Zend OPcache is loaded, enabled, and is configured to discard comments.
*/
public function discardsComments(): bool
{
if (\extension_loaded('Zend Optimizer+') && (\ini_get('zend_optimizerplus.save_comments') === '0' || \ini_get('opcache.save_comments') === '0')) {
if (!\extension_loaded('Zend OPcache')) {
return false;
}
if (\ini_get('opcache.save_comments') !== '0') {
return false;
}
if ((\PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg') && \ini_get('opcache.enable_cli') === '1') {
return true;
}
if (\extension_loaded('Zend OPcache') && \ini_get('opcache.save_comments') == 0) {
if (\PHP_SAPI !== 'cli' && \PHP_SAPI !== 'phpdbg' && \ini_get('opcache.enable') === '1') {
return true;
}
@@ -100,6 +106,29 @@ final class Runtime
return $this->getName() . ' ' . $this->getVersion();
}
public function getNameWithVersionAndCodeCoverageDriver(): string
{
if (!$this->canCollectCodeCoverage() || $this->hasPHPDBGCodeCoverage()) {
return $this->getNameWithVersion();
}
if ($this->hasXdebug()) {
return \sprintf(
'%s with Xdebug %s',
$this->getNameWithVersion(),
\phpversion('xdebug')
);
}
if ($this->hasPCOV()) {
return \sprintf(
'%s with PCOV %s',
$this->getNameWithVersion(),
\phpversion('pcov')
);
}
}
public function getName(): string
{
if ($this->isHHVM()) {
@@ -174,11 +203,63 @@ final class Runtime
/**
* Returns true when the runtime used is PHP with the PHPDBG SAPI
* and the phpdbg_*_oplog() functions are available (PHP >= 7.0).
*
* @codeCoverageIgnore
*/
public function hasPHPDBGCodeCoverage(): bool
{
return $this->isPHPDBG();
}
/**
* Returns true when the runtime used is PHP with PCOV loaded and enabled
*/
public function hasPCOV(): bool
{
return $this->isPHP() && \extension_loaded('pcov') && \ini_get('pcov.enabled');
}
/**
* Parses the loaded php.ini file (if any) as well as all
* additional php.ini files from the additional ini dir for
* a list of all configuration settings loaded from files
* at startup. Then checks for each php.ini setting passed
* via the `$values` parameter whether this setting has
* been changed at runtime. Returns an array of strings
* where each string has the format `key=value` denoting
* the name of a changed php.ini setting with its new value.
*
* @return string[]
*/
public function getCurrentSettings(array $values): array
{
$diff = [];
$files = [];
if ($file = \php_ini_loaded_file()) {
$files[] = $file;
}
if ($scanned = \php_ini_scanned_files()) {
$files = \array_merge(
$files,
\array_map(
'trim',
\explode(",\n", $scanned)
)
);
}
foreach ($files as $ini) {
$config = \parse_ini_file($ini, true);
foreach ($values as $value) {
$set = \ini_get($value);
if (isset($config[$value]) && $set != $config[$value]) {
$diff[] = \sprintf('%s=%s', $value, $set);
}
}
}
return $diff;
}
}

View File

@@ -32,7 +32,7 @@ final class ConsoleTest extends TestCase
*/
public function testCanDetectIfStdoutIsInteractiveByDefault(): void
{
$this->assertInternalType('boolean', $this->console->isInteractive());
$this->assertIsBool($this->console->isInteractive());
}
/**
@@ -41,7 +41,7 @@ final class ConsoleTest extends TestCase
*/
public function testCanDetectIfFileDescriptorIsInteractive(): void
{
$this->assertInternalType('boolean', $this->console->isInteractive(\STDOUT));
$this->assertIsBool($this->console->isInteractive(\STDOUT));
}
/**
@@ -50,7 +50,7 @@ final class ConsoleTest extends TestCase
*/
public function testCanDetectColorSupport(): void
{
$this->assertInternalType('boolean', $this->console->hasColorSupport());
$this->assertIsBool($this->console->hasColorSupport());
}
/**
@@ -59,6 +59,6 @@ final class ConsoleTest extends TestCase
*/
public function testCanDetectNumberOfColumns(): void
{
$this->assertInternalType('integer', $this->console->getNumberOfColumns());
$this->assertIsInt($this->console->getNumberOfColumns());
}
}

View File

@@ -33,4 +33,28 @@ final class OperatingSystemTest extends TestCase
{
$this->assertEquals('Linux', $this->os->getFamily());
}
/**
* @requires OS Darwin
*/
public function testFamilyReturnsDarwinWhenRunningOnDarwin(): void
{
$this->assertEquals('Darwin', $this->os->getFamily());
}
/**
* @requires OS Windows
*/
public function testGetFamilyReturnsWindowsWhenRunningOnWindows(): void
{
$this->assertSame('Windows', $this->os->getFamily());
}
/**
* @requires PHP 7.2.0
*/
public function testGetFamilyReturnsPhpOsFamilyWhenRunningOnPhp72AndGreater(): void
{
$this->assertSame(\PHP_OS_FAMILY, $this->os->getFamily());
}
}

View File

@@ -27,83 +27,139 @@ final class RuntimeTest extends TestCase
}
/**
* @todo Now that this component is PHP 7-only and uses return type declarations
* this test makes even less sense than before
* @requires extension xdebug
*/
public function testAbilityToCollectCodeCoverageCanBeAssessed(): void
public function testCanCollectCodeCoverageWhenXdebugExtensionIsEnabled(): void
{
$this->assertInternalType('boolean', $this->env->canCollectCodeCoverage());
$this->assertTrue($this->env->canCollectCodeCoverage());
}
/**
* @todo Now that this component is PHP 7-only and uses return type declarations
* this test makes even less sense than before
* @requires extension pcov
*/
public function testCanCollectCodeCoverageWhenPcovExtensionIsEnabled(): void
{
$this->assertTrue($this->env->canCollectCodeCoverage());
}
public function testCanCollectCodeCoverageWhenRunningOnPhpdbg(): void
{
$this->markTestSkippedWhenNotRunningOnPhpdbg();
$this->assertTrue($this->env->canCollectCodeCoverage());
}
public function testBinaryCanBeRetrieved(): void
{
$this->assertInternalType('string', $this->env->getBinary());
$this->assertNotEmpty($this->env->getBinary());
}
/**
* @todo Now that this component is PHP 7-only and uses return type declarations
* this test makes even less sense than before
* @requires PHP
*/
public function testCanBeDetected(): void
public function testIsHhvmReturnsFalseWhenRunningOnPhp(): void
{
$this->assertInternalType('boolean', $this->env->isHHVM());
$this->assertFalse($this->env->isHHVM());
}
/**
* @todo Now that this component is PHP 7-only and uses return type declarations
* this test makes even less sense than before
* @requires PHP
*/
public function testCanBeDetected2(): void
public function testIsPhpReturnsTrueWhenRunningOnPhp(): void
{
$this->assertInternalType('boolean', $this->env->isPHP());
$this->markTestSkippedWhenRunningOnPhpdbg();
$this->assertTrue($this->env->isPHP());
}
/**
* @todo Now that this component is PHP 7-only and uses return type declarations
* this test makes even less sense than before
* @requires extension pcov
*/
public function testPCOVCanBeDetected(): void
{
$this->assertTrue($this->env->hasPCOV());
}
public function testPhpdbgCanBeDetected(): void
{
$this->markTestSkippedWhenNotRunningOnPhpdbg();
$this->assertTrue($this->env->hasPHPDBGCodeCoverage());
}
/**
* @requires extension xdebug
*/
public function testXdebugCanBeDetected(): void
{
$this->assertInternalType('boolean', $this->env->hasXdebug());
$this->markTestSkippedWhenRunningOnPhpdbg();
$this->assertTrue($this->env->hasXdebug());
}
/**
* @todo Now that this component is PHP 7-only and uses return type declarations
* this test makes even less sense than before
*/
public function testNameAndVersionCanBeRetrieved(): void
{
$this->assertInternalType('string', $this->env->getNameWithVersion());
$this->assertNotEmpty($this->env->getNameWithVersion());
}
public function testGetNameReturnsPhpdbgWhenRunningOnPhpdbg(): void
{
$this->markTestSkippedWhenNotRunningOnPhpdbg();
$this->assertSame('PHPDBG', $this->env->getName());
}
/**
* @todo Now that this component is PHP 7-only and uses return type declarations
* this test makes even less sense than before
* @requires PHP
*/
public function testNameCanBeRetrieved(): void
public function testGetNameReturnsPhpdbgWhenRunningOnPhp(): void
{
$this->assertInternalType('string', $this->env->getName());
$this->markTestSkippedWhenRunningOnPhpdbg();
$this->assertSame('PHP', $this->env->getName());
}
public function testNameAndCodeCoverageDriverCanBeRetrieved(): void
{
$this->assertNotEmpty($this->env->getNameWithVersionAndCodeCoverageDriver());
}
/**
* @todo Now that this component is PHP 7-only and uses return type declarations
* this test makes even less sense than before
* @requires PHP
*/
public function testVersionCanBeRetrieved(): void
public function testGetVersionReturnsPhpVersionWhenRunningPhp(): void
{
$this->assertInternalType('string', $this->env->getVersion());
$this->assertSame(\PHP_VERSION, $this->env->getVersion());
}
/**
* @todo Now that this component is PHP 7-only and uses return type declarations
* this test makes even less sense than before
* @requires PHP
*/
public function testVendorUrlCanBeRetrieved(): void
public function testGetVendorUrlReturnsPhpDotNetWhenRunningPhp(): void
{
$this->assertInternalType('string', $this->env->getVendorUrl());
$this->assertSame('https://secure.php.net/', $this->env->getVendorUrl());
}
private function markTestSkippedWhenNotRunningOnPhpdbg(): void
{
if ($this->isRunningOnPhpdbg()) {
return;
}
$this->markTestSkipped('PHPDBG is required.');
}
private function markTestSkippedWhenRunningOnPhpdbg(): void
{
if (!$this->isRunningOnPhpdbg()) {
return;
}
$this->markTestSkipped('Cannot run on PHPDBG');
}
private function isRunningOnPhpdbg(): bool
{
return \PHP_SAPI === 'phpdbg';
}
}

View File

@@ -1,4 +0,0 @@
/.idea
/composer.lock
/vendor
/.php_cs.cache

View File

@@ -1,77 +0,0 @@
<?php
$header = <<<'EOF'
This file is part of the exporter package.
(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,
'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')
->name('*.php')
);

View File

@@ -1,26 +0,0 @@
language: php
php:
- 7.0
- 7.0snapshot
- 7.1
- 7.1snapshot
- master
sudo: false
before_install:
- composer self-update
- composer clear-cache
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

36
vendor/sebastian/exporter/ChangeLog.md vendored Normal file
View File

@@ -0,0 +1,36 @@
# ChangeLog
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [3.1.5] - 2022-09-14
### Fixed
* [#47](https://github.com/sebastianbergmann/exporter/pull/47): Fix `float` export precision
## [3.1.4] - 2021-11-11
### Changed
* [#38](https://github.com/sebastianbergmann/exporter/pull/38): Improve export of closed resources
## [3.1.3] - 2020-11-30
### Changed
* Changed PHP version constraint in `composer.json` from `^7.0` to `>=7.0`
## [3.1.2] - 2019-09-14
### Fixed
* [#29](https://github.com/sebastianbergmann/exporter/pull/29): Second parameter for `str_repeat()` must be an integer
### Removed
* Remove HHVM-specific code that is no longer needed
[3.1.5]: https://github.com/sebastianbergmann/exporter/compare/3.1.4...3.1.5
[3.1.4]: https://github.com/sebastianbergmann/exporter/compare/3.1.3...3.1.4
[3.1.3]: https://github.com/sebastianbergmann/exporter/compare/3.1.2...3.1.3
[3.1.2]: https://github.com/sebastianbergmann/exporter/compare/3.1.1...3.1.2

View File

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

View File

@@ -1,8 +1,6 @@
Exporter
========
[![Build Status](https://secure.travis-ci.org/sebastianbergmann/exporter.png?branch=master)](https://travis-ci.org/sebastianbergmann/exporter)
This component provides the functionality to export PHP variables for visualization.
## Usage
@@ -22,7 +20,6 @@ Exception Object &0000000078de0f0d000000002003a261 (
'code' => 0
'file' => '/home/sebastianbergmann/test.php'
'line' => 34
'trace' => Array &0 ()
'previous' => null
)
*/

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="exporter" default="setup">
<target name="setup" depends="clean,composer"/>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/composer.lock"/>
</target>
<target name="composer" depends="clean" description="Install dependencies with Composer">
<exec executable="composer" taskname="composer">
<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

@@ -23,15 +23,20 @@
},
{
"name": "Bernhard Schussek",
"email": "bschussek@2bepublished.at"
"email": "bschussek@gmail.com"
}
],
"config": {
"optimize-autoloader": true,
"sort-packages": true
},
"prefer-stable": true,
"require": {
"php": "^7.0",
"php": ">=7.0",
"sebastian/recursion-context": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpunit/phpunit": "^8.5",
"ext-mbstring": "*"
},
"autoload": {

View File

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

View File

@@ -1,13 +1,12 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of the exporter package.
* This file is part of exporter package.
*
* (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.
*/
namespace SebastianBergmann\Exporter;
use SebastianBergmann\RecursionContext\Context;
@@ -38,8 +37,7 @@ class Exporter
* - Carriage returns and newlines are normalized to \n
* - Recursion and repeated rendering is treated properly
*
* @param mixed $value
* @param int $indentation The indentation level of the 2nd+ line
* @param int $indentation The indentation level of the 2nd+ line
*
* @return string
*/
@@ -49,8 +47,8 @@ class Exporter
}
/**
* @param mixed $data
* @param Context $context
* @param array<mixed> $data
* @param Context $context
*
* @return string
*/
@@ -67,11 +65,11 @@ class Exporter
$context->add($data);
foreach ($array as $key => $value) {
if (is_array($value)) {
if (\is_array($value)) {
if ($context->contains($data[$key]) !== false) {
$result[] = '*RECURSION*';
} else {
$result[] = sprintf(
$result[] = \sprintf(
'array(%s)',
$this->shortenedRecursiveExport($data[$key], $context)
);
@@ -81,7 +79,7 @@ class Exporter
}
}
return implode(', ', $result);
return \implode(', ', $result);
}
/**
@@ -93,42 +91,40 @@ class Exporter
* Newlines are replaced by the visible string '\n'.
* Contents of arrays and objects (if any) are replaced by '...'.
*
* @param mixed $value
*
* @return string
*
* @see SebastianBergmann\Exporter\Exporter::export
*/
public function shortenedExport($value)
{
if (is_string($value)) {
$string = str_replace("\n", '', $this->export($value));
if (\is_string($value)) {
$string = \str_replace("\n", '', $this->export($value));
if (function_exists('mb_strlen')) {
if (mb_strlen($string) > 40) {
$string = mb_substr($string, 0, 30) . '...' . mb_substr($string, -7);
if (\function_exists('mb_strlen')) {
if (\mb_strlen($string) > 40) {
$string = \mb_substr($string, 0, 30) . '...' . \mb_substr($string, -7);
}
} else {
if (strlen($string) > 40) {
$string = substr($string, 0, 30) . '...' . substr($string, -7);
if (\strlen($string) > 40) {
$string = \substr($string, 0, 30) . '...' . \substr($string, -7);
}
}
return $string;
}
if (is_object($value)) {
return sprintf(
if (\is_object($value)) {
return \sprintf(
'%s Object (%s)',
get_class($value),
count($this->toArray($value)) > 0 ? '...' : ''
\get_class($value),
\count($this->toArray($value)) > 0 ? '...' : ''
);
}
if (is_array($value)) {
return sprintf(
if (\is_array($value)) {
return \sprintf(
'Array (%s)',
count($value) > 0 ? '...' : ''
\count($value) > 0 ? '...' : ''
);
}
@@ -139,24 +135,29 @@ class Exporter
* Converts an object to an array containing all of its private, protected
* and public properties.
*
* @param mixed $value
*
* @return array
*/
public function toArray($value)
{
if (!is_object($value)) {
if (!\is_object($value)) {
return (array) $value;
}
$array = [];
foreach ((array) $value as $key => $val) {
// Exception traces commonly reference hundreds to thousands of
// objects currently loaded in memory. Including them in the result
// has a severe negative performance impact.
if ("\0Error\0trace" === $key || "\0Exception\0trace" === $key) {
continue;
}
// properties are transformed to keys in the following way:
// private $property => "\0Classname\0property"
// protected $property => "\0*\0property"
// public $property => "property"
if (preg_match('/^\0.+\0(.+)$/', $key, $matches)) {
if (\preg_match('/^\0.+\0(.+)$/', (string) $key, $matches)) {
$key = $matches[1];
}
@@ -172,20 +173,8 @@ class Exporter
// above (fast) mechanism nor with reflection in Zend.
// Format the output similarly to print_r() in this case
if ($value instanceof \SplObjectStorage) {
// However, the fast method does work in HHVM, and exposes the
// internal implementation. Hide it again.
if (property_exists('\SplObjectStorage', '__storage')) {
unset($array['__storage']);
} elseif (property_exists('\SplObjectStorage', 'storage')) {
unset($array['storage']);
}
if (property_exists('\SplObjectStorage', '__key')) {
unset($array['__key']);
}
foreach ($value as $key => $val) {
$array[spl_object_hash($val)] = [
$array[\spl_object_hash($val)] = [
'obj' => $val,
'inf' => $value->getInfo(),
];
@@ -220,27 +209,47 @@ class Exporter
return 'false';
}
if (is_float($value) && floatval(intval($value)) === $value) {
return "$value.0";
if (\is_float($value)) {
$precisionBackup = \ini_get('precision');
\ini_set('precision', '-1');
try {
$valueStr = (string) $value;
if ((string) (int) $value === $valueStr) {
return $valueStr . '.0';
}
return $valueStr;
} finally {
\ini_set('precision', $precisionBackup);
}
}
if (is_resource($value)) {
return sprintf(
if ($this->isClosedResource($value)) {
return 'resource (closed)';
}
if (\is_resource($value)) {
return \sprintf(
'resource(%d) of type (%s)',
$value,
get_resource_type($value)
\get_resource_type($value)
);
}
if (is_string($value)) {
if (\is_string($value)) {
// Match for most non printable chars somewhat taking multibyte chars into account
if (preg_match('/[^\x09-\x0d\x1b\x20-\xff]/', $value)) {
return 'Binary String: 0x' . bin2hex($value);
if (\preg_match('/[^\x09-\x0d\x1b\x20-\xff]/', $value)) {
return 'Binary String: 0x' . \bin2hex($value);
}
return "'" .
str_replace('<lf>', "\n",
str_replace(
\str_replace(
'<lf>',
"\n",
\str_replace(
["\r\n", "\n\r", "\r", "\n"],
['\r\n<lf>', '\n\r<lf>', '\r<lf>', '\n<lf>'],
$value
@@ -249,13 +258,13 @@ class Exporter
"'";
}
$whitespace = str_repeat(' ', 4 * $indentation);
$whitespace = \str_repeat(' ', (int)(4 * $indentation));
if (!$processed) {
$processed = new Context;
}
if (is_array($value)) {
if (\is_array($value)) {
if (($key = $processed->contains($value)) !== false) {
return 'Array &' . $key;
}
@@ -264,9 +273,9 @@ class Exporter
$key = $processed->add($value);
$values = '';
if (count($array) > 0) {
if (\count($array) > 0) {
foreach ($array as $k => $v) {
$values .= sprintf(
$values .= \sprintf(
'%s %s => %s' . "\n",
$whitespace,
$this->recursiveExport($k, $indentation),
@@ -277,23 +286,23 @@ class Exporter
$values = "\n" . $values . $whitespace;
}
return sprintf('Array &%s (%s)', $key, $values);
return \sprintf('Array &%s (%s)', $key, $values);
}
if (is_object($value)) {
$class = get_class($value);
if (\is_object($value)) {
$class = \get_class($value);
if ($hash = $processed->contains($value)) {
return sprintf('%s Object &%s', $class, $hash);
return \sprintf('%s Object &%s', $class, $hash);
}
$hash = $processed->add($value);
$values = '';
$array = $this->toArray($value);
if (count($array) > 0) {
if (\count($array) > 0) {
foreach ($array as $k => $v) {
$values .= sprintf(
$values .= \sprintf(
'%s %s => %s' . "\n",
$whitespace,
$this->recursiveExport($k, $indentation),
@@ -304,9 +313,68 @@ class Exporter
$values = "\n" . $values . $whitespace;
}
return sprintf('%s Object &%s (%s)', $class, $hash, $values);
return \sprintf('%s Object &%s (%s)', $class, $hash, $values);
}
return var_export($value, true);
return \var_export($value, true);
}
/**
* Determines whether a variable represents a resource, either open or closed.
*
* @param mixed $actual The variable to test.
*
* @return bool
*/
private function isResource($value)
{
return $value !== null
&& \is_scalar($value) === false
&& \is_array($value) === false
&& \is_object($value) === false;
}
/**
* Determines whether a variable represents a closed resource.
*
* @param mixed $actual The variable to test.
*
* @return bool
*/
private function isClosedResource($value)
{
/*
* PHP 7.2 introduced "resource (closed)".
*/
if (\gettype($value) === 'resource (closed)') {
return true;
}
/*
* If gettype did not work, attempt to determine whether this is
* a closed resource in another way.
*/
$isResource = \is_resource($value);
$isNotNonResource = $this->isResource($value);
if ($isResource === false && $isNotNonResource === true) {
return true;
}
if ($isNotNonResource === true) {
try {
$resourceType = @\get_resource_type($value);
if ($resourceType === 'Unknown') {
return true;
}
} catch (TypeError $e) {
// Ignore. Not a resource.
} catch (Exception $e) {
// Ignore. Not a resource.
}
}
return false;
}
}

View File

@@ -1,361 +0,0 @@
<?php
/*
* This file is part of the Exporter package.
*
* (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.
*/
namespace SebastianBergmann\Exporter;
use PHPUnit\Framework\TestCase;
/**
* @covers SebastianBergmann\Exporter\Exporter
*/
class ExporterTest extends TestCase
{
/**
* @var Exporter
*/
private $exporter;
protected function setUp()
{
$this->exporter = new Exporter;
}
public function exportProvider()
{
$obj2 = new \stdClass;
$obj2->foo = 'bar';
$obj3 = (object)array(1,2,"Test\r\n",4,5,6,7,8);
$obj = new \stdClass;
//@codingStandardsIgnoreStart
$obj->null = null;
//@codingStandardsIgnoreEnd
$obj->boolean = true;
$obj->integer = 1;
$obj->double = 1.2;
$obj->string = '1';
$obj->text = "this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext";
$obj->object = $obj2;
$obj->objectagain = $obj2;
$obj->array = array('foo' => 'bar');
$obj->self = $obj;
$storage = new \SplObjectStorage;
$storage->attach($obj2);
$storage->foo = $obj2;
return array(
'export null' => array(null, 'null'),
'export boolean true' => array(true, 'true'),
'export boolean false' => array(false, 'false'),
'export int 1' => array(1, '1'),
'export float 1.0' => array(1.0, '1.0'),
'export float 1.2' => array(1.2, '1.2'),
'export stream' => array(fopen('php://memory', 'r'), 'resource(%d) of type (stream)'),
'export numeric string' => array('1', "'1'"),
'export multidimentional array' => array(array(array(1,2,3), array(3,4,5)),
<<<EOF
Array &0 (
0 => Array &1 (
0 => 1
1 => 2
2 => 3
)
1 => Array &2 (
0 => 3
1 => 4
2 => 5
)
)
EOF
),
// \n\r and \r is converted to \n
'export multiline text' => array("this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext",
<<<EOF
'this\\n
is\\n
a\\n
very\\n
very\\n
very\\n
very\\n
very\\n
very\\r
long\\n\\r
text'
EOF
),
'export empty stdclass' => array(new \stdClass, 'stdClass Object &%x ()'),
'export non empty stdclass' => array($obj,
<<<EOF
stdClass Object &%x (
'null' => null
'boolean' => true
'integer' => 1
'double' => 1.2
'string' => '1'
'text' => 'this\\n
is\\n
a\\n
very\\n
very\\n
very\\n
very\\n
very\\n
very\\r
long\\n\\r
text'
'object' => stdClass Object &%x (
'foo' => 'bar'
)
'objectagain' => stdClass Object &%x
'array' => Array &%d (
'foo' => 'bar'
)
'self' => stdClass Object &%x
)
EOF
),
'export empty array' => array(array(), 'Array &%d ()'),
'export splObjectStorage' => array($storage,
<<<EOF
SplObjectStorage Object &%x (
'foo' => stdClass Object &%x (
'foo' => 'bar'
)
'%x' => Array &0 (
'obj' => stdClass Object &%x
'inf' => null
)
)
EOF
),
'export stdClass with numeric properties' => array($obj3,
<<<EOF
stdClass Object &%x (
0 => 1
1 => 2
2 => 'Test\\r\\n
'
3 => 4
4 => 5
5 => 6
6 => 7
7 => 8
)
EOF
),
array(
chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5),
'Binary String: 0x000102030405'
),
array(
implode('', array_map('chr', range(0x0e, 0x1f))),
'Binary String: 0x0e0f101112131415161718191a1b1c1d1e1f'
),
array(
chr(0x00) . chr(0x09),
'Binary String: 0x0009'
),
array(
'',
"''"
),
);
}
/**
* @dataProvider exportProvider
*/
public function testExport($value, $expected)
{
$this->assertStringMatchesFormat(
$expected,
$this->trimNewline($this->exporter->export($value))
);
}
public function testExport2()
{
if (PHP_VERSION === '5.3.3') {
$this->markTestSkipped('Skipped due to "Nesting level too deep - recursive dependency?" fatal error');
}
$obj = new \stdClass;
$obj->foo = 'bar';
$array = array(
0 => 0,
'null' => null,
'boolean' => true,
'integer' => 1,
'double' => 1.2,
'string' => '1',
'text' => "this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext",
'object' => $obj,
'objectagain' => $obj,
'array' => array('foo' => 'bar'),
);
$array['self'] = &$array;
$expected = <<<EOF
Array &%d (
0 => 0
'null' => null
'boolean' => true
'integer' => 1
'double' => 1.2
'string' => '1'
'text' => 'this\\n
is\\n
a\\n
very\\n
very\\n
very\\n
very\\n
very\\n
very\\r
long\\n\\r
text'
'object' => stdClass Object &%x (
'foo' => 'bar'
)
'objectagain' => stdClass Object &%x
'array' => Array &%d (
'foo' => 'bar'
)
'self' => Array &%d (
0 => 0
'null' => null
'boolean' => true
'integer' => 1
'double' => 1.2
'string' => '1'
'text' => 'this\\n
is\\n
a\\n
very\\n
very\\n
very\\n
very\\n
very\\n
very\\r
long\\n\\r
text'
'object' => stdClass Object &%x
'objectagain' => stdClass Object &%x
'array' => Array &%d (
'foo' => 'bar'
)
'self' => Array &%d
)
)
EOF;
$this->assertStringMatchesFormat(
$expected,
$this->trimNewline($this->exporter->export($array))
);
}
public function shortenedExportProvider()
{
$obj = new \stdClass;
$obj->foo = 'bar';
$array = array(
'foo' => 'bar',
);
return array(
'shortened export null' => array(null, 'null'),
'shortened export boolean true' => array(true, 'true'),
'shortened export integer 1' => array(1, '1'),
'shortened export float 1.0' => array(1.0, '1.0'),
'shortened export float 1.2' => array(1.2, '1.2'),
'shortened export numeric string' => array('1', "'1'"),
// \n\r and \r is converted to \n
'shortened export multilinestring' => array("this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext", "'this\\nis\\na\\nvery\\nvery\\nvery...\\rtext'"),
'shortened export empty stdClass' => array(new \stdClass, 'stdClass Object ()'),
'shortened export not empty stdClass' => array($obj, 'stdClass Object (...)'),
'shortened export empty array' => array(array(), 'Array ()'),
'shortened export not empty array' => array($array, 'Array (...)'),
);
}
/**
* @dataProvider shortenedExportProvider
*/
public function testShortenedExport($value, $expected)
{
$this->assertSame(
$expected,
$this->trimNewline($this->exporter->shortenedExport($value))
);
}
/**
* @requires extension mbstring
*/
public function testShortenedExportForMultibyteCharacters()
{
$oldMbLanguage = mb_language();
mb_language('Japanese');
$oldMbInternalEncoding = mb_internal_encoding();
mb_internal_encoding('UTF-8');
try {
$this->assertSame(
"'いろはにほへとちりぬるをわかよたれそつねならむうゐのおくや...しゑひもせす'",
$this->trimNewline($this->exporter->shortenedExport('いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす'))
);
} catch (\Exception $e) {
mb_internal_encoding($oldMbInternalEncoding);
mb_language($oldMbLanguage);
throw $e;
}
mb_internal_encoding($oldMbInternalEncoding);
mb_language($oldMbLanguage);
}
public function provideNonBinaryMultibyteStrings()
{
return array(
array(implode('', array_map('chr', range(0x09, 0x0d))), 9),
array(implode('', array_map('chr', range(0x20, 0x7f))), 96),
array(implode('', array_map('chr', range(0x80, 0xff))), 128),
);
}
/**
* @dataProvider provideNonBinaryMultibyteStrings
*/
public function testNonBinaryStringExport($value, $expectedLength)
{
$this->assertRegExp(
"~'.{{$expectedLength}}'\$~s",
$this->exporter->export($value)
);
}
public function testNonObjectCanBeReturnedAsArray()
{
$this->assertEquals(array(true), $this->exporter->toArray(true));
}
private function trimNewline($string)
{
return preg_replace('/[ ]*\n/', "\n", $string);
}
}

View File

@@ -2,6 +2,12 @@
All notable changes to `sebastianbergmann/object-enumerator` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [3.0.4] - 2020-11-30
### Changed
* Changed PHP version constraint in `composer.json` from `^7.0` to `>=7.0`
## [3.0.3] - 2017-08-03
### Changed
@@ -44,6 +50,7 @@ All notable changes to `sebastianbergmann/object-enumerator` are documented in t
* Initial release
[3.0.4]: https://github.com/sebastianbergmann/object-enumerator/compare/3.0.3...3.0.4
[3.0.3]: https://github.com/sebastianbergmann/object-enumerator/compare/3.0.2...3.0.3
[3.0.2]: https://github.com/sebastianbergmann/object-enumerator/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/sebastianbergmann/object-enumerator/compare/3.0.0...3.0.1

View File

@@ -10,7 +10,7 @@
}
],
"require": {
"php": "^7.0",
"php": ">=7.0",
"sebastian/object-reflector": "^1.1.1",
"sebastian/recursion-context": "^3.0"
},

View File

@@ -2,6 +2,12 @@
All notable changes to `sebastianbergmann/object-reflector` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## 1.1.2 - 2020-11-30
### Changed
* Changed PHP version constraint in `composer.json` from `^7.0` to `>=7.1`
## 1.1.1 - 2017-03-29
* Fixed [#1](https://github.com/sebastianbergmann/object-reflector/issues/1): Attributes that with non-string names are not handled correctly
@@ -16,5 +22,6 @@ All notable changes to `sebastianbergmann/object-reflector` are documented in th
* Initial release
[1.1.2]: https://github.com/sebastianbergmann/object-enumerator/compare/1.1.1...1.1.2
[1.1.1]: https://github.com/sebastianbergmann/object-enumerator/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/sebastianbergmann/object-enumerator/compare/1.0.0...1.1.0

View File

@@ -10,7 +10,7 @@
}
],
"require": {
"php": "^7.0"
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"

View File

@@ -18,7 +18,7 @@
}
],
"require": {
"php": "^7.0"
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"

View File

@@ -2,6 +2,12 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [2.0.2] - 2020-11-30
### Changed
* Changed PHP version constraint in `composer.json` from `^7.1` to `>=7.1`
## [2.0.1] - 2018-10-04
### Fixed
@@ -22,5 +28,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release
[2.0.2]: https://github.com/sebastianbergmann/comparator/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/sebastianbergmann/comparator/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/sebastianbergmann/comparator/compare/1.0.0...2.0.0

View File

@@ -10,7 +10,7 @@
}
],
"require": {
"php": "^7.1"
"php": ">=7.1"
},
"autoload": {
"classmap": [