TransactionStrategyTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 4.3.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\TestSuite;
  17. use Cake\Datasource\ConnectionManager;
  18. use Cake\TestSuite\Fixture\TransactionStrategy;
  19. use Cake\TestSuite\TestCase;
  20. class TransactionStrategyTest extends TestCase
  21. {
  22. protected array $fixtures = ['core.Articles'];
  23. /**
  24. * Tests truncation strategy.
  25. */
  26. public function testStrategy(): void
  27. {
  28. /**
  29. * @var \Cake\Database\Connection $connection
  30. */
  31. $connection = ConnectionManager::get('test');
  32. $connection->deleteQuery()->delete('articles')->execute()->closeCursor();
  33. $rows = $connection->selectQuery()->select('*')->from('articles')->execute();
  34. $this->assertEmpty($rows->fetchAll());
  35. $rows->closeCursor();
  36. $strategy = new TransactionStrategy();
  37. $strategy->setupTest(['core.Articles']);
  38. $rows = $connection->selectQuery()->select('*')->from('articles')->execute();
  39. $this->assertNotEmpty($rows->fetchAll());
  40. $rows->closeCursor();
  41. $strategy->teardownTest();
  42. $rows = $connection->selectQuery()->select('*')->from('articles')->execute();
  43. $this->assertEmpty($rows->fetchAll());
  44. $rows->closeCursor();
  45. }
  46. }