FixturizedTestCase.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 array<string>
  28. */
  29. protected $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. }
  69. /**
  70. * test that a fixtures are unloaded even if the test throws exceptions
  71. *
  72. * @throws \Exception
  73. */
  74. public function testThrowException(): void
  75. {
  76. throw new Exception();
  77. }
  78. }