FixtureManagerTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestSuite;
  16. use Cake\Core\Plugin;
  17. use Cake\Database\ConnectionManager;
  18. use Cake\TestSuite\Fixture\FixtureManager;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * Fixture manager test case.
  22. */
  23. class FixtureManagerTest extends TestCase
  24. {
  25. /**
  26. * Setup method
  27. *
  28. * @return void
  29. */
  30. public function setUp()
  31. {
  32. parent::setUp();
  33. $this->manager = new FixtureManager();
  34. }
  35. /**
  36. * Test loading core fixtures.
  37. *
  38. * @return void
  39. */
  40. public function testFixturizeCore()
  41. {
  42. $test = $this->getMock('Cake\TestSuite\TestCase');
  43. $test->fixtures = ['core.articles'];
  44. $this->manager->fixturize($test);
  45. $fixtures = $this->manager->loaded();
  46. $this->assertCount(1, $fixtures);
  47. $this->assertArrayHasKey('core.articles', $fixtures);
  48. $this->assertInstanceOf('Cake\Test\Fixture\ArticlesFixture', $fixtures['core.articles']);
  49. }
  50. /**
  51. * Test loading app fixtures.
  52. *
  53. * @return void
  54. */
  55. public function testFixturizePlugin()
  56. {
  57. Plugin::load('TestPlugin');
  58. $test = $this->getMock('Cake\TestSuite\TestCase');
  59. $test->fixtures = ['plugin.test_plugin.articles'];
  60. $this->manager->fixturize($test);
  61. $fixtures = $this->manager->loaded();
  62. $this->assertCount(1, $fixtures);
  63. $this->assertArrayHasKey('plugin.test_plugin.articles', $fixtures);
  64. $this->assertInstanceOf(
  65. 'TestPlugin\Test\Fixture\ArticlesFixture',
  66. $fixtures['plugin.test_plugin.articles']
  67. );
  68. }
  69. /**
  70. * Test loading app fixtures.
  71. *
  72. * @return void
  73. */
  74. public function testFixturizeCustom()
  75. {
  76. $test = $this->getMock('Cake\TestSuite\TestCase');
  77. $test->fixtures = ['plugin.Company/TestPluginThree.articles'];
  78. $this->manager->fixturize($test);
  79. $fixtures = $this->manager->loaded();
  80. $this->assertCount(1, $fixtures);
  81. $this->assertArrayHasKey('plugin.Company/TestPluginThree.articles', $fixtures);
  82. $this->assertInstanceOf(
  83. 'Company\TestPluginThree\Test\Fixture\ArticlesFixture',
  84. $fixtures['plugin.Company/TestPluginThree.articles']
  85. );
  86. }
  87. /**
  88. * Test that unknown types are handled gracefully.
  89. *
  90. * @expectedException \UnexpectedValueException
  91. * @expectedExceptionMessage Referenced fixture class "Test\Fixture\Derp.derpFixture" not found. Fixture "derp.derp" was referenced
  92. */
  93. public function testFixturizeInvalidType()
  94. {
  95. $test = $this->getMock('Cake\TestSuite\TestCase');
  96. $test->fixtures = ['derp.derp'];
  97. $this->manager->fixturize($test);
  98. }
  99. }