ExcelServiceProviderTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Maatwebsite\Excel\Tests;
  3. use Composer\InstalledVersions;
  4. use Composer\Semver\VersionParser;
  5. use Illuminate\Contracts\Console\Kernel;
  6. use Maatwebsite\Excel\Cache\MemoryCache;
  7. use Maatwebsite\Excel\Cache\MemoryCacheDeprecated;
  8. use Maatwebsite\Excel\Excel;
  9. use Maatwebsite\Excel\Tests\Data\Stubs\CustomTransactionHandler;
  10. use Maatwebsite\Excel\Transactions\TransactionManager;
  11. use PhpOffice\PhpSpreadsheet\Settings;
  12. class ExcelServiceProviderTest extends TestCase
  13. {
  14. /**
  15. * @test
  16. */
  17. public function custom_transaction_handler_is_bound()
  18. {
  19. $this->app->make(TransactionManager::class)->extend('handler', function () {
  20. return new CustomTransactionHandler;
  21. });
  22. $this->assertInstanceOf(CustomTransactionHandler::class, $this->app->make(TransactionManager::class)->driver('handler'));
  23. }
  24. /**
  25. * @test
  26. */
  27. public function is_bound()
  28. {
  29. $this->assertTrue($this->app->bound('excel'));
  30. }
  31. /**
  32. * @test
  33. */
  34. public function has_aliased()
  35. {
  36. $this->assertTrue($this->app->isAlias(Excel::class));
  37. $this->assertEquals('excel', $this->app->getAlias(Excel::class));
  38. }
  39. /**
  40. * @test
  41. */
  42. public function registers_console_commands()
  43. {
  44. /** @var Kernel $kernel */
  45. $kernel = $this->app->make(Kernel::class);
  46. $commands = $kernel->all();
  47. $this->assertArrayHasKey('make:export', $commands);
  48. $this->assertArrayHasKey('make:import', $commands);
  49. }
  50. /**
  51. * @test
  52. */
  53. public function sets_php_spreadsheet_settings()
  54. {
  55. $driver = config('excel.cache.driver');
  56. $this->assertEquals('memory', $driver);
  57. if (InstalledVersions::satisfies(new VersionParser, 'psr/simple-cache', '^3.0')) {
  58. $this->assertInstanceOf(
  59. MemoryCache::class,
  60. Settings::getCache()
  61. );
  62. } else {
  63. $this->assertInstanceOf(
  64. MemoryCacheDeprecated::class,
  65. Settings::getCache()
  66. );
  67. }
  68. }
  69. }