FixturizedTestCase.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Cake\Test\Fixture;
  3. use Cake\ORM\TableRegistry;
  4. use Cake\TestSuite\TestCase;
  5. use Exception;
  6. /**
  7. * This class helps in testing the life-cycle of fixtures inside a CakeTestCase
  8. */
  9. class FixturizedTestCase extends TestCase
  10. {
  11. /**
  12. * Fixtures to use in this test
  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 = TableRegistry::get('Articles')->get(1);
  43. $this->assertSame(1, $article->id);
  44. $category = TableRegistry::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. }