TableRegressionTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. class TableRegressionTest extends TestCase
  24. {
  25. /**
  26. * Fixture to be used
  27. *
  28. * @var array
  29. */
  30. public $fixtures = [
  31. 'core.authors',
  32. ];
  33. /**
  34. * Tear down
  35. *
  36. * @return void
  37. */
  38. public function tearDown()
  39. {
  40. parent::tearDown();
  41. TableRegistry::clear();
  42. }
  43. /**
  44. * Tests that an exception is thrown if the transaction is aborted
  45. * in the afterSave callback
  46. *
  47. * @see https://github.com/cakephp/cakephp/issues/9079
  48. * @expectedException Cake\ORM\Exception\RolledbackTransactionException
  49. * @return void
  50. */
  51. public function testAfterSaveRollbackTransaction()
  52. {
  53. $table = TableRegistry::get('Authors');
  54. $table->eventManager()->on(
  55. 'Model.afterSave',
  56. function () use ($table) {
  57. $table->connection()->rollback();
  58. }
  59. );
  60. $entity = $table->newEntity(['name' => 'Jon']);
  61. $table->save($entity);
  62. }
  63. }