Skip to content

Commit

Permalink
Allow Laravel 11 (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Mar 23, 2024
2 parents 83628f8 + 708ff3e commit 442a725
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 41 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/tests.yml
Expand Up @@ -27,21 +27,21 @@ jobs:
composer: v2

- deps: 'stable'
php: 8.3
php: '8.3'
symfony: '6.x'
laravel: '10.x'
experimental: false
composer: v2

- deps: 'dev'
php: 8.3
php: '8.3'
symfony: '7.x'
laravel: '11.x'
experimental: false
composer: v2

- deps: 'dev'
php: 8.4
php: '8.4'
symfony: '7.x'
laravel: '11.x'
experimental: true
Expand Down Expand Up @@ -84,13 +84,13 @@ jobs:
echo "LARAVEL_REQUIRE=$(echo '${{ matrix.laravel }}' | tr x \\*)" >> $GITHUB_ENV
fi
if [ "${{ matrix.symfony }}" = "7.x" ]; then
# Psalm Symfony Plugin doesn't support Symfony 7 yet
composer remove --no-update --dev vimeo/psalm psalm/plugin-symfony
#if [ "${{ matrix.symfony }}" = "7.x" ]; then
# # Psalm Symfony Plugin doesn't support Symfony 7 yet
# composer remove --no-update --dev vimeo/psalm psalm/plugin-symfony
# Carbon needs version 3
composer require --no-update nesbot/carbon:"3.x-dev as 2.99.0"
fi
# # Carbon needs version 3
# composer require --no-update nesbot/carbon:"3.x-dev as 2.99.0"
#fi
echo "PHP_VERSION=${{ matrix.php }}" >> $GITHUB_ENV
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Expand Up @@ -7,9 +7,9 @@

"require": {
"php": "^8.0",
"illuminate/database": "^9.0 || ^10.0",
"illuminate/events": "^9.0 || ^10.0",
"illuminate/console": "^9.39 || ^10.0",
"illuminate/database": "^9.0 || ^10.0 || ^11.0",
"illuminate/events": "^9.0 || ^10.0 || ^11.0",
"illuminate/console": "^9.39 || ^10.0 || ^11.0",
"symfony/framework-bundle": "^6.0 || ^7.0",
"symfony/dependency-injection": "^6.0 || ^7.0",
"jdorn/sql-formatter": "^1.2.17"
Expand All @@ -33,12 +33,12 @@
"symfony/twig-bridge": "^6.0 || ^7.0",
"symfony/var-dumper": "^6.0 || ^7.0",
"symfony/process": "^6.0 || ^7.0",
"twig/twig": "^1.26 || ^2.0 || ^3.0",
"vimeo/psalm": "^3.18.2 || ^4.0",
"psalm/plugin-symfony": "^1.5.0 || ^2.0 || ^3.0"
"twig/twig": "^2.0 || ^3.0",
"vimeo/psalm": "^5.0",
"psalm/plugin-symfony": "^5.0"
},
"conflict": {
"illuminate/console": ">=9.21,<9.39"
"nesbot/carbon": "<2.63"
},

"autoload": { "psr-4": { "WouterJ\\EloquentBundle\\": "src" } },
Expand Down
8 changes: 8 additions & 0 deletions psalm.xml
Expand Up @@ -3,6 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
errorLevel="4"
>
<projectFiles>
Expand All @@ -22,8 +24,14 @@
<UndefinedMethod>
<errorLevel type="suppress">
<referencedMethod name="WouterJ\EloquentBundle\Seeder::run"/>
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeDefinition::fixXmlConfig"/>
</errorLevel>
</UndefinedMethod>
<UndefinedInterfaceMethod>
<errorLevel type="suppress">
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeParentInterface::scalarNode"/>
</errorLevel>
</UndefinedInterfaceMethod>
</issueHandlers>

<plugins>
Expand Down
2 changes: 1 addition & 1 deletion src/Command/BaseMigrateCommand.php
Expand Up @@ -46,7 +46,7 @@ protected function getMigrationPath(): string
return $this->migrationPath;
}

protected function getMigrationPaths(InputInterface $input = null): array
protected function getMigrationPaths(?InputInterface $input = null): array
{
if (null !== $input && $input->hasOption('path') && null !== $path = $input->getOption('path')) {
return [getcwd().'/'.$path];
Expand Down
3 changes: 1 addition & 2 deletions src/DataCollector/EloquentDataCollector.php
Expand Up @@ -38,10 +38,9 @@ public function __construct(Manager $capsule, QueryListener $queryListener)

public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
/** @psalm-suppress UndefinedInterfaceMethod */
$connections = array_map(function ($config) {
return $this->cloneVar($config);
}, $this->capsule->getContainer()['config']['database.connections']);
}, $this->capsule->getContainer()->make('config')['database.connections']);

$usedConnections = [];
foreach (array_keys($this->capsule->getDatabaseManager()->getConnections()) as $name) {
Expand Down
8 changes: 1 addition & 7 deletions src/DependencyInjection/Configuration.php
Expand Up @@ -26,13 +26,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('wouterj_eloquent');
/** @psalm-suppress RedundantCondition */
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
/** @psalm-suppress UndefinedMethod */
$root = $treeBuilder->root('wouterj_eloquent');
}
$root = $treeBuilder->getRootNode();

$this->addAliasesSection($root);
$this->addCapsuleSection($root);
Expand Down
4 changes: 1 addition & 3 deletions src/Factory/Factory.php
Expand Up @@ -6,16 +6,14 @@
use Illuminate\Database\Eloquent\Model;

/**
* @psalm-suppress TooManyTemplateParams BC with Laravel 8
* @template TModel of Model
* @extends IlluminateFactory<TModel>
*/
abstract class Factory extends IlluminateFactory
{
public function modelName(): string
{
/** @psalm-suppress RedundantPropertyInitializationCheck */
$resolver = static::$modelNameResolver ?? function (self $factory) {
$resolver = static::$modelNameResolver ?: function (self $factory) {
$name = $factory::class;
if (str_ends_with($name, 'Factory')) {
$name = substr($name, 0, -7);
Expand Down
3 changes: 1 addition & 2 deletions src/Migrations/Migrator.php
Expand Up @@ -36,8 +36,7 @@ public function __construct(MigrationRepositoryInterface $repository, Resolver $
// BC with Laravel <10
$this->repository = $repository;
$this->resolver = $resolver;
/** @psalm-suppress InvalidPropertyAssignmentValue */
$this->files = new class {
$this->files = new class extends Filesystem {
public function getRequire($path, array $data = [])
{
if (is_file($path)) {
Expand Down
4 changes: 3 additions & 1 deletion src/Security/EloquentUserProvider.php
Expand Up @@ -20,7 +20,9 @@
use Symfony\Component\Security\Core\User\UserProviderInterface;

/**
* @template TUserObject of Model&UserInterface
* @psalm-suppress TooManyTemplateParams BC with Symfony 6
* @template-covariant TUserObject of Model&UserInterface
* @implements UserProviderInterface<TUserObject>
*
* @final
* @author Wouter de Jong <wouter@wouterj.nl>
Expand Down
20 changes: 11 additions & 9 deletions tests/DataCollector/EloquentDataCollectorTest.php
Expand Up @@ -11,7 +11,9 @@

namespace WouterJ\EloquentBundle\DataCollector;

use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager;
use Illuminate\Support\Fluent;
use WouterJ\EloquentBundle\MockeryTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -21,14 +23,18 @@ class EloquentDataCollectorTest extends TestCase
{
use MockeryTrait;

private Container $container;
private $capsule;
private $queryListener;
private $collector;

protected function setUp(): void
{
$this->container = new Container();
$this->container->instance('config', new Fluent(['database.connections' => []]));

$this->capsule = \Mockery::mock(Manager::class);
$this->capsule->allows()->getContainer()->andReturn(['config' => ['database.connections' => []]])->byDefault();
$this->capsule->allows()->getContainer()->andReturn($this->container);
$this->capsule->allows()->getDatabaseManager()->andReturn(new class{
public function getConnections() { return []; }
})->byDefault();
Expand All @@ -42,14 +48,10 @@ public function getConnections() { return []; }
/** @test */
public function it_collects_connections()
{
$this->capsule->allows()->getContainer()->andReturn([
'config' => [
'database.connections' => [
'db1' => ['db' => 'foobar'],
'db2' => ['db' => 'something else']
],
],
]);
$this->container['config']['database.connections'] = [
'db1' => ['db' => 'foobar'],
'db2' => ['db' => 'something else']
];

$this->capsule->allows()->getDatabaseManager()->andReturn(new class{
public function getConnections() {
Expand Down

0 comments on commit 442a725

Please sign in to comment.