Skip to content

Commit

Permalink
SA: Bump psalm to level 6
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Apr 5, 2021
1 parent 6cfdd71 commit 4d347fa
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 46 deletions.
9 changes: 7 additions & 2 deletions Controller/ProfilerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use PDO;
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -45,8 +46,12 @@ public function explainAction($token, $connectionName, $query)
assert($profiler instanceof Profiler);
$profiler->disable();

$profile = $profiler->loadProfile($token);
$queries = $profile->getCollector('db')->getQueries();
$profile = $profiler->loadProfile($token);
$collector = $profile->getCollector('db');

assert($collector instanceof DoctrineDataCollector);

$queries = $collector->getQueries();

if (! isset($queries[$connectionName][$query])) {
return new Response('This query does not exist.');
Expand Down
2 changes: 1 addition & 1 deletion Dbal/RegexSchemaAssetFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function __invoke($assetName): bool
$assetName = $assetName->getName();
}

return preg_match($this->filterExpression, $assetName);
return (bool) preg_match($this->filterExpression, $assetName);
}
}
19 changes: 12 additions & 7 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,18 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
$shardNode = $connectionNode
->children()
->arrayNode('shards')
->prototype('array')
->children()
->integerNode('id')
->min(1)
->isRequired()
->end()
->end();
->prototype('array');

// TODO: Remove when https://github.com/psalm/psalm-plugin-symfony/pull/168 is released
assert($shardNode instanceof ArrayNodeDefinition);

$shardNode
->children()
->integerNode('id')
->min(1)
->isRequired()
->end()
->end();
$this->configureDbalDriverNode($shardNode);

return $node;
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ public function getNamespace(): string
*/
public function getConfiguration(array $config, ContainerBuilder $container): Configuration
{
return new Configuration($container->getParameter('kernel.debug'));
return new Configuration((bool) $container->getParameter('kernel.debug'));
}

protected function getMetadataDriverClass(string $driverType): string
Expand Down
4 changes: 2 additions & 2 deletions DoctrineBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function boot()
return;
}

$namespace = $this->container->getParameter('doctrine.orm.proxy_namespace');
$dir = $this->container->getParameter('doctrine.orm.proxy_dir');
$namespace = (string) $this->container->getParameter('doctrine.orm.proxy_namespace');
$dir = (string) $this->container->getParameter('doctrine.orm.proxy_dir');
$proxyGenerator = null;

if ($this->container->getParameter('doctrine.orm.auto_generate_proxy_classes')) {
Expand Down
9 changes: 6 additions & 3 deletions Tests/Command/CreateDatabaseDoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace Doctrine\Bundle\DoctrineBundle\Tests\Command;

use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
use Doctrine\DBAL\Connection;
use Doctrine\Persistence\ManagerRegistry;
use Generator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Container;

use function array_merge;
use function sys_get_temp_dir;
Expand Down Expand Up @@ -119,15 +122,15 @@ public function provideShardOption(): Generator
private function getMockContainer(string $connectionName, ?array $params = null): MockObject
{
// Mock the container and everything you'll need here
$mockDoctrine = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')
$mockDoctrine = $this->getMockBuilder(ManagerRegistry::class)
->getMock();

$mockDoctrine->expects($this->any())
->method('getDefaultConnectionName')
->withAnyParameters()
->willReturn($connectionName);

$mockConnection = $this->getMockBuilder('Doctrine\DBAL\Connection')
$mockConnection = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->setMethods(['getParams'])
->getMockForAbstractClass();
Expand All @@ -142,7 +145,7 @@ private function getMockContainer(string $connectionName, ?array $params = null)
->withAnyParameters()
->willReturn($mockConnection);

$mockContainer = $this->getMockBuilder('Symfony\Component\DependencyInjection\Container')
$mockContainer = $this->getMockBuilder(Container::class)
->setMethods(['get'])
->getMock();

Expand Down
2 changes: 1 addition & 1 deletion Tests/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testContainer(): void
$mappingTypes = [0];
$exception = class_exists(Driver\AbstractDriverException::class) ?
new DriverException('', $this->createMock(Driver\AbstractDriverException::class)) :
new DriverException($this->createMock(Driver\AbstractException::class), null);
new DriverException('', $this->createMock(Driver\AbstractException::class));

// put the mock into the fake driver
FakeDriver::$exception = $exception;
Expand Down
6 changes: 4 additions & 2 deletions Tests/DataCollector/DoctrineDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Doctrine\Bundle\DoctrineBundle\Tests\DataCollector;

use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -79,7 +81,7 @@ public function testDoesNotCollectEntities(): void

public function testGetGroupedQueries(): void
{
$logger = $this->getMockBuilder('Doctrine\DBAL\Logging\DebugStack')->getMock();
$logger = $this->getMockBuilder(DebugStack::class)->getMock();
$logger->queries = [];
$logger->queries[] = [
'sql' => 'SELECT * FROM foo WHERE bar = :bar',
Expand Down Expand Up @@ -128,7 +130,7 @@ private function createEntityMetadata(string $entityFQCN): ClassMetadataInfo
*/
private function createCollector(array $managers, bool $shouldValidateSchema = true): DoctrineDataCollector
{
$registry = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')->getMock();
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry
->expects($this->any())
->method('getConnectionNames')
Expand Down
11 changes: 7 additions & 4 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection;

use Doctrine\Bundle\DoctrineBundle\Dbal\BlacklistSchemaAssetFilter;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DbalSchemaFilterPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\EntityListenerPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\WellKnownSchemaFilterPass;
Expand Down Expand Up @@ -970,8 +971,9 @@ public function testWellKnownSchemaFilterDefaultTables(string $fileName, string

$filter = $container->get('well_known_filter');

$this->assertFalse($filter($tableName));
$this->assertTrue($filter('anything_else'));
$this->assertInstanceOf(BlacklistSchemaAssetFilter::class, $filter);
$this->assertFalse($filter->__invoke($tableName));
$this->assertTrue($filter->__invoke('anything_else'));
}

public static function dataWellKnownSchemaOverriddenTablesFilterServices(): Generator
Expand Down Expand Up @@ -1000,7 +1002,8 @@ public function testWellKnownSchemaFilterOverriddenTables(string $fileName, stri

$filter = $container->get('well_known_filter');

$this->assertFalse($filter($tableName));
$this->assertInstanceOf(BlacklistSchemaAssetFilter::class, $filter);
$this->assertFalse($filter->__invoke($tableName));
}

public function testEntityListenerResolver(): void
Expand Down Expand Up @@ -1201,7 +1204,7 @@ public function testAbstractEntityListener(): void
$this->expectException(InvalidArgumentException::class);
if (method_exists($this, 'expectExceptionMessageMatches')) {
$this->expectExceptionMessageMatches('/The service ".*" must not be abstract\./');
} else {
} elseif (method_exists($this, 'expectExceptionMessageRegExp')) {
$this->expectExceptionMessageRegExp('/The service ".*" must not be abstract\./');
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ public function testInvalidCacheConfiguration(): void
}

/**
* @param array<string, array<string, string|array{type: ?string, pool?: string}>> $cacheConfig
* @param array{pool?: string, type: ?string} $cacheConfig
*
* @dataProvider cacheConfigurationProvider
*/
Expand All @@ -913,7 +913,7 @@ public function testCacheConfiguration(string $expectedAliasName, string $expect
}

/**
* @param array<string, array<string, string|array{type: ?string, pool?: string}>> $cacheConfig
* @param array{pool?: string, type: ?string} $cacheConfig
*
* @dataProvider legacyCacheConfigurationProvider
* @group legacy
Expand Down
1 change: 1 addition & 0 deletions Tests/Mapping/ContainerEntityListenerResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public function testRegisterStringException(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('An object was expected, but got "string".');
/** @psalm-suppress InvalidArgument */
$this->resolver->register('CompanyContractListener');
}
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/Mapping/DisconnectedMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Bundle\DoctrineBundle\Tests\TestCase;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Persistence\ManagerRegistry;
use RuntimeException;

use function interface_exists;
Expand All @@ -27,7 +28,7 @@ public function testCannotFindNamespaceAndPathForMetadata(): void
$class = new ClassMetadataInfo(self::class);
$collection = new ClassMetadataCollection([$class]);

$registry = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')->getMock();
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$factory = new DisconnectedMetadataFactory($registry);

$this->expectException(RuntimeException::class);
Expand All @@ -43,7 +44,7 @@ public function testFindNamespaceAndPathForMetadata(): void
$class = new ClassMetadataInfo('\Vendor\Package\Class');
$collection = new ClassMetadataCollection([$class]);

$registry = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')->getMock();
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$factory = new DisconnectedMetadataFactory($registry);

$factory->findNamespaceAndPathForMetadata($collection, '/path/to/code');
Expand Down
6 changes: 4 additions & 2 deletions Tests/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function setUp(): void
$twigLoaderFilesystem->addPath(__DIR__ . '/../vendor/symfony/web-profiler-bundle/Resources/views', 'WebProfiler');
$this->twig = new Environment($twigLoaderFilesystem, ['debug' => true, 'strict_variables' => true]);

$fragmentHandler = $this->getMockBuilder(FragmentHandler::class)->disableOriginalConstructor()->getMock();
$fragmentHandler = $this->getMockBuilder(FragmentHandler::class);
$fragmentHandler->disableOriginalConstructor();
$fragmentHandler = $fragmentHandler->getMock();
$fragmentHandler->method('render')->willReturn('');

$kernelRuntime = new HttpKernelRuntime($fragmentHandler);
Expand All @@ -59,7 +61,7 @@ public function setUp(): void

$this->twig->addExtension(new CodeExtension('', '', ''));
$this->twig->addExtension(new RoutingExtension($urlGenerator));
$this->twig->addExtension(new HttpKernelExtension($fragmentHandler));
$this->twig->addExtension(new HttpKernelExtension());
$this->twig->addExtension(new WebProfilerExtension());
$this->twig->addExtension(new DoctrineExtension());

Expand Down
23 changes: 12 additions & 11 deletions Tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use InvalidArgumentException;
use ProxyManager\Proxy\ProxyInterface;
use stdClass;
use Symfony\Component\DependencyInjection\ContainerInterface;

use function assert;
use function interface_exists;
Expand All @@ -19,15 +20,15 @@ class RegistryTest extends TestCase
{
public function testGetDefaultConnectionName(): void
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');

$this->assertEquals('default', $registry->getDefaultConnectionName());
}

public function testGetDefaultEntityManagerName(): void
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');

$this->assertEquals('default', $registry->getDefaultManagerName());
Expand All @@ -36,7 +37,7 @@ public function testGetDefaultEntityManagerName(): void
public function testGetDefaultConnection(): void
{
$conn = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.dbal.default_connection'))
Expand All @@ -50,7 +51,7 @@ public function testGetDefaultConnection(): void
public function testGetConnection(): void
{
$conn = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.dbal.default_connection'))
Expand All @@ -63,7 +64,7 @@ public function testGetConnection(): void

public function testGetUnknownConnection(): void
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');

$this->expectException(InvalidArgumentException::class);
Expand All @@ -73,7 +74,7 @@ public function testGetUnknownConnection(): void

public function testGetConnectionNames(): void
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default');

$this->assertEquals(['default' => 'doctrine.dbal.default_connection'], $registry->getConnectionNames());
Expand All @@ -82,7 +83,7 @@ public function testGetConnectionNames(): void
public function testGetDefaultEntityManager(): void
{
$em = new stdClass();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.orm.default_entity_manager'))
Expand All @@ -96,7 +97,7 @@ public function testGetDefaultEntityManager(): void
public function testGetEntityManager(): void
{
$em = new stdClass();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->once())
->method('get')
->with($this->equalTo('doctrine.orm.default_entity_manager'))
Expand All @@ -109,7 +110,7 @@ public function testGetEntityManager(): void

public function testGetUnknownEntityManager(): void
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');

$this->expectException(InvalidArgumentException::class);
Expand All @@ -121,7 +122,7 @@ public function testGetUnknownEntityManager(): void

public function testResetUnknownEntityManager(): void
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$registry = new Registry($container, [], [], 'default', 'default');

$this->expectException(InvalidArgumentException::class);
Expand All @@ -146,7 +147,7 @@ public function testReset(): void
->method('setProxyInitializer')
->with($this->isInstanceOf(Closure::class));

$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->any())
->method('initialized')
->withConsecutive(['doctrine.orm.uninitialized_entity_manager'], ['doctrine.orm.noproxy_entity_manager'], ['doctrine.orm.proxy_entity_manager'])
Expand Down
Loading

0 comments on commit 4d347fa

Please sign in to comment.