Skip to content

Commit

Permalink
Merge branch '2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
julienfalque committed Nov 23, 2019
2 parents e5d7876 + 653f619 commit 7e61d48
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"symbol-whitelist" : [
"Symfony\\Contracts\\EventDispatcher\\Event",
"Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface",
"Symfony\\Component\\EventDispatcher\\Event",
"PhpCsFixer\\Tests\\Test\\Constraint\\SameStringsConstraint",
"PhpCsFixer\\Tests\\Test\\IsIdenticalConstraint",
"PHPUnit\\Framework\\Constraint\\IsIdentical",
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
<<: *STANDARD_TEST_JOB
stage: Test
php: 7.2
env: SYMFONY_DEPRECATIONS_HELPER=disabled PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER=1 SYMFONY_VERSION="^5.0"

-
<<: *STANDARD_TEST_JOB
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"composer/xdebug-handler": "^1.2",
"doctrine/annotations": "^1.2",
"php-cs-fixer/diff": "^1.3",
"symfony/console": "^3.4.17 || ^4.1.6",
"symfony/event-dispatcher": "^3.0 || ^4.0",
"symfony/filesystem": "^3.0 || ^4.0",
"symfony/finder": "^3.0 || ^4.0",
"symfony/options-resolver": "^3.0 || ^4.0",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0",
"symfony/event-dispatcher": "^3.0 || ^4.0 || ^5.0",
"symfony/filesystem": "^3.0 || ^4.0 || ^5.0",
"symfony/finder": "^3.0 || ^4.0 || ^5.0",
"symfony/options-resolver": "^3.0 || ^4.0 || ^5.0",
"symfony/polyfill-php70": "^1.0",
"symfony/polyfill-php72": "^1.4",
"symfony/process": "^3.0 || ^4.0",
"symfony/stopwatch": "^3.0 || ^4.0"
"symfony/process": "^3.0 || ^4.0 || ^5.0",
"symfony/stopwatch": "^3.0 || ^4.0 || ^5.0"
},
"require-dev": {
"johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0",
Expand All @@ -42,8 +42,8 @@
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.1",
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.1",
"phpunitgoodpractices/traits": "^1.8",
"symfony/phpunit-bridge": "^4.3",
"symfony/yaml": "^3.0 || ^4.0"
"symfony/phpunit-bridge": "^4.3 || ^5.0",
"symfony/yaml": "^3.0 || ^4.0 || ^5.0"
},
"suggest": {
"ext-mbstring": "For handling non-UTF8 characters in cache signature.",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ parameters:
- '/^Return typehint of method PhpCsFixer\\Tests\\Test\\.+::createIsIdenticalStringConstraint\(\) has invalid type PHPUnit_Framework_Constraint_IsIdentical\.$/'
## cannot analyse out of PHP 7.4
- '/^Constant T_FN not found\.$/'
- '/^Class (Symfony\\Contracts\\EventDispatcher\\Event|Symfony\\Component\\EventDispatcher\\Event) not found.$/'
12 changes: 8 additions & 4 deletions src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,15 @@ public function getDirectory()
{
if (null === $this->directory) {
$path = $this->getCacheFile();
$filesystem = new Filesystem();
if (null === $path) {
$absolutePath = $this->cwd;
} else {
$filesystem = new Filesystem();

$absolutePath = $filesystem->isAbsolutePath($path)
? $path
: $this->cwd.\DIRECTORY_SEPARATOR.$path;
$absolutePath = $filesystem->isAbsolutePath($path)
? $path
: $this->cwd.\DIRECTORY_SEPARATOR.$path;
}

$this->directory = new Directory(\dirname($absolutePath));
}
Expand Down
26 changes: 26 additions & 0 deletions src/Event/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <[email protected]>
* Dariusz Rumiński <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace PhpCsFixer\Event;

// Since PHP-CS-FIXER is PHP 5.6 compliant we can't always use Symfony Contracts (currently needs PHP ^7.1.3)
// This conditionnal inheritance will be useless when PHP-CS-FIXER no longer supports PHP versions
// inferior to Symfony/Contracts PHP minimal version
if (class_exists(\Symfony\Contracts\EventDispatcher\Event::class)) {
class Event extends \Symfony\Contracts\EventDispatcher\Event
{
}
} else {
class Event extends \Symfony\Component\EventDispatcher\Event
{
}
}
2 changes: 1 addition & 1 deletion src/FixerFileProcessedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace PhpCsFixer;

use Symfony\Component\EventDispatcher\Event;
use PhpCsFixer\Event\Event;

/**
* Event that is fired when file was processed by Fixer.
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/FileFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
namespace PhpCsFixer\Runner;

use PhpCsFixer\Cache\CacheManagerInterface;
use PhpCsFixer\Event\Event;
use PhpCsFixer\FileReader;
use PhpCsFixer\FixerFileProcessedEvent;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
use PhpCsFixer\Differ\DifferInterface;
use PhpCsFixer\Error\Error;
use PhpCsFixer\Error\ErrorsManager;
use PhpCsFixer\Event\Event;
use PhpCsFixer\FileReader;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\FixerFileProcessedEvent;
use PhpCsFixer\Linter\LinterInterface;
use PhpCsFixer\Linter\LintingException;
use PhpCsFixer\Linter\LintingResultInterface;
use PhpCsFixer\Tokenizer\Tokens;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Filesystem\Exception\IOException;

Expand Down
1 change: 1 addition & 0 deletions tests/AutoReview/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function (\ReflectionClass $interface) {
// @TODO: 3.0 should be removed
$exceptionMethodsPerClass = [
\PhpCsFixer\Config::class => ['create'],
\PhpCsFixer\Event\Event::class => ['stopPropagation'],
\PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer::class => ['fixSpace'],
];

Expand Down
41 changes: 41 additions & 0 deletions tests/Console/ConfigurationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,47 @@ public function provideDeprecatedFixerConfiguredCases()
];
}

public function provideGetDirectoryCases()
{
return [
[null, '/my/path/my/file', 'path/my/file'],
['/my/path2/dir/.php_cs.cache', '/my/path2/dir/dir2/file', 'dir2/file'],
['dir/.php_cs.cache', '/my/path/dir/dir3/file', 'dir3/file'],
];
}

/**
* @dataProvider provideGetDirectoryCases
*
* @param null|string $cacheFile
* @param string $file
* @param string $expectedPathRelativeToFile
*/
public function testGetDirectory($cacheFile, $file, $expectedPathRelativeToFile)
{
if (null !== $cacheFile) {
$cacheFile = $this->normalizePath($cacheFile);
}
$file = $this->normalizePath($file);
$expectedPathRelativeToFile = $this->normalizePath($expectedPathRelativeToFile);

$config = new Config();
if (null === $cacheFile) {
$config->setUsingCache(false);
} else {
$config->setCacheFile($cacheFile);
}

$resolver = new ConfigurationResolver($config, [], $this->normalizePath('/my/path'), new ToolInfo());
$directory = $resolver->getDirectory();
static::assertSame($expectedPathRelativeToFile, $directory->getRelativePathTo($file));
}

private function normalizePath($path)
{
return str_replace('/', \DIRECTORY_SEPARATOR, $path);
}

private static function assertSameRules(array $expected, array $actual, $message = '')
{
ksort($expected);
Expand Down
33 changes: 33 additions & 0 deletions tests/Event/EventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <[email protected]>
* Dariusz Rumiński <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace PhpCsFixer\Tests\Event;

use PhpCsFixer\Event\Event;
use PhpCsFixer\Tests\TestCase;

/**
* @internal
* @covers \PhpCsFixer\Event\Event
*/
final class EventTest extends TestCase
{
public function testInheritance()
{
$event = new Event();
if (class_exists(\Symfony\Contracts\EventDispatcher\Event::class)) {
static::assertInstanceOf(\Symfony\Contracts\EventDispatcher\Event::class, $event);
} else {
static::assertInstanceOf(\Symfony\Component\EventDispatcher\Event::class, $event);
}
}
}

0 comments on commit 7e61d48

Please sign in to comment.