FixturizedTestCase.php 1.9 KB

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