Skip to content

Commit

Permalink
Add Rector (#132)
Browse files Browse the repository at this point in the history
* Add Rector
* fix phpunit prophecy warning
* migrate phpunit config
  • Loading branch information
ilario-pierbattista authored Nov 11, 2023
1 parent 008dc49 commit a9d7804
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 34 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ jobs:
- php: 7.4
mongo-ext: 1.6.0
mongo-img: 4.2
- php: 7.4
mongo-ext: 1.9.0
mongo-img: 4.4
- php: 8.1
mongo-ext: 1.12.0
mongo-img: 5.0
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ setup-82: | build-82 --setup-common
.PHONY: sh stop
sh: docker-compose.yml
$(DOCKER_COMPOSE) up -d --force-recreate
$(DOCKER_COMPOSE) exec -ti php bash
$(DOCKER_COMPOSE) exec php bash

stop: docker-compose.yml
$(DOCKER_COMPOSE) stop
Expand Down Expand Up @@ -82,3 +82,9 @@ cs-fix:
composer cs-fix
cs-check:
composer cs-check

.PHONY: rector rector-apply
rector:
bin/rector process --dry-run
rector-apply:
bin/rector process
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"phpstan/phpstan": "1.10.41",
"phpstan/extension-installer": "1.3.1",
"jangregor/phpstan-prophecy": "1.0.0",
"phpspec/prophecy": "^1.17"
"phpspec/prophecy": "^1.17",
"rector/rector": "^0.18.6",
"phpspec/prophecy-phpunit": "^2.0"
},
"minimum-stability": "stable",
"suggest": {
Expand Down
50 changes: 21 additions & 29 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.0/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
</php>

<testsuites>
<testsuite name="MongoBundle Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/</directory>
<exclude>
<directory>./src/Resources</directory>
<directory>./tests</directory>
<directory>./docs</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory>./src/</directory>
</include>
<exclude>
<directory>./src/Resources</directory>
<directory>./tests</directory>
<directory>./docs</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
</php>
<testsuites>
<testsuite name="MongoBundle Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(\Rector\PHPUnit\PHPUnit100\Rector\Class_\AddProphecyTraitRector::class);

$rectorConfig->sets([
PHPUnitSetList::PHPUNIT_90,
]);
};
2 changes: 2 additions & 0 deletions tests/Functional/Capsule/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

class CollectionTest extends AppTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;

private function getManager(): Manager
{
/** @var \Facile\MongoDbBundle\Services\ClientRegistry $reg */
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Controller/ProfilerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

class ProfilerControllerTest extends AppTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;

protected function setUp(): void
{
$this->setEnvDev();
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Capsule/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class ClientTest extends TestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;

public function test_mongodb_client_encapsulation()
{
$client = new Client('mongodb://localhost:27017', [], [], 'test_client', $this->prophesize(EventDispatcherInterface::class)->reveal());
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Capsule/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

class DatabaseTest extends TestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;

public function test_selectCollection(): void
{
$manager = new Manager('mongodb://localhost');
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/DataCollector/MongoQuerySerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

class MongoQuerySerializerTest extends TestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;

/**
* @param $unserializedData
*
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Services/ClientRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

class ClientRegistryTest extends TestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;

public function test_client_connection_url_provided_manually()
{
$registry = new ClientRegistry($this->createEventDispatcherMock(), false, null);
Expand Down

0 comments on commit a9d7804

Please sign in to comment.