I have partly resolved this by downloading the latest version of Debug 
Toolkit as that was not handling the underlying error properly (
http://cakephp.lighthouseapp.com/projects/42880/tickets/91-serializing-pdo-instances).
 
I now just need to learn more about using fixtures as it is causing a 
'table already exists' error. Why would that happen if I've specified a 
fixture, or am I missing something fundamental?

On Friday, 3 August 2012 06:44:12 UTC+1, Jeremy Burns wrote:
>
> To my shame, I haven't done much with testing but have taken the plunge 
> and am adopting it for all future projects, starting now.
>
> I have the seed of a site that has a database (normal and test version) 
> and model/view/controller. I can access faq_categories/index when using 
> either the normal or test database configuration.
>
> I have a controller test and a model test, both work fine and pass. When I 
> add in a fixture the site goes into an endless spiral. Not sure what I'm 
> doing wrong - here's the model test, the fixture and the errors. Note that 
> it works fine until uncomment the fixture.
>
> // /app/Test/Case/Model/FaqCategoryTest.php
> <?php
> App::uses('FaqCategory', 'Model');
>
> class FaqCategoryTest extends CakeTestCase {
>     
>     // public $fixtures = array('app.faq_category');
>     
> public function setUp() {
> parent::setUp();
> $this->FaqCategory = ClassRegistry::init('FaqCategory');
> }
>  public function testEnabled() {
> $result = $this->FaqCategory->enabled();
>
> $expected = array(
> array('FaqCategory' => array('id' => 1, 'name' => 'First Category')),
> array('FaqCategory' => array('id' => 3, 'name' => 'Third Category'))
> );
>  $this->assertEquals($expected, $result);
> }
>     
> }
>
> // /app/Test/Fixture/FaqCategoryFixture.php
>
> <?php
> class FaqCategoryFixture extends CakeTestFixture {
>
> /* Optional. Set this property to load fixtures to a different test 
> datasource */
> public $useDbConfig = 'test';
>
> public $fields = array(
> 'id' => array(
> 'type' => 'integer',
> 'length' => 3,
> 'key' => 'primary'
> ),
> 'name' => array(
> 'type' => 'string',
> 'length' => 255,
> 'null' => false,
> 'default' => ''
> ),
> 'display_order' => array(
> 'type' => 'integer',
> 'length' => 3,
> 'null' => false,
> 'default' => 255
> ),
> 'enabled' => array(
> 'type' => 'integer',
> 'length' => 1,
> 'null' => false,
> 'default' => 1
> ),
> 'created' => 'datetime',
> 'modified' => 'datetime'
> );
>
> public $records = array(
> array(
> 'id' => 1,
> 'name' => 'First Category',
> 'display_order' => 10,
> 'enabled' => 1,
> 'created' => '2012-08-02 18:00:00',
> 'modified' => '2012-08-02 18:00:00'
> ),
> array(
> 'id' => 2,
> 'name' => 'Second Category',
> 'display_order' => 20,
> 'enabled' => 0,
> 'created' => '2012-08-02 18:00:00',
> 'modified' => '2012-08-02 18:00:00'
> ),
> array(
> 'id' => 3,
> 'name' => 'Third Category',
> 'display_order' => 30,
> 'enabled' => 1,
> 'created' => '2012-08-02 18:00:00',
> 'modified' => '2012-08-02 18:00:00'
> )
> );
>
> }
>
> // RESULTS
>
> // without a fixture:
> 1/1 test methods complete: *1* passes, *0* fails, *1* assertions and 
> *0*exceptions.
>
> // with a fixture
> // first error only occurs when I specify a db config - but then I would 
> not expect a fixture to create a table - am I wrong? If so, I guess I need 
> to use teardown?
>
> 2012-08-03 05:37:16 Error: Fixture creation for "faq_categories" failed 
> "SQLSTATE[42S01]: Base table or view already exists: 1050 Table 
> 'faq_categories' already exists"
>
> // next error (whether the first error is present or not)
> #0 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Model/Datasource/DboSource.php(2919):
>  
> PDOStatement->execute()
> #1 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/TestSuite/Fixture/CakeTestFixture.php(254):
>  
> DboSource->insertMulti('faq_categories', Array, Array)
> #2 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php(215):
>  
> CakeTestFixture->insert(Object(Mysql))
> #3 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/TestSuite/CakeTestCase.php(76):
>  
> CakeFixtureManager->load(Object(FaqCategoryTest))
> #4 /usr/lib/php/pear/PHPUnit/Framework/TestSuite.php(772): 
> CakeTestCase->run(Object(PHPUnit_Framework_TestResult))
> #5 /usr/lib/php/pear/PHPUnit/Framework/TestSuite.php(745): 
> PHPUnit_Framework_TestSuite->runTest(Object(FaqCategoryTest), 
> Object(PHPUnit_Framework_TestResult))
> #6 /usr/lib/php/pear/PHPUnit/TextUI/TestRunner.php(325): 
> PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult), 
> false, Array, Array, false)
> #7 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/TestSuite/CakeTestRunner.php(57):
>  
> PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
> #8 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/TestSuite/CakeTestSuiteCommand.php(111):
>  
> CakeTestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
> #9 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php(242):
>  
> CakeTestSuiteCommand->run(Array)
> #10 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php(99):
>  
> CakeTestSuiteDispatcher->_runTestCase()
> #11 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php(116):
>  
> CakeTestSuiteDispatcher->dispatch()
> #12 /Volumes/Data/jeremyburns/Sites/mysite/app/webroot/test.php(92): 
> CakeTestSuiteDispatcher::run()
> #13 {main}
> 2012-08-03 05:37:16 Error: Fatal Error (256): [PDOException] You cannot 
> serialize or unserialize PDO instances
>
> // and then this block repeats
> #0 [internal function]: PDO->__sleep()
> #1 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Cache/Engine/FileEngine.php(131):
>  
> serialize(Array)
> #2 /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Cache/Cache.php(298): 
> FileEngine->write('cake_toolbar_ca...', Array, 14400)
> #3 
> /Volumes/Data/jeremyburns/Sites/mysite/app/Plugin/DebugKit/Controller/Component/ToolbarComponent.php(368):
>  
> Cache::write('toolbar_cache5b...', Array, 'debug_kit')
> #4 
> /Volumes/Data/jeremyburns/Sites/mysite/app/Plugin/DebugKit/Controller/Component/ToolbarComponent.php(233):
>  
> ToolbarComponent->_saveState(Object(CakeErrorController), Array)
> #5 [internal function]: 
> ToolbarComponent->beforeRender(Object(CakeErrorController))
> #6 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Utility/ObjectCollection.php(130):
>  
> call_user_func_array(Array, Array)
> #7 [internal function]: ObjectCollection->trigger(Object(CakeEvent))
> #8 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Event/CakeEventManager.php(246):
>  
> call_user_func(Array, Object(CakeEvent))
> #9 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Controller/Controller.php(922):
>  
> CakeEventManager->dispatch(Object(CakeEvent))
> #10 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Error/ExceptionRenderer.php(297):
>  
> Controller->render('error500')
> #11 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Error/ExceptionRenderer.php(278):
>  
> ExceptionRenderer->_outputMessageSafe('error500')
> #12 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Error/ExceptionRenderer.php(257):
>  
> ExceptionRenderer->_outputMessage('pdo_error')
> #13 [internal function]: ExceptionRenderer->pdoError(Object(PDOException))
> #14 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Error/ExceptionRenderer.php(170):
>  
> call_user_func_array(Array, Array)
> #15 
> /Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Error/ErrorHandler.php(127): 
> ExceptionRenderer->render()
> #16 [internal function]: 
> ErrorHandler::handleException(Object(PDOException))
> #17 {main} in 
> [/Volumes/Data/jeremyburns/Sites/mysite/lib/Cake/Error/ErrorHandler.php, 
> line 136]
> 2012-08-03 05:37:16 Error: [FatalErrorException] [PDOException] You cannot 
> serialize or unserialize PDO instances
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to