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