pictcode / lib / Cake / Test / Case / TestSuite / Fixture / CakeFixtureManagerTest.php @ f4745fee
履歴 | 表示 | アノテート | ダウンロード (2.8 KB)
| 1 | 635eef61 | spyder1211 | <?php
|
|---|---|---|---|
| 2 | /**
|
||
| 3 | * CakeFixtureManager file
|
||
| 4 | *
|
||
| 5 | * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||
| 6 | * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
| 7 | *
|
||
| 8 | * Licensed under The MIT License
|
||
| 9 | * For full copyright and license information, please see the LICENSE.txt
|
||
| 10 | * Redistributions of files must retain the above copyright notice.
|
||
| 11 | *
|
||
| 12 | * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
| 13 | * @link http://cakephp.org CakePHP Project
|
||
| 14 | * @package Cake.Test.Case.TestSuite.Fixture
|
||
| 15 | * @since CakePHP v 2.5
|
||
| 16 | * @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||
| 17 | */
|
||
| 18 | |||
| 19 | App::uses('DboSource', 'Model/Datasource'); |
||
| 20 | App::uses('CakeFixtureManager', 'TestSuite/Fixture'); |
||
| 21 | App::uses('UuidFixture', 'Test/Fixture'); |
||
| 22 | |||
| 23 | /**
|
||
| 24 | * Test Case for CakeFixtureManager class
|
||
| 25 | *
|
||
| 26 | * @package Cake.Test.Case.TestSuite
|
||
| 27 | */
|
||
| 28 | class CakeFixtureManagerTest extends CakeTestCase { |
||
| 29 | |||
| 30 | /**
|
||
| 31 | * reset environment.
|
||
| 32 | *
|
||
| 33 | * @return void
|
||
| 34 | */
|
||
| 35 | public function setUp() { |
||
| 36 | parent::setUp();
|
||
| 37 | $this->fixtureManager = new CakeFixtureManager(); |
||
| 38 | } |
||
| 39 | |||
| 40 | /**
|
||
| 41 | * tearDown
|
||
| 42 | *
|
||
| 43 | * @return void
|
||
| 44 | */
|
||
| 45 | public function tearDown() { |
||
| 46 | parent::tearDown();
|
||
| 47 | unset($this->fixtureManager); |
||
| 48 | } |
||
| 49 | |||
| 50 | /**
|
||
| 51 | * testLoadTruncatesTable
|
||
| 52 | *
|
||
| 53 | * @return void
|
||
| 54 | */
|
||
| 55 | public function testLoadTruncatesTable() { |
||
| 56 | $MockFixture = $this->getMock('UuidFixture', array('truncate')); |
||
| 57 | $MockFixture
|
||
| 58 | ->expects($this->once())
|
||
| 59 | ->method('truncate')
|
||
| 60 | ->will($this->returnValue(true)); |
||
| 61 | |||
| 62 | $fixtureManager = $this->fixtureManager; |
||
| 63 | $fixtureManagerReflection = new ReflectionClass($fixtureManager); |
||
| 64 | |||
| 65 | $loadedProperty = $fixtureManagerReflection->getProperty('_loaded'); |
||
| 66 | $loadedProperty->setAccessible(true); |
||
| 67 | $loadedProperty->setValue($fixtureManager, array('core.uuid' => $MockFixture)); |
||
| 68 | |||
| 69 | $TestCase = $this->getMock('CakeTestCase'); |
||
| 70 | $TestCase->fixtures = array('core.uuid'); |
||
| 71 | $TestCase->autoFixtures = true; |
||
| 72 | $TestCase->dropTables = false; |
||
| 73 | |||
| 74 | $fixtureManager->load($TestCase); |
||
| 75 | } |
||
| 76 | |||
| 77 | /**
|
||
| 78 | * testLoadSingleTruncatesTable
|
||
| 79 | *
|
||
| 80 | * @return void
|
||
| 81 | */
|
||
| 82 | public function testLoadSingleTruncatesTable() { |
||
| 83 | $MockFixture = $this->getMock('UuidFixture', array('truncate')); |
||
| 84 | $MockFixture
|
||
| 85 | ->expects($this->once())
|
||
| 86 | ->method('truncate')
|
||
| 87 | ->will($this->returnValue(true)); |
||
| 88 | |||
| 89 | $fixtureManager = $this->fixtureManager; |
||
| 90 | $fixtureManagerReflection = new ReflectionClass($fixtureManager); |
||
| 91 | |||
| 92 | $fixtureMapProperty = $fixtureManagerReflection->getProperty('_fixtureMap'); |
||
| 93 | $fixtureMapProperty->setAccessible(true); |
||
| 94 | $fixtureMapProperty->setValue($fixtureManager, array('UuidFixture' => $MockFixture)); |
||
| 95 | |||
| 96 | $dboMethods = array_diff(get_class_methods('DboSource'), array('enabled')); |
||
| 97 | $dboMethods[] = 'connect'; |
||
| 98 | $db = $this->getMock('DboSource', $dboMethods); |
||
| 99 | $db->config['prefix'] = ''; |
||
| 100 | |||
| 101 | $fixtureManager->loadSingle('Uuid', $db, false); |
||
| 102 | } |
||
| 103 | } |