Hi everybody

I'd like to use a test DB so I can safely test my app. Following the
"Preparing Test Data" tutorial (http://book.cakephp.org/view/358/
Preparing-test-data) I created the following 3 files:

models/article.php:
<?php
        class Article extends AppModel {
                  var $name = 'Article';

                  function published($fields = null) {
                          $conditions = array(
                                  $this->name . '.published' => 1
                          );

                          return $this->findAll($conditions, $fields);
                  }

        }
?>

test/cases/models/article.test.php
<?php
App::import('Model', 'Article');

class ArticleTestCase extends CakeTestCase {
        var $fixtures = array( 'app.article' );

        function testPublished() {
                $this->Article =& ClassRegistry::init('Article');

                $result = $this->Article->published(array('id', 'title'));
                $expected = array(
                        array('Article' => array( 'id' => 1, 'title' => 'First 
Article' )),
                        array('Article' => array( 'id' => 2, 'title' => 'Second
Article' )),
                        array('Article' => array( 'id' => 3, 'title' => 'Third 
Article' ))
                );

                $this->assertEqual($result, $expected);
        }
}
?>

tests/fixtures/article_fixture.php:
<?php
 class ArticleFixture extends CakeTestFixture {
      var $name = 'Article';

      var $fields = array(
          'id' => array('type' => 'integer', 'key' => 'primary'),
          'title' => array('type' => 'string', 'length' => 255, 'null'
=> false),
          'body' => 'text',
          'published' => array('type' => 'integer', 'default' => '0',
'null' => false),
          'created' => 'datetime',
          'updated' => 'datetime'
      );

      var $records = array(
          array ('id' => 1, 'title' => 'First Article', 'body' =>
'First Article Body', 'published' => '1', 'created' => '2007-03-18
10:39:23', 'updated' => '2007-03-18 10:41:31'),
          array ('id' => 2, 'title' => 'Second Article', 'body' =>
'Second Article Body', 'published' => '1', 'created' => '2007-03-18
10:41:23', 'updated' => '2007-03-18 10:43:31'),
          array ('id' => 3, 'title' => 'Third Article', 'body' =>
'Third Article Body', 'published' => '1', 'created' => '2007-03-18
10:43:23', 'updated' => '2007-03-18 10:45:31')
      );
 }
 ?>

So far, so good. But now it's getting confusing:
- When I'm running my test for the first time, I get the error
"Error:  Database table articles for model Article was not found." But
at the same time, it creates me an (empty!) articles table.
- When I'm running my test for the second time, I get the same error
again, but this time the database contains the 3 records specified in
article_fixture.php!

This looks very strange to me. Anybody got an idea what's going on
here?

Thank you
Josh

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to