TableRegressionTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.2.13
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\ORM;
  16. use Cake\Core\Plugin;
  17. use Cake\I18n\Time;
  18. use Cake\ORM\TableRegistry;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * Contains regression test for the Table class
  22. *
  23. */
  24. class TableRegressionTest extends TestCase
  25. {
  26. /**
  27. * Fixture to be used
  28. *
  29. * @var array
  30. */
  31. public $fixtures = [
  32. 'core.authors',
  33. ];
  34. /**
  35. * Tear down
  36. *
  37. * @return void
  38. */
  39. public function tearDown()
  40. {
  41. parent::tearDown();
  42. TableRegistry::clear();
  43. }
  44. /**
  45. * Tests that an exception is thrown if the transaction is aborted
  46. * in the afterSave callback
  47. *
  48. * @see https://github.com/cakephp/cakephp/issues/9079
  49. * @expectedException Cake\ORM\Exception\RolledbackTransactionException
  50. * @return void
  51. */
  52. public function testAfterSaveRollbackTransaction()
  53. {
  54. $table = TableRegistry::get('Authors');
  55. $table->eventManager()->on(
  56. 'Model.afterSave',
  57. function () use ($table) {
  58. $table->connection()->rollback();
  59. }
  60. );
  61. $entity = $table->newEntity(['name' => 'Jon']);
  62. $table->save($entity);
  63. }
  64. }