Skip to content

Commit

Permalink
Merge pull request #85 from php-enqueue/phpstan
Browse files Browse the repository at this point in the history
Run phpstan and php-cs-fixer on travis
  • Loading branch information
makasim authored May 16, 2017
2 parents a0b94ef + bdcee8c commit cfd1901
Show file tree
Hide file tree
Showing 35 changed files with 70 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ bin/doctrine*
bin/php-cs-fixer
bin/phpunit
bin/sql-formatter
bin/phpstan
bin/jp.php
bin/php-parse
vendor
.php_cs
.php_cs.cache
Expand Down
22 changes: 17 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ matrix:
include:
- php: 5.6
sudo: false
env: SYMFONY_VERSION=2.8.* FUNCTIONAL_TESTS=false
env: SYMFONY_VERSION=2.8.* UNIT_TESTS=true
- php: 7.1
sudo: false
env: SYMFONY_VERSION=3.0.* PHPSTAN=true
- php: 7.1
sudo: false
env: SYMFONY_VERSION=3.0.* PHP_CS_FIXER=true
- php: 7.0
sudo: false
env: SYMFONY_VERSION=2.8.* FUNCTIONAL_TESTS=false
env: SYMFONY_VERSION=2.8.* UNIT_TESTS=true
- php: 5.6
sudo: false
env: SYMFONY_VERSION=3.0.* FUNCTIONAL_TESTS=false SYMFONY_DEPRECATIONS_HELPER=weak
env: SYMFONY_VERSION=3.0.* UNIT_TESTS=true SYMFONY_DEPRECATIONS_HELPER=weak
- php: 7.0
sudo: false
env: SYMFONY_VERSION=3.0.* FUNCTIONAL_TESTS=false SYMFONY_DEPRECATIONS_HELPER=weak
env: SYMFONY_VERSION=3.0.* UNIT_TESTS=true SYMFONY_DEPRECATIONS_HELPER=weak
- php: 7.0
sudo: required
services: docker
Expand All @@ -40,5 +46,11 @@ install:
- if [ "$FUNCTIONAL_TESTS" = true ]; then bin/dev -b; fi

script:
- if [ "$FUNCTIONAL_TESTS" = false ]; then bin/phpunit --exclude-group=functional; fi
# misssing pkg/amqp-ext pkg/job-queue pkg/redis
- if [ "$PHPSTAN" = true ]; then ./bin/phpstan analyse -l 1 -c phpstan.neon pkg/enqueue pkg/psr-queue pkg/fs pkg/simple-client; fi
- if [ "$PHPSTAN" = true ]; then ./bin/phpstan analyse -l 1 -c phpstan.neon pkg/stomp pkg/dbal pkg/enqueue-bundle pkg/null pkg/sqs pkg/test; fi
- if [ "$PHP_CS_FIXER" = true ]; then IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}")); unset IFS; fi
- if [ "$PHP_CS_FIXER" = true ]; then ./bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}"; fi
- if [ "$UNIT_TESTS" = true ]; then bin/phpunit --exclude-group=functional; fi
- if [ "$FUNCTIONAL_TESTS" = true ]; then bin/dev -t; fi

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"symfony/browser-kit": "^2.8|^3",
"symfony/expression-language": "^2.8|^3",
"friendsofphp/php-cs-fixer": "^2",
"empi89/php-amqp-stubs": "*@dev"
"empi89/php-amqp-stubs": "*@dev",
"phpstan/phpstan": "^0.7.0"
},
"autoload": {
"files": ["pkg/enqueue/functions_include.php"]
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
excludes_analyse:
- pkg/enqueue/Util/UUID.php
2 changes: 1 addition & 1 deletion pkg/amqp-ext/Tests/Client/AmqpDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public function testShouldSetupBroker()

$meta = new QueueMetaRegistry($this->createDummyConfig(), [
'default' => [],
], 'default');
]);

$driver = new AmqpDriver(
$context,
Expand Down
2 changes: 1 addition & 1 deletion pkg/dbal/Tests/DbalProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testShouldThrowIfDestinationOfInvalidType()

$producer = new DbalProducer($this->createContextMock());

$producer->send(new NotSupportedDestination1(''), new DbalMessage());
$producer->send(new NotSupportedDestination1(), new DbalMessage());
}

public function testShouldThrowIfInsertMessageFailed()
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function testTransportConsumeMessagesCommandShouldConsumeMessage(array $e
*/
public static function getKernelClass()
{
include_once __DIR__.'/app/CustomAppKernel.php';
include_once __DIR__.'/App/CustomAppKernel.php';

return CustomAppKernel::class;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue-bundle/Tests/Functional/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp()
*/
public static function getKernelClass()
{
include_once __DIR__.'/app/AppKernel.php';
include_once __DIR__.'/App/AppKernel.php';

return AppKernel::class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testShouldImplementCompilerPass()

public function testCouldBeConstructedWithoutAntArguments()
{
new AddTopicMetaPass([]);
new AddTopicMetaPass();
}

public function testCouldBeConstructedByCreateFactoryMethod()
Expand Down
7 changes: 6 additions & 1 deletion pkg/enqueue/Client/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class Message
*/
private $correlationId;

/**
* @var string
*/
private $scope;

/**
* @var array
*/
Expand All @@ -89,7 +94,7 @@ public function getBody()
}

/**
* @param null|string|number|array|\JsonSerializable $body
* @param null|string|int|float|array|\JsonSerializable $body
*/
public function setBody($body)
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/enqueue/Consumption/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Result
private $reply;

/**
* @param string $status
* @param string $reason
* @param mixed $status
* @param mixed $reason
*/
public function __construct($status, $reason = '')
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testCouldBeConstructedWithRequiredArguments()

public function testShouldSetupBroker()
{
$logger = new NullLogger('');
$logger = new NullLogger();

$driver = $this->createDriverMock();
$driver
Expand All @@ -45,7 +45,7 @@ public function testShouldSetupBroker()

public function testShouldSetupBrokerOnlyOnce()
{
$logger = new NullLogger('');
$logger = new NullLogger();

$driver = $this->createDriverMock();
$driver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Enqueue\Tests\Consumption;
namespace Enqueue\Tests\Consumption\Exception;

use Enqueue\Consumption\Exception\ConsumptionInterruptedException;
use Enqueue\Consumption\Exception\ExceptionInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Enqueue\Tests\Consumption;
namespace Enqueue\Tests\Consumption\Exception;

use Enqueue\Consumption\Exception\ExceptionInterface;
use Enqueue\Consumption\Exception\IllegalContextModificationException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Enqueue\Tests\Consumption;
namespace Enqueue\Tests\Consumption\Exception;

use Enqueue\Consumption\Exception\ExceptionInterface;
use Enqueue\Consumption\Exception\InvalidArgumentException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Enqueue\Tests\Consumption;
namespace Enqueue\Tests\Consumption\Exception;

use Enqueue\Consumption\Exception\ExceptionInterface;
use Enqueue\Consumption\Exception\LogicException;
Expand Down
7 changes: 1 addition & 6 deletions pkg/enqueue/Tests/Consumption/QueueConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,7 @@ public function testShouldCallOnStartExtensionMethod()
->expects($this->once())
->method('onStart')
->with($this->isInstanceOf(Context::class))
->willReturnCallback(function (Context $context) use (
$contextStub,
$messageConsumerStub,
$processorMock
) {
->willReturnCallback(function (Context $context) use ($contextStub) {
$this->assertSame($contextStub, $context->getPsrContext());
$this->assertNull($context->getPsrConsumer());
$this->assertNull($context->getPsrProcessor());
Expand Down Expand Up @@ -446,7 +442,6 @@ public function testShouldCallOnBeforeReceiveExtensionMethod()
$contextStub,
$messageConsumerStub,
$processorMock,
$expectedMessage,
$queue
) {
$this->assertSame($contextStub, $context->getPsrContext());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Enqueue\Tests\Router;
namespace Enqueue\Tests\Functions;

use Enqueue\AmqpExt\AmqpConnectionFactory;
use Enqueue\Fs\FsConnectionFactory;
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Tests/Functions/DsnToContextFunctionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Enqueue\Tests\Router;
namespace Enqueue\Tests\Functions;

use Enqueue\AmqpExt\AmqpContext;
use Enqueue\Fs\FsContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private function createQueueMetaRegistry(array $destinationNames)
'aRouterProcessorName'
);

return new QueueMetaRegistry($config, $destinationNames, 'default');
return new QueueMetaRegistry($config, $destinationNames);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion pkg/fs/FsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function purge(PsrQueue $queue)
{
InvalidDestinationException::assertDestinationInstanceOf($queue, FsDestination::class);

$this->workWithFile($queue, 'c', function (FsDestination $destination, $file) use ($queue) {
$this->workWithFile($queue, 'c', function (FsDestination $destination, $file) {
ftruncate($file, 0);
});
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fs/Tests/Client/FsDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function testShouldSetupBroker()

$meta = new QueueMetaRegistry($this->createDummyConfig(), [
'default' => [],
], 'default');
]);

$driver = new FsDriver(
$context,
Expand Down
6 changes: 6 additions & 0 deletions pkg/fs/Tests/Functional/FsContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
namespace Enqueue\Fs\Tests\Functional;

use Enqueue\Fs\FsConnectionFactory;
use Enqueue\Fs\FsContext;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;

class FsContextTest extends TestCase
{
/**
* @var FsContext|null
*/
private $fsContext;

public function tearDown()
{
$fs = new Filesystem();
Expand Down
2 changes: 1 addition & 1 deletion pkg/redis/RedisContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct($redis)
$this->redisFactory = $redis;
} else {
throw new \InvalidArgumentException(sprintf(
'The $redis argument must be either %s or callable that returns $s once called.',
'The $redis argument must be either %s or callable that returns %s once called.',
Redis::class,
Redis::class
));
Expand Down
2 changes: 1 addition & 1 deletion pkg/redis/Tests/Client/RedisDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function testShouldDoNothingOnSetupBroker()

$meta = new QueueMetaRegistry(Config::create(), [
'default' => [],
], 'default');
]);

$driver = new RedisDriver(
$context,
Expand Down
2 changes: 1 addition & 1 deletion pkg/redis/Tests/RedisConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testShouldReturnDestinationSetInConstructorOnGetQueue()
{
$destination = new RedisDestination('aQueue');

$consumer = new RedisConsumer($this->createContextMock(), $destination, 1);
$consumer = new RedisConsumer($this->createContextMock(), $destination);

$this->assertSame($destination, $consumer->getQueue());
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/redis/Tests/RedisContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testCouldBeConstructedWithRedisFactoryAsFirstArgument()
public function testThrowIfNeitherRedisNorFactoryGiven()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The $redis argument must be either Enqueue\Redis\Redis or callable that returns $s once called.');
$this->expectExceptionMessage('The $redis argument must be either Enqueue\Redis\Redis or callable that returns Enqueue\Redis\Redis once called.');
new RedisContext(new \stdClass());
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/stomp/Tests/Client/RabbitMqStompDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testShouldReturnConfigObject()

public function testShouldCreateAndReturnQueueInstance()
{
$expectedQueue = new StompDestination('aName');
$expectedQueue = new StompDestination();

$context = $this->createPsrContextMock();
$context
Expand Down Expand Up @@ -86,7 +86,7 @@ public function testShouldCreateAndReturnQueueInstance()

public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName()
{
$expectedQueue = new StompDestination('aName');
$expectedQueue = new StompDestination();

$context = $this->createPsrContextMock();
$context
Expand Down Expand Up @@ -306,7 +306,7 @@ public function testShouldThrowExceptionIfDelayIsSetButDelayPluginInstalledOptio

public function testShouldSendMessageToRouter()
{
$topic = new StompDestination('');
$topic = new StompDestination();
$transportMessage = new StompMessage();

$producer = $this->createPsrProducerMock();
Expand Down Expand Up @@ -362,7 +362,7 @@ public function testShouldThrowExceptionIfTopicParameterIsNotSet()

public function testShouldSendMessageToProcessor()
{
$queue = new StompDestination('');
$queue = new StompDestination();
$transportMessage = new StompMessage();

$producer = $this->createPsrProducerMock();
Expand Down Expand Up @@ -405,8 +405,8 @@ public function testShouldSendMessageToProcessor()

public function testShouldSendMessageToDelayExchangeIfDelaySet()
{
$queue = new StompDestination('');
$delayTopic = new StompDestination('');
$queue = new StompDestination();
$delayTopic = new StompDestination();
$transportMessage = new StompMessage();

$producer = $this->createPsrProducerMock();
Expand Down
8 changes: 4 additions & 4 deletions pkg/stomp/Tests/Client/StompDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testShouldReturnConfigObject()

public function testShouldCreateAndReturnQueueInstance()
{
$expectedQueue = new StompDestination('aName');
$expectedQueue = new StompDestination();

$context = $this->createPsrContextMock();
$context
Expand All @@ -66,7 +66,7 @@ public function testShouldCreateAndReturnQueueInstance()

public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName()
{
$expectedQueue = new StompDestination('aName');
$expectedQueue = new StompDestination();

$context = $this->createPsrContextMock();
$context
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testShouldConvertClientMessageToTransportMessage()

public function testShouldSendMessageToRouter()
{
$topic = new StompDestination('');
$topic = new StompDestination();
$transportMessage = new StompMessage();

$producer = $this->createPsrProducerMock();
Expand Down Expand Up @@ -207,7 +207,7 @@ public function testShouldThrowExceptionIfTopicParameterIsNotSet()

public function testShouldSendMessageToProcessor()
{
$queue = new StompDestination('');
$queue = new StompDestination();
$transportMessage = new StompMessage();

$producer = $this->createPsrProducerMock();
Expand Down

0 comments on commit cfd1901

Please sign in to comment.