Skip to content

Commit

Permalink
Installed testbench; removed problematic InteractsWithEntities trait …
Browse files Browse the repository at this point in the history
…and test
  • Loading branch information
TomHAnderson committed Oct 29, 2024
1 parent 96135be commit cb8b148
Show file tree
Hide file tree
Showing 23 changed files with 263 additions and 294 deletions.
27 changes: 23 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpunit/phpunit": "^11.4",
"fakerphp/faker": "^1.23",
"laravel/framework": "^10.0 || ^11.0"
"laravel/framework": "^10.0 || ^11.0",
"orchestra/testbench": "^9.5"
},
"conflict": {
"laravel/lumen": "*"
Expand All @@ -61,7 +62,10 @@
},
"autoload-dev": {
"psr-4": {
"LaravelDoctrineTest\\ORM\\": "tests/"
"LaravelDoctrineTest\\ORM\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"suggest": {
Expand Down Expand Up @@ -95,6 +99,21 @@
"vendor/bin/phpunit",
"vendor/bin/phpstan analyze src --level 1"
],
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage"
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage",
"post-autoload-dump": [
"@clear",
"@prepare"
],
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve --ansi"
],
"lint": [
"@php vendor/bin/phpstan analyse --verbose --ansi"
]
}
}
}
60 changes: 5 additions & 55 deletions src/DoctrineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
use Doctrine\ORM\Proxy\Autoloader;
use Doctrine\Persistence\ManagerRegistry;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use InvalidArgumentException;
use LaravelDoctrine\ORM\Auth\DoctrineUserProvider;
use LaravelDoctrine\ORM\Configuration\Cache\CacheManager;
Expand All @@ -38,7 +36,6 @@
use function assert;
use function class_exists;
use function config_path;
use function property_exists;

class DoctrineServiceProvider extends ServiceProvider
{
Expand All @@ -50,13 +47,9 @@ public function boot(): void
$this->extendAuthManager();
$this->extendNotificationChannel();

if (! $this->isLumen()) {
$this->publishes([
$this->getConfigPath() => config_path('doctrine.php'),
], 'config');
}

$this->ensureValidatorIsUsable();
$this->publishes([
$this->getConfigPath() => config_path('doctrine.php'),
], 'config');
}

/**
Expand All @@ -83,28 +76,6 @@ public function register(): void
$this->registerPresenceVerifierProvider();
}

protected function ensureValidatorIsUsable(): void
{
if (! $this->isLumen()) {
return;
}

assert(property_exists($this->app, 'availableBindings'));

if ($this->shouldRegisterDoctrinePresenceValidator()) {
// due to weirdness the default presence verifier overrides one set by a service provider
// so remove them so we can re add our implementation later
unset($this->app->availableBindings['validator']);
unset($this->app->availableBindings[ValidationFactory::class]);
} else {
// resolve the db,
// this makes `isset($this->app['db']) == true`
// which is required to set the presence verifier
// in the default ValidationServiceProvider implementation
$this->app['db'];
}
}

/**
* Merge config
*/
Expand All @@ -114,14 +85,6 @@ protected function mergeConfig(): void
$this->getConfigPath(),
'doctrine',
);

if (! $this->isLumen()) {
return;
}

$this->app->configure('cache');
$this->app->configure('database');
$this->app->configure('doctrine');
}

/**
Expand Down Expand Up @@ -232,15 +195,7 @@ protected function registerExtensions(): void
*/
protected function registerPresenceVerifierProvider(): void
{
if ($this->isLumen()) {
$this->app->singleton('validator', function () {
$this->app->register(PresenceVerifierProvider::class);

return $this->app->make('validator');
});
} else {
$this->app->register(PresenceVerifierProvider::class);
}
$this->app->register(PresenceVerifierProvider::class);
}

/**
Expand Down Expand Up @@ -279,7 +234,7 @@ protected function extendAuthManager(): void

/**
* Boots the extension manager at the appropriate time depending on if the app
* is running as Laravel HTTP, Lumen HTTP or in a console environment
* is running as Laravel HTTP or in a console environment
*/
protected function bootExtensionManager(): void
{
Expand Down Expand Up @@ -354,11 +309,6 @@ protected function registerConsoleCommands(): void
]);
}

protected function isLumen(): bool
{
return Str::contains($this->app->version(), 'Lumen');
}

protected function shouldRegisterDoctrinePresenceValidator(): bool
{
return $this->app['config']->get('doctrine.doctrine_presence_verifier', true);
Expand Down
102 changes: 0 additions & 102 deletions src/Testing/Concerns/InteractsWithEntities.php

This file was deleted.

20 changes: 20 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
providers:
- LaravelDoctrine\ORM\DoctrineServiceProvider

workbench:
start: '/'
install: true
health: false
discovers:
web: fale
api: false
commands: false
components: false
views: false
build:
- asset-publish
- create-sqlite-db
- db-wipe
assets:
- laravel-assets
sync: []
14 changes: 7 additions & 7 deletions tests/Feature/Configuration/Cache/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ class CacheManagerTest extends TestCase
{
protected CacheManager $manager;

protected Container $app;
protected Container $testApp;

protected Repository $config;

protected function setUp(): void
{
$this->app = m::mock(Container::class);
$this->app->shouldReceive('make')->andReturn(m::self());
$this->app->shouldReceive('get')->with('doctrine.cache.default', 'array')->andReturn('array');
$this->testApp = m::mock(Container::class);
$this->testApp->shouldReceive('make')->andReturn(m::self());
$this->testApp->shouldReceive('get')->with('doctrine.cache.default', 'array')->andReturn('array');

$this->manager = new CacheManager(
$this->app,
$this->testApp,
);

parent::setUp();
}

public function testDriverReturnsTheDefaultDriver(): void
{
$this->app->shouldReceive('resolve')->andReturn(new ArrayCacheProvider());
$this->testApp->shouldReceive('resolve')->andReturn(new ArrayCacheProvider());

$this->assertInstanceOf(ArrayCacheProvider::class, $this->manager->driver());
$this->assertInstanceOf(ArrayAdapter::class, $this->manager->driver()->resolve());
Expand All @@ -49,7 +49,7 @@ public function testDriverCanReturnAGivenDriver(): void
$config = m::mock(Repository::class);
$app = m::mock(Application::class);

$this->app->shouldReceive('resolve')->andReturn(new FileCacheProvider(
$this->testApp->shouldReceive('resolve')->andReturn(new FileCacheProvider(
$config,
$app,
));
Expand Down
5 changes: 4 additions & 1 deletion tests/Feature/Configuration/Cache/FileCacheProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public function getProvider(): mixed
{
$config = m::mock(Repository::class);
$config->shouldReceive('get')
->with('cache.stores.file.path', '/storage/framework/cache')
->with(
'cache.stores.file.path',
$this->applicationBasePath() . '/storage/framework/cache',
)
->once()
->andReturn('/tmp');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public function getProvider(): mixed
{
$config = m::mock(Repository::class);
$config->shouldReceive('get')
->with('cache.stores.file.path', '/storage/framework/cache')
->with(
'cache.stores.file.path',
$this->applicationBasePath() . '/storage/framework/cache',
)
->once()
->andReturn('/tmp');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ class ConnectionManagerTest extends TestCase
{
protected ConnectionManager $manager;

protected Container $app;
protected Container $testApp;

protected Repository $config;

protected function setUp(): void
{
$this->app = m::mock(Container::class);
$this->app->shouldReceive('make')->andReturn(m::self());
$this->testApp = m::mock(Container::class);
$this->testApp->shouldReceive('make')->andReturn(m::self());

$this->config = m::mock(Repository::class);
$this->config->shouldReceive('get');

$this->manager = new ConnectionManager(
$this->app,
$this->testApp,
);

parent::setUp();
}

public function testDriverReturnsTheDefaultDriver(): void
{
$this->app->shouldReceive('resolve')->andReturn(
$this->testApp->shouldReceive('resolve')->andReturn(
(new MysqlConnection($this->config))->resolve(),
);

Expand All @@ -50,7 +50,7 @@ public function testDriverReturnsTheDefaultDriver(): void

public function testDriverCanReturnAGivenDriver(): void
{
$this->app->shouldReceive('resolve')->andReturn(
$this->testApp->shouldReceive('resolve')->andReturn(
(new SqliteConnection($this->config))->resolve(),
);

Expand Down
Loading

0 comments on commit cb8b148

Please sign in to comment.