NullAdapterTests.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. use League\Flysystem\Adapter\NullAdapter;
  3. use League\Flysystem\Config;
  4. use League\Flysystem\FileNotFoundException;
  5. use League\Flysystem\Filesystem;
  6. use PHPUnit\Framework\TestCase;
  7. class NullAdapterTest extends TestCase
  8. {
  9. /**
  10. * @return Filesystem
  11. */
  12. protected function getFilesystem()
  13. {
  14. return new Filesystem(new NullAdapter());
  15. }
  16. protected function getAdapter()
  17. {
  18. return new NullAdapter();
  19. }
  20. public function testWrite()
  21. {
  22. $fs = $this->getFilesystem();
  23. $result = $fs->write('path', 'contents');
  24. $this->assertTrue($result);
  25. $this->assertFalse($fs->has('path'));
  26. }
  27. public function testRead()
  28. {
  29. $this->expectException(FileNotFoundException::class);
  30. $fs = $this->getFilesystem();
  31. $fs->read('something');
  32. }
  33. public function testHas()
  34. {
  35. $fs = $this->getFilesystem();
  36. $this->assertFalse($fs->has('something'));
  37. }
  38. public function testDelete()
  39. {
  40. $adapter = $this->getAdapter();
  41. $this->assertFalse($adapter->delete('something'));
  42. }
  43. public function expectedFailsProvider()
  44. {
  45. return [
  46. ['read'],
  47. ['update'],
  48. ['read'],
  49. ['rename'],
  50. ['delete'],
  51. ['listContents', []],
  52. ['getMetadata'],
  53. ['getSize'],
  54. ['getMimetype'],
  55. ['getTimestamp'],
  56. ['getVisibility'],
  57. ['deleteDir'],
  58. ];
  59. }
  60. /**
  61. * @dataProvider expectedFailsProvider
  62. */
  63. public function testExpectedFails($method, $result = false)
  64. {
  65. $adapter = new NullAdapter();
  66. $this->assertEquals($result, $adapter->{$method}('one', 'two', new Config()));
  67. }
  68. public function expectedArrayResultProvider()
  69. {
  70. return [
  71. ['write'],
  72. ['setVisibility'],
  73. ];
  74. }
  75. /**
  76. * @dataProvider expectedArrayResultProvider
  77. */
  78. public function testArrayResult($method)
  79. {
  80. $adapter = new NullAdapter();
  81. $this->assertIsArray($adapter->{$method}('one', tmpfile(), new Config(['visibility' => 'public'])));
  82. }
  83. public function testArrayResultForCreateDir()
  84. {
  85. $adapter = new NullAdapter();
  86. $this->assertIsArray($adapter->createDir('one', new Config(['visibility' => 'public'])));
  87. }
  88. }