Skip to content

Commit

Permalink
Merge pull request #606 from TomHAnderson/hotfix/coverage-1
Browse files Browse the repository at this point in the history
3.0 Hotfix/coverage 1
  • Loading branch information
TomHAnderson authored Oct 20, 2024
2 parents 376d863 + 0f59594 commit 75c167d
Show file tree
Hide file tree
Showing 21 changed files with 206 additions and 68 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ An integration library for Laravel and Doctrine ORM
Version 3.0 Notes
-----------------

This library has been around for years as version 1 and 2. However these old versions don't
support the latest Doctrine libraries. Version 3 does not try to maintain backwards compatibility
with the old versions of this library. However, this author dropped it into the
[LDOG Stack](https://ldog.apiskeletons.dev)
and it worked without modification. Version 3 supports DBAL ^4.0 and ORM ^3.0.
Version 3 supports DBAL ^4.0 and ORM ^3.0. See the
[upgrade guide](https://laravel-doctrine-orm-official.readthedocs.io/en/latest/upgrade.html)
for more information.


Installation
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
"laravel/lumen": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
"doctrine/coding-standard": "^12.0",
"illuminate/log": "^10.0|^11.0",
"illuminate/notifications": "^10.0|^11.0",
"illuminate/queue": "^10.0|^11.0",
"mockery/mockery": "^1.6.12",
"illuminate/log": "^9.0|^10.0|^11.0",
"illuminate/notifications": "^9.0|^10.0|^11.0",
"illuminate/queue": "^9.0|^10.0|^11.0",
"nikic/php-parser": "^4.19 || ^5.0",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-deprecation-rules": "^1.1",
"doctrine/coding-standard": "^12.0",
"php-parallel-lint/php-parallel-lint": "^1.4",
"vimeo/psalm": "^0.3.14"
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 2 additions & 0 deletions docs/upgrade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ you are upgrading from version 2.0.
extension and doesn't fit with the goal of Laravel and Doctrine integration.
* EnsureProductionSettingsCommand has been removed - Doctrine no longer
ships with this command.
* Annotations and YAML metadata drivers have been removed -
these have been removed from Doctrine.


.. role:: raw-html(raw)
Expand Down
9 changes: 8 additions & 1 deletion src/Auth/Authenticatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function getAuthIdentifierName(): string

/**
* Get the unique identifier for the user.
*
* @codeCoverageIgnoreStart
*/
public function getAuthIdentifier(): mixed
{
Expand All @@ -32,6 +34,7 @@ public function getAuthIdentifier(): mixed
return $this->{$name};
}

/** @codeCoverageIgnoreEnd */
public function getPassword(): string
{
return $this->password;
Expand Down Expand Up @@ -60,8 +63,9 @@ public function getRememberToken(): string

/**
* Set the token value for the "remember me" session.
*
* phpcs:disable
*/
// phpcs:disable
public function setRememberToken($value): void
{
// phpcs:enable
Expand All @@ -76,8 +80,11 @@ public function getRememberTokenName(): string
return 'rememberToken';
}

/** @codeCoverageIgnoreStart */
public function getAuthPasswordName(): string
{
return 'password';
}

// @codeCoverageIgnoreEnd
}
4 changes: 4 additions & 0 deletions src/Auth/DoctrineUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@ protected function getEntity(): Authenticatable

/**
* Returns entity namespace.
*
* @codeCoverageIgnoreStart
*/
public function getModel(): string
{
return $this->entity;
}

// @codeCoverageIgnoreEnd

/** @param mixed[] $credentials */
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false): void
{
Expand Down
10 changes: 9 additions & 1 deletion src/Auth/Passwords/DoctrineTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ protected function getTable(): QueryBuilder
$schema = $this->connection->createSchemaManager();

if (! $schema->tablesExist([$this->table])) {
// @codeCoverageIgnoreStart
$schema->createTable($this->getTableDefinition());
// @codeCoverageIgnoreEnd
}

return $this->getConnection()->createQueryBuilder();
Expand All @@ -223,9 +225,15 @@ public function getConnection(): Connection
return $this->connection;
}

/** @throws Exception */
/**
* @throws Exception
*
* @codeCoverageIgnoreStart
* */
protected function getTableDefinition(): Table
{
return (new PasswordResetTable($this->table))->build();
}

// @codeCoverageIgnoreEnd
}
13 changes: 0 additions & 13 deletions src/Configuration/Cache/IlluminateCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\Psr16Adapter;

use function trigger_error;

use const E_USER_DEPRECATED;

class IlluminateCacheProvider implements Driver
{
protected string|null $store = null;
Expand All @@ -31,15 +27,6 @@ public function resolve(array $settings = []): CacheItemPoolInterface
throw new InvalidArgumentException('Please specify the `store` when using the "illuminate" cache driver.');
}

if ($this->store && isset($settings['store'])) {
trigger_error('Using driver "' . $this->store . '" with a custom store is deprecated. Please use the "illuminate" driver.', E_USER_DEPRECATED);
}

return new Psr16Adapter($this->cache->store($store), $settings['namespace'] ?? '', $settings['default_lifetime'] ?? 0);
}

public function getStore(): string
{
return $this->store;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public function resolve(array $settings = []): array
$writeReplicas = $this->getReplicasConfiguration($settings['write'] ?? [], $driver);

if (count($writeReplicas) !== 1) {
// @codeCoverageIgnoreStart
throw new InvalidArgumentException(
'There should be exactly 1 write replica. ' . count($writeReplicas) . ' found.',
);
// @codeCoverageIgnoreEnd
}

$resolvedSettings = [
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration/Connections/SqlsrvConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public function resolve(array $settings = []): array
'wrapperClass' => Arr::get($settings, 'wrapperClass'),
'driverOptions' => array_merge(
Arr::get($settings, 'options', []),
// @codeCoverageIgnoreStart
isset($settings['encrypt'])
? ['encrypt' => Arr::get($settings, 'encrypt')]
: [],
isset($settings['trust_server_certificate'])
? ['trustServerCertificate' => Arr::get($settings, 'trust_server_certificate')]
: [],
// @codeCoverageIgnoreEnd
),
];
}
Expand Down
11 changes: 0 additions & 11 deletions src/Configuration/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Support\Str;
use LaravelDoctrine\ORM\Exceptions\DriverNotFound;

use function call_user_func_array;
use function class_exists;

abstract class Manager
Expand Down Expand Up @@ -121,14 +120,4 @@ public function getDrivers(): array
{
return $this->drivers;
}

/**
* Dynamically call the default driver instance.
*
* @param mixed[] $parameters
*/
public function __call(string $method, array $parameters): mixed
{
return call_user_func_array([$this->driver(), $method], $parameters);
}
}
21 changes: 6 additions & 15 deletions src/Notifications/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ class Notification

/**
* Indicate that the notification gives information about a successful operation.
*
* @return $this
*/
public function success()
public function success(): self
{
$this->level = 'success';

Expand All @@ -54,10 +52,8 @@ public function success()

/**
* Indicate that the notification gives information about an error.
*
* @return $this
*/
public function error()
public function error(): self
{
$this->level = 'error';

Expand All @@ -66,18 +62,15 @@ public function error()

/**
* Set the "level" of the notification (success, error, etc.).
*
* @return $this
*/
public function level(string $level)
public function level(string $level): self
{
$this->level = $level;

return $this;
}

/** @return $this */
public function message(string $message)
public function message(string $message): self
{
$this->message = $message;

Expand All @@ -86,18 +79,16 @@ public function message(string $message)

/**
* Configure the "call to action" button.
*
* @return $this
*/
public function action(string $text, string $url)
public function action(string $text, string $url): self
{
$this->actionText = $text;
$this->actionUrl = $url;

return $this;
}

public function to(mixed $user): Notification
public function to(mixed $user): self
{
$this->user = $user;

Expand Down
13 changes: 3 additions & 10 deletions src/Resolvers/EntityListenerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@

use Doctrine\ORM\Mapping\EntityListenerResolver as ResolverContract;
use Illuminate\Contracts\Container\Container;
use InvalidArgumentException;

use function gettype;
use function is_object;
use function sprintf;
use function trim;

// phpcs:disable
class EntityListenerResolver implements ResolverContract
{
/** @var object[] Map of class name to entity listener instances. */
Expand All @@ -33,7 +30,7 @@ public function clear(string|null $className = null): void
$this->instances = [];
}

public function resolve(string $className): object
public function resolve($className): object
{
$hasInstance = isset($this->instances[$className = trim($className, '\\')]);
if ($hasInstance) {
Expand All @@ -43,12 +40,8 @@ public function resolve(string $className): object
return $this->instances[$className] = $this->container->make($className);
}

public function register(object $object): void
public function register($object): void
{
if (! is_object($object)) {
throw new InvalidArgumentException(sprintf('An object was expected, but got "%s".', gettype($object)));
}

$this->instances[$object::class] = $object;
}
}
6 changes: 6 additions & 0 deletions src/Validation/DoctrinePresenceVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,17 @@ protected function prepareParam(string $column): string

/**
* Set the connection to be used.
*
* Required by DatabasePresenceVerifierInterface
*
* @codeCoverageIgnoreStart
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint
public function setConnection($connection): void
{
// phpcs:enable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint
$this->connection = $connection;
}

/** @codeCoverageIgnoreStart */
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public function test_can_create_custom_drivers()
return 'connection';
});

$drivers = $this->manager->getDrivers();

$this->assertEquals('connection', $this->manager->driver('new'));
}

Expand Down
36 changes: 36 additions & 0 deletions tests/Feature/Configuration/MetaData/AttributesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use LaravelDoctrine\ORM\Configuration\MetaData\Attributes;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class AttributesTest extends TestCase
{
/**
* @var Attributes
*/
protected $meta;

protected function setUp(): void
{
$this->meta = new Attributes();
}

public function test_can_resolve()
{
$resolved = $this->meta->resolve([
'paths' => ['entities'],
'dev' => true,
'proxies' => ['path' => 'path'],
]);

$this->assertInstanceOf(MappingDriver::class, $resolved);
$this->assertInstanceOf(\Doctrine\ORM\Mapping\Driver\AttributeDriver::class, $resolved);
}

protected function tearDown(): void
{
m::close();
}
}
15 changes: 15 additions & 0 deletions tests/Feature/Extensions/MappingDriverChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ public function test_can_add_paths_to_filedriver()
$this->assertTrue(true);
}

public function test_can_add_mappings_to_filedriver()
{
$driver = m::mock(XmlDriver::class);
$locator = m::mock(DefaultFileLocator::class);
$chain = new MappingDriverChain($driver, 'Namespace');

$locator->shouldReceive('addMappings')->with(['paths']);
$locator->shouldReceive('addMappings')->with(['paths2']);

$chain->addMappings(['paths']);
$chain->addMappings(['paths2']);

$this->assertTrue(true);
}

public function test_can_add_paths_to_simplified_filedriver()
{
$driver = m::mock(SimplifiedXmlDriver::class);
Expand Down
Loading

0 comments on commit 75c167d

Please sign in to comment.