Cakephp Modulation Testing Models, Lighting Problem

So, I am working with CakePHP v1.2.5. In my current project, I decided to start writing tests when I code functionality (yay TDD). I'm having problems booting the device.

To help in this process, I will describe my code (actually quite simple right now). My model is defined like this

// app/models/newsitem.php
<?php
class NewsItem extends AppModel
{
  var $name='NewsItem';
}
?>

// app/tests/fixtures/newsitem_fixture.php
<?php

class NewsItemFixture extends CakeTestFixture 
{
    var $name = 'NewsItem';
    var $import = 'NewsItem';

    var $records = array(
        array('id' => '1', 'title' => 'News Item 1', 'body' => 'This is the first piece of news', 'created' => '2007-03-18 10:39:23', 'modified' => '2007-03-18 10:41:31'),
        array('id' => '2', 'title' => 'News 2', 'body' => 'This is some other piece of news', 'created' => '2009-05-04 9:00:00', 'modified' => '2009-05-05 12:34:56')
    );
}

?>

// app/tests/models/newsitem.test.php
<?php
App::Import('Model', 'NewsItem');

class NewsItemTestCase extends CakeTestCase
{
    var $fixtures = array('app.newsitem');

    function setUp()
    {
        $this->NewsItem =& ClassRegistry::init('NewsItem');
    }

    function testFindAll()
    {
        $results = $this->NewsItem->findAll();
        $expected = array(
            array('NewsItem' => array('id' => '1', 'title' => 'News Item 1', 'body' => 'This is the first piece of news', 'created' => '2007-03-18 10:39:23', 'modified' => '2007-03-18 10:41:31')),
            array('NewsItem' => array('id' => '2', 'title' => 'News 2', 'body' => 'This is some other piece of news', 'created' => '2009-05-04 9:00:00', 'modified' => '2009-05-05 12:34:56'))
        );
        print_r($results);
        $this->assertEqual($results, $expected);
    }   
}

?>

Anyway, my problem is that when I run the test package in the browser (going to http: //localhost/test.php ), the tester tries to load my application layout (this is strange because I'm just testing the model), which refers to another model that is not explicitly loaded into the test database, and I get an error.

var $fixtures = array('app.newsitem') NewsItemTestCase, , ( ).

, ? , .

+3
1

, , "NewsItemFixture", news_item_fixture, newsitem_fixture. , , newsitem_fixture, . News/Template.

, , .

+2

Source: https://habr.com/ru/post/1725359/


All Articles