Skip to content

Commit

Permalink
chore: migrate and update php-cs-fixer 2 => 3 (#234)
Browse files Browse the repository at this point in the history
* chore: migrate and update php-cs-fixer 2 => 3

---------

Co-authored-by: Christopher Georg <christopher.georg@sr-travel.de>
  • Loading branch information
Chris53897 and Chris8934 committed Jun 3, 2023
1 parent f3dfba7 commit e19bfbb
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: PHP-CS-Fixer
uses: docker://jakzal/phpqa:1.58.7-php7.4-alpine
uses: docker://jakzal/phpqa:1.80.0-php7.4-alpine
with:
args: php-cs-fixer --dry-run --diff --no-interaction --ansi fix

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.idea/
composer.lock
vendor
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
.phpunit.cache

Expand Down
18 changes: 8 additions & 10 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
with this source code in the file LICENSE.
HEADER;


$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->notPath('/cache/')
;

return PhpCsFixer\Config::create()
$config = new PhpCsFixer\Config();
return $config
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
Expand All @@ -28,21 +30,17 @@
'header_comment' => [
'header' => $header,
],
'no_extra_consecutive_blank_lines' => true,
'no_extra_blank_lines' => true,
'no_php4_constructor' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
],
'phpdoc_order' => true,
'@PHP56Migration' => true,
'@PHP56Migration:risky' => true,
'@PHP70Migration' => true,
'@PHP70Migration:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'strict_comparison' => true,
'strict_param' => true,
'php_unit_strict' => true,
])
->setUsingCache(true)
;
;
10 changes: 4 additions & 6 deletions src/Services/DatabaseBackup/AbstractDatabaseBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

namespace Liip\TestFixturesBundle\Services\DatabaseBackup;

use DateTime;
use Liip\TestFixturesBundle\Services\FixturesLoaderFactory;
use ReflectionClass;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down Expand Up @@ -67,7 +65,7 @@ public function init(array $metadatas, array $classNames, bool $append = false):
*/
protected function isBackupUpToDate(string $backup): bool
{
$backupLastModifiedDateTime = DateTime::createFromFormat('U', (string) filemtime($backup));
$backupLastModifiedDateTime = \DateTime::createFromFormat('U', (string) filemtime($backup));

$loader = $this->fixturesLoaderFactory->getFixtureLoader($this->classNames);

Expand All @@ -90,15 +88,15 @@ protected function isBackupUpToDate(string $backup): bool
* @param string $class The fully qualified class name of the fixture class to
* check modification date on
*/
protected function getFixtureLastModified($class): ?DateTime
protected function getFixtureLastModified($class): ?\DateTime
{
$lastModifiedDateTime = null;

$reflClass = new ReflectionClass($class);
$reflClass = new \ReflectionClass($class);
$classFileName = $reflClass->getFileName();

if (file_exists($classFileName)) {
$lastModifiedDateTime = new DateTime();
$lastModifiedDateTime = new \DateTime();
$lastModifiedDateTime->setTimestamp(filemtime($classFileName));
}

Expand Down
3 changes: 1 addition & 2 deletions src/Services/DatabaseBackup/SqliteDatabaseBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\Common\DataFixtures\Executor\AbstractExecutor;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use InvalidArgumentException;

/**
* @author Aleksey Tupichenkov <alekseytupichenkov@gmail.com>
Expand Down Expand Up @@ -71,7 +70,7 @@ private function getDatabaseName(Connection $connection): string

$name = $params['path'] ?? ($params['dbname'] ?? false);
if (!$name) {
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
throw new \InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
}

return $name;
Expand Down
10 changes: 4 additions & 6 deletions src/Services/DatabaseTools/AbstractDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@

namespace Liip\TestFixturesBundle\Services\DatabaseTools;

use BadMethodCallException;
use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader;
use Doctrine\Common\DataFixtures\Executor\AbstractExecutor;
use Doctrine\DBAL\Connection;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use InvalidArgumentException;
use Liip\TestFixturesBundle\Services\DatabaseBackup\DatabaseBackupInterface;
use Liip\TestFixturesBundle\Services\FixturesLoaderFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -168,13 +166,13 @@ public function loadAllFixtures(array $groups = []): ?AbstractExecutor
}

/**
* @throws BadMethodCallException
* @throws \BadMethodCallException
*/
public function loadAliceFixture(array $paths = [], bool $append = false): array
{
$persisterLoaderServiceName = 'fidry_alice_data_fixtures.loader.doctrine';
if (!$this->container->has($persisterLoaderServiceName)) {
throw new BadMethodCallException('theofidry/alice-data-fixtures must be installed to use this method.');
throw new \BadMethodCallException('theofidry/alice-data-fixtures must be installed to use this method.');
}

if (false === $append) {
Expand Down Expand Up @@ -219,7 +217,7 @@ protected function cleanDatabase(): void
/**
* Locate fixture files.
*
* @throws InvalidArgumentException if a wrong path is given outside a bundle
* @throws \InvalidArgumentException if a wrong path is given outside a bundle
*/
protected function locateResources(array $paths): array
{
Expand All @@ -230,7 +228,7 @@ protected function locateResources(array $paths): array
foreach ($paths as $path) {
if ('@' !== $path[0]) {
if (!file_exists($path)) {
throw new InvalidArgumentException(sprintf('Unable to find file "%s".', $path));
throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $path));
}
$files[] = $path;

Expand Down
6 changes: 2 additions & 4 deletions tests/AppConfigPhpcr/DataFixtures/PHPCR/LoadTaskData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\ODM\PHPCR\DocumentManager;
use Doctrine\Persistence\ObjectManager;
use Exception;
use Liip\Acme\Tests\AppConfigPhpcr\Document\Task;
use RuntimeException;

class LoadTaskData implements FixtureInterface
{
Expand All @@ -27,13 +25,13 @@ public function load(ObjectManager $manager): void
if (!$manager instanceof DocumentManager) {
$class = \get_class($manager);

throw new RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '{$class}' given.");
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '{$class}' given.");
}

$rootTask = $manager->find(null, '/');

if (!$rootTask) {
throw new Exception('Could not find / document!');
throw new \Exception('Could not find / document!');
}

$task = new Task();
Expand Down
2 changes: 2 additions & 0 deletions tests/Test/ConfigEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("dataProvider")
*
* @internal
Expand Down
2 changes: 2 additions & 0 deletions tests/Test/ConfigMysqlCacheDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("group")
*
* @internal
Expand Down
2 changes: 2 additions & 0 deletions tests/Test/ConfigMysqlKeepDatabaseAndSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("group")
*
* @internal
Expand Down
2 changes: 2 additions & 0 deletions tests/Test/ConfigMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("group")
*
* @internal
Expand Down
1 change: 1 addition & 0 deletions tests/Test/ConfigMysqlUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @internal
Expand Down
1 change: 1 addition & 0 deletions tests/Test/ConfigPgsqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @internal
Expand Down
1 change: 1 addition & 0 deletions tests/Test/ConfigPhpcrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @internal
Expand Down
6 changes: 3 additions & 3 deletions tests/Test/ConfigSqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\Persistence\ObjectRepository;
use InvalidArgumentException;
use Liip\Acme\Tests\App\Entity\User;
use Liip\Acme\Tests\AppConfigSqlite\AppConfigSqliteKernel;
use Liip\Acme\Tests\Traits\ContainerProvider;
Expand All @@ -33,6 +32,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence

/**
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("depends")
Expand Down Expand Up @@ -348,7 +348,7 @@ public function testLoadFixturesFiles(): void
*/
public function testLoadNonexistentFixturesFiles(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);

$this->databaseTool->loadAliceFixture([
'@AcmeBundle/DataFixtures/ORM/nonexistent.yml',
Expand Down Expand Up @@ -458,7 +458,7 @@ public function testLoadNonexistentFixturesFilesPaths(): void
{
$path = ['/nonexistent.yml'];

$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);

$this->databaseTool->loadAliceFixture($path);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Test/ConfigSqliteUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
* Run SQLite tests by using an URL for Doctrine.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("depends")
Expand Down
3 changes: 2 additions & 1 deletion tests/Test/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* Avoid conflict with PHPUnit annotation when reading QueryCount
Expand Down Expand Up @@ -144,7 +145,7 @@ public function testCacheCanBeDisabled(): void
/** @var User $user1 */
$user1 = $this->userRepository->findOneBy(['id' => 1]);

//The salt are not the same because cache were not used
// The salt are not the same because cache were not used
$this->assertNotSame($user1Salt, $user1->getSalt());

// Enable the cache again
Expand Down

0 comments on commit e19bfbb

Please sign in to comment.