Laravel 5.6 updates
Travis config update Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
40
vendor/sebastian/comparator/.github/stale.yml
vendored
Normal file
40
vendor/sebastian/comparator/.github/stale.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# Configuration for probot-stale - https://github.com/probot/stale
|
||||
|
||||
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
||||
daysUntilStale: 60
|
||||
|
||||
# Number of days of inactivity before a stale Issue or Pull Request is closed.
|
||||
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
|
||||
daysUntilClose: 7
|
||||
|
||||
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
||||
exemptLabels:
|
||||
- enhancement
|
||||
|
||||
# Set to true to ignore issues in a project (defaults to false)
|
||||
exemptProjects: false
|
||||
|
||||
# Set to true to ignore issues in a milestone (defaults to false)
|
||||
exemptMilestones: false
|
||||
|
||||
# Label to use when marking as stale
|
||||
staleLabel: stale
|
||||
|
||||
# Comment to post when marking as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions.
|
||||
|
||||
# Comment to post when removing the stale label.
|
||||
# unmarkComment: >
|
||||
# Your comment here.
|
||||
|
||||
# Comment to post when closing a stale Issue or Pull Request.
|
||||
closeComment: >
|
||||
This issue has been automatically closed because it has not had activity since it was marked as stale. Thank you for your contributions.
|
||||
|
||||
# Limit the number of actions per hour, from 1-30. Default is 30
|
||||
limitPerRun: 30
|
||||
|
||||
# Limit to only `issues` or `pulls`
|
||||
only: issues
|
||||
|
113
vendor/sebastian/comparator/.php_cs.dist
vendored
113
vendor/sebastian/comparator/.php_cs.dist
vendored
@@ -12,71 +12,173 @@ return PhpCsFixer\Config::create()
|
||||
->setRiskyAllowed(true)
|
||||
->setRules(
|
||||
[
|
||||
'align_multiline_comment' => true,
|
||||
'array_indentation' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'binary_operator_spaces' => [
|
||||
'align_double_arrow' => true,
|
||||
'align_equals' => true
|
||||
'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,
|
||||
'method_argument_space' => 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_consecutive_blank_lines' => 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,
|
||||
'ternary_operator_spaces' => 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(
|
||||
@@ -84,5 +186,4 @@ return PhpCsFixer\Config::create()
|
||||
->files()
|
||||
->in(__DIR__ . '/src')
|
||||
->in(__DIR__ . '/tests')
|
||||
->name('*.php')
|
||||
);
|
||||
|
1
vendor/sebastian/comparator/.travis.yml
vendored
1
vendor/sebastian/comparator/.travis.yml
vendored
@@ -3,7 +3,6 @@ language: php
|
||||
sudo: false
|
||||
|
||||
php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- master
|
||||
|
28
vendor/sebastian/comparator/ChangeLog.md
vendored
28
vendor/sebastian/comparator/ChangeLog.md
vendored
@@ -2,6 +2,29 @@
|
||||
|
||||
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
|
||||
|
||||
## [3.0.2] - 2018-07-12
|
||||
|
||||
### Changed
|
||||
|
||||
* By default, `MockObjectComparator` is now tried before all other (default) comparators
|
||||
|
||||
## [3.0.1] - 2018-06-14
|
||||
|
||||
### 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
|
||||
|
||||
## [3.0.0] - 2018-04-18
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#48](https://github.com/sebastianbergmann/comparator/issues/48): `DateTimeComparator` does not support fractional second deltas
|
||||
|
||||
### Removed
|
||||
|
||||
* Removed support for PHP 7.0
|
||||
|
||||
## [2.1.3] - 2018-02-01
|
||||
|
||||
### Changed
|
||||
@@ -12,7 +35,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fix comparison of DateTimeImmutable objects
|
||||
* Fix comparison of `DateTimeImmutable` objects
|
||||
|
||||
## [2.1.1] - 2017-12-22
|
||||
|
||||
@@ -27,6 +50,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.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
|
||||
[2.1.3]: https://github.com/sebastianbergmann/comparator/compare/2.1.2...2.1.3
|
||||
[2.1.2]: https://github.com/sebastianbergmann/comparator/compare/2.1.1...2.1.2
|
||||
[2.1.1]: https://github.com/sebastianbergmann/comparator/compare/2.1.0...2.1.1
|
||||
|
2
vendor/sebastian/comparator/LICENSE
vendored
2
vendor/sebastian/comparator/LICENSE
vendored
@@ -1,6 +1,6 @@
|
||||
Comparator
|
||||
|
||||
Copyright (c) 2002-2017, Sebastian Bergmann <sebastian@phpunit.de>.
|
||||
Copyright (c) 2002-2018, Sebastian Bergmann <sebastian@phpunit.de>.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
8
vendor/sebastian/comparator/composer.json
vendored
8
vendor/sebastian/comparator/composer.json
vendored
@@ -24,12 +24,12 @@
|
||||
],
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"php": "^7.0",
|
||||
"sebastian/diff": "^2.0 || ^3.0",
|
||||
"php": "^7.1",
|
||||
"sebastian/diff": "^3.0",
|
||||
"sebastian/exporter": "^3.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6.4"
|
||||
"phpunit/phpunit": "^7.1"
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
@@ -47,7 +47,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.1.x-dev"
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
vendor/sebastian/comparator/phpunit.xml
vendored
11
vendor/sebastian/comparator/phpunit.xml
vendored
@@ -1,14 +1,17 @@
|
||||
<?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"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
forceCoversAnnotation="true"
|
||||
beStrictAboutCoversAnnotation="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
beStrictAboutTodoAnnotatedTests="true"
|
||||
verbose="true">
|
||||
<testsuite>
|
||||
<directory suffix="Test.php">tests</directory>
|
||||
</testsuite>
|
||||
<testsuites>
|
||||
<testsuite name="default">
|
||||
<directory suffix="Test.php">tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
@@ -32,9 +31,6 @@ abstract class Comparator
|
||||
$this->exporter = new Exporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Factory $factory
|
||||
*/
|
||||
public function setFactory(Factory $factory)
|
||||
{
|
||||
$this->factory = $factory;
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
@@ -62,13 +61,13 @@ class ComparisonFailure extends \RuntimeException
|
||||
/**
|
||||
* Initialises with the expected value and the actual value.
|
||||
*
|
||||
* @param mixed $expected Expected value retrieved.
|
||||
* @param mixed $actual Actual value retrieved.
|
||||
* @param mixed $expected expected value retrieved
|
||||
* @param mixed $actual actual value retrieved
|
||||
* @param string $expectedAsString
|
||||
* @param string $actualAsString
|
||||
* @param bool $identical
|
||||
* @param string $message A string which is prefixed on all returned lines
|
||||
* in the difference output.
|
||||
* @param string $message a string which is prefixed on all returned lines
|
||||
* in the difference output
|
||||
*/
|
||||
public function __construct($expected, $actual, $expectedAsString, $actualAsString, $identical = false, $message = '')
|
||||
{
|
||||
@@ -79,17 +78,11 @@ class ComparisonFailure extends \RuntimeException
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActual()
|
||||
{
|
||||
return $this->actual;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExpected()
|
||||
{
|
||||
return $this->expected;
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use DOMDocument;
|
||||
@@ -82,6 +81,6 @@ class DOMNodeComparator extends ObjectComparator
|
||||
|
||||
$text = $node instanceof DOMDocument ? $node->saveXML() : $document->saveXML($node);
|
||||
|
||||
return $ignoreCase ? $text : \strtolower($text);
|
||||
return $ignoreCase ? \strtolower($text) : $text;
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
@@ -26,7 +25,7 @@ class DateTimeComparator extends ObjectComparator
|
||||
public function accepts($expected, $actual)
|
||||
{
|
||||
return ($expected instanceof \DateTime || $expected instanceof \DateTimeInterface) &&
|
||||
($actual instanceof \DateTime || $actual instanceof \DateTimeInterface);
|
||||
($actual instanceof \DateTime || $actual instanceof \DateTimeInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,13 +38,16 @@ class DateTimeComparator extends ObjectComparator
|
||||
* @param bool $ignoreCase Case is ignored when set to true
|
||||
* @param array $processed List of already processed elements (used to prevent infinite recursion)
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = [])
|
||||
{
|
||||
/** @var \DateTimeInterface $expected */
|
||||
/** @var \DateTimeInterface $actual */
|
||||
$delta = new \DateInterval(\sprintf('PT%dS', \abs($delta)));
|
||||
$absDelta = \abs($delta);
|
||||
$delta = new \DateInterval(\sprintf('PT%dS', $absDelta));
|
||||
$delta->f = $absDelta - \floor($absDelta);
|
||||
|
||||
$actualClone = (clone $actual)
|
||||
->setTimezone(new \DateTimeZone('UTC'));
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
33
vendor/sebastian/comparator/src/Factory.php
vendored
33
vendor/sebastian/comparator/src/Factory.php
vendored
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
@@ -15,6 +14,11 @@ namespace SebastianBergmann\Comparator;
|
||||
*/
|
||||
class Factory
|
||||
{
|
||||
/**
|
||||
* @var Factory
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @var Comparator[]
|
||||
*/
|
||||
@@ -25,11 +29,6 @@ class Factory
|
||||
*/
|
||||
private $defaultComparators = [];
|
||||
|
||||
/**
|
||||
* @var Factory
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @return Factory
|
||||
*/
|
||||
@@ -116,23 +115,23 @@ class Factory
|
||||
|
||||
private function registerDefaultComparators()
|
||||
{
|
||||
$this->registerDefaultComparator(new TypeComparator);
|
||||
$this->registerDefaultComparator(new ScalarComparator);
|
||||
$this->registerDefaultComparator(new NumericComparator);
|
||||
$this->registerDefaultComparator(new DoubleComparator);
|
||||
$this->registerDefaultComparator(new ArrayComparator);
|
||||
$this->registerDefaultComparator(new ResourceComparator);
|
||||
$this->registerDefaultComparator(new ObjectComparator);
|
||||
$this->registerDefaultComparator(new ExceptionComparator);
|
||||
$this->registerDefaultComparator(new SplObjectStorageComparator);
|
||||
$this->registerDefaultComparator(new DOMNodeComparator);
|
||||
$this->registerDefaultComparator(new MockObjectComparator);
|
||||
$this->registerDefaultComparator(new DateTimeComparator);
|
||||
$this->registerDefaultComparator(new DOMNodeComparator);
|
||||
$this->registerDefaultComparator(new SplObjectStorageComparator);
|
||||
$this->registerDefaultComparator(new ExceptionComparator);
|
||||
$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);
|
||||
}
|
||||
|
||||
private function registerDefaultComparator(Comparator $comparator)
|
||||
{
|
||||
\array_unshift($this->defaultComparators, $comparator);
|
||||
$this->defaultComparators[] = $comparator;
|
||||
|
||||
$comparator->setFactory($this);
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
@@ -46,11 +45,11 @@ class NumericComparator extends ScalarComparator
|
||||
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
|
||||
{
|
||||
if (\is_infinite($actual) && \is_infinite($expected)) {
|
||||
return;
|
||||
return; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if ((\is_infinite($actual) xor \is_infinite($expected)) ||
|
||||
(\is_nan($actual) or \is_nan($expected)) ||
|
||||
(\is_nan($actual) || \is_nan($expected)) ||
|
||||
\abs($actual - $expected) > $delta) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
@@ -62,18 +61,18 @@ class ScalarComparator extends Comparator
|
||||
}
|
||||
}
|
||||
|
||||
if ($expectedToCompare != $actualToCompare) {
|
||||
if (\is_string($expected) && \is_string($actual)) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$this->exporter->export($expected),
|
||||
$this->exporter->export($actual),
|
||||
false,
|
||||
'Failed asserting that two strings are equal.'
|
||||
);
|
||||
}
|
||||
if ($expectedToCompare !== $actualToCompare && \is_string($expected) && \is_string($actual)) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$this->exporter->export($expected),
|
||||
$this->exporter->export($actual),
|
||||
false,
|
||||
'Failed asserting that two strings are equal.'
|
||||
);
|
||||
}
|
||||
|
||||
if ($expectedToCompare != $actualToCompare) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
@@ -7,26 +7,25 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\ArrayComparator
|
||||
* @covers \SebastianBergmann\Comparator\ArrayComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class ArrayComparatorTest extends TestCase
|
||||
final class ArrayComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ArrayComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new ArrayComparator;
|
||||
$this->comparator->setFactory(new Factory);
|
||||
@@ -35,92 +34,89 @@ class ArrayComparatorTest extends TestCase
|
||||
public function acceptsFailsProvider()
|
||||
{
|
||||
return [
|
||||
[[], null],
|
||||
[null, []],
|
||||
[null, null]
|
||||
[[], 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
|
||||
],
|
||||
[
|
||||
['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
|
||||
]
|
||||
[
|
||||
[],
|
||||
[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
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
*/
|
||||
public function testAcceptsSucceeds()
|
||||
public function testAcceptsSucceeds(): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts([], [])
|
||||
@@ -128,10 +124,9 @@ class ArrayComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -139,10 +134,9 @@ class ArrayComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0, $canonicalize = false)
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0, $canonicalize = false): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -155,10 +149,9 @@ class ArrayComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual, $delta = 0.0, $canonicalize = false)
|
||||
public function testAssertEqualsFails($expected, $actual, $delta = 0.0, $canonicalize = false): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage('Failed asserting that two arrays are equal');
|
||||
|
@@ -7,17 +7,18 @@
|
||||
* 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
|
||||
* @covers \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
*/
|
||||
final class ComparisonFailureTest extends TestCase
|
||||
{
|
||||
public function testComparisonFailure()
|
||||
public function testComparisonFailure(): void
|
||||
{
|
||||
$actual = "\nB\n";
|
||||
$expected = "\nA\n";
|
||||
@@ -49,7 +50,7 @@ final class ComparisonFailureTest extends TestCase
|
||||
$this->assertSame($message . $diff, $failure->toString());
|
||||
}
|
||||
|
||||
public function testDiffNotPossible()
|
||||
public function testDiffNotPossible(): void
|
||||
{
|
||||
$failure = new ComparisonFailure('a', 'b', false, false, true, 'test');
|
||||
$this->assertSame('', $failure->getDiff());
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use DOMDocument;
|
||||
@@ -15,17 +14,20 @@ use DOMNode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\DOMNodeComparator
|
||||
* @covers \SebastianBergmann\Comparator\DOMNodeComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class DOMNodeComparatorTest extends TestCase
|
||||
final class DOMNodeComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var DOMNodeComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new DOMNodeComparator;
|
||||
}
|
||||
@@ -36,10 +38,10 @@ class DOMNodeComparatorTest extends TestCase
|
||||
$node = new DOMNode;
|
||||
|
||||
return [
|
||||
[$document, $document],
|
||||
[$node, $node],
|
||||
[$document, $node],
|
||||
[$node, $document]
|
||||
[$document, $document],
|
||||
[$node, $node],
|
||||
[$document, $node],
|
||||
[$node, $document]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -48,60 +50,125 @@ class DOMNodeComparatorTest extends TestCase
|
||||
$document = new DOMDocument;
|
||||
|
||||
return [
|
||||
[$document, null],
|
||||
[null, $document],
|
||||
[null, null]
|
||||
[$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/>')
|
||||
],
|
||||
[
|
||||
$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('<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;
|
||||
@@ -110,54 +177,4 @@ class DOMNodeComparatorTest extends TestCase
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsSucceedsProvider
|
||||
*/
|
||||
public function testAcceptsSucceeds($expected, $actual)
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual)
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
try {
|
||||
$this->comparator->assertEquals($expected, $actual);
|
||||
} catch (ComparisonFailure $exception) {
|
||||
}
|
||||
|
||||
$this->assertNull($exception, 'Unexpected ComparisonFailure');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual)
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage('Failed asserting that two DOM');
|
||||
|
||||
$this->comparator->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use DateTime;
|
||||
@@ -16,20 +15,20 @@ use DateTimeZone;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\DateTimeComparator
|
||||
* @covers \SebastianBergmann\Comparator\DateTimeComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class DateTimeComparatorTest extends TestCase
|
||||
final class DateTimeComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var DateTimeComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new DateTimeComparator;
|
||||
}
|
||||
@@ -39,9 +38,9 @@ class DateTimeComparatorTest extends TestCase
|
||||
$datetime = new DateTime;
|
||||
|
||||
return [
|
||||
[$datetime, null],
|
||||
[null, $datetime],
|
||||
[null, null]
|
||||
[$datetime, null],
|
||||
[null, $datetime],
|
||||
[null, null]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -93,6 +92,11 @@ class DateTimeComparatorTest extends TestCase
|
||||
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
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -146,10 +150,7 @@ class DateTimeComparatorTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
*/
|
||||
public function testAcceptsSucceeds()
|
||||
public function testAcceptsSucceeds(): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts(
|
||||
@@ -160,10 +161,9 @@ class DateTimeComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -171,10 +171,9 @@ class DateTimeComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0)
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -187,10 +186,9 @@ class DateTimeComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual, $delta = 0.0)
|
||||
public function testAssertEqualsFails($expected, $actual, $delta = 0.0): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage('Failed asserting that two DateTime objects are equal.');
|
||||
@@ -198,20 +196,12 @@ class DateTimeComparatorTest extends TestCase
|
||||
$this->comparator->assertEquals($expected, $actual, $delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.5
|
||||
* @covers ::accepts
|
||||
*/
|
||||
public function testAcceptsDateTimeInterface()
|
||||
public function testAcceptsDateTimeInterface(): void
|
||||
{
|
||||
$this->assertTrue($this->comparator->accepts(new DateTime, new DateTimeImmutable));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.5
|
||||
* @covers ::assertEquals
|
||||
*/
|
||||
public function testSupportsDateTimeInterface()
|
||||
public function testSupportsDateTimeInterface(): void
|
||||
{
|
||||
$this->assertNull(
|
||||
$this->comparator->assertEquals(
|
||||
|
@@ -7,23 +7,25 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\DoubleComparator
|
||||
* @covers \SebastianBergmann\Comparator\DoubleComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class DoubleComparatorTest extends TestCase
|
||||
final class DoubleComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var DoubleComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new DoubleComparator;
|
||||
}
|
||||
@@ -31,65 +33,64 @@ class DoubleComparatorTest extends TestCase
|
||||
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)]
|
||||
[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]
|
||||
[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)]
|
||||
[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)]
|
||||
[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)]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsSucceedsProvider
|
||||
*/
|
||||
public function testAcceptsSucceeds($expected, $actual)
|
||||
public function testAcceptsSucceeds($expected, $actual): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -97,10 +98,9 @@ class DoubleComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -108,10 +108,9 @@ class DoubleComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0)
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -124,10 +123,9 @@ class DoubleComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual, $delta = 0.0)
|
||||
public function testAssertEqualsFails($expected, $actual, $delta = 0.0): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage('matches expected');
|
||||
|
@@ -7,25 +7,27 @@
|
||||
* 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 \RuntimeException;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\ExceptionComparator
|
||||
* @covers \SebastianBergmann\Comparator\ExceptionComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class ExceptionComparatorTest extends TestCase
|
||||
final class ExceptionComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ExceptionComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new ExceptionComparator;
|
||||
$this->comparator->setFactory(new Factory);
|
||||
@@ -34,18 +36,18 @@ class ExceptionComparatorTest extends TestCase
|
||||
public function acceptsSucceedsProvider()
|
||||
{
|
||||
return [
|
||||
[new Exception, new Exception],
|
||||
[new RuntimeException, new RuntimeException],
|
||||
[new Exception, new RuntimeException]
|
||||
[new Exception, new Exception],
|
||||
[new RuntimeException, new RuntimeException],
|
||||
[new Exception, new RuntimeException]
|
||||
];
|
||||
}
|
||||
|
||||
public function acceptsFailsProvider()
|
||||
{
|
||||
return [
|
||||
[new Exception, null],
|
||||
[null, new Exception],
|
||||
[null, null]
|
||||
[new Exception, null],
|
||||
[null, new Exception],
|
||||
[null, null]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -58,10 +60,10 @@ class ExceptionComparatorTest extends TestCase
|
||||
$exception4 = new RuntimeException('Error', 100);
|
||||
|
||||
return [
|
||||
[$exception1, $exception1],
|
||||
[$exception1, $exception2],
|
||||
[$exception3, $exception3],
|
||||
[$exception3, $exception4]
|
||||
[$exception1, $exception1],
|
||||
[$exception1, $exception2],
|
||||
[$exception3, $exception3],
|
||||
[$exception3, $exception4]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -78,19 +80,18 @@ class ExceptionComparatorTest extends TestCase
|
||||
$exception5 = new RuntimeException('Error', 101);
|
||||
|
||||
return [
|
||||
[$exception1, $exception2, $equalMessage],
|
||||
[$exception1, $exception3, $equalMessage],
|
||||
[$exception1, $exception4, $typeMessage],
|
||||
[$exception2, $exception3, $equalMessage],
|
||||
[$exception4, $exception5, $equalMessage]
|
||||
[$exception1, $exception2, $equalMessage],
|
||||
[$exception1, $exception3, $equalMessage],
|
||||
[$exception1, $exception4, $typeMessage],
|
||||
[$exception2, $exception3, $equalMessage],
|
||||
[$exception4, $exception5, $equalMessage]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsSucceedsProvider
|
||||
*/
|
||||
public function testAcceptsSucceeds($expected, $actual)
|
||||
public function testAcceptsSucceeds($expected, $actual): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -98,10 +99,9 @@ class ExceptionComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -109,10 +109,9 @@ class ExceptionComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual)
|
||||
public function testAssertEqualsSucceeds($expected, $actual): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -125,10 +124,9 @@ class ExceptionComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual, $message)
|
||||
public function testAssertEqualsFails($expected, $actual, $message): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage($message);
|
||||
|
@@ -7,19 +7,18 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\Factory
|
||||
* @covers \SebastianBergmann\Comparator\Factory
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class FactoryTest extends TestCase
|
||||
final class FactoryTest extends TestCase
|
||||
{
|
||||
public function instanceProvider()
|
||||
{
|
||||
@@ -70,20 +69,15 @@ class FactoryTest extends TestCase
|
||||
|
||||
/**
|
||||
* @dataProvider instanceProvider
|
||||
* @covers ::getComparatorFor
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testGetComparatorFor($a, $b, $expected)
|
||||
public function testGetComparatorFor($a, $b, $expected): void
|
||||
{
|
||||
$factory = new Factory;
|
||||
$actual = $factory->getComparatorFor($a, $b);
|
||||
$this->assertInstanceOf($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::register
|
||||
*/
|
||||
public function testRegister()
|
||||
public function testRegister(): void
|
||||
{
|
||||
$comparator = new TestClassComparator;
|
||||
|
||||
@@ -99,10 +93,7 @@ class FactoryTest extends TestCase
|
||||
$this->assertInstanceOf($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::unregister
|
||||
*/
|
||||
public function testUnregister()
|
||||
public function testUnregister(): void
|
||||
{
|
||||
$comparator = new TestClassComparator;
|
||||
|
||||
@@ -118,7 +109,7 @@ class FactoryTest extends TestCase
|
||||
$this->assertInstanceOf($expected, $actual);
|
||||
}
|
||||
|
||||
public function testIsSingleton()
|
||||
public function testIsSingleton(): void
|
||||
{
|
||||
$f = Factory::getInstance();
|
||||
$this->assertSame($f, Factory::getInstance());
|
||||
|
@@ -7,24 +7,26 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\MockObjectComparator
|
||||
* @covers \SebastianBergmann\Comparator\MockObjectComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class MockObjectComparatorTest extends TestCase
|
||||
final class MockObjectComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MockObjectComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new MockObjectComparator;
|
||||
$this->comparator->setFactory(new Factory);
|
||||
@@ -36,9 +38,9 @@ class MockObjectComparatorTest extends TestCase
|
||||
$stdmock = $this->createMock(stdClass::class);
|
||||
|
||||
return [
|
||||
[$testmock, $testmock],
|
||||
[$stdmock, $stdmock],
|
||||
[$stdmock, $testmock]
|
||||
[$testmock, $testmock],
|
||||
[$stdmock, $stdmock],
|
||||
[$stdmock, $testmock]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -47,9 +49,9 @@ class MockObjectComparatorTest extends TestCase
|
||||
$stdmock = $this->createMock(stdClass::class);
|
||||
|
||||
return [
|
||||
[$stdmock, null],
|
||||
[null, $stdmock],
|
||||
[null, null]
|
||||
[$stdmock, null],
|
||||
[null, $stdmock],
|
||||
[null, null]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -67,15 +69,15 @@ class MockObjectComparatorTest extends TestCase
|
||||
$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
|
||||
]
|
||||
[$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
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -101,28 +103,27 @@ class MockObjectComparatorTest extends TestCase
|
||||
$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
|
||||
]
|
||||
[
|
||||
$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
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsSucceedsProvider
|
||||
*/
|
||||
public function testAcceptsSucceeds($expected, $actual)
|
||||
public function testAcceptsSucceeds($expected, $actual): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -130,10 +131,9 @@ class MockObjectComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -141,10 +141,9 @@ class MockObjectComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0)
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -157,10 +156,9 @@ class MockObjectComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual, $message, $delta = 0.0)
|
||||
public function testAssertEqualsFails($expected, $actual, $message, $delta = 0.0): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage($message);
|
||||
|
@@ -7,23 +7,25 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\NumericComparator
|
||||
* @covers \SebastianBergmann\Comparator\NumericComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class NumericComparatorTest extends TestCase
|
||||
final class NumericComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var NumericComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new NumericComparator;
|
||||
}
|
||||
@@ -31,53 +33,52 @@ class NumericComparatorTest extends TestCase
|
||||
public function acceptsSucceedsProvider()
|
||||
{
|
||||
return [
|
||||
[5, 10],
|
||||
[8, '0'],
|
||||
['10', 0],
|
||||
[0x74c3b00c, 42],
|
||||
[0755, 0777]
|
||||
[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]
|
||||
['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],
|
||||
[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],
|
||||
[1337, 1338],
|
||||
['1338', 1337],
|
||||
[0x539, 1338],
|
||||
[1337, 1339, 1],
|
||||
['1337', 1340, 2],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsSucceedsProvider
|
||||
*/
|
||||
public function testAcceptsSucceeds($expected, $actual)
|
||||
public function testAcceptsSucceeds($expected, $actual): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -85,10 +86,9 @@ class NumericComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -96,10 +96,9 @@ class NumericComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0)
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -112,10 +111,9 @@ class NumericComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual, $delta = 0.0)
|
||||
public function testAssertEqualsFails($expected, $actual, $delta = 0.0): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage('matches expected');
|
||||
|
@@ -7,24 +7,26 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\ObjectComparator
|
||||
* @covers \SebastianBergmann\Comparator\ObjectComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class ObjectComparatorTest extends TestCase
|
||||
final class ObjectComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new ObjectComparator;
|
||||
$this->comparator->setFactory(new Factory);
|
||||
@@ -33,18 +35,18 @@ class ObjectComparatorTest extends TestCase
|
||||
public function acceptsSucceedsProvider()
|
||||
{
|
||||
return [
|
||||
[new TestClass, new TestClass],
|
||||
[new stdClass, new stdClass],
|
||||
[new stdClass, new TestClass]
|
||||
[new TestClass, new TestClass],
|
||||
[new stdClass, new stdClass],
|
||||
[new stdClass, new TestClass]
|
||||
];
|
||||
}
|
||||
|
||||
public function acceptsFailsProvider()
|
||||
{
|
||||
return [
|
||||
[new stdClass, null],
|
||||
[null, new stdClass],
|
||||
[null, null]
|
||||
[new stdClass, null],
|
||||
[null, new stdClass],
|
||||
[null, null]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -62,11 +64,11 @@ class ObjectComparatorTest extends TestCase
|
||||
$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]
|
||||
[$object1, $object1],
|
||||
[$object1, $object2],
|
||||
[$book1, $book1],
|
||||
[$book1, $book2],
|
||||
[new Struct(2.3), new Struct(2.5), 0.5]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -92,19 +94,18 @@ class ObjectComparatorTest extends TestCase
|
||||
$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]
|
||||
[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]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsSucceedsProvider
|
||||
*/
|
||||
public function testAcceptsSucceeds($expected, $actual)
|
||||
public function testAcceptsSucceeds($expected, $actual): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -112,10 +113,9 @@ class ObjectComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -123,10 +123,9 @@ class ObjectComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0)
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -139,10 +138,9 @@ class ObjectComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual, $message, $delta = 0.0)
|
||||
public function testAssertEqualsFails($expected, $actual, $message, $delta = 0.0): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage($message);
|
||||
|
@@ -7,23 +7,25 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\ResourceComparator
|
||||
* @covers \SebastianBergmann\Comparator\ResourceComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class ResourceComparatorTest extends TestCase
|
||||
final class ResourceComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ResourceComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new ResourceComparator;
|
||||
}
|
||||
@@ -34,9 +36,9 @@ class ResourceComparatorTest extends TestCase
|
||||
$tmpfile2 = \tmpfile();
|
||||
|
||||
return [
|
||||
[$tmpfile1, $tmpfile1],
|
||||
[$tmpfile2, $tmpfile2],
|
||||
[$tmpfile1, $tmpfile2]
|
||||
[$tmpfile1, $tmpfile1],
|
||||
[$tmpfile2, $tmpfile2],
|
||||
[$tmpfile1, $tmpfile2]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -45,9 +47,9 @@ class ResourceComparatorTest extends TestCase
|
||||
$tmpfile1 = \tmpfile();
|
||||
|
||||
return [
|
||||
[$tmpfile1, null],
|
||||
[null, $tmpfile1],
|
||||
[null, null]
|
||||
[$tmpfile1, null],
|
||||
[null, $tmpfile1],
|
||||
[null, null]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -57,8 +59,8 @@ class ResourceComparatorTest extends TestCase
|
||||
$tmpfile2 = \tmpfile();
|
||||
|
||||
return [
|
||||
[$tmpfile1, $tmpfile1],
|
||||
[$tmpfile2, $tmpfile2]
|
||||
[$tmpfile1, $tmpfile1],
|
||||
[$tmpfile2, $tmpfile2]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -68,16 +70,15 @@ class ResourceComparatorTest extends TestCase
|
||||
$tmpfile2 = \tmpfile();
|
||||
|
||||
return [
|
||||
[$tmpfile1, $tmpfile2],
|
||||
[$tmpfile2, $tmpfile1]
|
||||
[$tmpfile1, $tmpfile2],
|
||||
[$tmpfile2, $tmpfile1]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsSucceedsProvider
|
||||
*/
|
||||
public function testAcceptsSucceeds($expected, $actual)
|
||||
public function testAcceptsSucceeds($expected, $actual): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -85,10 +86,9 @@ class ResourceComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -96,10 +96,9 @@ class ResourceComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual)
|
||||
public function testAssertEqualsSucceeds($expected, $actual): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -112,10 +111,9 @@ class ResourceComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual)
|
||||
public function testAssertEqualsFails($expected, $actual): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
|
||||
|
@@ -7,23 +7,25 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\ScalarComparator
|
||||
* @covers \SebastianBergmann\Comparator\ScalarComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class ScalarComparatorTest extends TestCase
|
||||
final class ScalarComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ScalarComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new ScalarComparator;
|
||||
}
|
||||
@@ -31,55 +33,55 @@ class ScalarComparatorTest extends TestCase
|
||||
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']
|
||||
['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()]
|
||||
[[], []],
|
||||
['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]
|
||||
['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]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -89,31 +91,35 @@ class ScalarComparatorTest extends TestCase
|
||||
$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]
|
||||
['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],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsSucceedsProvider
|
||||
*/
|
||||
public function testAcceptsSucceeds($expected, $actual)
|
||||
public function testAcceptsSucceeds($expected, $actual): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -121,10 +127,9 @@ class ScalarComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -132,10 +137,9 @@ class ScalarComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $ignoreCase = false)
|
||||
public function testAssertEqualsSucceeds($expected, $actual, $ignoreCase = false): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -148,10 +152,9 @@ class ScalarComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual, $message)
|
||||
public function testAssertEqualsFails($expected, $actual, $message): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage($message);
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* 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;
|
||||
@@ -15,17 +14,20 @@ use SplObjectStorage;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\SplObjectStorageComparator
|
||||
* @covers \SebastianBergmann\Comparator\SplObjectStorageComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class SplObjectStorageComparatorTest extends TestCase
|
||||
final class SplObjectStorageComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var SplObjectStorageComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new SplObjectStorageComparator;
|
||||
}
|
||||
@@ -33,9 +35,9 @@ class SplObjectStorageComparatorTest extends TestCase
|
||||
public function acceptsFailsProvider()
|
||||
{
|
||||
return [
|
||||
[new SplObjectStorage, new stdClass],
|
||||
[new stdClass, new SplObjectStorage],
|
||||
[new stdClass, new stdClass]
|
||||
[new SplObjectStorage, new stdClass],
|
||||
[new stdClass, new SplObjectStorage],
|
||||
[new stdClass, new stdClass]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -56,10 +58,10 @@ class SplObjectStorageComparatorTest extends TestCase
|
||||
$storage4->attach($object1);
|
||||
|
||||
return [
|
||||
[$storage1, $storage1],
|
||||
[$storage1, $storage2],
|
||||
[$storage3, $storage3],
|
||||
[$storage3, $storage4]
|
||||
[$storage1, $storage1],
|
||||
[$storage1, $storage2],
|
||||
[$storage3, $storage3],
|
||||
[$storage3, $storage4]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -78,16 +80,13 @@ class SplObjectStorageComparatorTest extends TestCase
|
||||
$storage3->attach($object1);
|
||||
|
||||
return [
|
||||
[$storage1, $storage2],
|
||||
[$storage1, $storage3],
|
||||
[$storage2, $storage3],
|
||||
[$storage1, $storage2],
|
||||
[$storage1, $storage3],
|
||||
[$storage2, $storage3],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
*/
|
||||
public function testAcceptsSucceeds()
|
||||
public function testAcceptsSucceeds(): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts(
|
||||
@@ -98,10 +97,9 @@ class SplObjectStorageComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsFailsProvider
|
||||
*/
|
||||
public function testAcceptsFails($expected, $actual)
|
||||
public function testAcceptsFails($expected, $actual): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -109,10 +107,9 @@ class SplObjectStorageComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual)
|
||||
public function testAssertEqualsSucceeds($expected, $actual): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -125,10 +122,9 @@ class SplObjectStorageComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual)
|
||||
public function testAssertEqualsFails($expected, $actual): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage('Failed asserting that two objects are equal.');
|
||||
@@ -136,7 +132,7 @@ class SplObjectStorageComparatorTest extends TestCase
|
||||
$this->comparator->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testAssertEqualsFails2()
|
||||
public function testAssertEqualsFails2(): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage('Failed asserting that two objects are equal.');
|
||||
|
@@ -7,24 +7,26 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass SebastianBergmann\Comparator\TypeComparator
|
||||
* @covers \SebastianBergmann\Comparator\TypeComparator<extended>
|
||||
*
|
||||
* @uses SebastianBergmann\Comparator\Comparator
|
||||
* @uses SebastianBergmann\Comparator\Factory
|
||||
* @uses SebastianBergmann\Comparator\ComparisonFailure
|
||||
* @uses \SebastianBergmann\Comparator\Comparator
|
||||
* @uses \SebastianBergmann\Comparator\Factory
|
||||
* @uses \SebastianBergmann\Comparator\ComparisonFailure
|
||||
*/
|
||||
class TypeComparatorTest extends TestCase
|
||||
final class TypeComparatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var TypeComparator
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comparator = new TypeComparator;
|
||||
}
|
||||
@@ -32,46 +34,45 @@ class TypeComparatorTest extends TestCase
|
||||
public function acceptsSucceedsProvider()
|
||||
{
|
||||
return [
|
||||
[true, 1],
|
||||
[false, [1]],
|
||||
[null, new stdClass],
|
||||
[1.0, 5],
|
||||
['', '']
|
||||
[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]]
|
||||
[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]
|
||||
[true, null],
|
||||
[null, false],
|
||||
[1.0, 0],
|
||||
[new stdClass, []],
|
||||
['1', 1]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::accepts
|
||||
* @dataProvider acceptsSucceedsProvider
|
||||
*/
|
||||
public function testAcceptsSucceeds($expected, $actual)
|
||||
public function testAcceptsSucceeds($expected, $actual): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->comparator->accepts($expected, $actual)
|
||||
@@ -79,10 +80,9 @@ class TypeComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsSucceedsProvider
|
||||
*/
|
||||
public function testAssertEqualsSucceeds($expected, $actual)
|
||||
public function testAssertEqualsSucceeds($expected, $actual): void
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
@@ -95,10 +95,9 @@ class TypeComparatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEquals
|
||||
* @dataProvider assertEqualsFailsProvider
|
||||
*/
|
||||
public function testAssertEqualsFails($expected, $actual)
|
||||
public function testAssertEqualsFails($expected, $actual): void
|
||||
{
|
||||
$this->expectException(ComparisonFailure::class);
|
||||
$this->expectExceptionMessage('does not match expected type');
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
@@ -16,5 +15,5 @@ namespace SebastianBergmann\Comparator;
|
||||
class Book
|
||||
{
|
||||
// the order of properties is important for testing the cycle!
|
||||
public $author = null;
|
||||
public $author;
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
class ClassWithToString
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
@@ -16,7 +15,9 @@ namespace SebastianBergmann\Comparator;
|
||||
class SampleClass
|
||||
{
|
||||
public $a;
|
||||
|
||||
protected $b;
|
||||
|
||||
protected $c;
|
||||
|
||||
public function __construct($a, $b, $c)
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
class TestClass
|
||||
|
@@ -7,7 +7,6 @@
|
||||
* 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
|
||||
|
40
vendor/sebastian/diff/.github/stale.yml
vendored
Normal file
40
vendor/sebastian/diff/.github/stale.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# Configuration for probot-stale - https://github.com/probot/stale
|
||||
|
||||
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
||||
daysUntilStale: 60
|
||||
|
||||
# Number of days of inactivity before a stale Issue or Pull Request is closed.
|
||||
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
|
||||
daysUntilClose: 7
|
||||
|
||||
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
||||
exemptLabels:
|
||||
- enhancement
|
||||
|
||||
# Set to true to ignore issues in a project (defaults to false)
|
||||
exemptProjects: false
|
||||
|
||||
# Set to true to ignore issues in a milestone (defaults to false)
|
||||
exemptMilestones: false
|
||||
|
||||
# Label to use when marking as stale
|
||||
staleLabel: wontfix
|
||||
|
||||
# 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
|
||||
|
81
vendor/sebastian/diff/.php_cs
vendored
81
vendor/sebastian/diff/.php_cs
vendored
@@ -1,81 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
$header = <<<'EOF'
|
||||
This file is part of sebastian/diff.
|
||||
|
||||
(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'],
|
||||
'declare_strict_types' => true,
|
||||
'elseif' => true,
|
||||
'encoding' => true,
|
||||
'full_opening_tag' => true,
|
||||
'function_declaration' => true,
|
||||
'header_comment' => ['header' => $header, 'separate' => 'none'],
|
||||
'indentation_type' => true,
|
||||
'line_ending' => true,
|
||||
'lowercase_constants' => true,
|
||||
'lowercase_keywords' => true,
|
||||
'method_argument_space' => true,
|
||||
'native_function_invocation' => true,
|
||||
'no_alias_functions' => true,
|
||||
'no_blank_lines_after_class_opening' => true,
|
||||
'no_blank_lines_after_phpdoc' => true,
|
||||
'no_closing_tag' => true,
|
||||
'no_empty_phpdoc' => true,
|
||||
'no_empty_statement' => true,
|
||||
'no_extra_consecutive_blank_lines' => true,
|
||||
'no_leading_namespace_whitespace' => true,
|
||||
'no_singleline_whitespace_before_semicolons' => true,
|
||||
'no_spaces_after_function_name' => true,
|
||||
'no_spaces_inside_parenthesis' => true,
|
||||
'no_trailing_comma_in_list_call' => true,
|
||||
'no_trailing_whitespace' => true,
|
||||
'no_unused_imports' => true,
|
||||
'no_whitespace_in_blank_line' => true,
|
||||
'phpdoc_align' => true,
|
||||
'phpdoc_indent' => true,
|
||||
'phpdoc_no_access' => true,
|
||||
'phpdoc_no_empty_return' => true,
|
||||
'phpdoc_no_package' => true,
|
||||
'phpdoc_scalar' => true,
|
||||
'phpdoc_separation' => true,
|
||||
'phpdoc_to_comment' => true,
|
||||
'phpdoc_trim' => true,
|
||||
'phpdoc_types' => true,
|
||||
'phpdoc_var_without_name' => true,
|
||||
'pow_to_exponentiation' => true,
|
||||
'self_accessor' => true,
|
||||
'simplified_null_return' => true,
|
||||
'single_blank_line_at_eof' => true,
|
||||
'single_import_per_statement' => true,
|
||||
'single_line_after_imports' => true,
|
||||
'single_quote' => true,
|
||||
'ternary_operator_spaces' => true,
|
||||
'trim_array_spaces' => true,
|
||||
'visibility_required' => true,
|
||||
]
|
||||
)
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
->files()
|
||||
->in(__DIR__ . '/src')
|
||||
->in(__DIR__ . '/tests')
|
||||
->name('*.php')
|
||||
);
|
168
vendor/sebastian/diff/.php_cs.dist
vendored
Normal file
168
vendor/sebastian/diff/.php_cs.dist
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php declare(strict_types=1);
|
||||
$header = <<<'EOF'
|
||||
This file is part of sebastian/diff.
|
||||
|
||||
(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' => [
|
||||
'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' => ['method']],
|
||||
'compact_nullable_typehint' => true,
|
||||
'concat_space' => ['spacing' => 'one'],
|
||||
'declare_equal_normalize' => ['space' => 'none'],
|
||||
'declare_strict_types' => true,
|
||||
'dir_constant' => true,
|
||||
'elseif' => true,
|
||||
'encoding' => true,
|
||||
'full_opening_tag' => true,
|
||||
'function_declaration' => true,
|
||||
'header_comment' => ['header' => $header, 'separate' => 'none'],
|
||||
'indentation_type' => true,
|
||||
'line_ending' => true,
|
||||
'list_syntax' => ['syntax' => 'short'],
|
||||
'lowercase_cast' => true,
|
||||
'lowercase_constants' => true,
|
||||
'lowercase_keywords' => true,
|
||||
'magic_constant_casing' => true,
|
||||
'method_argument_space' => ['ensure_fully_multiline' => true],
|
||||
'modernize_types_casting' => true,
|
||||
'native_function_casing' => true,
|
||||
'native_function_invocation' => true,
|
||||
'no_alias_functions' => true,
|
||||
'no_blank_lines_after_class_opening' => true,
|
||||
'no_blank_lines_after_phpdoc' => true,
|
||||
'no_closing_tag' => true,
|
||||
'no_empty_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_null_property_initialization' => 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_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_unused_imports' => true,
|
||||
'no_useless_else' => 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_types' => true,
|
||||
'phpdoc_types_order' => true,
|
||||
'phpdoc_var_without_name' => true,
|
||||
'pow_to_exponentiation' => true,
|
||||
'protected_to_private' => true,
|
||||
'return_type_declaration' => ['space_before' => 'none'],
|
||||
'self_accessor' => 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')
|
||||
);
|
4
vendor/sebastian/diff/.travis.yml
vendored
4
vendor/sebastian/diff/.travis.yml
vendored
@@ -1,10 +1,8 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 7.0
|
||||
- 7.0snapshot
|
||||
- 7.1
|
||||
- 7.1snapshot
|
||||
- 7.2
|
||||
- master
|
||||
|
||||
sudo: false
|
||||
|
24
vendor/sebastian/diff/ChangeLog.md
vendored
24
vendor/sebastian/diff/ChangeLog.md
vendored
@@ -2,6 +2,28 @@
|
||||
|
||||
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
|
||||
|
||||
## [3.0.1] - 2018-06-10
|
||||
|
||||
### Fixed
|
||||
|
||||
* Removed `"minimum-stability": "dev",` from `composer.json`
|
||||
|
||||
## [3.0.0] - 2018-02-01
|
||||
|
||||
* The `StrictUnifiedDiffOutputBuilder` implementation of the `DiffOutputBuilderInterface` was added
|
||||
|
||||
### Changed
|
||||
|
||||
* The default `DiffOutputBuilderInterface` implementation now generates context lines (unchanged lines)
|
||||
|
||||
### Removed
|
||||
|
||||
* Removed support for PHP 7.0
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#70](https://github.com/sebastianbergmann/diff/issues/70): Diffing of arrays no longer works
|
||||
|
||||
## [2.0.1] - 2017-08-03
|
||||
|
||||
### Fixed
|
||||
@@ -18,5 +40,7 @@ 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.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
|
||||
[2.0.0]: https://github.com/sebastianbergmann/diff/compare/1.4...c341c98ce083db77f896a0aa64f5ee7652915970
|
||||
|
2
vendor/sebastian/diff/LICENSE
vendored
2
vendor/sebastian/diff/LICENSE
vendored
@@ -1,6 +1,6 @@
|
||||
sebastian/diff
|
||||
|
||||
Copyright (c) 2002-2017, Sebastian Bergmann <sebastian@phpunit.de>.
|
||||
Copyright (c) 2002-2018, Sebastian Bergmann <sebastian@phpunit.de>.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
89
vendor/sebastian/diff/README.md
vendored
89
vendor/sebastian/diff/README.md
vendored
@@ -14,9 +14,12 @@ If you only need this library during development, for instance to run your proje
|
||||
|
||||
### Usage
|
||||
|
||||
#### Generating diff
|
||||
|
||||
The `Differ` class can be used to generate a textual representation of the difference between two strings:
|
||||
|
||||
```php
|
||||
<?php
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
|
||||
$differ = new Differ;
|
||||
@@ -24,12 +27,83 @@ print $differ->diff('foo', 'bar');
|
||||
```
|
||||
|
||||
The code above yields the output below:
|
||||
```diff
|
||||
--- Original
|
||||
+++ New
|
||||
@@ @@
|
||||
-foo
|
||||
+bar
|
||||
```
|
||||
|
||||
--- Original
|
||||
+++ New
|
||||
@@ @@
|
||||
-foo
|
||||
+bar
|
||||
There are three output builders available in this package:
|
||||
|
||||
#### UnifiedDiffOutputBuilder
|
||||
|
||||
This is default builder, which generates the output close to udiff and is used by PHPUnit.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
|
||||
|
||||
$builder = new UnifiedDiffOutputBuilder(
|
||||
"--- Original\n+++ New\n", // custom header
|
||||
false // do not add line numbers to the diff
|
||||
);
|
||||
|
||||
$differ = new Differ($builder);
|
||||
print $differ->diff('foo', 'bar');
|
||||
```
|
||||
|
||||
#### StrictUnifiedDiffOutputBuilder
|
||||
|
||||
Generates (strict) Unified diff's (unidiffs) with hunks,
|
||||
similar to `diff -u` and compatible with `patch` and `git apply`.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
use SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder;
|
||||
|
||||
$builder = new StrictUnifiedDiffOutputBuilder([
|
||||
'collapseRanges' => true, // ranges of length one are rendered with the trailing `,1`
|
||||
'commonLineThreshold' => 6, // number of same lines before ending a new hunk and creating a new one (if needed)
|
||||
'contextLines' => 3, // like `diff: -u, -U NUM, --unified[=NUM]`, for patch/git apply compatibility best to keep at least @ 3
|
||||
'fromFile' => null,
|
||||
'fromFileDate' => null,
|
||||
'toFile' => null,
|
||||
'toFileDate' => null,
|
||||
]);
|
||||
|
||||
$differ = new Differ($builder);
|
||||
print $differ->diff('foo', 'bar');
|
||||
```
|
||||
|
||||
#### DiffOnlyOutputBuilder
|
||||
|
||||
Output only the lines that differ.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
use SebastianBergmann\Diff\Output\DiffOnlyOutputBuilder;
|
||||
|
||||
$builder = new DiffOnlyOutputBuilder(
|
||||
"--- Original\n+++ New\n"
|
||||
);
|
||||
|
||||
$differ = new Differ($builder);
|
||||
print $differ->diff('foo', 'bar');
|
||||
```
|
||||
|
||||
#### DiffOutputBuilderInterface
|
||||
|
||||
You can pass any output builder to the `Differ` class as longs as it implements the `DiffOutputBuilderInterface`.
|
||||
|
||||
#### Parsing diff
|
||||
|
||||
The `Parser` class can be used to parse a unified diff into an object graph:
|
||||
|
||||
@@ -114,13 +188,8 @@ The code above yields the output below:
|
||||
[type:SebastianBergmann\Diff\Line:private] => 3
|
||||
[content:SebastianBergmann\Diff\Line:private] => $b = new Money(2, new Currency('EUR'));
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
|
14
vendor/sebastian/diff/composer.json
vendored
14
vendor/sebastian/diff/composer.json
vendored
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "sebastian/diff",
|
||||
"description": "Diff implementation",
|
||||
"keywords": ["diff"],
|
||||
"keywords": ["diff", "udiff", "unidiff", "unified diff"],
|
||||
"homepage": "https://github.com/sebastianbergmann/diff",
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
@@ -15,19 +15,25 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.0"
|
||||
"php": "^7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6.2"
|
||||
"phpunit/phpunit": "^7.0",
|
||||
"symfony/process": "^2 || ^3.3 || ^4"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"classmap": [
|
||||
"tests/"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
vendor/sebastian/diff/phpunit.xml
vendored
10
vendor/sebastian/diff/phpunit.xml
vendored
@@ -1,15 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.2/phpunit.xsd"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
forceCoversAnnotation="true"
|
||||
beStrictAboutCoversAnnotation="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
beStrictAboutTodoAnnotatedTests="true"
|
||||
verbose="true">
|
||||
<testsuite>
|
||||
<directory suffix="Test.php">tests</directory>
|
||||
</testsuite>
|
||||
<testsuites>
|
||||
<testsuite name="default">
|
||||
<directory suffix="Test.php">tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
|
2
vendor/sebastian/diff/src/Chunk.php
vendored
2
vendor/sebastian/diff/src/Chunk.php
vendored
@@ -71,7 +71,7 @@ final class Chunk
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
public function setLines(array $lines)
|
||||
public function setLines(array $lines): void
|
||||
{
|
||||
$this->lines = $lines;
|
||||
}
|
||||
|
2
vendor/sebastian/diff/src/Diff.php
vendored
2
vendor/sebastian/diff/src/Diff.php
vendored
@@ -60,7 +60,7 @@ final class Diff
|
||||
/**
|
||||
* @param Chunk[] $chunks
|
||||
*/
|
||||
public function setChunks(array $chunks)
|
||||
public function setChunks(array $chunks): void
|
||||
{
|
||||
$this->chunks = $chunks;
|
||||
}
|
||||
|
79
vendor/sebastian/diff/src/Differ.php
vendored
79
vendor/sebastian/diff/src/Differ.php
vendored
@@ -18,6 +18,12 @@ use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
|
||||
*/
|
||||
final class Differ
|
||||
{
|
||||
public const OLD = 0;
|
||||
public const ADDED = 1;
|
||||
public const REMOVED = 2;
|
||||
public const DIFF_LINE_END_WARNING = 3;
|
||||
public const NO_LINE_END_EOF_WARNING = 4;
|
||||
|
||||
/**
|
||||
* @var DiffOutputBuilderInterface
|
||||
*/
|
||||
@@ -54,35 +60,21 @@ final class Differ
|
||||
*
|
||||
* @param array|string $from
|
||||
* @param array|string $to
|
||||
* @param LongestCommonSubsequenceCalculator|null $lcs
|
||||
* @param null|LongestCommonSubsequenceCalculator $lcs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null): string
|
||||
{
|
||||
$from = $this->validateDiffInput($from);
|
||||
$to = $this->validateDiffInput($to);
|
||||
$diff = $this->diffToArray($from, $to, $lcs);
|
||||
$diff = $this->diffToArray(
|
||||
$this->normalizeDiffInput($from),
|
||||
$this->normalizeDiffInput($to),
|
||||
$lcs
|
||||
);
|
||||
|
||||
return $this->outputBuilder->getDiff($diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts variable to string if it is not a string or array.
|
||||
*
|
||||
* @param mixed $input
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function validateDiffInput($input): string
|
||||
{
|
||||
if (!\is_array($input) && !\is_string($input)) {
|
||||
return (string) $input;
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the diff between two arrays or strings as array.
|
||||
*
|
||||
@@ -105,16 +97,16 @@ final class Differ
|
||||
if (\is_string($from)) {
|
||||
$from = $this->splitStringByLines($from);
|
||||
} elseif (!\is_array($from)) {
|
||||
throw new \InvalidArgumentException('"from" must be an array or string.');
|
||||
throw new InvalidArgumentException('"from" must be an array or string.');
|
||||
}
|
||||
|
||||
if (\is_string($to)) {
|
||||
$to = $this->splitStringByLines($to);
|
||||
} elseif (!\is_array($to)) {
|
||||
throw new \InvalidArgumentException('"to" must be an array or string.');
|
||||
throw new InvalidArgumentException('"to" must be an array or string.');
|
||||
}
|
||||
|
||||
list($from, $to, $start, $end) = self::getArrayDiffParted($from, $to);
|
||||
[$from, $to, $start, $end] = self::getArrayDiffParted($from, $to);
|
||||
|
||||
if ($lcs === null) {
|
||||
$lcs = $this->selectLcsImplementation($from, $to);
|
||||
@@ -124,7 +116,7 @@ final class Differ
|
||||
$diff = [];
|
||||
|
||||
foreach ($start as $token) {
|
||||
$diff[] = [$token, 0 /* OLD */];
|
||||
$diff[] = [$token, self::OLD];
|
||||
}
|
||||
|
||||
\reset($from);
|
||||
@@ -132,38 +124,54 @@ final class Differ
|
||||
|
||||
foreach ($common as $token) {
|
||||
while (($fromToken = \reset($from)) !== $token) {
|
||||
$diff[] = [\array_shift($from), 2 /* REMOVED */];
|
||||
$diff[] = [\array_shift($from), self::REMOVED];
|
||||
}
|
||||
|
||||
while (($toToken = \reset($to)) !== $token) {
|
||||
$diff[] = [\array_shift($to), 1 /* ADDED */];
|
||||
$diff[] = [\array_shift($to), self::ADDED];
|
||||
}
|
||||
|
||||
$diff[] = [$token, 0 /* OLD */];
|
||||
$diff[] = [$token, self::OLD];
|
||||
|
||||
\array_shift($from);
|
||||
\array_shift($to);
|
||||
}
|
||||
|
||||
while (($token = \array_shift($from)) !== null) {
|
||||
$diff[] = [$token, 2 /* REMOVED */];
|
||||
$diff[] = [$token, self::REMOVED];
|
||||
}
|
||||
|
||||
while (($token = \array_shift($to)) !== null) {
|
||||
$diff[] = [$token, 1 /* ADDED */];
|
||||
$diff[] = [$token, self::ADDED];
|
||||
}
|
||||
|
||||
foreach ($end as $token) {
|
||||
$diff[] = [$token, 0 /* OLD */];
|
||||
$diff[] = [$token, self::OLD];
|
||||
}
|
||||
|
||||
if ($this->detectUnmatchedLineEndings($diff)) {
|
||||
\array_unshift($diff, ["#Warning: Strings contain different line endings!\n", 3]);
|
||||
\array_unshift($diff, ["#Warning: Strings contain different line endings!\n", self::DIFF_LINE_END_WARNING]);
|
||||
}
|
||||
|
||||
return $diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts variable to string if it is not a string or array.
|
||||
*
|
||||
* @param mixed $input
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
private function normalizeDiffInput($input)
|
||||
{
|
||||
if (!\is_array($input) && !\is_string($input)) {
|
||||
return (string) $input;
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if input is string, if so it will split it line-by-line.
|
||||
*
|
||||
@@ -203,7 +211,7 @@ final class Differ
|
||||
* @param array $from
|
||||
* @param array $to
|
||||
*
|
||||
* @return int|float
|
||||
* @return float|int
|
||||
*/
|
||||
private function calculateEstimatedFootprint(array $from, array $to)
|
||||
{
|
||||
@@ -225,13 +233,13 @@ final class Differ
|
||||
$oldLineBreaks = ['' => true];
|
||||
|
||||
foreach ($diff as $entry) {
|
||||
if (0 === $entry[1]) { /* OLD */
|
||||
if (self::OLD === $entry[1]) {
|
||||
$ln = $this->getLinebreak($entry[0]);
|
||||
$oldLineBreaks[$ln] = true;
|
||||
$newLineBreaks[$ln] = true;
|
||||
} elseif (1 === $entry[1]) { /* ADDED */
|
||||
} elseif (self::ADDED === $entry[1]) {
|
||||
$newLineBreaks[$this->getLinebreak($entry[0])] = true;
|
||||
} elseif (2 === $entry[1]) { /* REMOVED */
|
||||
} elseif (self::REMOVED === $entry[1]) {
|
||||
$oldLineBreaks[$this->getLinebreak($entry[0])] = true;
|
||||
}
|
||||
}
|
||||
@@ -264,6 +272,7 @@ final class Differ
|
||||
}
|
||||
|
||||
$lc = \substr($line, -1);
|
||||
|
||||
if ("\r" === $lc) {
|
||||
return "\r";
|
||||
}
|
||||
|
40
vendor/sebastian/diff/src/Exception/ConfigurationException.php
vendored
Normal file
40
vendor/sebastian/diff/src/Exception/ConfigurationException.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff;
|
||||
|
||||
final class ConfigurationException extends InvalidArgumentException
|
||||
{
|
||||
/**
|
||||
* @param string $option
|
||||
* @param string $expected
|
||||
* @param mixed $value
|
||||
* @param int $code
|
||||
* @param null|\Exception $previous
|
||||
*/
|
||||
public function __construct(
|
||||
string $option,
|
||||
string $expected,
|
||||
$value,
|
||||
int $code = 0,
|
||||
\Exception $previous = null
|
||||
) {
|
||||
parent::__construct(
|
||||
\sprintf(
|
||||
'Option "%s" must be %s, got "%s".',
|
||||
$option,
|
||||
$expected,
|
||||
\is_object($value) ? \get_class($value) : (null === $value ? '<null>' : \gettype($value) . '#' . $value)
|
||||
),
|
||||
$code,
|
||||
$previous
|
||||
);
|
||||
}
|
||||
}
|
6
vendor/sebastian/diff/src/Line.php
vendored
6
vendor/sebastian/diff/src/Line.php
vendored
@@ -12,9 +12,9 @@ namespace SebastianBergmann\Diff;
|
||||
|
||||
final class Line
|
||||
{
|
||||
const ADDED = 1;
|
||||
const REMOVED = 2;
|
||||
const UNCHANGED = 3;
|
||||
public const ADDED = 1;
|
||||
public const REMOVED = 2;
|
||||
public const UNCHANGED = 3;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
|
@@ -7,8 +7,11 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Diff\Output;
|
||||
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
|
||||
/**
|
||||
* Builds a diff string representation in a loose unified diff format
|
||||
* listing only changes lines. Does not include line numbers.
|
||||
@@ -31,17 +34,18 @@ final class DiffOnlyOutputBuilder implements DiffOutputBuilderInterface
|
||||
|
||||
if ('' !== $this->header) {
|
||||
\fwrite($buffer, $this->header);
|
||||
|
||||
if ("\n" !== \substr($this->header, -1, 1)) {
|
||||
\fwrite($buffer, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($diff as $diffEntry) {
|
||||
if ($diffEntry[1] === 1 /* ADDED */) {
|
||||
if ($diffEntry[1] === Differ::ADDED) {
|
||||
\fwrite($buffer, '+' . $diffEntry[0]);
|
||||
} elseif ($diffEntry[1] === 2 /* REMOVED */) {
|
||||
} elseif ($diffEntry[1] === Differ::REMOVED) {
|
||||
\fwrite($buffer, '-' . $diffEntry[0]);
|
||||
} elseif ($diffEntry[1] === 3 /* WARNING */) {
|
||||
} elseif ($diffEntry[1] === Differ::DIFF_LINE_END_WARNING) {
|
||||
\fwrite($buffer, ' ' . $diffEntry[0]);
|
||||
|
||||
continue; // Warnings should not be tested for line break, it will always be there
|
||||
@@ -50,6 +54,7 @@ final class DiffOnlyOutputBuilder implements DiffOutputBuilderInterface
|
||||
}
|
||||
|
||||
$lc = \substr($diffEntry[0], -1);
|
||||
|
||||
if ($lc !== "\n" && $lc !== "\r") {
|
||||
\fwrite($buffer, "\n"); // \No newline at end of file
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Diff\Output;
|
||||
|
||||
/**
|
||||
|
318
vendor/sebastian/diff/src/Output/StrictUnifiedDiffOutputBuilder.php
vendored
Normal file
318
vendor/sebastian/diff/src/Output/StrictUnifiedDiffOutputBuilder.php
vendored
Normal file
@@ -0,0 +1,318 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Output;
|
||||
|
||||
use SebastianBergmann\Diff\ConfigurationException;
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
|
||||
/**
|
||||
* Strict Unified diff output builder.
|
||||
*
|
||||
* Generates (strict) Unified diff's (unidiffs) with hunks.
|
||||
*/
|
||||
final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
|
||||
{
|
||||
private static $default = [
|
||||
'collapseRanges' => true, // ranges of length one are rendered with the trailing `,1`
|
||||
'commonLineThreshold' => 6, // number of same lines before ending a new hunk and creating a new one (if needed)
|
||||
'contextLines' => 3, // like `diff: -u, -U NUM, --unified[=NUM]`, for patch/git apply compatibility best to keep at least @ 3
|
||||
'fromFile' => null,
|
||||
'fromFileDate' => null,
|
||||
'toFile' => null,
|
||||
'toFileDate' => null,
|
||||
];
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $changed;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $collapseRanges;
|
||||
|
||||
/**
|
||||
* @var int >= 0
|
||||
*/
|
||||
private $commonLineThreshold;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $header;
|
||||
|
||||
/**
|
||||
* @var int >= 0
|
||||
*/
|
||||
private $contextLines;
|
||||
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$options = \array_merge(self::$default, $options);
|
||||
|
||||
if (!\is_bool($options['collapseRanges'])) {
|
||||
throw new ConfigurationException('collapseRanges', 'a bool', $options['collapseRanges']);
|
||||
}
|
||||
|
||||
if (!\is_int($options['contextLines']) || $options['contextLines'] < 0) {
|
||||
throw new ConfigurationException('contextLines', 'an int >= 0', $options['contextLines']);
|
||||
}
|
||||
|
||||
if (!\is_int($options['commonLineThreshold']) || $options['commonLineThreshold'] <= 0) {
|
||||
throw new ConfigurationException('commonLineThreshold', 'an int > 0', $options['commonLineThreshold']);
|
||||
}
|
||||
|
||||
foreach (['fromFile', 'toFile'] as $option) {
|
||||
if (!\is_string($options[$option])) {
|
||||
throw new ConfigurationException($option, 'a string', $options[$option]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['fromFileDate', 'toFileDate'] as $option) {
|
||||
if (null !== $options[$option] && !\is_string($options[$option])) {
|
||||
throw new ConfigurationException($option, 'a string or <null>', $options[$option]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->header = \sprintf(
|
||||
"--- %s%s\n+++ %s%s\n",
|
||||
$options['fromFile'],
|
||||
null === $options['fromFileDate'] ? '' : "\t" . $options['fromFileDate'],
|
||||
$options['toFile'],
|
||||
null === $options['toFileDate'] ? '' : "\t" . $options['toFileDate']
|
||||
);
|
||||
|
||||
$this->collapseRanges = $options['collapseRanges'];
|
||||
$this->commonLineThreshold = $options['commonLineThreshold'];
|
||||
$this->contextLines = $options['contextLines'];
|
||||
}
|
||||
|
||||
public function getDiff(array $diff): string
|
||||
{
|
||||
if (0 === \count($diff)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->changed = false;
|
||||
|
||||
$buffer = \fopen('php://memory', 'r+b');
|
||||
\fwrite($buffer, $this->header);
|
||||
|
||||
$this->writeDiffHunks($buffer, $diff);
|
||||
|
||||
if (!$this->changed) {
|
||||
\fclose($buffer);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$diff = \stream_get_contents($buffer, -1, 0);
|
||||
|
||||
\fclose($buffer);
|
||||
|
||||
// If the last char is not a linebreak: add it.
|
||||
// This might happen when both the `from` and `to` do not have a trailing linebreak
|
||||
$last = \substr($diff, -1);
|
||||
|
||||
return "\n" !== $last && "\r" !== $last
|
||||
? $diff . "\n"
|
||||
: $diff
|
||||
;
|
||||
}
|
||||
|
||||
private function writeDiffHunks($output, array $diff): void
|
||||
{
|
||||
// detect "No newline at end of file" and insert into `$diff` if needed
|
||||
|
||||
$upperLimit = \count($diff);
|
||||
|
||||
if (0 === $diff[$upperLimit - 1][1]) {
|
||||
$lc = \substr($diff[$upperLimit - 1][0], -1);
|
||||
|
||||
if ("\n" !== $lc) {
|
||||
\array_splice($diff, $upperLimit, 0, [["\n\\ No newline at end of file\n", Differ::NO_LINE_END_EOF_WARNING]]);
|
||||
}
|
||||
} else {
|
||||
// search back for the last `+` and `-` line,
|
||||
// check if has trailing linebreak, else add under it warning under it
|
||||
$toFind = [1 => true, 2 => true];
|
||||
|
||||
for ($i = $upperLimit - 1; $i >= 0; --$i) {
|
||||
if (isset($toFind[$diff[$i][1]])) {
|
||||
unset($toFind[$diff[$i][1]]);
|
||||
$lc = \substr($diff[$i][0], -1);
|
||||
|
||||
if ("\n" !== $lc) {
|
||||
\array_splice($diff, $i + 1, 0, [["\n\\ No newline at end of file\n", Differ::NO_LINE_END_EOF_WARNING]]);
|
||||
}
|
||||
|
||||
if (!\count($toFind)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write hunks to output buffer
|
||||
|
||||
$cutOff = \max($this->commonLineThreshold, $this->contextLines);
|
||||
$hunkCapture = false;
|
||||
$sameCount = $toRange = $fromRange = 0;
|
||||
$toStart = $fromStart = 1;
|
||||
|
||||
foreach ($diff as $i => $entry) {
|
||||
if (0 === $entry[1]) { // same
|
||||
if (false === $hunkCapture) {
|
||||
++$fromStart;
|
||||
++$toStart;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
++$sameCount;
|
||||
++$toRange;
|
||||
++$fromRange;
|
||||
|
||||
if ($sameCount === $cutOff) {
|
||||
$contextStartOffset = ($hunkCapture - $this->contextLines) < 0
|
||||
? $hunkCapture
|
||||
: $this->contextLines
|
||||
;
|
||||
|
||||
// note: $contextEndOffset = $this->contextLines;
|
||||
//
|
||||
// because we never go beyond the end of the diff.
|
||||
// with the cutoff/contextlines here the follow is never true;
|
||||
//
|
||||
// if ($i - $cutOff + $this->contextLines + 1 > \count($diff)) {
|
||||
// $contextEndOffset = count($diff) - 1;
|
||||
// }
|
||||
//
|
||||
// ; that would be true for a trailing incomplete hunk case which is dealt with after this loop
|
||||
|
||||
$this->writeHunk(
|
||||
$diff,
|
||||
$hunkCapture - $contextStartOffset,
|
||||
$i - $cutOff + $this->contextLines + 1,
|
||||
$fromStart - $contextStartOffset,
|
||||
$fromRange - $cutOff + $contextStartOffset + $this->contextLines,
|
||||
$toStart - $contextStartOffset,
|
||||
$toRange - $cutOff + $contextStartOffset + $this->contextLines,
|
||||
$output
|
||||
);
|
||||
|
||||
$fromStart += $fromRange;
|
||||
$toStart += $toRange;
|
||||
|
||||
$hunkCapture = false;
|
||||
$sameCount = $toRange = $fromRange = 0;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$sameCount = 0;
|
||||
|
||||
if ($entry[1] === Differ::NO_LINE_END_EOF_WARNING) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->changed = true;
|
||||
|
||||
if (false === $hunkCapture) {
|
||||
$hunkCapture = $i;
|
||||
}
|
||||
|
||||
if (Differ::ADDED === $entry[1]) { // added
|
||||
++$toRange;
|
||||
}
|
||||
|
||||
if (Differ::REMOVED === $entry[1]) { // removed
|
||||
++$fromRange;
|
||||
}
|
||||
}
|
||||
|
||||
if (false === $hunkCapture) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we end here when cutoff (commonLineThreshold) was not reached, but we where capturing a hunk,
|
||||
// do not render hunk till end automatically because the number of context lines might be less than the commonLineThreshold
|
||||
|
||||
$contextStartOffset = $hunkCapture - $this->contextLines < 0
|
||||
? $hunkCapture
|
||||
: $this->contextLines
|
||||
;
|
||||
|
||||
// prevent trying to write out more common lines than there are in the diff _and_
|
||||
// do not write more than configured through the context lines
|
||||
$contextEndOffset = \min($sameCount, $this->contextLines);
|
||||
|
||||
$fromRange -= $sameCount;
|
||||
$toRange -= $sameCount;
|
||||
|
||||
$this->writeHunk(
|
||||
$diff,
|
||||
$hunkCapture - $contextStartOffset,
|
||||
$i - $sameCount + $contextEndOffset + 1,
|
||||
$fromStart - $contextStartOffset,
|
||||
$fromRange + $contextStartOffset + $contextEndOffset,
|
||||
$toStart - $contextStartOffset,
|
||||
$toRange + $contextStartOffset + $contextEndOffset,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
private function writeHunk(
|
||||
array $diff,
|
||||
int $diffStartIndex,
|
||||
int $diffEndIndex,
|
||||
int $fromStart,
|
||||
int $fromRange,
|
||||
int $toStart,
|
||||
int $toRange,
|
||||
$output
|
||||
): void {
|
||||
\fwrite($output, '@@ -' . $fromStart);
|
||||
|
||||
if (!$this->collapseRanges || 1 !== $fromRange) {
|
||||
\fwrite($output, ',' . $fromRange);
|
||||
}
|
||||
|
||||
\fwrite($output, ' +' . $toStart);
|
||||
|
||||
if (!$this->collapseRanges || 1 !== $toRange) {
|
||||
\fwrite($output, ',' . $toRange);
|
||||
}
|
||||
|
||||
\fwrite($output, " @@\n");
|
||||
|
||||
for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
|
||||
if ($diff[$i][1] === Differ::ADDED) {
|
||||
$this->changed = true;
|
||||
\fwrite($output, '+' . $diff[$i][0]);
|
||||
} elseif ($diff[$i][1] === Differ::REMOVED) {
|
||||
$this->changed = true;
|
||||
\fwrite($output, '-' . $diff[$i][0]);
|
||||
} elseif ($diff[$i][1] === Differ::OLD) {
|
||||
\fwrite($output, ' ' . $diff[$i][0]);
|
||||
} elseif ($diff[$i][1] === Differ::NO_LINE_END_EOF_WARNING) {
|
||||
$this->changed = true;
|
||||
\fwrite($output, $diff[$i][0]);
|
||||
}
|
||||
//} elseif ($diff[$i][1] === Differ::DIFF_LINE_END_WARNING) { // custom comment inserted by PHPUnit/diff package
|
||||
// skip
|
||||
//} else {
|
||||
// unknown/invalid
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,11 +10,28 @@
|
||||
|
||||
namespace SebastianBergmann\Diff\Output;
|
||||
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
|
||||
/**
|
||||
* Builds a diff string representation in unified diff format in chunks.
|
||||
*/
|
||||
final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $collapseRanges = true;
|
||||
|
||||
/**
|
||||
* @var int >= 0
|
||||
*/
|
||||
private $commonLineThreshold = 6;
|
||||
|
||||
/**
|
||||
* @var int >= 0
|
||||
*/
|
||||
private $contextLines = 3;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -37,89 +54,191 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
||||
|
||||
if ('' !== $this->header) {
|
||||
\fwrite($buffer, $this->header);
|
||||
|
||||
if ("\n" !== \substr($this->header, -1, 1)) {
|
||||
\fwrite($buffer, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeDiffChunked($buffer, $diff, $this->getCommonChunks($diff));
|
||||
if (0 !== \count($diff)) {
|
||||
$this->writeDiffHunks($buffer, $diff);
|
||||
}
|
||||
|
||||
$diff = \stream_get_contents($buffer, -1, 0);
|
||||
|
||||
\fclose($buffer);
|
||||
|
||||
return $diff;
|
||||
// If the last char is not a linebreak: add it.
|
||||
// This might happen when both the `from` and `to` do not have a trailing linebreak
|
||||
$last = \substr($diff, -1);
|
||||
|
||||
return "\n" !== $last && "\r" !== $last
|
||||
? $diff . "\n"
|
||||
: $diff
|
||||
;
|
||||
}
|
||||
|
||||
// `old` is an array with key => value pairs . Each pair represents a start and end index of `diff`
|
||||
// of a list of elements all containing `same` (0) entries.
|
||||
private function writeDiffChunked($output, array $diff, array $old)
|
||||
private function writeDiffHunks($output, array $diff): void
|
||||
{
|
||||
// detect "No newline at end of file" and insert into `$diff` if needed
|
||||
|
||||
$upperLimit = \count($diff);
|
||||
$start = 0;
|
||||
$fromStart = 0;
|
||||
$toStart = 0;
|
||||
|
||||
if (\count($old)) { // no common parts, list all diff entries
|
||||
\reset($old);
|
||||
if (0 === $diff[$upperLimit - 1][1]) {
|
||||
$lc = \substr($diff[$upperLimit - 1][0], -1);
|
||||
|
||||
// iterate the diff, go from chunk to chunk skipping common chunk of lines between those
|
||||
do {
|
||||
$commonStart = \key($old);
|
||||
$commonEnd = \current($old);
|
||||
if ("\n" !== $lc) {
|
||||
\array_splice($diff, $upperLimit, 0, [["\n\\ No newline at end of file\n", Differ::NO_LINE_END_EOF_WARNING]]);
|
||||
}
|
||||
} else {
|
||||
// search back for the last `+` and `-` line,
|
||||
// check if has trailing linebreak, else add under it warning under it
|
||||
$toFind = [1 => true, 2 => true];
|
||||
|
||||
if ($commonStart !== $start) {
|
||||
list($fromRange, $toRange) = $this->getChunkRange($diff, $start, $commonStart);
|
||||
$this->writeChunk($output, $diff, $start, $commonStart, $fromStart, $fromRange, $toStart, $toRange);
|
||||
for ($i = $upperLimit - 1; $i >= 0; --$i) {
|
||||
if (isset($toFind[$diff[$i][1]])) {
|
||||
unset($toFind[$diff[$i][1]]);
|
||||
$lc = \substr($diff[$i][0], -1);
|
||||
|
||||
$fromStart += $fromRange;
|
||||
$toStart += $toRange;
|
||||
if ("\n" !== $lc) {
|
||||
\array_splice($diff, $i + 1, 0, [["\n\\ No newline at end of file\n", Differ::NO_LINE_END_EOF_WARNING]]);
|
||||
}
|
||||
|
||||
if (!\count($toFind)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$start = $commonEnd + 1;
|
||||
$commonLength = $commonEnd - $commonStart + 1; // calculate number of non-change lines in the common part
|
||||
$fromStart += $commonLength;
|
||||
$toStart += $commonLength;
|
||||
} while (false !== \next($old));
|
||||
|
||||
\end($old); // short cut for finding possible last `change entry`
|
||||
$tmp = \key($old);
|
||||
\reset($old);
|
||||
if ($old[$tmp] === $upperLimit - 1) {
|
||||
$upperLimit = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if ($start < $upperLimit - 1) { // check for trailing (non) diff entries
|
||||
do {
|
||||
--$upperLimit;
|
||||
} while (isset($diff[$upperLimit][1]) && $diff[$upperLimit][1] === 0);
|
||||
++$upperLimit;
|
||||
// write hunks to output buffer
|
||||
|
||||
list($fromRange, $toRange) = $this->getChunkRange($diff, $start, $upperLimit);
|
||||
$this->writeChunk($output, $diff, $start, $upperLimit, $fromStart, $fromRange, $toStart, $toRange);
|
||||
$cutOff = \max($this->commonLineThreshold, $this->contextLines);
|
||||
$hunkCapture = false;
|
||||
$sameCount = $toRange = $fromRange = 0;
|
||||
$toStart = $fromStart = 1;
|
||||
|
||||
foreach ($diff as $i => $entry) {
|
||||
if (0 === $entry[1]) { // same
|
||||
if (false === $hunkCapture) {
|
||||
++$fromStart;
|
||||
++$toStart;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
++$sameCount;
|
||||
++$toRange;
|
||||
++$fromRange;
|
||||
|
||||
if ($sameCount === $cutOff) {
|
||||
$contextStartOffset = ($hunkCapture - $this->contextLines) < 0
|
||||
? $hunkCapture
|
||||
: $this->contextLines
|
||||
;
|
||||
|
||||
// note: $contextEndOffset = $this->contextLines;
|
||||
//
|
||||
// because we never go beyond the end of the diff.
|
||||
// with the cutoff/contextlines here the follow is never true;
|
||||
//
|
||||
// if ($i - $cutOff + $this->contextLines + 1 > \count($diff)) {
|
||||
// $contextEndOffset = count($diff) - 1;
|
||||
// }
|
||||
//
|
||||
// ; that would be true for a trailing incomplete hunk case which is dealt with after this loop
|
||||
|
||||
$this->writeHunk(
|
||||
$diff,
|
||||
$hunkCapture - $contextStartOffset,
|
||||
$i - $cutOff + $this->contextLines + 1,
|
||||
$fromStart - $contextStartOffset,
|
||||
$fromRange - $cutOff + $contextStartOffset + $this->contextLines,
|
||||
$toStart - $contextStartOffset,
|
||||
$toRange - $cutOff + $contextStartOffset + $this->contextLines,
|
||||
$output
|
||||
);
|
||||
|
||||
$fromStart += $fromRange;
|
||||
$toStart += $toRange;
|
||||
|
||||
$hunkCapture = false;
|
||||
$sameCount = $toRange = $fromRange = 0;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$sameCount = 0;
|
||||
|
||||
if ($entry[1] === Differ::NO_LINE_END_EOF_WARNING) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false === $hunkCapture) {
|
||||
$hunkCapture = $i;
|
||||
}
|
||||
|
||||
if (Differ::ADDED === $entry[1]) {
|
||||
++$toRange;
|
||||
}
|
||||
|
||||
if (Differ::REMOVED === $entry[1]) {
|
||||
++$fromRange;
|
||||
}
|
||||
}
|
||||
|
||||
if (false === $hunkCapture) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we end here when cutoff (commonLineThreshold) was not reached, but we where capturing a hunk,
|
||||
// do not render hunk till end automatically because the number of context lines might be less than the commonLineThreshold
|
||||
|
||||
$contextStartOffset = $hunkCapture - $this->contextLines < 0
|
||||
? $hunkCapture
|
||||
: $this->contextLines
|
||||
;
|
||||
|
||||
// prevent trying to write out more common lines than there are in the diff _and_
|
||||
// do not write more than configured through the context lines
|
||||
$contextEndOffset = \min($sameCount, $this->contextLines);
|
||||
|
||||
$fromRange -= $sameCount;
|
||||
$toRange -= $sameCount;
|
||||
|
||||
$this->writeHunk(
|
||||
$diff,
|
||||
$hunkCapture - $contextStartOffset,
|
||||
$i - $sameCount + $contextEndOffset + 1,
|
||||
$fromStart - $contextStartOffset,
|
||||
$fromRange + $contextStartOffset + $contextEndOffset,
|
||||
$toStart - $contextStartOffset,
|
||||
$toRange + $contextStartOffset + $contextEndOffset,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
private function writeChunk(
|
||||
$output,
|
||||
private function writeHunk(
|
||||
array $diff,
|
||||
int $diffStartIndex,
|
||||
int $diffEndIndex,
|
||||
int $fromStart,
|
||||
int $fromRange,
|
||||
int $toStart,
|
||||
int $toRange
|
||||
) {
|
||||
int $toRange,
|
||||
$output
|
||||
): void {
|
||||
if ($this->addLineNumbers) {
|
||||
\fwrite($output, '@@ -' . (1 + $fromStart));
|
||||
\fwrite($output, '@@ -' . $fromStart);
|
||||
|
||||
if ($fromRange > 1) {
|
||||
if (!$this->collapseRanges || 1 !== $fromRange) {
|
||||
\fwrite($output, ',' . $fromRange);
|
||||
}
|
||||
|
||||
\fwrite($output, ' +' . (1 + $toStart));
|
||||
if ($toRange > 1) {
|
||||
\fwrite($output, ' +' . $toStart);
|
||||
|
||||
if (!$this->collapseRanges || 1 !== $toRange) {
|
||||
\fwrite($output, ',' . $toRange);
|
||||
}
|
||||
|
||||
@@ -129,37 +248,17 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
||||
}
|
||||
|
||||
for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
|
||||
if ($diff[$i][1] === 1 /* ADDED */) {
|
||||
if ($diff[$i][1] === Differ::ADDED) {
|
||||
\fwrite($output, '+' . $diff[$i][0]);
|
||||
} elseif ($diff[$i][1] === 2 /* REMOVED */) {
|
||||
} elseif ($diff[$i][1] === Differ::REMOVED) {
|
||||
\fwrite($output, '-' . $diff[$i][0]);
|
||||
} else { /* Not changed (old) 0 or Warning 3 */
|
||||
} elseif ($diff[$i][1] === Differ::OLD) {
|
||||
\fwrite($output, ' ' . $diff[$i][0]);
|
||||
} elseif ($diff[$i][1] === Differ::NO_LINE_END_EOF_WARNING) {
|
||||
\fwrite($output, "\n"); // $diff[$i][0]
|
||||
} else { /* Not changed (old) Differ::OLD or Warning Differ::DIFF_LINE_END_WARNING */
|
||||
\fwrite($output, ' ' . $diff[$i][0]);
|
||||
}
|
||||
|
||||
$lc = \substr($diff[$i][0], -1);
|
||||
if ($lc !== "\n" && $lc !== "\r") {
|
||||
\fwrite($output, "\n"); // \No newline at end of file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getChunkRange(array $diff, int $diffStartIndex, int $diffEndIndex): array
|
||||
{
|
||||
$toRange = 0;
|
||||
$fromRange = 0;
|
||||
|
||||
for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
|
||||
if ($diff[$i][1] === 1) { // added
|
||||
++$toRange;
|
||||
} elseif ($diff[$i][1] === 2) { // removed
|
||||
++$fromRange;
|
||||
} elseif ($diff[$i][1] === 0) { // same
|
||||
++$fromRange;
|
||||
++$toRange;
|
||||
}
|
||||
}
|
||||
|
||||
return [$fromRange, $toRange];
|
||||
}
|
||||
}
|
||||
|
2
vendor/sebastian/diff/src/Parser.php
vendored
2
vendor/sebastian/diff/src/Parser.php
vendored
@@ -64,7 +64,7 @@ final class Parser
|
||||
return $diffs;
|
||||
}
|
||||
|
||||
private function parseFileDiff(Diff $diff, array $lines)
|
||||
private function parseFileDiff(Diff $diff, array $lines): void
|
||||
{
|
||||
$chunks = [];
|
||||
$chunk = null;
|
||||
|
16
vendor/sebastian/diff/tests/ChunkTest.php
vendored
16
vendor/sebastian/diff/tests/ChunkTest.php
vendored
@@ -22,42 +22,42 @@ final class ChunkTest extends TestCase
|
||||
*/
|
||||
private $chunk;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->chunk = new Chunk;
|
||||
}
|
||||
|
||||
public function testCanBeCreatedWithoutArguments()
|
||||
public function testCanBeCreatedWithoutArguments(): void
|
||||
{
|
||||
$this->assertInstanceOf(Chunk::class, $this->chunk);
|
||||
}
|
||||
|
||||
public function testStartCanBeRetrieved()
|
||||
public function testStartCanBeRetrieved(): void
|
||||
{
|
||||
$this->assertSame(0, $this->chunk->getStart());
|
||||
}
|
||||
|
||||
public function testStartRangeCanBeRetrieved()
|
||||
public function testStartRangeCanBeRetrieved(): void
|
||||
{
|
||||
$this->assertSame(1, $this->chunk->getStartRange());
|
||||
}
|
||||
|
||||
public function testEndCanBeRetrieved()
|
||||
public function testEndCanBeRetrieved(): void
|
||||
{
|
||||
$this->assertSame(0, $this->chunk->getEnd());
|
||||
}
|
||||
|
||||
public function testEndRangeCanBeRetrieved()
|
||||
public function testEndRangeCanBeRetrieved(): void
|
||||
{
|
||||
$this->assertSame(1, $this->chunk->getEndRange());
|
||||
}
|
||||
|
||||
public function testLinesCanBeRetrieved()
|
||||
public function testLinesCanBeRetrieved(): void
|
||||
{
|
||||
$this->assertSame([], $this->chunk->getLines());
|
||||
}
|
||||
|
||||
public function testLinesCanBeSet()
|
||||
public function testLinesCanBeSet(): void
|
||||
{
|
||||
$this->assertSame([], $this->chunk->getLines());
|
||||
|
||||
|
6
vendor/sebastian/diff/tests/DiffTest.php
vendored
6
vendor/sebastian/diff/tests/DiffTest.php
vendored
@@ -19,7 +19,7 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class DiffTest extends TestCase
|
||||
{
|
||||
public function testGettersAfterConstructionWithDefault()
|
||||
public function testGettersAfterConstructionWithDefault(): void
|
||||
{
|
||||
$from = 'line1a';
|
||||
$to = 'line2a';
|
||||
@@ -30,7 +30,7 @@ final class DiffTest extends TestCase
|
||||
$this->assertSame([], $diff->getChunks(), 'Expect chunks to be default value "array()".');
|
||||
}
|
||||
|
||||
public function testGettersAfterConstructionWithChunks()
|
||||
public function testGettersAfterConstructionWithChunks(): void
|
||||
{
|
||||
$from = 'line1b';
|
||||
$to = 'line2b';
|
||||
@@ -43,7 +43,7 @@ final class DiffTest extends TestCase
|
||||
$this->assertSame($chunks, $diff->getChunks(), 'Expect chunks to be passed value.');
|
||||
}
|
||||
|
||||
public function testSetChunksAfterConstruction()
|
||||
public function testSetChunksAfterConstruction(): void
|
||||
{
|
||||
$diff = new Diff('line1c', 'line2c');
|
||||
$this->assertSame([], $diff->getChunks(), 'Expect chunks to be default value "array()".');
|
||||
|
806
vendor/sebastian/diff/tests/DifferTest.php
vendored
806
vendor/sebastian/diff/tests/DifferTest.php
vendored
File diff suppressed because it is too large
Load Diff
83
vendor/sebastian/diff/tests/DifferTestTest.php
vendored
83
vendor/sebastian/diff/tests/DifferTestTest.php
vendored
@@ -1,83 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @requires OS Linux
|
||||
*/
|
||||
final class DifferTestTest extends TestCase
|
||||
{
|
||||
private $fileFrom;
|
||||
private $filePatch;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$dir = \realpath(__DIR__ . '/../') . '/';
|
||||
$this->fileFrom = $dir . 'from.txt';
|
||||
$this->filePatch = $dir . 'patch.txt';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDiffWithLineNumbers
|
||||
*/
|
||||
public function testTheTestProvideDiffWithLineNumbers($expected, $from, $to)
|
||||
{
|
||||
$this->runThisTest($expected, $from, $to);
|
||||
}
|
||||
|
||||
public function provideDiffWithLineNumbers()
|
||||
{
|
||||
require_once __DIR__ . '/DifferTest.php';
|
||||
$test = new DifferTest();
|
||||
$tests = $test->provideDiffWithLineNumbers();
|
||||
|
||||
$tests = \array_filter(
|
||||
$tests,
|
||||
function ($key) {
|
||||
return !\is_string($key) || false === \strpos($key, 'non_patch_compat');
|
||||
},
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
private function runThisTest(string $expected, string $from, string $to)
|
||||
{
|
||||
$expected = \str_replace('--- Original', '--- from.txt', $expected);
|
||||
$expected = \str_replace('+++ New', '+++ from.txt', $expected);
|
||||
|
||||
@\unlink($this->fileFrom);
|
||||
@\unlink($this->filePatch);
|
||||
|
||||
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
|
||||
$this->assertNotFalse(\file_put_contents($this->filePatch, $expected));
|
||||
|
||||
$command = \sprintf(
|
||||
'patch -u --verbose %s < %s', // --posix
|
||||
\escapeshellarg($this->fileFrom),
|
||||
\escapeshellarg($this->filePatch)
|
||||
);
|
||||
|
||||
\exec($command, $output, $d);
|
||||
|
||||
$this->assertSame(0, $d, \sprintf('%s | %s', $command, \implode("\n", $output)));
|
||||
|
||||
$patched = \file_get_contents($this->fileFrom);
|
||||
$this->assertSame($patched, $to);
|
||||
|
||||
@\unlink($this->fileFrom . '.orig');
|
||||
@\unlink($this->fileFrom);
|
||||
@\unlink($this->filePatch);
|
||||
}
|
||||
}
|
41
vendor/sebastian/diff/tests/Exception/ConfigurationExceptionTest.php
vendored
Normal file
41
vendor/sebastian/diff/tests/Exception/ConfigurationExceptionTest.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\ConfigurationException
|
||||
*/
|
||||
final class ConfigurationExceptionTest extends TestCase
|
||||
{
|
||||
public function testConstructWithDefaults(): void
|
||||
{
|
||||
$e = new ConfigurationException('test', 'A', 'B');
|
||||
|
||||
$this->assertSame(0, $e->getCode());
|
||||
$this->assertNull($e->getPrevious());
|
||||
$this->assertSame('Option "test" must be A, got "string#B".', $e->getMessage());
|
||||
}
|
||||
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$e = new ConfigurationException(
|
||||
'test',
|
||||
'integer',
|
||||
new \SplFileInfo(__FILE__),
|
||||
789,
|
||||
new \BadMethodCallException(__METHOD__)
|
||||
);
|
||||
|
||||
$this->assertSame('Option "test" must be integer, got "SplFileInfo".', $e->getMessage());
|
||||
}
|
||||
}
|
33
vendor/sebastian/diff/tests/Exception/InvalidArgumentExceptionTest.php
vendored
Normal file
33
vendor/sebastian/diff/tests/Exception/InvalidArgumentExceptionTest.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\InvalidArgumentException
|
||||
*/
|
||||
final class InvalidArgumentExceptionTest extends TestCase
|
||||
{
|
||||
public function testInvalidArgumentException(): void
|
||||
{
|
||||
$previousException = new \LogicException();
|
||||
$message = 'test';
|
||||
$code = 123;
|
||||
|
||||
$exception = new InvalidArgumentException($message, $code, $previousException);
|
||||
|
||||
$this->assertInstanceOf(Exception::class, $exception);
|
||||
$this->assertSame($message, $exception->getMessage());
|
||||
$this->assertSame($code, $exception->getCode());
|
||||
$this->assertSame($previousException, $exception->getPrevious());
|
||||
}
|
||||
}
|
8
vendor/sebastian/diff/tests/LineTest.php
vendored
8
vendor/sebastian/diff/tests/LineTest.php
vendored
@@ -22,22 +22,22 @@ final class LineTest extends TestCase
|
||||
*/
|
||||
private $line;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->line = new Line;
|
||||
}
|
||||
|
||||
public function testCanBeCreatedWithoutArguments()
|
||||
public function testCanBeCreatedWithoutArguments(): void
|
||||
{
|
||||
$this->assertInstanceOf(Line::class, $this->line);
|
||||
}
|
||||
|
||||
public function testTypeCanBeRetrieved()
|
||||
public function testTypeCanBeRetrieved(): void
|
||||
{
|
||||
$this->assertSame(Line::UNCHANGED, $this->line->getType());
|
||||
}
|
||||
|
||||
public function testContentCanBeRetrieved()
|
||||
public function testContentCanBeRetrieved(): void
|
||||
{
|
||||
$this->assertSame('', $this->line->getContent());
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
*/
|
||||
private $stress_sizes = [1, 2, 3, 100, 500, 1000, 2000];
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->memoryLimit = \ini_get('memory_limit');
|
||||
\ini_set('memory_limit', '256M');
|
||||
@@ -40,17 +40,12 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
$this->implementation = $this->createImplementation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LongestCommonSubsequenceCalculator
|
||||
*/
|
||||
abstract protected function createImplementation();
|
||||
|
||||
protected function tearDown()
|
||||
protected function tearDown(): void
|
||||
{
|
||||
\ini_set('memory_limit', $this->memoryLimit);
|
||||
}
|
||||
|
||||
public function testBothEmpty()
|
||||
public function testBothEmpty(): void
|
||||
{
|
||||
$from = [];
|
||||
$to = [];
|
||||
@@ -59,11 +54,11 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
$this->assertSame([], $common);
|
||||
}
|
||||
|
||||
public function testIsStrictComparison()
|
||||
public function testIsStrictComparison(): void
|
||||
{
|
||||
$from = [
|
||||
false, 0, 0.0, '', null, [],
|
||||
true, 1, 1.0, 'foo', ['foo', 'bar'], ['foo' => 'bar']
|
||||
true, 1, 1.0, 'foo', ['foo', 'bar'], ['foo' => 'bar'],
|
||||
];
|
||||
$to = $from;
|
||||
$common = $this->implementation->calculate($from, $to);
|
||||
@@ -72,7 +67,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
|
||||
$to = [
|
||||
false, false, false, false, false, false,
|
||||
true, true, true, true, true, true
|
||||
true, true, true, true, true, true,
|
||||
];
|
||||
|
||||
$expected = [
|
||||
@@ -85,7 +80,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
$this->assertSame($expected, $common);
|
||||
}
|
||||
|
||||
public function testEqualSequences()
|
||||
public function testEqualSequences(): void
|
||||
{
|
||||
foreach ($this->stress_sizes as $size) {
|
||||
$range = \range(1, $size);
|
||||
@@ -97,7 +92,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testDistinctSequences()
|
||||
public function testDistinctSequences(): void
|
||||
{
|
||||
$from = ['A'];
|
||||
$to = ['B'];
|
||||
@@ -117,7 +112,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testCommonSubsequence()
|
||||
public function testCommonSubsequence(): void
|
||||
{
|
||||
$from = ['A', 'C', 'E', 'F', 'G'];
|
||||
$to = ['A', 'B', 'D', 'E', 'H'];
|
||||
@@ -141,7 +136,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testSingleElementSubsequenceAtStart()
|
||||
public function testSingleElementSubsequenceAtStart(): void
|
||||
{
|
||||
foreach ($this->stress_sizes as $size) {
|
||||
$from = \range(1, $size);
|
||||
@@ -152,7 +147,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testSingleElementSubsequenceAtMiddle()
|
||||
public function testSingleElementSubsequenceAtMiddle(): void
|
||||
{
|
||||
foreach ($this->stress_sizes as $size) {
|
||||
$from = \range(1, $size);
|
||||
@@ -163,7 +158,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testSingleElementSubsequenceAtEnd()
|
||||
public function testSingleElementSubsequenceAtEnd(): void
|
||||
{
|
||||
foreach ($this->stress_sizes as $size) {
|
||||
$from = \range(1, $size);
|
||||
@@ -174,7 +169,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testReversedSequences()
|
||||
public function testReversedSequences(): void
|
||||
{
|
||||
$from = ['A', 'B'];
|
||||
$to = ['B', 'A'];
|
||||
@@ -191,11 +186,16 @@ abstract class LongestCommonSubsequenceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testStrictTypeCalculate()
|
||||
public function testStrictTypeCalculate(): void
|
||||
{
|
||||
$diff = $this->implementation->calculate(['5'], ['05']);
|
||||
|
||||
$this->assertInternalType('array', $diff);
|
||||
$this->assertCount(0, $diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LongestCommonSubsequenceCalculator
|
||||
*/
|
||||
abstract protected function createImplementation(): LongestCommonSubsequenceCalculator;
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ namespace SebastianBergmann\Diff;
|
||||
*/
|
||||
final class MemoryEfficientImplementationTest extends LongestCommonSubsequenceTest
|
||||
{
|
||||
protected function createImplementation()
|
||||
protected function createImplementation(): LongestCommonSubsequenceCalculator
|
||||
{
|
||||
return new MemoryEfficientLongestCommonSubsequenceCalculator;
|
||||
}
|
||||
|
152
vendor/sebastian/diff/tests/Output/AbstractChunkOutputBuilderTest.php
vendored
Normal file
152
vendor/sebastian/diff/tests/Output/AbstractChunkOutputBuilderTest.php
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\Output\AbstractChunkOutputBuilder
|
||||
*
|
||||
* @uses SebastianBergmann\Diff\Differ
|
||||
* @uses SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder
|
||||
* @uses SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator
|
||||
*/
|
||||
final class AbstractChunkOutputBuilderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param array $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param int $lineThreshold
|
||||
*
|
||||
* @dataProvider provideGetCommonChunks
|
||||
*/
|
||||
public function testGetCommonChunks(array $expected, string $from, string $to, int $lineThreshold = 5): void
|
||||
{
|
||||
$output = new class extends AbstractChunkOutputBuilder {
|
||||
public function getDiff(array $diff): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getChunks(array $diff, $lineThreshold)
|
||||
{
|
||||
return $this->getCommonChunks($diff, $lineThreshold);
|
||||
}
|
||||
};
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$output->getChunks((new Differ)->diffToArray($from, $to), $lineThreshold)
|
||||
);
|
||||
}
|
||||
|
||||
public function provideGetCommonChunks(): array
|
||||
{
|
||||
return[
|
||||
'same (with default threshold)' => [
|
||||
[],
|
||||
'A',
|
||||
'A',
|
||||
],
|
||||
'same (threshold 0)' => [
|
||||
[0 => 0],
|
||||
'A',
|
||||
'A',
|
||||
0,
|
||||
],
|
||||
'empty' => [
|
||||
[],
|
||||
'',
|
||||
'',
|
||||
],
|
||||
'single line diff' => [
|
||||
[],
|
||||
'A',
|
||||
'B',
|
||||
],
|
||||
'below threshold I' => [
|
||||
[],
|
||||
"A\nX\nC",
|
||||
"A\nB\nC",
|
||||
],
|
||||
'below threshold II' => [
|
||||
[],
|
||||
"A\n\n\n\nX\nC",
|
||||
"A\n\n\n\nB\nC",
|
||||
],
|
||||
'below threshold III' => [
|
||||
[0 => 5],
|
||||
"A\n\n\n\n\n\nB",
|
||||
"A\n\n\n\n\n\nA",
|
||||
],
|
||||
'same start' => [
|
||||
[0 => 5],
|
||||
"A\n\n\n\n\n\nX\nC",
|
||||
"A\n\n\n\n\n\nB\nC",
|
||||
],
|
||||
'same start long' => [
|
||||
[0 => 13],
|
||||
"\n\n\n\n\n\n\n\n\n\n\n\n\n\nA",
|
||||
"\n\n\n\n\n\n\n\n\n\n\n\n\n\nB",
|
||||
],
|
||||
'same part in between' => [
|
||||
[2 => 8],
|
||||
"A\n\n\n\n\n\n\nX\nY\nZ\n\n",
|
||||
"B\n\n\n\n\n\n\nX\nA\nZ\n\n",
|
||||
],
|
||||
'same trailing' => [
|
||||
[2 => 14],
|
||||
"A\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
|
||||
"B\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
|
||||
],
|
||||
'same part in between, same trailing' => [
|
||||
[2 => 7, 10 => 15],
|
||||
"A\n\n\n\n\n\n\nA\n\n\n\n\n\n\n",
|
||||
"B\n\n\n\n\n\n\nB\n\n\n\n\n\n\n",
|
||||
],
|
||||
'below custom threshold I' => [
|
||||
[],
|
||||
"A\n\nB",
|
||||
"A\n\nD",
|
||||
2,
|
||||
],
|
||||
'custom threshold I' => [
|
||||
[0 => 1],
|
||||
"A\n\nB",
|
||||
"A\n\nD",
|
||||
1,
|
||||
],
|
||||
'custom threshold II' => [
|
||||
[],
|
||||
"A\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
|
||||
"A\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
|
||||
19,
|
||||
],
|
||||
[
|
||||
[3 => 9],
|
||||
"a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk",
|
||||
"a\np\nc\nd\ne\nf\ng\nh\ni\nw\nk",
|
||||
],
|
||||
[
|
||||
[0 => 5, 8 => 13],
|
||||
"A\nA\nA\nA\nA\nA\nX\nC\nC\nC\nC\nC\nC",
|
||||
"A\nA\nA\nA\nA\nA\nB\nC\nC\nC\nC\nC\nC",
|
||||
],
|
||||
[
|
||||
[0 => 5, 8 => 13],
|
||||
"A\nA\nA\nA\nA\nA\nX\nC\nC\nC\nC\nC\nC\nX",
|
||||
"A\nA\nA\nA\nA\nA\nB\nC\nC\nC\nC\nC\nC\nY",
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
76
vendor/sebastian/diff/tests/Output/DiffOnlyOutputBuilderTest.php
vendored
Normal file
76
vendor/sebastian/diff/tests/Output/DiffOnlyOutputBuilderTest.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\Output\DiffOnlyOutputBuilder
|
||||
*
|
||||
* @uses SebastianBergmann\Diff\Differ
|
||||
* @uses SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator
|
||||
*/
|
||||
final class DiffOnlyOutputBuilderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param string $header
|
||||
*
|
||||
* @dataProvider textForNoNonDiffLinesProvider
|
||||
*/
|
||||
public function testDiffDoNotShowNonDiffLines(string $expected, string $from, string $to, string $header = ''): void
|
||||
{
|
||||
$differ = new Differ(new DiffOnlyOutputBuilder($header));
|
||||
|
||||
$this->assertSame($expected, $differ->diff($from, $to));
|
||||
}
|
||||
|
||||
public function textForNoNonDiffLinesProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
" #Warning: Strings contain different line endings!\n-A\r\n+B\n",
|
||||
"A\r\n",
|
||||
"B\n",
|
||||
],
|
||||
[
|
||||
"-A\n+B\n",
|
||||
"\nA",
|
||||
"\nB",
|
||||
],
|
||||
[
|
||||
'',
|
||||
'a',
|
||||
'a',
|
||||
],
|
||||
[
|
||||
"-A\n+C\n",
|
||||
"A\n\n\nB",
|
||||
"C\n\n\nB",
|
||||
],
|
||||
[
|
||||
"header\n",
|
||||
'a',
|
||||
'a',
|
||||
'header',
|
||||
],
|
||||
[
|
||||
"header\n",
|
||||
'a',
|
||||
'a',
|
||||
"header\n",
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
299
vendor/sebastian/diff/tests/Output/Integration/StrictUnifiedDiffOutputBuilderIntegrationTest.php
vendored
Normal file
299
vendor/sebastian/diff/tests/Output/Integration/StrictUnifiedDiffOutputBuilderIntegrationTest.php
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
use SebastianBergmann\Diff\Utils\FileUtils;
|
||||
use SebastianBergmann\Diff\Utils\UnifiedDiffAssertTrait;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder
|
||||
*
|
||||
* @uses SebastianBergmann\Diff\Differ
|
||||
* @uses SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator
|
||||
*
|
||||
* @requires OS Linux
|
||||
*/
|
||||
final class StrictUnifiedDiffOutputBuilderIntegrationTest extends TestCase
|
||||
{
|
||||
use UnifiedDiffAssertTrait;
|
||||
|
||||
private $dir;
|
||||
|
||||
private $fileFrom;
|
||||
|
||||
private $fileTo;
|
||||
|
||||
private $filePatch;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->dir = \realpath(__DIR__ . '/../../fixtures/out') . '/';
|
||||
$this->fileFrom = $this->dir . 'from.txt';
|
||||
$this->fileTo = $this->dir . 'to.txt';
|
||||
$this->filePatch = $this->dir . 'diff.patch';
|
||||
|
||||
if (!\is_dir($this->dir)) {
|
||||
throw new \RuntimeException('Integration test working directory not found.');
|
||||
}
|
||||
|
||||
$this->cleanUpTempFiles();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->cleanUpTempFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Integration test
|
||||
*
|
||||
* - get a file pair
|
||||
* - create a `diff` between the files
|
||||
* - test applying the diff using `git apply`
|
||||
* - test applying the diff using `patch`
|
||||
*
|
||||
* @param string $fileFrom
|
||||
* @param string $fileTo
|
||||
*
|
||||
* @dataProvider provideFilePairs
|
||||
*/
|
||||
public function testIntegrationUsingPHPFileInVendorGitApply(string $fileFrom, string $fileTo): void
|
||||
{
|
||||
$from = FileUtils::getFileContent($fileFrom);
|
||||
$to = FileUtils::getFileContent($fileTo);
|
||||
|
||||
$diff = (new Differ(new StrictUnifiedDiffOutputBuilder(['fromFile' => 'Original', 'toFile' => 'New'])))->diff($from, $to);
|
||||
|
||||
if ('' === $diff && $from === $to) {
|
||||
// odd case: test after executing as it is more efficient than to read the files and check the contents every time
|
||||
$this->addToAssertionCount(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->doIntegrationTestGitApply($diff, $from, $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Integration test
|
||||
*
|
||||
* - get a file pair
|
||||
* - create a `diff` between the files
|
||||
* - test applying the diff using `git apply`
|
||||
* - test applying the diff using `patch`
|
||||
*
|
||||
* @param string $fileFrom
|
||||
* @param string $fileTo
|
||||
*
|
||||
* @dataProvider provideFilePairs
|
||||
*/
|
||||
public function testIntegrationUsingPHPFileInVendorPatch(string $fileFrom, string $fileTo): void
|
||||
{
|
||||
$from = FileUtils::getFileContent($fileFrom);
|
||||
$to = FileUtils::getFileContent($fileTo);
|
||||
|
||||
$diff = (new Differ(new StrictUnifiedDiffOutputBuilder(['fromFile' => 'Original', 'toFile' => 'New'])))->diff($from, $to);
|
||||
|
||||
if ('' === $diff && $from === $to) {
|
||||
// odd case: test after executing as it is more efficient than to read the files and check the contents every time
|
||||
$this->addToAssertionCount(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->doIntegrationTestPatch($diff, $from, $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
*
|
||||
* @dataProvider provideOutputBuildingCases
|
||||
* @dataProvider provideSample
|
||||
* @dataProvider provideBasicDiffGeneration
|
||||
*/
|
||||
public function testIntegrationOfUnitTestCasesGitApply(string $expected, string $from, string $to): void
|
||||
{
|
||||
$this->doIntegrationTestGitApply($expected, $from, $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
*
|
||||
* @dataProvider provideOutputBuildingCases
|
||||
* @dataProvider provideSample
|
||||
* @dataProvider provideBasicDiffGeneration
|
||||
*/
|
||||
public function testIntegrationOfUnitTestCasesPatch(string $expected, string $from, string $to): void
|
||||
{
|
||||
$this->doIntegrationTestPatch($expected, $from, $to);
|
||||
}
|
||||
|
||||
public function provideOutputBuildingCases(): array
|
||||
{
|
||||
return StrictUnifiedDiffOutputBuilderDataProvider::provideOutputBuildingCases();
|
||||
}
|
||||
|
||||
public function provideSample(): array
|
||||
{
|
||||
return StrictUnifiedDiffOutputBuilderDataProvider::provideSample();
|
||||
}
|
||||
|
||||
public function provideBasicDiffGeneration(): array
|
||||
{
|
||||
return StrictUnifiedDiffOutputBuilderDataProvider::provideBasicDiffGeneration();
|
||||
}
|
||||
|
||||
public function provideFilePairs(): array
|
||||
{
|
||||
$cases = [];
|
||||
$fromFile = __FILE__;
|
||||
$vendorDir = \realpath(__DIR__ . '/../../../vendor');
|
||||
|
||||
$fileIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($vendorDir, \RecursiveDirectoryIterator::SKIP_DOTS));
|
||||
|
||||
/** @var \SplFileInfo $file */
|
||||
foreach ($fileIterator as $file) {
|
||||
if ('php' !== $file->getExtension()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$toFile = $file->getPathname();
|
||||
$cases[\sprintf("Diff file:\n\"%s\"\nvs.\n\"%s\"\n", \realpath($fromFile), \realpath($toFile))] = [$fromFile, $toFile];
|
||||
$fromFile = $toFile;
|
||||
}
|
||||
|
||||
return $cases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare diff create by builder and against one create by `diff` command.
|
||||
*
|
||||
* @param string $diff
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
*
|
||||
* @dataProvider provideBasicDiffGeneration
|
||||
*/
|
||||
public function testIntegrationDiffOutputBuilderVersusDiffCommand(string $diff, string $from, string $to): void
|
||||
{
|
||||
$this->assertNotSame('', $diff);
|
||||
$this->assertValidUnifiedDiffFormat($diff);
|
||||
|
||||
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
|
||||
$this->assertNotFalse(\file_put_contents($this->fileTo, $to));
|
||||
|
||||
$p = new Process(\sprintf('diff -u %s %s', \escapeshellarg($this->fileFrom), \escapeshellarg($this->fileTo)));
|
||||
$p->run();
|
||||
$this->assertSame(1, $p->getExitCode()); // note: Process assumes exit code 0 for `isSuccessful`, however `diff` uses the exit code `1` for success with diff
|
||||
|
||||
$output = $p->getOutput();
|
||||
|
||||
$diffLines = \preg_split('/(.*\R)/', $diff, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$diffLines[0] = \preg_replace('#^\-\-\- .*#', '--- /' . $this->fileFrom, $diffLines[0], 1);
|
||||
$diffLines[1] = \preg_replace('#^\+\+\+ .*#', '+++ /' . $this->fileFrom, $diffLines[1], 1);
|
||||
$diff = \implode('', $diffLines);
|
||||
|
||||
$outputLines = \preg_split('/(.*\R)/', $output, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$outputLines[0] = \preg_replace('#^\-\-\- .*#', '--- /' . $this->fileFrom, $outputLines[0], 1);
|
||||
$outputLines[1] = \preg_replace('#^\+\+\+ .*#', '+++ /' . $this->fileFrom, $outputLines[1], 1);
|
||||
$output = \implode('', $outputLines);
|
||||
|
||||
$this->assertSame($diff, $output);
|
||||
}
|
||||
|
||||
private function doIntegrationTestGitApply(string $diff, string $from, string $to): void
|
||||
{
|
||||
$this->assertNotSame('', $diff);
|
||||
$this->assertValidUnifiedDiffFormat($diff);
|
||||
|
||||
$diff = self::setDiffFileHeader($diff, $this->fileFrom);
|
||||
|
||||
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
|
||||
$this->assertNotFalse(\file_put_contents($this->filePatch, $diff));
|
||||
|
||||
$p = new Process(\sprintf(
|
||||
'git --git-dir %s apply --check -v --unsafe-paths --ignore-whitespace %s',
|
||||
\escapeshellarg($this->dir),
|
||||
\escapeshellarg($this->filePatch)
|
||||
));
|
||||
|
||||
$p->run();
|
||||
|
||||
$this->assertProcessSuccessful($p);
|
||||
}
|
||||
|
||||
private function doIntegrationTestPatch(string $diff, string $from, string $to): void
|
||||
{
|
||||
$this->assertNotSame('', $diff);
|
||||
$this->assertValidUnifiedDiffFormat($diff);
|
||||
|
||||
$diff = self::setDiffFileHeader($diff, $this->fileFrom);
|
||||
|
||||
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
|
||||
$this->assertNotFalse(\file_put_contents($this->filePatch, $diff));
|
||||
|
||||
$command = \sprintf(
|
||||
'patch -u --verbose --posix %s < %s',
|
||||
\escapeshellarg($this->fileFrom),
|
||||
\escapeshellarg($this->filePatch)
|
||||
);
|
||||
|
||||
$p = new Process($command);
|
||||
$p->run();
|
||||
|
||||
$this->assertProcessSuccessful($p);
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
$this->fileFrom,
|
||||
$to,
|
||||
\sprintf('Patch command "%s".', $command)
|
||||
);
|
||||
}
|
||||
|
||||
private function assertProcessSuccessful(Process $p): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$p->isSuccessful(),
|
||||
\sprintf(
|
||||
"Command exec. was not successful:\n\"%s\"\nOutput:\n\"%s\"\nStdErr:\n\"%s\"\nExit code %d.\n",
|
||||
$p->getCommandLine(),
|
||||
$p->getOutput(),
|
||||
$p->getErrorOutput(),
|
||||
$p->getExitCode()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function cleanUpTempFiles(): void
|
||||
{
|
||||
@\unlink($this->fileFrom . '.orig');
|
||||
@\unlink($this->fileFrom . '.rej');
|
||||
@\unlink($this->fileFrom);
|
||||
@\unlink($this->fileTo);
|
||||
@\unlink($this->filePatch);
|
||||
}
|
||||
|
||||
private static function setDiffFileHeader(string $diff, string $file): string
|
||||
{
|
||||
$diffLines = \preg_split('/(.*\R)/', $diff, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$diffLines[0] = \preg_replace('#^\-\-\- .*#', '--- /' . $file, $diffLines[0], 1);
|
||||
$diffLines[1] = \preg_replace('#^\+\+\+ .*#', '+++ /' . $file, $diffLines[1], 1);
|
||||
|
||||
return \implode('', $diffLines);
|
||||
}
|
||||
}
|
163
vendor/sebastian/diff/tests/Output/Integration/UnifiedDiffOutputBuilderIntegrationTest.php
vendored
Normal file
163
vendor/sebastian/diff/tests/Output/Integration/UnifiedDiffOutputBuilderIntegrationTest.php
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SebastianBergmann\Diff\Utils\UnifiedDiffAssertTrait;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder
|
||||
*
|
||||
* @uses SebastianBergmann\Diff\Differ
|
||||
* @uses SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator
|
||||
*
|
||||
* @requires OS Linux
|
||||
*/
|
||||
final class UnifiedDiffOutputBuilderIntegrationTest extends TestCase
|
||||
{
|
||||
use UnifiedDiffAssertTrait;
|
||||
|
||||
private $dir;
|
||||
|
||||
private $fileFrom;
|
||||
|
||||
private $filePatch;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->dir = \realpath(__DIR__ . '/../../fixtures/out/') . '/';
|
||||
$this->fileFrom = $this->dir . 'from.txt';
|
||||
$this->filePatch = $this->dir . 'patch.txt';
|
||||
|
||||
$this->cleanUpTempFiles();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->cleanUpTempFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDiffWithLineNumbers
|
||||
*
|
||||
* @param mixed $expected
|
||||
* @param mixed $from
|
||||
* @param mixed $to
|
||||
*/
|
||||
public function testDiffWithLineNumbersPath($expected, $from, $to): void
|
||||
{
|
||||
$this->doIntegrationTestPatch($expected, $from, $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDiffWithLineNumbers
|
||||
*
|
||||
* @param mixed $expected
|
||||
* @param mixed $from
|
||||
* @param mixed $to
|
||||
*/
|
||||
public function testDiffWithLineNumbersGitApply($expected, $from, $to): void
|
||||
{
|
||||
$this->doIntegrationTestGitApply($expected, $from, $to);
|
||||
}
|
||||
|
||||
public function provideDiffWithLineNumbers()
|
||||
{
|
||||
return \array_filter(
|
||||
UnifiedDiffOutputBuilderDataProvider::provideDiffWithLineNumbers(),
|
||||
static function ($key) {
|
||||
return !\is_string($key) || false === \strpos($key, 'non_patch_compat');
|
||||
},
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
}
|
||||
|
||||
private function doIntegrationTestPatch(string $diff, string $from, string $to): void
|
||||
{
|
||||
$this->assertNotSame('', $diff);
|
||||
$this->assertValidUnifiedDiffFormat($diff);
|
||||
|
||||
$diff = self::setDiffFileHeader($diff, $this->fileFrom);
|
||||
|
||||
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
|
||||
$this->assertNotFalse(\file_put_contents($this->filePatch, $diff));
|
||||
|
||||
$command = \sprintf(
|
||||
'patch -u --verbose --posix %s < %s', // --posix
|
||||
\escapeshellarg($this->fileFrom),
|
||||
\escapeshellarg($this->filePatch)
|
||||
);
|
||||
|
||||
$p = new Process($command);
|
||||
$p->run();
|
||||
|
||||
$this->assertProcessSuccessful($p);
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
$this->fileFrom,
|
||||
$to,
|
||||
\sprintf('Patch command "%s".', $command)
|
||||
);
|
||||
}
|
||||
|
||||
private function doIntegrationTestGitApply(string $diff, string $from, string $to): void
|
||||
{
|
||||
$this->assertNotSame('', $diff);
|
||||
$this->assertValidUnifiedDiffFormat($diff);
|
||||
|
||||
$diff = self::setDiffFileHeader($diff, $this->fileFrom);
|
||||
|
||||
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
|
||||
$this->assertNotFalse(\file_put_contents($this->filePatch, $diff));
|
||||
|
||||
$command = \sprintf(
|
||||
'git --git-dir %s apply --check -v --unsafe-paths --ignore-whitespace %s',
|
||||
\escapeshellarg($this->dir),
|
||||
\escapeshellarg($this->filePatch)
|
||||
);
|
||||
|
||||
$p = new Process($command);
|
||||
$p->run();
|
||||
|
||||
$this->assertProcessSuccessful($p);
|
||||
}
|
||||
|
||||
private function assertProcessSuccessful(Process $p): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
$p->isSuccessful(),
|
||||
\sprintf(
|
||||
"Command exec. was not successful:\n\"%s\"\nOutput:\n\"%s\"\nStdErr:\n\"%s\"\nExit code %d.\n",
|
||||
$p->getCommandLine(),
|
||||
$p->getOutput(),
|
||||
$p->getErrorOutput(),
|
||||
$p->getExitCode()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function cleanUpTempFiles(): void
|
||||
{
|
||||
@\unlink($this->fileFrom . '.orig');
|
||||
@\unlink($this->fileFrom);
|
||||
@\unlink($this->filePatch);
|
||||
}
|
||||
|
||||
private static function setDiffFileHeader(string $diff, string $file): string
|
||||
{
|
||||
$diffLines = \preg_split('/(.*\R)/', $diff, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$diffLines[0] = \preg_replace('#^\-\-\- .*#', '--- /' . $file, $diffLines[0], 1);
|
||||
$diffLines[1] = \preg_replace('#^\+\+\+ .*#', '+++ /' . $file, $diffLines[1], 1);
|
||||
|
||||
return \implode('', $diffLines);
|
||||
}
|
||||
}
|
189
vendor/sebastian/diff/tests/Output/StrictUnifiedDiffOutputBuilderDataProvider.php
vendored
Normal file
189
vendor/sebastian/diff/tests/Output/StrictUnifiedDiffOutputBuilderDataProvider.php
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Output;
|
||||
|
||||
final class StrictUnifiedDiffOutputBuilderDataProvider
|
||||
{
|
||||
public static function provideOutputBuildingCases(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,3 +1,4 @@
|
||||
+b
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
@@ -16,5 +17,4 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-
|
||||
-B
|
||||
+A
|
||||
',
|
||||
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nB\n",
|
||||
"b\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nA\n",
|
||||
[
|
||||
'fromFile' => 'input.txt',
|
||||
'toFile' => 'output.txt',
|
||||
],
|
||||
],
|
||||
[
|
||||
'--- ' . __FILE__ . "\t2017-10-02 17:38:11.586413675 +0100
|
||||
+++ output1.txt\t2017-10-03 12:09:43.086719482 +0100
|
||||
@@ -1,1 +1,1 @@
|
||||
-B
|
||||
+X
|
||||
",
|
||||
"B\n",
|
||||
"X\n",
|
||||
[
|
||||
'fromFile' => __FILE__,
|
||||
'fromFileDate' => '2017-10-02 17:38:11.586413675 +0100',
|
||||
'toFile' => 'output1.txt',
|
||||
'toFileDate' => '2017-10-03 12:09:43.086719482 +0100',
|
||||
'collapseRanges' => false,
|
||||
],
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1 +1 @@
|
||||
-B
|
||||
+X
|
||||
',
|
||||
"B\n",
|
||||
"X\n",
|
||||
[
|
||||
'fromFile' => 'input.txt',
|
||||
'toFile' => 'output.txt',
|
||||
'collapseRanges' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function provideSample(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,6 +1,6 @@
|
||||
1
|
||||
2
|
||||
3
|
||||
-4
|
||||
+X
|
||||
5
|
||||
6
|
||||
',
|
||||
"1\n2\n3\n4\n5\n6\n",
|
||||
"1\n2\n3\nX\n5\n6\n",
|
||||
[
|
||||
'fromFile' => 'input.txt',
|
||||
'toFile' => 'output.txt',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function provideBasicDiffGeneration(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
"--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,2 +1 @@
|
||||
-A
|
||||
-B
|
||||
+A\rB
|
||||
",
|
||||
"A\nB\n",
|
||||
"A\rB\n",
|
||||
],
|
||||
[
|
||||
"--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1 +1 @@
|
||||
-
|
||||
+\r
|
||||
\\ No newline at end of file
|
||||
",
|
||||
"\n",
|
||||
"\r",
|
||||
],
|
||||
[
|
||||
"--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1 +1 @@
|
||||
-\r
|
||||
\\ No newline at end of file
|
||||
+
|
||||
",
|
||||
"\r",
|
||||
"\n",
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,3 +1,3 @@
|
||||
X
|
||||
A
|
||||
-A
|
||||
+B
|
||||
',
|
||||
"X\nA\nA\n",
|
||||
"X\nA\nB\n",
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,3 +1,3 @@
|
||||
X
|
||||
A
|
||||
-A
|
||||
\ No newline at end of file
|
||||
+B
|
||||
',
|
||||
"X\nA\nA",
|
||||
"X\nA\nB\n",
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,3 +1,3 @@
|
||||
A
|
||||
A
|
||||
-A
|
||||
+B
|
||||
\ No newline at end of file
|
||||
',
|
||||
"A\nA\nA\n",
|
||||
"A\nA\nB",
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1 +1 @@
|
||||
-A
|
||||
\ No newline at end of file
|
||||
+B
|
||||
\ No newline at end of file
|
||||
',
|
||||
'A',
|
||||
'B',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
684
vendor/sebastian/diff/tests/Output/StrictUnifiedDiffOutputBuilderTest.php
vendored
Normal file
684
vendor/sebastian/diff/tests/Output/StrictUnifiedDiffOutputBuilderTest.php
vendored
Normal file
@@ -0,0 +1,684 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SebastianBergmann\Diff\ConfigurationException;
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
use SebastianBergmann\Diff\Utils\UnifiedDiffAssertTrait;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder
|
||||
*
|
||||
* @uses SebastianBergmann\Diff\Differ
|
||||
*/
|
||||
final class StrictUnifiedDiffOutputBuilderTest extends TestCase
|
||||
{
|
||||
use UnifiedDiffAssertTrait;
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param array $options
|
||||
*
|
||||
* @dataProvider provideOutputBuildingCases
|
||||
*/
|
||||
public function testOutputBuilding(string $expected, string $from, string $to, array $options): void
|
||||
{
|
||||
$diff = $this->getDiffer($options)->diff($from, $to);
|
||||
|
||||
$this->assertValidDiffFormat($diff);
|
||||
$this->assertSame($expected, $diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param array $options
|
||||
*
|
||||
* @dataProvider provideSample
|
||||
*/
|
||||
public function testSample(string $expected, string $from, string $to, array $options): void
|
||||
{
|
||||
$diff = $this->getDiffer($options)->diff($from, $to);
|
||||
|
||||
$this->assertValidDiffFormat($diff);
|
||||
$this->assertSame($expected, $diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function assertValidDiffFormat(string $diff): void
|
||||
{
|
||||
$this->assertValidUnifiedDiffFormat($diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideOutputBuildingCases(): array
|
||||
{
|
||||
return StrictUnifiedDiffOutputBuilderDataProvider::provideOutputBuildingCases();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideSample(): array
|
||||
{
|
||||
return StrictUnifiedDiffOutputBuilderDataProvider::provideSample();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
*
|
||||
* @dataProvider provideBasicDiffGeneration
|
||||
*/
|
||||
public function testBasicDiffGeneration(string $expected, string $from, string $to): void
|
||||
{
|
||||
$diff = $this->getDiffer([
|
||||
'fromFile' => 'input.txt',
|
||||
'toFile' => 'output.txt',
|
||||
])->diff($from, $to);
|
||||
|
||||
$this->assertValidDiffFormat($diff);
|
||||
$this->assertSame($expected, $diff);
|
||||
}
|
||||
|
||||
public function provideBasicDiffGeneration(): array
|
||||
{
|
||||
return StrictUnifiedDiffOutputBuilderDataProvider::provideBasicDiffGeneration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param array $config
|
||||
*
|
||||
* @dataProvider provideConfiguredDiffGeneration
|
||||
*/
|
||||
public function testConfiguredDiffGeneration(string $expected, string $from, string $to, array $config = []): void
|
||||
{
|
||||
$diff = $this->getDiffer(\array_merge([
|
||||
'fromFile' => 'input.txt',
|
||||
'toFile' => 'output.txt',
|
||||
], $config))->diff($from, $to);
|
||||
|
||||
$this->assertValidDiffFormat($diff);
|
||||
$this->assertSame($expected, $diff);
|
||||
}
|
||||
|
||||
public function provideConfiguredDiffGeneration(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1 +1 @@
|
||||
-a
|
||||
\ No newline at end of file
|
||||
+b
|
||||
\ No newline at end of file
|
||||
',
|
||||
'a',
|
||||
'b',
|
||||
],
|
||||
[
|
||||
'',
|
||||
"1\n2",
|
||||
"1\n2",
|
||||
],
|
||||
[
|
||||
'',
|
||||
"1\n",
|
||||
"1\n",
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -4 +4 @@
|
||||
-X
|
||||
+4
|
||||
',
|
||||
"1\n2\n3\nX\n5\n6\n7\n8\n9\n0\n",
|
||||
"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n",
|
||||
[
|
||||
'contextLines' => 0,
|
||||
],
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -3,3 +3,3 @@
|
||||
3
|
||||
-X
|
||||
+4
|
||||
5
|
||||
',
|
||||
"1\n2\n3\nX\n5\n6\n7\n8\n9\n0\n",
|
||||
"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n",
|
||||
[
|
||||
'contextLines' => 1,
|
||||
],
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,10 +1,10 @@
|
||||
1
|
||||
2
|
||||
3
|
||||
-X
|
||||
+4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
0
|
||||
',
|
||||
"1\n2\n3\nX\n5\n6\n7\n8\n9\n0\n",
|
||||
"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n",
|
||||
[
|
||||
'contextLines' => 999,
|
||||
],
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,0 +1,2 @@
|
||||
+
|
||||
+A
|
||||
',
|
||||
'',
|
||||
"\nA\n",
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,2 +1,0 @@
|
||||
-
|
||||
-A
|
||||
',
|
||||
"\nA\n",
|
||||
'',
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,5 +1,5 @@
|
||||
1
|
||||
-X
|
||||
+2
|
||||
3
|
||||
-Y
|
||||
+4
|
||||
5
|
||||
@@ -8,3 +8,3 @@
|
||||
8
|
||||
-X
|
||||
+9
|
||||
0
|
||||
',
|
||||
"1\nX\n3\nY\n5\n6\n7\n8\nX\n0\n",
|
||||
"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n",
|
||||
[
|
||||
'commonLineThreshold' => 2,
|
||||
'contextLines' => 1,
|
||||
],
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -2 +2 @@
|
||||
-X
|
||||
+2
|
||||
@@ -4 +4 @@
|
||||
-Y
|
||||
+4
|
||||
@@ -9 +9 @@
|
||||
-X
|
||||
+9
|
||||
',
|
||||
"1\nX\n3\nY\n5\n6\n7\n8\nX\n0\n",
|
||||
"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n",
|
||||
[
|
||||
'commonLineThreshold' => 1,
|
||||
'contextLines' => 0,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testReUseBuilder(): void
|
||||
{
|
||||
$differ = $this->getDiffer([
|
||||
'fromFile' => 'input.txt',
|
||||
'toFile' => 'output.txt',
|
||||
]);
|
||||
|
||||
$diff = $differ->diff("A\nB\n", "A\nX\n");
|
||||
$this->assertSame(
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,2 +1,2 @@
|
||||
A
|
||||
-B
|
||||
+X
|
||||
',
|
||||
$diff
|
||||
);
|
||||
|
||||
$diff = $differ->diff("A\n", "A\n");
|
||||
$this->assertSame(
|
||||
'',
|
||||
$diff
|
||||
);
|
||||
}
|
||||
|
||||
public function testEmptyDiff(): void
|
||||
{
|
||||
$builder = new StrictUnifiedDiffOutputBuilder([
|
||||
'fromFile' => 'input.txt',
|
||||
'toFile' => 'output.txt',
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
'',
|
||||
$builder->getDiff([])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* @param string $message
|
||||
*
|
||||
* @dataProvider provideInvalidConfiguration
|
||||
*/
|
||||
public function testInvalidConfiguration(array $options, string $message): void
|
||||
{
|
||||
$this->expectException(ConfigurationException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote($message, '#')));
|
||||
|
||||
new StrictUnifiedDiffOutputBuilder($options);
|
||||
}
|
||||
|
||||
public function provideInvalidConfiguration(): array
|
||||
{
|
||||
$time = \time();
|
||||
|
||||
return [
|
||||
[
|
||||
['collapseRanges' => 1],
|
||||
'Option "collapseRanges" must be a bool, got "integer#1".',
|
||||
],
|
||||
[
|
||||
['contextLines' => 'a'],
|
||||
'Option "contextLines" must be an int >= 0, got "string#a".',
|
||||
],
|
||||
[
|
||||
['commonLineThreshold' => -2],
|
||||
'Option "commonLineThreshold" must be an int > 0, got "integer#-2".',
|
||||
],
|
||||
[
|
||||
['commonLineThreshold' => 0],
|
||||
'Option "commonLineThreshold" must be an int > 0, got "integer#0".',
|
||||
],
|
||||
[
|
||||
['fromFile' => new \SplFileInfo(__FILE__)],
|
||||
'Option "fromFile" must be a string, got "SplFileInfo".',
|
||||
],
|
||||
[
|
||||
['fromFile' => null],
|
||||
'Option "fromFile" must be a string, got "<null>".',
|
||||
],
|
||||
[
|
||||
[
|
||||
'fromFile' => __FILE__,
|
||||
'toFile' => 1,
|
||||
],
|
||||
'Option "toFile" must be a string, got "integer#1".',
|
||||
],
|
||||
[
|
||||
[
|
||||
'fromFile' => __FILE__,
|
||||
'toFile' => __FILE__,
|
||||
'toFileDate' => $time,
|
||||
],
|
||||
'Option "toFileDate" must be a string or <null>, got "integer#' . $time . '".',
|
||||
],
|
||||
[
|
||||
[],
|
||||
'Option "fromFile" must be a string, got "<null>".',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param int $threshold
|
||||
*
|
||||
* @dataProvider provideCommonLineThresholdCases
|
||||
*/
|
||||
public function testCommonLineThreshold(string $expected, string $from, string $to, int $threshold): void
|
||||
{
|
||||
$diff = $this->getDiffer([
|
||||
'fromFile' => 'input.txt',
|
||||
'toFile' => 'output.txt',
|
||||
'commonLineThreshold' => $threshold,
|
||||
'contextLines' => 0,
|
||||
])->diff($from, $to);
|
||||
|
||||
$this->assertValidDiffFormat($diff);
|
||||
$this->assertSame($expected, $diff);
|
||||
}
|
||||
|
||||
public function provideCommonLineThresholdCases(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -2,3 +2,3 @@
|
||||
-X
|
||||
+B
|
||||
C12
|
||||
-Y
|
||||
+D
|
||||
@@ -7 +7 @@
|
||||
-X
|
||||
+Z
|
||||
',
|
||||
"A\nX\nC12\nY\nA\nA\nX\n",
|
||||
"A\nB\nC12\nD\nA\nA\nZ\n",
|
||||
2,
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -2 +2 @@
|
||||
-X
|
||||
+B
|
||||
@@ -4 +4 @@
|
||||
-Y
|
||||
+D
|
||||
',
|
||||
"A\nX\nV\nY\n",
|
||||
"A\nB\nV\nD\n",
|
||||
1,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param int $contextLines
|
||||
* @param int $commonLineThreshold
|
||||
*
|
||||
* @dataProvider provideContextLineConfigurationCases
|
||||
*/
|
||||
public function testContextLineConfiguration(string $expected, string $from, string $to, int $contextLines, int $commonLineThreshold = 6): void
|
||||
{
|
||||
$diff = $this->getDiffer([
|
||||
'fromFile' => 'input.txt',
|
||||
'toFile' => 'output.txt',
|
||||
'contextLines' => $contextLines,
|
||||
'commonLineThreshold' => $commonLineThreshold,
|
||||
])->diff($from, $to);
|
||||
|
||||
$this->assertValidDiffFormat($diff);
|
||||
$this->assertSame($expected, $diff);
|
||||
}
|
||||
|
||||
public function provideContextLineConfigurationCases(): array
|
||||
{
|
||||
$from = "A\nB\nC\nD\nE\nF\nX\nG\nH\nI\nJ\nK\nL\nM\n";
|
||||
$to = "A\nB\nC\nD\nE\nF\nY\nG\nH\nI\nJ\nK\nL\nM\n";
|
||||
|
||||
return [
|
||||
'EOF 0' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -3 +3 @@
|
||||
-X
|
||||
\\ No newline at end of file
|
||||
+Y
|
||||
\\ No newline at end of file
|
||||
",
|
||||
"A\nB\nX",
|
||||
"A\nB\nY",
|
||||
0,
|
||||
],
|
||||
'EOF 1' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -2,2 +2,2 @@
|
||||
B
|
||||
-X
|
||||
\\ No newline at end of file
|
||||
+Y
|
||||
\\ No newline at end of file
|
||||
",
|
||||
"A\nB\nX",
|
||||
"A\nB\nY",
|
||||
1,
|
||||
],
|
||||
'EOF 2' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,3 +1,3 @@
|
||||
A
|
||||
B
|
||||
-X
|
||||
\\ No newline at end of file
|
||||
+Y
|
||||
\\ No newline at end of file
|
||||
",
|
||||
"A\nB\nX",
|
||||
"A\nB\nY",
|
||||
2,
|
||||
],
|
||||
'EOF 200' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,3 +1,3 @@
|
||||
A
|
||||
B
|
||||
-X
|
||||
\\ No newline at end of file
|
||||
+Y
|
||||
\\ No newline at end of file
|
||||
",
|
||||
"A\nB\nX",
|
||||
"A\nB\nY",
|
||||
200,
|
||||
],
|
||||
'n/a 0' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -7 +7 @@\n-X\n+Y\n",
|
||||
$from,
|
||||
$to,
|
||||
0,
|
||||
],
|
||||
'G' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -6,3 +6,3 @@\n F\n-X\n+Y\n G\n",
|
||||
$from,
|
||||
$to,
|
||||
1,
|
||||
],
|
||||
'H' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -5,5 +5,5 @@\n E\n F\n-X\n+Y\n G\n H\n",
|
||||
$from,
|
||||
$to,
|
||||
2,
|
||||
],
|
||||
'I' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -4,7 +4,7 @@\n D\n E\n F\n-X\n+Y\n G\n H\n I\n",
|
||||
$from,
|
||||
$to,
|
||||
3,
|
||||
],
|
||||
'J' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -3,9 +3,9 @@\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n",
|
||||
$from,
|
||||
$to,
|
||||
4,
|
||||
],
|
||||
'K' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -2,11 +2,11 @@\n B\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n K\n",
|
||||
$from,
|
||||
$to,
|
||||
5,
|
||||
],
|
||||
'L' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,13 +1,13 @@\n A\n B\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n K\n L\n",
|
||||
$from,
|
||||
$to,
|
||||
6,
|
||||
],
|
||||
'M' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,14 +1,14 @@\n A\n B\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n K\n L\n M\n",
|
||||
$from,
|
||||
$to,
|
||||
7,
|
||||
],
|
||||
'M no linebreak EOF .1' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,14 +1,14 @@\n A\n B\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n K\n L\n-M\n+M\n\\ No newline at end of file\n",
|
||||
$from,
|
||||
\substr($to, 0, -1),
|
||||
7,
|
||||
],
|
||||
'M no linebreak EOF .2' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,14 +1,14 @@\n A\n B\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n K\n L\n-M\n\\ No newline at end of file\n+M\n",
|
||||
\substr($from, 0, -1),
|
||||
$to,
|
||||
7,
|
||||
],
|
||||
'M no linebreak EOF .3' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,14 +1,14 @@\n A\n B\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n K\n L\n M\n",
|
||||
\substr($from, 0, -1),
|
||||
\substr($to, 0, -1),
|
||||
7,
|
||||
],
|
||||
'M no linebreak EOF .4' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,14 +1,14 @@\n A\n B\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n K\n L\n M\n\\ No newline at end of file\n",
|
||||
\substr($from, 0, -1),
|
||||
\substr($to, 0, -1),
|
||||
10000,
|
||||
10000,
|
||||
],
|
||||
'M+1' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,14 +1,14 @@\n A\n B\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n K\n L\n M\n",
|
||||
$from,
|
||||
$to,
|
||||
8,
|
||||
],
|
||||
'M+100' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -1,14 +1,14 @@\n A\n B\n C\n D\n E\n F\n-X\n+Y\n G\n H\n I\n J\n K\n L\n M\n",
|
||||
$from,
|
||||
$to,
|
||||
107,
|
||||
],
|
||||
'0 II' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -12 +12 @@\n-X\n+Y\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nX\nM\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nY\nM\n",
|
||||
0,
|
||||
999,
|
||||
],
|
||||
'0\' II' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -12 +12 @@\n-X\n+Y\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nX\nM\nA\nA\nA\nA\nA\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nY\nM\nA\nA\nA\nA\nA\n",
|
||||
0,
|
||||
999,
|
||||
],
|
||||
'0\'\' II' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -12,2 +12,2 @@\n-X\n-M\n\\ No newline at end of file\n+Y\n+M\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nX\nM",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nY\nM\n",
|
||||
0,
|
||||
],
|
||||
'0\'\'\' II' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -12,2 +12,2 @@\n-X\n-X1\n+Y\n+Y2\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nX\nX1\nM\nA\nA\nA\nA\nA\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nY\nY2\nM\nA\nA\nA\nA\nA\n",
|
||||
0,
|
||||
999,
|
||||
],
|
||||
'1 II' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -11,3 +11,3 @@\n K\n-X\n+Y\n M\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nX\nM\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nY\nM\n",
|
||||
1,
|
||||
],
|
||||
'5 II' => [
|
||||
"--- input.txt\n+++ output.txt\n@@ -7,7 +7,7 @@\n G\n H\n I\n J\n K\n-X\n+Y\n M\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nX\nM\n",
|
||||
"A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nY\nM\n",
|
||||
5,
|
||||
],
|
||||
[
|
||||
'--- input.txt
|
||||
+++ output.txt
|
||||
@@ -1,28 +1,28 @@
|
||||
A
|
||||
-X
|
||||
+B
|
||||
V
|
||||
-Y
|
||||
+D
|
||||
1
|
||||
A
|
||||
2
|
||||
A
|
||||
3
|
||||
A
|
||||
4
|
||||
A
|
||||
8
|
||||
A
|
||||
9
|
||||
A
|
||||
5
|
||||
A
|
||||
A
|
||||
A
|
||||
A
|
||||
A
|
||||
A
|
||||
A
|
||||
A
|
||||
A
|
||||
A
|
||||
A
|
||||
',
|
||||
"A\nX\nV\nY\n1\nA\n2\nA\n3\nA\n4\nA\n8\nA\n9\nA\n5\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\n",
|
||||
"A\nB\nV\nD\n1\nA\n2\nA\n3\nA\n4\nA\n8\nA\n9\nA\n5\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\n",
|
||||
9999,
|
||||
99999,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of a Differ with a new instance of the class (DiffOutputBuilderInterface) under test.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return Differ
|
||||
*/
|
||||
private function getDiffer(array $options = []): Differ
|
||||
{
|
||||
return new Differ(new StrictUnifiedDiffOutputBuilder($options));
|
||||
}
|
||||
}
|
396
vendor/sebastian/diff/tests/Output/UnifiedDiffOutputBuilderDataProvider.php
vendored
Normal file
396
vendor/sebastian/diff/tests/Output/UnifiedDiffOutputBuilderDataProvider.php
vendored
Normal file
@@ -0,0 +1,396 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Output;
|
||||
|
||||
final class UnifiedDiffOutputBuilderDataProvider
|
||||
{
|
||||
public static function provideDiffWithLineNumbers(): array
|
||||
{
|
||||
return [
|
||||
'diff line 1 non_patch_compat' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1 +1 @@
|
||||
-AA
|
||||
+BA
|
||||
',
|
||||
'AA',
|
||||
'BA',
|
||||
],
|
||||
'diff line +1 non_patch_compat' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1 +1,2 @@
|
||||
-AZ
|
||||
+
|
||||
+B
|
||||
',
|
||||
'AZ',
|
||||
"\nB",
|
||||
],
|
||||
'diff line -1 non_patch_compat' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,2 +1 @@
|
||||
-
|
||||
-AF
|
||||
+B
|
||||
',
|
||||
"\nAF",
|
||||
'B',
|
||||
],
|
||||
'II non_patch_compat' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,4 +1,2 @@
|
||||
-
|
||||
-
|
||||
A
|
||||
1
|
||||
',
|
||||
"\n\nA\n1",
|
||||
"A\n1",
|
||||
],
|
||||
'diff last line II - no trailing linebreak non_patch_compat' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -5,4 +5,4 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-E
|
||||
+B
|
||||
',
|
||||
"A\n\n\n\n\n\n\nE",
|
||||
"A\n\n\n\n\n\n\nB",
|
||||
],
|
||||
[
|
||||
"--- Original\n+++ New\n@@ -1,2 +1 @@\n \n-\n",
|
||||
"\n\n",
|
||||
"\n",
|
||||
],
|
||||
'diff line endings non_patch_compat' => [
|
||||
"--- Original\n+++ New\n@@ -1 +1 @@\n #Warning: Strings contain different line endings!\n-<?php\r\n+<?php\n",
|
||||
"<?php\r\n",
|
||||
"<?php\n",
|
||||
],
|
||||
'same non_patch_compat' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
',
|
||||
"AT\n",
|
||||
"AT\n",
|
||||
],
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,4 +1,4 @@
|
||||
-b
|
||||
+a
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
',
|
||||
"b\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
|
||||
"a\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
|
||||
],
|
||||
'diff line @1' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,2 +1,2 @@
|
||||
' . '
|
||||
-AG
|
||||
+B
|
||||
',
|
||||
"\nAG\n",
|
||||
"\nB\n",
|
||||
],
|
||||
'same multiple lines' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,4 +1,4 @@
|
||||
' . '
|
||||
' . '
|
||||
-V
|
||||
+B
|
||||
C213
|
||||
',
|
||||
"\n\nV\nC213",
|
||||
"\n\nB\nC213",
|
||||
],
|
||||
'diff last line I' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -5,4 +5,4 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-E
|
||||
+B
|
||||
',
|
||||
"A\n\n\n\n\n\n\nE\n",
|
||||
"A\n\n\n\n\n\n\nB\n",
|
||||
],
|
||||
'diff line middle' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -5,7 +5,7 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-X
|
||||
+Z
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
',
|
||||
"A\n\n\n\n\n\n\nX\n\n\n\n\n\n\nAY",
|
||||
"A\n\n\n\n\n\n\nZ\n\n\n\n\n\n\nAY",
|
||||
],
|
||||
'diff last line III' => [
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -12,4 +12,4 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-A
|
||||
+B
|
||||
',
|
||||
"A\n\n\n\n\n\n\nA\n\n\n\n\n\n\nA\n",
|
||||
"A\n\n\n\n\n\n\nA\n\n\n\n\n\n\nB\n",
|
||||
],
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,8 +1,8 @@
|
||||
A
|
||||
-B
|
||||
+B1
|
||||
D
|
||||
E
|
||||
EE
|
||||
F
|
||||
-G
|
||||
+G1
|
||||
H
|
||||
',
|
||||
"A\nB\nD\nE\nEE\nF\nG\nH",
|
||||
"A\nB1\nD\nE\nEE\nF\nG1\nH",
|
||||
],
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,4 +1,5 @@
|
||||
Z
|
||||
+
|
||||
a
|
||||
b
|
||||
c
|
||||
@@ -7,5 +8,5 @@
|
||||
f
|
||||
g
|
||||
h
|
||||
-i
|
||||
+x
|
||||
j
|
||||
',
|
||||
'Z
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
e
|
||||
f
|
||||
g
|
||||
h
|
||||
i
|
||||
j
|
||||
',
|
||||
'Z
|
||||
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
e
|
||||
f
|
||||
g
|
||||
h
|
||||
x
|
||||
j
|
||||
',
|
||||
],
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,7 +1,5 @@
|
||||
-
|
||||
-a
|
||||
+b
|
||||
A
|
||||
-X
|
||||
-
|
||||
+Y
|
||||
' . '
|
||||
A
|
||||
',
|
||||
"\na\nA\nX\n\n\nA\n",
|
||||
"b\nA\nY\n\nA\n",
|
||||
],
|
||||
[
|
||||
<<<EOF
|
||||
--- Original
|
||||
+++ New
|
||||
@@ -1,7 +1,5 @@
|
||||
-
|
||||
-
|
||||
a
|
||||
-b
|
||||
+p
|
||||
c
|
||||
d
|
||||
e
|
||||
@@ -9,5 +7,5 @@
|
||||
g
|
||||
h
|
||||
i
|
||||
-j
|
||||
+w
|
||||
k
|
||||
|
||||
EOF
|
||||
,
|
||||
"\n\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\n",
|
||||
"a\np\nc\nd\ne\nf\ng\nh\ni\nw\nk\n",
|
||||
],
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,7 +8,7 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-A
|
||||
+C
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
',
|
||||
"E\n\n\n\n\nB\n\n\n\n\nA\n\n\n\n\n\n\n\n\nD1",
|
||||
"E\n\n\n\n\nB\n\n\n\n\nC\n\n\n\n\n\n\n\n\nD1",
|
||||
],
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -5,7 +5,7 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-Z
|
||||
+U
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
@@ -12,7 +12,7 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-X
|
||||
+V
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
@@ -19,7 +19,7 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-Y
|
||||
+W
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
@@ -26,7 +26,7 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-W
|
||||
+X
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
@@ -33,7 +33,7 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-V
|
||||
+Y
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
@@ -40,4 +40,4 @@
|
||||
' . '
|
||||
' . '
|
||||
' . '
|
||||
-U
|
||||
+Z
|
||||
',
|
||||
"\n\n\n\n\n\n\nZ\n\n\n\n\n\n\nX\n\n\n\n\n\n\nY\n\n\n\n\n\n\nW\n\n\n\n\n\n\nV\n\n\n\n\n\n\nU\n",
|
||||
"\n\n\n\n\n\n\nU\n\n\n\n\n\n\nV\n\n\n\n\n\n\nW\n\n\n\n\n\n\nX\n\n\n\n\n\n\nY\n\n\n\n\n\n\nZ\n",
|
||||
],
|
||||
[
|
||||
<<<EOF
|
||||
--- Original
|
||||
+++ New
|
||||
@@ -1,5 +1,5 @@
|
||||
a
|
||||
-b
|
||||
+p
|
||||
c
|
||||
d
|
||||
e
|
||||
@@ -7,5 +7,5 @@
|
||||
g
|
||||
h
|
||||
i
|
||||
-j
|
||||
+w
|
||||
k
|
||||
|
||||
EOF
|
||||
,
|
||||
"a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\n",
|
||||
"a\np\nc\nd\ne\nf\ng\nh\ni\nw\nk\n",
|
||||
],
|
||||
[
|
||||
<<<EOF
|
||||
--- Original
|
||||
+++ New
|
||||
@@ -1,4 +1,4 @@
|
||||
-A
|
||||
+B
|
||||
1
|
||||
2
|
||||
3
|
||||
|
||||
EOF
|
||||
,
|
||||
"A\n1\n2\n3\n4\n5\n6\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
|
||||
"B\n1\n2\n3\n4\n5\n6\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
|
||||
],
|
||||
[
|
||||
"--- Original\n+++ New\n@@ -4,7 +4,7 @@\n D\n E\n F\n-X\n+Y\n G\n H\n I\n",
|
||||
"A\nB\nC\nD\nE\nF\nX\nG\nH\nI\nJ\nK\nL\nM\n",
|
||||
"A\nB\nC\nD\nE\nF\nY\nG\nH\nI\nJ\nK\nL\nM\n",
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
90
vendor/sebastian/diff/tests/Output/UnifiedDiffOutputBuilderTest.php
vendored
Normal file
90
vendor/sebastian/diff/tests/Output/UnifiedDiffOutputBuilderTest.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder
|
||||
*
|
||||
* @uses SebastianBergmann\Diff\Differ
|
||||
* @uses SebastianBergmann\Diff\Output\AbstractChunkOutputBuilder
|
||||
* @uses SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator
|
||||
*/
|
||||
final class UnifiedDiffOutputBuilderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param string $header
|
||||
*
|
||||
* @dataProvider headerProvider
|
||||
*/
|
||||
public function testCustomHeaderCanBeUsed(string $expected, string $from, string $to, string $header): void
|
||||
{
|
||||
$differ = new Differ(new UnifiedDiffOutputBuilder($header));
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$differ->diff($from, $to)
|
||||
);
|
||||
}
|
||||
|
||||
public function headerProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
"CUSTOM HEADER\n@@ @@\n-a\n+b\n",
|
||||
'a',
|
||||
'b',
|
||||
'CUSTOM HEADER',
|
||||
],
|
||||
[
|
||||
"CUSTOM HEADER\n@@ @@\n-a\n+b\n",
|
||||
'a',
|
||||
'b',
|
||||
"CUSTOM HEADER\n",
|
||||
],
|
||||
[
|
||||
"CUSTOM HEADER\n\n@@ @@\n-a\n+b\n",
|
||||
'a',
|
||||
'b',
|
||||
"CUSTOM HEADER\n\n",
|
||||
],
|
||||
[
|
||||
"@@ @@\n-a\n+b\n",
|
||||
'a',
|
||||
'b',
|
||||
'',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
*
|
||||
* @dataProvider provideDiffWithLineNumbers
|
||||
*/
|
||||
public function testDiffWithLineNumbers($expected, $from, $to): void
|
||||
{
|
||||
$differ = new Differ(new UnifiedDiffOutputBuilder("--- Original\n+++ New\n", true));
|
||||
$this->assertSame($expected, $differ->diff($from, $to));
|
||||
}
|
||||
|
||||
public function provideDiffWithLineNumbers(): array
|
||||
{
|
||||
return UnifiedDiffOutputBuilderDataProvider::provideDiffWithLineNumbers();
|
||||
}
|
||||
}
|
46
vendor/sebastian/diff/tests/ParserTest.php
vendored
46
vendor/sebastian/diff/tests/ParserTest.php
vendored
@@ -11,6 +11,7 @@
|
||||
namespace SebastianBergmann\Diff;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SebastianBergmann\Diff\Utils\FileUtils;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\Parser
|
||||
@@ -26,14 +27,14 @@ final class ParserTest extends TestCase
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->parser = new Parser;
|
||||
}
|
||||
|
||||
public function testParse()
|
||||
public function testParse(): void
|
||||
{
|
||||
$content = \file_get_contents(__DIR__ . '/fixtures/patch.txt');
|
||||
$content = FileUtils::getFileContent(__DIR__ . '/fixtures/patch.txt');
|
||||
|
||||
$diffs = $this->parser->parse($content);
|
||||
|
||||
@@ -52,9 +53,9 @@ final class ParserTest extends TestCase
|
||||
$this->assertCount(4, $chunks[0]->getLines());
|
||||
}
|
||||
|
||||
public function testParseWithMultipleChunks()
|
||||
public function testParseWithMultipleChunks(): void
|
||||
{
|
||||
$content = \file_get_contents(__DIR__ . '/fixtures/patch2.txt');
|
||||
$content = FileUtils::getFileContent(__DIR__ . '/fixtures/patch2.txt');
|
||||
|
||||
$diffs = $this->parser->parse($content);
|
||||
|
||||
@@ -72,9 +73,9 @@ final class ParserTest extends TestCase
|
||||
$this->assertCount(4, $chunks[2]->getLines());
|
||||
}
|
||||
|
||||
public function testParseWithRemovedLines()
|
||||
public function testParseWithRemovedLines(): void
|
||||
{
|
||||
$content = <<<A
|
||||
$content = <<<END
|
||||
diff --git a/Test.txt b/Test.txt
|
||||
index abcdefg..abcdefh 100644
|
||||
--- a/Test.txt
|
||||
@@ -82,7 +83,7 @@ index abcdefg..abcdefh 100644
|
||||
@@ -49,9 +49,8 @@
|
||||
A
|
||||
-B
|
||||
A;
|
||||
END;
|
||||
$diffs = $this->parser->parse($content);
|
||||
$this->assertInternalType('array', $diffs);
|
||||
$this->assertContainsOnlyInstancesOf(Diff::class, $diffs);
|
||||
@@ -115,9 +116,9 @@ A;
|
||||
$this->assertSame(Line::REMOVED, $line->getType());
|
||||
}
|
||||
|
||||
public function testParseDiffForMulitpleFiles()
|
||||
public function testParseDiffForMulitpleFiles(): void
|
||||
{
|
||||
$content = <<<A
|
||||
$content = <<<END
|
||||
diff --git a/Test.txt b/Test.txt
|
||||
index abcdefg..abcdefh 100644
|
||||
--- a/Test.txt
|
||||
@@ -133,7 +134,7 @@ index abcdefg..abcdefh 100644
|
||||
@@ -1,2 +1,3 @@
|
||||
A
|
||||
+B
|
||||
A;
|
||||
END;
|
||||
$diffs = $this->parser->parse($content);
|
||||
$this->assertCount(2, $diffs);
|
||||
|
||||
@@ -148,4 +149,27 @@ A;
|
||||
$this->assertSame('b/Test2.txt', $diff->getTo());
|
||||
$this->assertCount(1, $diff->getChunks());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $diff
|
||||
* @param Diff[] $expected
|
||||
*
|
||||
* @dataProvider diffProvider
|
||||
*/
|
||||
public function testParser(string $diff, array $expected): void
|
||||
{
|
||||
$result = $this->parser->parse($diff);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function diffProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
"--- old.txt 2014-11-04 08:51:02.661868729 +0300\n+++ new.txt 2014-11-04 08:51:02.665868730 +0300\n@@ -1,3 +1,4 @@\n+2222111\n 1111111\n 1111111\n 1111111\n@@ -5,10 +6,8 @@\n 1111111\n 1111111\n 1111111\n +1121211\n 1111111\n -1111111\n -1111111\n -2222222\n 2222222\n 2222222\n 2222222\n@@ -17,5 +16,6 @@\n 2222222\n 2222222\n 2222222\n +2122212\n 2222222\n 2222222\n",
|
||||
\unserialize(FileUtils::getFileContent(__DIR__ . '/fixtures/serialized_diff.bin')),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ namespace SebastianBergmann\Diff;
|
||||
*/
|
||||
final class TimeEfficientImplementationTest extends LongestCommonSubsequenceTest
|
||||
{
|
||||
protected function createImplementation()
|
||||
protected function createImplementation(): LongestCommonSubsequenceCalculator
|
||||
{
|
||||
return new TimeEfficientLongestCommonSubsequenceCalculator;
|
||||
}
|
||||
|
31
vendor/sebastian/diff/tests/Utils/FileUtils.php
vendored
Normal file
31
vendor/sebastian/diff/tests/Utils/FileUtils.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Utils;
|
||||
|
||||
final class FileUtils
|
||||
{
|
||||
public static function getFileContent(string $file): string
|
||||
{
|
||||
$content = @\file_get_contents($file);
|
||||
|
||||
if (false === $content) {
|
||||
$error = \error_get_last();
|
||||
|
||||
throw new \RuntimeException(\sprintf(
|
||||
'Failed to read content of file "%s".%s',
|
||||
$file,
|
||||
$error ? ' ' . $error['message'] : ''
|
||||
));
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
277
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTrait.php
vendored
Normal file
277
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTrait.php
vendored
Normal file
@@ -0,0 +1,277 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Utils;
|
||||
|
||||
trait UnifiedDiffAssertTrait
|
||||
{
|
||||
/**
|
||||
* @param string $diff
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
*/
|
||||
public function assertValidUnifiedDiffFormat(string $diff): void
|
||||
{
|
||||
if ('' === $diff) {
|
||||
$this->addToAssertionCount(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// test diff ends with a line break
|
||||
$last = \substr($diff, -1);
|
||||
|
||||
if ("\n" !== $last && "\r" !== $last) {
|
||||
throw new \UnexpectedValueException(\sprintf('Expected diff to end with a line break, got "%s".', $last));
|
||||
}
|
||||
|
||||
$lines = \preg_split('/(.*\R)/', $diff, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$lineCount = \count($lines);
|
||||
$lineNumber = $diffLineFromNumber = $diffLineToNumber = 1;
|
||||
$fromStart = $fromTillOffset = $toStart = $toTillOffset = -1;
|
||||
$expectHunkHeader = true;
|
||||
|
||||
// check for header
|
||||
if ($lineCount > 1) {
|
||||
$this->unifiedDiffAssertLinePrefix($lines[0], 'Line 1.');
|
||||
$this->unifiedDiffAssertLinePrefix($lines[1], 'Line 2.');
|
||||
|
||||
if ('---' === \substr($lines[0], 0, 3)) {
|
||||
if ('+++' !== \substr($lines[1], 0, 3)) {
|
||||
throw new \UnexpectedValueException(\sprintf("Line 1 indicates a header, so line 2 must start with \"+++\".\nLine 1: \"%s\"\nLine 2: \"%s\".", $lines[0], $lines[1]));
|
||||
}
|
||||
|
||||
$this->unifiedDiffAssertHeaderLine($lines[0], '--- ', 'Line 1.');
|
||||
$this->unifiedDiffAssertHeaderLine($lines[1], '+++ ', 'Line 2.');
|
||||
|
||||
$lineNumber = 3;
|
||||
}
|
||||
}
|
||||
|
||||
$endOfLineTypes = [];
|
||||
$diffClosed = false;
|
||||
|
||||
// assert format of lines, get all hunks, test the line numbers
|
||||
for (; $lineNumber <= $lineCount; ++$lineNumber) {
|
||||
if ($diffClosed) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected line as 2 "No newline" markers have found, ". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
$line = $lines[$lineNumber - 1]; // line numbers start by 1, array index at 0
|
||||
$type = $this->unifiedDiffAssertLinePrefix($line, \sprintf('Line %d.', $lineNumber));
|
||||
|
||||
if ($expectHunkHeader && '@' !== $type && '\\' !== $type) {
|
||||
throw new \UnexpectedValueException(\sprintf('Expected hunk start (\'@\'), got "%s". Line %d.', $type, $lineNumber));
|
||||
}
|
||||
|
||||
if ('@' === $type) {
|
||||
if (!$expectHunkHeader) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected hunk start (\'@\'). Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
$previousHunkFromEnd = $fromStart + $fromTillOffset;
|
||||
$previousHunkTillEnd = $toStart + $toTillOffset;
|
||||
|
||||
[$fromStart, $fromTillOffset, $toStart, $toTillOffset] = $this->unifiedDiffAssertHunkHeader($line, \sprintf('Line %d.', $lineNumber));
|
||||
|
||||
// detect overlapping hunks
|
||||
if ($fromStart < $previousHunkFromEnd) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected new hunk; "from" (\'-\') start overlaps previous hunk. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
if ($toStart < $previousHunkTillEnd) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected new hunk; "to" (\'+\') start overlaps previous hunk. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
/* valid states; hunks touches against each other:
|
||||
$fromStart === $previousHunkFromEnd
|
||||
$toStart === $previousHunkTillEnd
|
||||
*/
|
||||
|
||||
$diffLineFromNumber = $fromStart;
|
||||
$diffLineToNumber = $toStart;
|
||||
$expectHunkHeader = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('-' === $type) {
|
||||
if (isset($endOfLineTypes['-'])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Not expected from (\'-\'), already closed by "\\ No newline at end of file". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
++$diffLineFromNumber;
|
||||
} elseif ('+' === $type) {
|
||||
if (isset($endOfLineTypes['+'])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Not expected to (\'+\'), already closed by "\\ No newline at end of file". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
++$diffLineToNumber;
|
||||
} elseif (' ' === $type) {
|
||||
if (isset($endOfLineTypes['-'])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Not expected same (\' \'), \'-\' already closed by "\\ No newline at end of file". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
if (isset($endOfLineTypes['+'])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Not expected same (\' \'), \'+\' already closed by "\\ No newline at end of file". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
++$diffLineFromNumber;
|
||||
++$diffLineToNumber;
|
||||
} elseif ('\\' === $type) {
|
||||
if (!isset($lines[$lineNumber - 2])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected "\\ No newline at end of file", it must be preceded by \'+\' or \'-\' line. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
$previousType = $this->unifiedDiffAssertLinePrefix($lines[$lineNumber - 2], \sprintf('Preceding line of "\\ No newline at end of file" of unexpected format. Line %d.', $lineNumber));
|
||||
|
||||
if (isset($endOfLineTypes[$previousType])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected "\\ No newline at end of file", "%s" was already closed. Line %d.', $type, $lineNumber));
|
||||
}
|
||||
|
||||
$endOfLineTypes[$previousType] = true;
|
||||
$diffClosed = \count($endOfLineTypes) > 1;
|
||||
} else {
|
||||
// internal state error
|
||||
throw new \RuntimeException(\sprintf('Unexpected line type "%s" Line %d.', $type, $lineNumber));
|
||||
}
|
||||
|
||||
$expectHunkHeader =
|
||||
$diffLineFromNumber === ($fromStart + $fromTillOffset)
|
||||
&& $diffLineToNumber === ($toStart + $toTillOffset)
|
||||
;
|
||||
}
|
||||
|
||||
if (
|
||||
$diffLineFromNumber !== ($fromStart + $fromTillOffset)
|
||||
&& $diffLineToNumber !== ($toStart + $toTillOffset)
|
||||
) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected EOF, number of lines in hunk "from" (\'-\')) and "to" (\'+\') mismatched. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
if ($diffLineFromNumber !== ($fromStart + $fromTillOffset)) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected EOF, number of lines in hunk "from" (\'-\')) mismatched. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
if ($diffLineToNumber !== ($toStart + $toTillOffset)) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected EOF, number of lines in hunk "to" (\'+\')) mismatched. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line
|
||||
* @param string $message
|
||||
*
|
||||
* @return string '+', '-', '@', ' ' or '\'
|
||||
*/
|
||||
private function unifiedDiffAssertLinePrefix(string $line, string $message): string
|
||||
{
|
||||
$this->unifiedDiffAssertStrLength($line, 2, $message); // 2: line type indicator ('+', '-', ' ' or '\') and a line break
|
||||
$firstChar = $line[0];
|
||||
|
||||
if ('+' === $firstChar || '-' === $firstChar || '@' === $firstChar || ' ' === $firstChar) {
|
||||
return $firstChar;
|
||||
}
|
||||
|
||||
if ("\\ No newline at end of file\n" === $line) {
|
||||
return '\\';
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException(\sprintf('Expected line to start with \'@\', \'-\' or \'+\', got "%s". %s', $line, $message));
|
||||
}
|
||||
|
||||
private function unifiedDiffAssertStrLength(string $line, int $min, string $message): void
|
||||
{
|
||||
$length = \strlen($line);
|
||||
|
||||
if ($length < $min) {
|
||||
throw new \UnexpectedValueException(\sprintf('Expected string length of minimal %d, got %d. %s', $min, $length, $message));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert valid unified diff header line
|
||||
*
|
||||
* Samples:
|
||||
* - "+++ from1.txt\t2017-08-24 19:51:29.383985722 +0200"
|
||||
* - "+++ from1.txt"
|
||||
*
|
||||
* @param string $line
|
||||
* @param string $start
|
||||
* @param string $message
|
||||
*/
|
||||
private function unifiedDiffAssertHeaderLine(string $line, string $start, string $message): void
|
||||
{
|
||||
if (0 !== \strpos($line, $start)) {
|
||||
throw new \UnexpectedValueException(\sprintf('Expected header line to start with "%s", got "%s". %s', $start . ' ', $line, $message));
|
||||
}
|
||||
|
||||
// sample "+++ from1.txt\t2017-08-24 19:51:29.383985722 +0200\n"
|
||||
$match = \preg_match(
|
||||
"/^([^\t]*)(?:[\t]([\\S].*[\\S]))?\n$/",
|
||||
\substr($line, 4), // 4 === string length of "+++ " / "--- "
|
||||
$matches
|
||||
);
|
||||
|
||||
if (1 !== $match) {
|
||||
throw new \UnexpectedValueException(\sprintf('Header line does not match expected pattern, got "%s". %s', $line, $message));
|
||||
}
|
||||
|
||||
// $file = $matches[1];
|
||||
|
||||
if (\count($matches) > 2) {
|
||||
$this->unifiedDiffAssertHeaderDate($matches[2], $message);
|
||||
}
|
||||
}
|
||||
|
||||
private function unifiedDiffAssertHeaderDate(string $date, string $message): void
|
||||
{
|
||||
// sample "2017-08-24 19:51:29.383985722 +0200"
|
||||
$match = \preg_match(
|
||||
'/^([\d]{4})-([01]?[\d])-([0123]?[\d])(:? [\d]{1,2}:[\d]{1,2}(?::[\d]{1,2}(:?\.[\d]+)?)?(?: ([\+\-][\d]{4}))?)?$/',
|
||||
$date,
|
||||
$matches
|
||||
);
|
||||
|
||||
if (1 !== $match || ($matchesCount = \count($matches)) < 4) {
|
||||
throw new \UnexpectedValueException(\sprintf('Date of header line does not match expected pattern, got "%s". %s', $date, $message));
|
||||
}
|
||||
|
||||
// [$full, $year, $month, $day, $time] = $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line
|
||||
* @param string $message
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function unifiedDiffAssertHunkHeader(string $line, string $message): array
|
||||
{
|
||||
if (1 !== \preg_match('#^@@ -([\d]+)((?:,[\d]+)?) \+([\d]+)((?:,[\d]+)?) @@\n$#', $line, $matches)) {
|
||||
throw new \UnexpectedValueException(
|
||||
\sprintf(
|
||||
'Hunk header line does not match expected pattern, got "%s". %s',
|
||||
$line,
|
||||
$message
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
(int) $matches[1],
|
||||
empty($matches[2]) ? 1 : (int) \substr($matches[2], 1),
|
||||
(int) $matches[3],
|
||||
empty($matches[4]) ? 1 : (int) \substr($matches[4], 1),
|
||||
];
|
||||
}
|
||||
}
|
129
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTraitIntegrationTest.php
vendored
Normal file
129
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTraitIntegrationTest.php
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Utils;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* @requires OS Linux
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class UnifiedDiffAssertTraitIntegrationTest extends TestCase
|
||||
{
|
||||
use UnifiedDiffAssertTrait;
|
||||
|
||||
private $filePatch;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->filePatch = __DIR__ . '/../fixtures/out/patch.txt';
|
||||
|
||||
$this->cleanUpTempFiles();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->cleanUpTempFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileFrom
|
||||
* @param string $fileTo
|
||||
*
|
||||
* @dataProvider provideFilePairsCases
|
||||
*/
|
||||
public function testValidPatches(string $fileFrom, string $fileTo): void
|
||||
{
|
||||
$command = \sprintf(
|
||||
'diff -u %s %s > %s',
|
||||
\escapeshellarg(\realpath($fileFrom)),
|
||||
\escapeshellarg(\realpath($fileTo)),
|
||||
\escapeshellarg($this->filePatch)
|
||||
);
|
||||
|
||||
$p = new Process($command);
|
||||
$p->run();
|
||||
|
||||
$exitCode = $p->getExitCode();
|
||||
|
||||
if (0 === $exitCode) {
|
||||
// odd case when two files have the same content. Test after executing as it is more efficient than to read the files and check the contents every time.
|
||||
$this->addToAssertionCount(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertSame(
|
||||
1, // means `diff` found a diff between the files we gave it
|
||||
$exitCode,
|
||||
\sprintf(
|
||||
"Command exec. was not successful:\n\"%s\"\nOutput:\n\"%s\"\nStdErr:\n\"%s\"\nExit code %d.\n",
|
||||
$command,
|
||||
$p->getOutput(),
|
||||
$p->getErrorOutput(),
|
||||
$p->getExitCode()
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(FileUtils::getFileContent($this->filePatch));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, string>>
|
||||
*/
|
||||
public function provideFilePairsCases(): array
|
||||
{
|
||||
$cases = [];
|
||||
|
||||
// created cases based on dedicated fixtures
|
||||
$dir = \realpath(__DIR__ . '/../fixtures/UnifiedDiffAssertTraitIntegrationTest');
|
||||
$dirLength = \strlen($dir);
|
||||
|
||||
for ($i = 1;; ++$i) {
|
||||
$fromFile = \sprintf('%s/%d_a.txt', $dir, $i);
|
||||
$toFile = \sprintf('%s/%d_b.txt', $dir, $i);
|
||||
|
||||
if (!\file_exists($fromFile)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->assertFileExists($toFile);
|
||||
$cases[\sprintf("Diff file:\n\"%s\"\nvs.\n\"%s\"\n", \substr(\realpath($fromFile), $dirLength), \substr(\realpath($toFile), $dirLength))] = [$fromFile, $toFile];
|
||||
}
|
||||
|
||||
// create cases based on PHP files within the vendor directory for integration testing
|
||||
$dir = \realpath(__DIR__ . '/../../vendor');
|
||||
$dirLength = \strlen($dir);
|
||||
|
||||
$fileIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS));
|
||||
$fromFile = __FILE__;
|
||||
|
||||
/** @var \SplFileInfo $file */
|
||||
foreach ($fileIterator as $file) {
|
||||
if ('php' !== $file->getExtension()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$toFile = $file->getPathname();
|
||||
$cases[\sprintf("Diff file:\n\"%s\"\nvs.\n\"%s\"\n", \substr(\realpath($fromFile), $dirLength), \substr(\realpath($toFile), $dirLength))] = [$fromFile, $toFile];
|
||||
$fromFile = $toFile;
|
||||
}
|
||||
|
||||
return $cases;
|
||||
}
|
||||
|
||||
private function cleanUpTempFiles(): void
|
||||
{
|
||||
@\unlink($this->filePatch);
|
||||
}
|
||||
}
|
434
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTraitTest.php
vendored
Normal file
434
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTraitTest.php
vendored
Normal file
@@ -0,0 +1,434 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (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\Diff\Utils;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\Utils\UnifiedDiffAssertTrait
|
||||
*/
|
||||
final class UnifiedDiffAssertTraitTest extends TestCase
|
||||
{
|
||||
use UnifiedDiffAssertTrait;
|
||||
|
||||
/**
|
||||
* @param string $diff
|
||||
*
|
||||
* @dataProvider provideValidCases
|
||||
*/
|
||||
public function testValidCases(string $diff): void
|
||||
{
|
||||
$this->assertValidUnifiedDiffFormat($diff);
|
||||
}
|
||||
|
||||
public function provideValidCases(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
+U
|
||||
',
|
||||
],
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
+U
|
||||
@@ -15 +15 @@
|
||||
-X
|
||||
+V
|
||||
',
|
||||
],
|
||||
'empty diff. is valid' => [
|
||||
'',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testNoLinebreakEnd(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Expected diff to end with a line break, got "C".', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat("A\nB\nC");
|
||||
}
|
||||
|
||||
public function testInvalidStartWithoutHeader(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Expected line to start with '@', '-' or '+', got \"A\n\". Line 1.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat("A\n");
|
||||
}
|
||||
|
||||
public function testInvalidStartHeader1(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Line 1 indicates a header, so line 2 must start with \"+++\".\nLine 1: \"--- A\n\"\nLine 2: \"+ 1\n\".", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat("--- A\n+ 1\n");
|
||||
}
|
||||
|
||||
public function testInvalidStartHeader2(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Header line does not match expected pattern, got \"+++ file X\n\". Line 2.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat("--- A\n+++ file\tX\n");
|
||||
}
|
||||
|
||||
public function testInvalidStartHeader3(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Date of header line does not match expected pattern, got "[invalid date]". Line 1.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
"--- Original\t[invalid date]
|
||||
+++ New
|
||||
@@ -1,2 +1,2 @@
|
||||
-A
|
||||
+B
|
||||
" . '
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidStartHeader4(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Expected header line to start with \"+++ \", got \"+++INVALID\n\". Line 2.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++INVALID
|
||||
@@ -1,2 +1,2 @@
|
||||
-A
|
||||
+B
|
||||
' . '
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidLine1(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Expected line to start with '@', '-' or '+', got \"1\n\". Line 5.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
1
|
||||
+U
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidLine2(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Expected string length of minimal 2, got 1. Line 4.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
|
||||
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testHunkInvalidFormat(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Hunk header line does not match expected pattern, got \"@@ INVALID -1,1 +1,1 @@\n\". Line 3.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ INVALID -1,1 +1,1 @@
|
||||
-Z
|
||||
+U
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testHunkOverlapFrom(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected new hunk; "from" (\'-\') start overlaps previous hunk. Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,1 +8,1 @@
|
||||
-Z
|
||||
+U
|
||||
@@ -7,1 +9,1 @@
|
||||
-Z
|
||||
+U
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testHunkOverlapTo(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected new hunk; "to" (\'+\') start overlaps previous hunk. Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,1 +8,1 @@
|
||||
-Z
|
||||
+U
|
||||
@@ -17,1 +7,1 @@
|
||||
-Z
|
||||
+U
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testExpectHunk1(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Expected hunk start (\'@\'), got "+". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
+U
|
||||
+O
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testExpectHunk2(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected hunk start (\'@\'). Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
' . '
|
||||
' . '
|
||||
@@ -38,12 +48,12 @@
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMisplacedLineAfterComments1(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected line as 2 "No newline" markers have found, ". Line 8.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
\ No newline at end of file
|
||||
+U
|
||||
\ No newline at end of file
|
||||
+A
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMisplacedLineAfterComments2(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected line as 2 "No newline" markers have found, ". Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
+U
|
||||
\ No newline at end of file
|
||||
\ No newline at end of file
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMisplacedLineAfterComments3(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected line as 2 "No newline" markers have found, ". Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
+U
|
||||
\ No newline at end of file
|
||||
\ No newline at end of file
|
||||
+A
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMisplacedComment(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected "\ No newline at end of file", it must be preceded by \'+\' or \'-\' line. Line 1.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnexpectedDuplicateNoNewLineEOF(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected "\\ No newline at end of file", "\\" was already closed. Line 8.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
' . '
|
||||
' . '
|
||||
\ No newline at end of file
|
||||
' . '
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromAfterClose(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Not expected from (\'-\'), already closed by "\ No newline at end of file". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
-A
|
||||
\ No newline at end of file
|
||||
-A
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSameAfterFromClose(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Not expected same (\' \'), \'-\' already closed by "\ No newline at end of file". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
-A
|
||||
\ No newline at end of file
|
||||
A
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testToAfterClose(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Not expected to (\'+\'), already closed by "\ No newline at end of file". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
+A
|
||||
\ No newline at end of file
|
||||
+A
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSameAfterToClose(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Not expected same (\' \'), \'+\' already closed by "\ No newline at end of file". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
+A
|
||||
\ No newline at end of file
|
||||
A
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnexpectedEOFFromMissingLines(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected EOF, number of lines in hunk "from" (\'-\')) mismatched. Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,19 +7,2 @@
|
||||
-A
|
||||
+B
|
||||
' . '
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnexpectedEOFToMissingLines(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected EOF, number of lines in hunk "to" (\'+\')) mismatched. Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,2 +7,3 @@
|
||||
-A
|
||||
+B
|
||||
' . '
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnexpectedEOFBothFromAndToMissingLines(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected EOF, number of lines in hunk "from" (\'-\')) and "to" (\'+\') mismatched. Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,12 +1,14 @@
|
||||
-A
|
||||
+B
|
||||
' . '
|
||||
'
|
||||
);
|
||||
}
|
||||
}
|
1
vendor/sebastian/diff/tests/fixtures/.editorconfig
vendored
Normal file
1
vendor/sebastian/diff/tests/fixtures/.editorconfig
vendored
Normal file
@@ -0,0 +1 @@
|
||||
root = true
|
1
vendor/sebastian/diff/tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/1_a.txt
vendored
Normal file
1
vendor/sebastian/diff/tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/1_a.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a
|
0
vendor/sebastian/diff/tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/1_b.txt
vendored
Normal file
0
vendor/sebastian/diff/tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/1_b.txt
vendored
Normal file
35
vendor/sebastian/diff/tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/2_a.txt
vendored
Normal file
35
vendor/sebastian/diff/tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/2_a.txt
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
18
vendor/sebastian/diff/tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/2_b.txt
vendored
Normal file
18
vendor/sebastian/diff/tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/2_b.txt
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
b
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
c
|
1
vendor/sebastian/diff/tests/fixtures/out/.editorconfig
vendored
Normal file
1
vendor/sebastian/diff/tests/fixtures/out/.editorconfig
vendored
Normal file
@@ -0,0 +1 @@
|
||||
root = true
|
2
vendor/sebastian/diff/tests/fixtures/out/.gitignore
vendored
Normal file
2
vendor/sebastian/diff/tests/fixtures/out/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# reset all ignore rules to create sandbox for integration test
|
||||
!/**
|
BIN
vendor/sebastian/diff/tests/fixtures/serialized_diff.bin
vendored
Normal file
BIN
vendor/sebastian/diff/tests/fixtures/serialized_diff.bin
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user