FixtureInterface.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.1.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Datasource;
  16. /**
  17. * Defines the interface that testing fixtures use.
  18. */
  19. interface FixtureInterface
  20. {
  21. /**
  22. * Create the fixture schema/mapping/definition
  23. *
  24. * @param \Cake\Datasource\ConnectionInterface $db An instance of the connection the fixture should be created on.
  25. * @return bool True on success, false on failure.
  26. */
  27. public function create(ConnectionInterface $db);
  28. /**
  29. * Run after all tests executed, should remove the table/collection from the connection.
  30. *
  31. * @param \Cake\Datasource\ConnectionInterface $db An instance of the connection the fixture should be removed from.
  32. * @return bool True on success, false on failure.
  33. */
  34. public function drop(ConnectionInterface $db);
  35. /**
  36. * Run before each test is executed.
  37. *
  38. * Should insert all the records into the test database.
  39. *
  40. * @param \Cake\Datasource\ConnectionInterface $db An instance of the connection into which the records will be inserted.
  41. * @return \Cake\Database\StatementInterface|bool on success or if there are no records to insert, or false on failure.
  42. */
  43. public function insert(ConnectionInterface $db);
  44. /**
  45. * Build and execute SQL queries necessary to create the constraints for the
  46. * fixture
  47. *
  48. * @param \Cake\Datasource\ConnectionInterface $db An instance of the database into which the constraints will be created
  49. * @return bool on success or if there are no constraints to create, or false on failure
  50. */
  51. public function createConstraints(ConnectionInterface $db);
  52. /**
  53. * Build and execute SQL queries necessary to drop the constraints for the
  54. * fixture
  55. *
  56. * @param \Cake\Datasource\ConnectionInterface $db An instance of the database into which the constraints will be dropped
  57. * @return bool on success or if there are no constraints to drop, or false on failure
  58. */
  59. public function dropConstraints(ConnectionInterface $db);
  60. /**
  61. * Truncates the current fixture.
  62. *
  63. * @param \Cake\Datasource\ConnectionInterface $db A reference to a db instance
  64. * @return bool
  65. */
  66. public function truncate(ConnectionInterface $db);
  67. /**
  68. * Get the connection name this fixture should be inserted into.
  69. *
  70. * @return string
  71. */
  72. public function connection();
  73. /**
  74. * Get the table/collection name for this fixture.
  75. *
  76. * @return string
  77. */
  78. public function sourceName();
  79. }