Skip to content

Commit cb8b148

Browse files
committed
Installed testbench; removed problematic InteractsWithEntities trait and test
1 parent 96135be commit cb8b148

23 files changed

+263
-294
lines changed

composer.json

+23-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"phpstan/phpstan-deprecation-rules": "^1.1",
4747
"phpunit/phpunit": "^11.4",
4848
"fakerphp/faker": "^1.23",
49-
"laravel/framework": "^10.0 || ^11.0"
49+
"laravel/framework": "^10.0 || ^11.0",
50+
"orchestra/testbench": "^9.5"
5051
},
5152
"conflict": {
5253
"laravel/lumen": "*"
@@ -61,7 +62,10 @@
6162
},
6263
"autoload-dev": {
6364
"psr-4": {
64-
"LaravelDoctrineTest\\ORM\\": "tests/"
65+
"LaravelDoctrineTest\\ORM\\": "tests/",
66+
"Workbench\\App\\": "workbench/app/",
67+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
68+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
6569
}
6670
},
6771
"suggest": {
@@ -95,6 +99,21 @@
9599
"vendor/bin/phpunit",
96100
"vendor/bin/phpstan analyze src --level 1"
97101
],
98-
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage"
102+
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage",
103+
"post-autoload-dump": [
104+
"@clear",
105+
"@prepare"
106+
],
107+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
108+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
109+
"build": "@php vendor/bin/testbench workbench:build --ansi",
110+
"serve": [
111+
"Composer\\Config::disableProcessTimeout",
112+
"@build",
113+
"@php vendor/bin/testbench serve --ansi"
114+
],
115+
"lint": [
116+
"@php vendor/bin/phpstan analyse --verbose --ansi"
117+
]
99118
}
100-
}
119+
}

src/DoctrineServiceProvider.php

+5-55
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
use Doctrine\ORM\Proxy\Autoloader;
1111
use Doctrine\Persistence\ManagerRegistry;
1212
use Illuminate\Contracts\Container\Container;
13-
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
1413
use Illuminate\Notifications\ChannelManager;
1514
use Illuminate\Support\ServiceProvider;
16-
use Illuminate\Support\Str;
1715
use InvalidArgumentException;
1816
use LaravelDoctrine\ORM\Auth\DoctrineUserProvider;
1917
use LaravelDoctrine\ORM\Configuration\Cache\CacheManager;
@@ -38,7 +36,6 @@
3836
use function assert;
3937
use function class_exists;
4038
use function config_path;
41-
use function property_exists;
4239

4340
class DoctrineServiceProvider extends ServiceProvider
4441
{
@@ -50,13 +47,9 @@ public function boot(): void
5047
$this->extendAuthManager();
5148
$this->extendNotificationChannel();
5249

53-
if (! $this->isLumen()) {
54-
$this->publishes([
55-
$this->getConfigPath() => config_path('doctrine.php'),
56-
], 'config');
57-
}
58-
59-
$this->ensureValidatorIsUsable();
50+
$this->publishes([
51+
$this->getConfigPath() => config_path('doctrine.php'),
52+
], 'config');
6053
}
6154

6255
/**
@@ -83,28 +76,6 @@ public function register(): void
8376
$this->registerPresenceVerifierProvider();
8477
}
8578

86-
protected function ensureValidatorIsUsable(): void
87-
{
88-
if (! $this->isLumen()) {
89-
return;
90-
}
91-
92-
assert(property_exists($this->app, 'availableBindings'));
93-
94-
if ($this->shouldRegisterDoctrinePresenceValidator()) {
95-
// due to weirdness the default presence verifier overrides one set by a service provider
96-
// so remove them so we can re add our implementation later
97-
unset($this->app->availableBindings['validator']);
98-
unset($this->app->availableBindings[ValidationFactory::class]);
99-
} else {
100-
// resolve the db,
101-
// this makes `isset($this->app['db']) == true`
102-
// which is required to set the presence verifier
103-
// in the default ValidationServiceProvider implementation
104-
$this->app['db'];
105-
}
106-
}
107-
10879
/**
10980
* Merge config
11081
*/
@@ -114,14 +85,6 @@ protected function mergeConfig(): void
11485
$this->getConfigPath(),
11586
'doctrine',
11687
);
117-
118-
if (! $this->isLumen()) {
119-
return;
120-
}
121-
122-
$this->app->configure('cache');
123-
$this->app->configure('database');
124-
$this->app->configure('doctrine');
12588
}
12689

12790
/**
@@ -232,15 +195,7 @@ protected function registerExtensions(): void
232195
*/
233196
protected function registerPresenceVerifierProvider(): void
234197
{
235-
if ($this->isLumen()) {
236-
$this->app->singleton('validator', function () {
237-
$this->app->register(PresenceVerifierProvider::class);
238-
239-
return $this->app->make('validator');
240-
});
241-
} else {
242-
$this->app->register(PresenceVerifierProvider::class);
243-
}
198+
$this->app->register(PresenceVerifierProvider::class);
244199
}
245200

246201
/**
@@ -279,7 +234,7 @@ protected function extendAuthManager(): void
279234

280235
/**
281236
* Boots the extension manager at the appropriate time depending on if the app
282-
* is running as Laravel HTTP, Lumen HTTP or in a console environment
237+
* is running as Laravel HTTP or in a console environment
283238
*/
284239
protected function bootExtensionManager(): void
285240
{
@@ -354,11 +309,6 @@ protected function registerConsoleCommands(): void
354309
]);
355310
}
356311

357-
protected function isLumen(): bool
358-
{
359-
return Str::contains($this->app->version(), 'Lumen');
360-
}
361-
362312
protected function shouldRegisterDoctrinePresenceValidator(): bool
363313
{
364314
return $this->app['config']->get('doctrine.doctrine_presence_verifier', true);

src/Testing/Concerns/InteractsWithEntities.php

-102
This file was deleted.

testbench.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
providers:
2+
- LaravelDoctrine\ORM\DoctrineServiceProvider
3+
4+
workbench:
5+
start: '/'
6+
install: true
7+
health: false
8+
discovers:
9+
web: fale
10+
api: false
11+
commands: false
12+
components: false
13+
views: false
14+
build:
15+
- asset-publish
16+
- create-sqlite-db
17+
- db-wipe
18+
assets:
19+
- laravel-assets
20+
sync: []

tests/Feature/Configuration/Cache/CacheManagerTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ class CacheManagerTest extends TestCase
1919
{
2020
protected CacheManager $manager;
2121

22-
protected Container $app;
22+
protected Container $testApp;
2323

2424
protected Repository $config;
2525

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

3232
$this->manager = new CacheManager(
33-
$this->app,
33+
$this->testApp,
3434
);
3535

3636
parent::setUp();
3737
}
3838

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

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

52-
$this->app->shouldReceive('resolve')->andReturn(new FileCacheProvider(
52+
$this->testApp->shouldReceive('resolve')->andReturn(new FileCacheProvider(
5353
$config,
5454
$app,
5555
));

tests/Feature/Configuration/Cache/FileCacheProviderTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public function getProvider(): mixed
1515
{
1616
$config = m::mock(Repository::class);
1717
$config->shouldReceive('get')
18-
->with('cache.stores.file.path', '/storage/framework/cache')
18+
->with(
19+
'cache.stores.file.path',
20+
$this->applicationBasePath() . '/storage/framework/cache',
21+
)
1922
->once()
2023
->andReturn('/tmp');
2124

tests/Feature/Configuration/Cache/PhpFileCacheProviderTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public function getProvider(): mixed
1515
{
1616
$config = m::mock(Repository::class);
1717
$config->shouldReceive('get')
18-
->with('cache.stores.file.path', '/storage/framework/cache')
18+
->with(
19+
'cache.stores.file.path',
20+
$this->applicationBasePath() . '/storage/framework/cache',
21+
)
1922
->once()
2023
->andReturn('/tmp');
2124

tests/Feature/Configuration/Connections/ConnectionManagerTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@ class ConnectionManagerTest extends TestCase
1919
{
2020
protected ConnectionManager $manager;
2121

22-
protected Container $app;
22+
protected Container $testApp;
2323

2424
protected Repository $config;
2525

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

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

3434
$this->manager = new ConnectionManager(
35-
$this->app,
35+
$this->testApp,
3636
);
3737

3838
parent::setUp();
3939
}
4040

4141
public function testDriverReturnsTheDefaultDriver(): void
4242
{
43-
$this->app->shouldReceive('resolve')->andReturn(
43+
$this->testApp->shouldReceive('resolve')->andReturn(
4444
(new MysqlConnection($this->config))->resolve(),
4545
);
4646

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

5151
public function testDriverCanReturnAGivenDriver(): void
5252
{
53-
$this->app->shouldReceive('resolve')->andReturn(
53+
$this->testApp->shouldReceive('resolve')->andReturn(
5454
(new SqliteConnection($this->config))->resolve(),
5555
);
5656

0 commit comments

Comments
 (0)