|
16 | 16 | use Illuminate\Contracts\Config\Repository;
|
17 | 17 | use Illuminate\Contracts\Container\Container;
|
18 | 18 | use LaravelDoctrine\ORM\Configuration\Cache\CacheManager;
|
| 19 | +use LaravelDoctrine\ORM\Configuration\Cache\IlluminateCacheAdapter; |
19 | 20 | use LaravelDoctrine\ORM\Configuration\Connections\ConnectionManager;
|
20 | 21 | use LaravelDoctrine\ORM\Configuration\LaravelNamingStrategy;
|
21 | 22 | use LaravelDoctrine\ORM\Configuration\MetaData\MetaDataManager;
|
@@ -485,6 +486,242 @@ public function test_can_set_repository_factory()
|
485 | 486 | $this->assertEntityManager($manager);
|
486 | 487 | }
|
487 | 488 |
|
| 489 | + public function test_illuminate_cache_provider_custom_store() |
| 490 | + { |
| 491 | + m::resetContainer(); |
| 492 | + |
| 493 | + $config = new ConfigRepository([ |
| 494 | + 'database.connections.mysql' => [ |
| 495 | + 'driver' => 'mysql' |
| 496 | + ], |
| 497 | + 'doctrine' => [ |
| 498 | + 'meta' => 'annotations', |
| 499 | + 'connection' => 'mysql', |
| 500 | + 'paths' => ['Entities'], |
| 501 | + 'proxies' => [ |
| 502 | + 'path' => 'dir', |
| 503 | + 'auto_generate' => false, |
| 504 | + 'namespace' => 'namespace' |
| 505 | + ], |
| 506 | + |
| 507 | + 'cache' => [ |
| 508 | + 'metadata' => [ |
| 509 | + 'driver' => 'illuminate', |
| 510 | + 'store' => 'myStoreName' |
| 511 | + ] |
| 512 | + ] |
| 513 | + ], |
| 514 | + 'doctrine.custom_datetime_functions' => [], |
| 515 | + 'doctrine.custom_numeric_functions' => [], |
| 516 | + 'doctrine.custom_string_functions' => [] |
| 517 | + ]); |
| 518 | + |
| 519 | + $container = new \Illuminate\Container\Container(); |
| 520 | + $container->singleton(Repository::class, function () use ($config) { |
| 521 | + return $config; |
| 522 | + }); |
| 523 | + |
| 524 | + $cache = M::mock(Illuminate\Contracts\Cache\Repository::class); |
| 525 | + |
| 526 | + $factory = M::mock(\Illuminate\Contracts\Cache\Factory::class); |
| 527 | + $factory->shouldReceive('store')->with('myStoreName')->andReturn($cache); |
| 528 | + |
| 529 | + $container->singleton(Illuminate\Contracts\Cache\Factory::class, function () use ($factory) { |
| 530 | + return $factory; |
| 531 | + }); |
| 532 | + |
| 533 | + $factory = new EntityManagerFactory( |
| 534 | + $container, |
| 535 | + new Setup(), |
| 536 | + new MetaDataManager($container), |
| 537 | + new ConnectionManager($container), |
| 538 | + new CacheManager($container), |
| 539 | + $config, |
| 540 | + new EntityListenerResolver($container) |
| 541 | + ); |
| 542 | + |
| 543 | + $manager = $factory->create($config->get('doctrine')); |
| 544 | + |
| 545 | + $this->assertInstanceOf(IlluminateCacheAdapter::class, $manager->getConfiguration()->getMetadataCacheImpl()); |
| 546 | + } |
| 547 | + |
| 548 | + public function test_illuminate_cache_provider_redis() |
| 549 | + { |
| 550 | + m::resetContainer(); |
| 551 | + |
| 552 | + $config = new ConfigRepository([ |
| 553 | + 'database.connections.mysql' => [ |
| 554 | + 'driver' => 'mysql' |
| 555 | + ], |
| 556 | + 'doctrine' => [ |
| 557 | + 'meta' => 'annotations', |
| 558 | + 'connection' => 'mysql', |
| 559 | + 'paths' => ['Entities'], |
| 560 | + 'proxies' => [ |
| 561 | + 'path' => 'dir', |
| 562 | + 'auto_generate' => false, |
| 563 | + 'namespace' => 'namespace' |
| 564 | + ], |
| 565 | + |
| 566 | + 'cache' => [ |
| 567 | + 'metadata' => [ |
| 568 | + 'driver' => 'redis', |
| 569 | + ] |
| 570 | + ] |
| 571 | + ], |
| 572 | + 'doctrine.custom_datetime_functions' => [], |
| 573 | + 'doctrine.custom_numeric_functions' => [], |
| 574 | + 'doctrine.custom_string_functions' => [] |
| 575 | + ]); |
| 576 | + |
| 577 | + $container = new \Illuminate\Container\Container(); |
| 578 | + $container->singleton(Repository::class, function () use ($config) { |
| 579 | + return $config; |
| 580 | + }); |
| 581 | + |
| 582 | + $cache = M::mock(Illuminate\Contracts\Cache\Repository::class); |
| 583 | + |
| 584 | + $factory = M::mock(\Illuminate\Contracts\Cache\Factory::class); |
| 585 | + $factory->shouldReceive('store')->with('redis')->andReturn($cache); |
| 586 | + |
| 587 | + $container->singleton(Illuminate\Contracts\Cache\Factory::class, function () use ($factory) { |
| 588 | + return $factory; |
| 589 | + }); |
| 590 | + |
| 591 | + $factory = new EntityManagerFactory( |
| 592 | + $container, |
| 593 | + new Setup(), |
| 594 | + new MetaDataManager($container), |
| 595 | + new ConnectionManager($container), |
| 596 | + new CacheManager($container), |
| 597 | + $config, |
| 598 | + new EntityListenerResolver($container) |
| 599 | + ); |
| 600 | + |
| 601 | + $manager = $factory->create($config->get('doctrine')); |
| 602 | + |
| 603 | + $this->assertInstanceOf(IlluminateCacheAdapter::class, $manager->getConfiguration()->getMetadataCacheImpl()); |
| 604 | + } |
| 605 | + |
| 606 | + public function test_illuminate_cache_provider_invalid_store() |
| 607 | + { |
| 608 | + m::resetContainer(); |
| 609 | + |
| 610 | + $config = new ConfigRepository([ |
| 611 | + 'database.connections.mysql' => [ |
| 612 | + 'driver' => 'mysql' |
| 613 | + ], |
| 614 | + 'doctrine' => [ |
| 615 | + 'meta' => 'annotations', |
| 616 | + 'connection' => 'mysql', |
| 617 | + 'paths' => ['Entities'], |
| 618 | + 'proxies' => [ |
| 619 | + 'path' => 'dir', |
| 620 | + 'auto_generate' => false, |
| 621 | + 'namespace' => 'namespace' |
| 622 | + ], |
| 623 | + |
| 624 | + 'cache' => [ |
| 625 | + 'metadata' => [ |
| 626 | + 'driver' => 'illuminate', |
| 627 | + ] |
| 628 | + ] |
| 629 | + ], |
| 630 | + 'doctrine.custom_datetime_functions' => [], |
| 631 | + 'doctrine.custom_numeric_functions' => [], |
| 632 | + 'doctrine.custom_string_functions' => [] |
| 633 | + ]); |
| 634 | + |
| 635 | + $container = new \Illuminate\Container\Container(); |
| 636 | + $container->singleton(Repository::class, function () use ($config) { |
| 637 | + return $config; |
| 638 | + }); |
| 639 | + |
| 640 | + $cache = M::mock(Illuminate\Contracts\Cache\Repository::class); |
| 641 | + |
| 642 | + $factory = M::mock(\Illuminate\Contracts\Cache\Factory::class); |
| 643 | + $factory->shouldReceive('store')->with('myStoreName')->andReturn($cache); |
| 644 | + |
| 645 | + $container->singleton(Illuminate\Contracts\Cache\Factory::class, function () use ($factory) { |
| 646 | + return $factory; |
| 647 | + }); |
| 648 | + |
| 649 | + $factory = new EntityManagerFactory( |
| 650 | + $container, |
| 651 | + new Setup(), |
| 652 | + new MetaDataManager($container), |
| 653 | + new ConnectionManager($container), |
| 654 | + new CacheManager($container), |
| 655 | + $config, |
| 656 | + new EntityListenerResolver($container) |
| 657 | + ); |
| 658 | + |
| 659 | + $this->expectException(InvalidArgumentException::class); |
| 660 | + |
| 661 | + $this->expectExceptionMessage('Please specify the `store` when using the "illuminate" cache driver.'); |
| 662 | + $factory->create($config->get('doctrine')); |
| 663 | + } |
| 664 | + |
| 665 | + public function test_php_file_cache_custom_path() |
| 666 | + { |
| 667 | + m::resetContainer(); |
| 668 | + |
| 669 | + $config = new ConfigRepository([ |
| 670 | + 'database.connections.mysql' => [ |
| 671 | + 'driver' => 'mysql' |
| 672 | + ], |
| 673 | + 'doctrine' => [ |
| 674 | + 'meta' => 'annotations', |
| 675 | + 'connection' => 'mysql', |
| 676 | + 'paths' => ['Entities'], |
| 677 | + 'proxies' => [ |
| 678 | + 'path' => 'dir', |
| 679 | + 'auto_generate' => false, |
| 680 | + 'namespace' => 'namespace' |
| 681 | + ], |
| 682 | + |
| 683 | + 'cache' => [ |
| 684 | + 'metadata' => [ |
| 685 | + 'driver' => 'php_file', |
| 686 | + 'path' => 'myCustomPath' |
| 687 | + ] |
| 688 | + ] |
| 689 | + ], |
| 690 | + 'doctrine.custom_datetime_functions' => [], |
| 691 | + 'doctrine.custom_numeric_functions' => [], |
| 692 | + 'doctrine.custom_string_functions' => [] |
| 693 | + ]); |
| 694 | + |
| 695 | + $container = new \Illuminate\Container\Container(); |
| 696 | + $container->singleton(Repository::class, function () use ($config) { |
| 697 | + return $config; |
| 698 | + }); |
| 699 | + |
| 700 | + $cache = M::mock(Illuminate\Contracts\Cache\Repository::class); |
| 701 | + |
| 702 | + $factory = M::mock(\Illuminate\Contracts\Cache\Factory::class); |
| 703 | + $factory->shouldReceive('store')->with('myStoreName')->andReturn($cache); |
| 704 | + |
| 705 | + $container->singleton(Illuminate\Contracts\Cache\Factory::class, function () use ($factory) { |
| 706 | + return $factory; |
| 707 | + }); |
| 708 | + |
| 709 | + $factory = new EntityManagerFactory( |
| 710 | + $container, |
| 711 | + new Setup(), |
| 712 | + new MetaDataManager($container), |
| 713 | + new ConnectionManager($container), |
| 714 | + new CacheManager($container), |
| 715 | + $config, |
| 716 | + new EntityListenerResolver($container) |
| 717 | + ); |
| 718 | + |
| 719 | + $manager = $factory->create($config->get('doctrine')); |
| 720 | + |
| 721 | + $this->assertInstanceOf(\Doctrine\Common\Cache\PhpFileCache::class, $manager->getConfiguration()->getMetadataCacheImpl()); |
| 722 | + $this->assertStringEndsWith('myCustomPath', $manager->getConfiguration()->getMetadataCacheImpl()->getDirectory()); |
| 723 | + } |
| 724 | + |
488 | 725 | public function test_wrapper_connection()
|
489 | 726 | {
|
490 | 727 | m::resetContainer();
|
@@ -592,8 +829,8 @@ protected function mockConfig($driverConfig = ['driver' => 'mysql'], $strictCall
|
592 | 829 |
|
593 | 830 | foreach ($this->caches as $cache) {
|
594 | 831 | $expectation = $this->config->shouldReceive('get')
|
595 |
| - ->with('doctrine.cache.' . $cache . '.driver', 'array') |
596 |
| - ->andReturn('array'); |
| 832 | + ->with('doctrine.cache.' . $cache, []) |
| 833 | + ->andReturn(['driver' => 'array']); |
597 | 834 |
|
598 | 835 | $strictCallCountChecking ? $expectation->once() : $expectation->never();
|
599 | 836 | }
|
|
0 commit comments