|
1 | 1 | <?php |
2 | 2 | namespace Mantle\Tests\Support; |
3 | 3 |
|
| 4 | +use Attribute; |
4 | 5 | use Mantle\Application\Application; |
5 | 6 | use Mantle\Console\Command; |
6 | 7 | use Mantle\Contracts\Providers as ProviderContracts; |
7 | 8 | use Mantle\Events\Dispatcher; |
8 | 9 | use Mantle\Support\Service_Provider; |
9 | 10 | use Mantle\Support\Attributes\Action; |
10 | 11 | use Mantle\Support\Attributes\Filter; |
| 12 | +use Mantle\Types\Validator; |
11 | 13 | use Mockery as m; |
12 | 14 |
|
13 | 15 | class ServiceProviderTest extends \Mockery\Adapter\Phpunit\MockeryTestCase { |
@@ -276,6 +278,30 @@ function ( $resolved ) { |
276 | 278 |
|
277 | 279 | $this->assertEquals( 'one', $_SERVER['__after_resolving'] ); |
278 | 280 | } |
| 281 | + |
| 282 | + public function test_service_provider_with_passing_validator(): void { |
| 283 | + $_SERVER['__service_provider_booted'] = false; |
| 284 | + |
| 285 | + $app = m::mock( Application::class )->makePartial(); |
| 286 | + |
| 287 | + $app->register( PassingValidatorServiceProvider::class ); |
| 288 | + |
| 289 | + $this->assertFalse( $_SERVER['__service_provider_booted'] ); |
| 290 | + $app->boot(); |
| 291 | + $this->assertTrue( $_SERVER['__service_provider_booted'] ); |
| 292 | + } |
| 293 | + |
| 294 | + public function test_service_provider_with_failing_validator(): void { |
| 295 | + $_SERVER['__service_provider_booted'] = false; |
| 296 | + |
| 297 | + $app = m::mock( Application::class )->makePartial(); |
| 298 | + |
| 299 | + $app->register( FailingValidatorServiceProvider::class ); |
| 300 | + |
| 301 | + $this->assertFalse( $_SERVER['__service_provider_booted'] ); |
| 302 | + $app->boot(); |
| 303 | + $this->assertFalse( $_SERVER['__service_provider_booted'] ); |
| 304 | + } |
279 | 305 | } |
280 | 306 |
|
281 | 307 | class Provider_Test_Hook extends Service_Provider { |
@@ -331,6 +357,40 @@ public function boot() { |
331 | 357 | } |
332 | 358 | } |
333 | 359 |
|
334 | | -class Example_Service_Provider_Event { |
| 360 | +class Example_Service_Provider_Event {} |
| 361 | + |
| 362 | +#[Attribute] |
| 363 | +class PassingValidator implements Validator { |
| 364 | + public function validate(): bool { |
| 365 | + return true; |
| 366 | + } |
| 367 | +} |
| 368 | + |
| 369 | +#[PassingValidator] |
| 370 | +class PassingValidatorServiceProvider extends Service_Provider { |
| 371 | + public function register() { |
| 372 | + $_SERVER['__service_provider_registered'] = true; |
| 373 | + } |
| 374 | + |
| 375 | + public function boot() { |
| 376 | + $_SERVER['__service_provider_booted'] = true; |
| 377 | + } |
| 378 | +} |
335 | 379 |
|
| 380 | +#[Attribute] |
| 381 | +class FailingValidator implements Validator { |
| 382 | + public function validate(): bool { |
| 383 | + return false; |
| 384 | + } |
| 385 | +} |
| 386 | + |
| 387 | +#[FailingValidator] |
| 388 | +class FailingValidatorServiceProvider extends Service_Provider { |
| 389 | + public function register() { |
| 390 | + $_SERVER['__service_provider_registered'] = true; |
| 391 | + } |
| 392 | + |
| 393 | + public function boot() { |
| 394 | + $_SERVER['__service_provider_booted'] = true; |
| 395 | + } |
336 | 396 | } |
0 commit comments