FixturizedTestCase.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\Fixture;
  16. use Cake\TestSuite\Fixture\FixtureManager;
  17. use Cake\TestSuite\TestCase;
  18. use Exception;
  19. /**
  20. * This class helps in testing the life-cycle of fixtures inside a CakeTestCase
  21. */
  22. class FixturizedTestCase extends TestCase
  23. {
  24. /**
  25. * Fixtures to use in this test
  26. *
  27. * @var list<string>
  28. */
  29. protected array $fixtures = ['core.Categories', 'core.Articles'];
  30. /**
  31. * test that the shared fixture is correctly set
  32. */
  33. public function testFixturePresent(): void
  34. {
  35. $this->assertInstanceOf(FixtureManager::class, $this->fixtureManager);
  36. }
  37. /**
  38. * test that it is possible to load fixtures on demand
  39. */
  40. public function testFixtureLoadOnDemand(): void
  41. {
  42. $this->loadFixtures('Categories');
  43. }
  44. /**
  45. * test that calling loadFixtures without args loads all fixtures
  46. */
  47. public function testLoadAllFixtures(): void
  48. {
  49. $this->loadFixtures();
  50. $article = $this->getTableLocator()->get('Articles')->get(1);
  51. $this->assertSame(1, $article->id);
  52. $category = $this->getTableLocator()->get('Categories')->get(1);
  53. $this->assertSame(1, $category->id);
  54. }
  55. /**
  56. * test that a test is marked as skipped using skipIf and its first parameter evaluates to true
  57. */
  58. public function testSkipIfTrue(): void
  59. {
  60. $this->skipIf(true);
  61. }
  62. /**
  63. * test that a test is not marked as skipped using skipIf and its first parameter evaluates to false
  64. */
  65. public function testSkipIfFalse(): void
  66. {
  67. $this->skipIf(false);
  68. $this->assertTrue(true, 'Avoid phpunit warnings');
  69. }
  70. /**
  71. * test that a fixtures are unloaded even if the test throws exceptions
  72. *
  73. * @throws \Exception
  74. */
  75. public function testThrowException(): void
  76. {
  77. throw new Exception();
  78. }
  79. }