DoctrineDbalTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Gaufrette\Functional\Adapter;
  3. use Doctrine\DBAL\DriverManager;
  4. use Gaufrette\Adapter\DoctrineDbal;
  5. use Gaufrette\Filesystem;
  6. class DoctrineDbalTest extends FunctionalTestCase
  7. {
  8. /** @var \Doctrine\DBAL\Connection */
  9. private $connection;
  10. public function setUp()
  11. {
  12. $this->connection = DriverManager::getConnection([
  13. 'driver' => 'pdo_sqlite',
  14. 'memory' => true,
  15. ]);
  16. $schema = $this->connection->getSchemaManager()->createSchema();
  17. $table = $schema->createTable('gaufrette');
  18. $table->addColumn('key', 'string', array('unique' => true));
  19. $table->addColumn('content', 'blob');
  20. $table->addColumn('mtime', 'integer');
  21. $table->addColumn('checksum', 'string', array('length' => 32));
  22. // Generates the SQL from the defined schema and execute each line
  23. array_map([$this->connection, 'exec'], $schema->toSql($this->connection->getDatabasePlatform()));
  24. $this->filesystem = new Filesystem(new DoctrineDbal($this->connection, 'gaufrette'));
  25. }
  26. public function tearDown()
  27. {
  28. $schemaManager = $this->connection->getSchemaManager();
  29. if (in_array('gaufrette', $schemaManager->listTableNames())) {
  30. $schemaManager->dropTable('gaufrette');
  31. }
  32. }
  33. /**
  34. * @test
  35. */
  36. public function shouldListKeys()
  37. {
  38. $this->filesystem->write('foo/foobar/bar.txt', 'data');
  39. $this->filesystem->write('foo/bar/buzz.txt', 'data');
  40. $this->filesystem->write('foobarbuz.txt', 'data');
  41. $this->filesystem->write('foo', 'data');
  42. $allKeys = $this->filesystem->listKeys(' ');
  43. //empty pattern results in ->keys call
  44. $this->assertEquals(
  45. $this->filesystem->keys(),
  46. $allKeys['keys']
  47. );
  48. //these values are canonicalized to avoid wrong order or keys issue
  49. $keys = $this->filesystem->listKeys('foo');
  50. $this->assertEquals(
  51. $this->filesystem->keys(),
  52. $keys['keys'],
  53. '', 0, 10, true);
  54. $keys = $this->filesystem->listKeys('foo/foob');
  55. $this->assertEquals(
  56. array('foo/foobar/bar.txt'),
  57. $keys['keys'],
  58. '', 0, 10, true);
  59. $keys = $this->filesystem->listKeys('foo/');
  60. $this->assertEquals(
  61. array('foo/foobar/bar.txt', 'foo/bar/buzz.txt'),
  62. $keys['keys'],
  63. '', 0, 10, true);
  64. $keys = $this->filesystem->listKeys('foo');
  65. $this->assertEquals(
  66. array('foo/foobar/bar.txt', 'foo/bar/buzz.txt', 'foobarbuz.txt', 'foo'),
  67. $keys['keys'],
  68. '', 0, 10, true);
  69. $keys = $this->filesystem->listKeys('fooz');
  70. $this->assertEquals(
  71. array(),
  72. $keys['keys'],
  73. '', 0, 10, true);
  74. }
  75. }