0

I am testing controllers add method (CakePHP2.0).
But the issue is that what ever data I send as post gets added to my default databases and not my test database. Heres the code.

public function testAdd() {
  $data = array(
  'Post' => array(
    'title' => 'Fourth Post Title',
    'body' => 'Fourth Post Body',
    'created' => '2012-01-22 21:31:52'
    )
  );
  $result = $this->testAction('/posts/add', array('data' => $data, 'method', 'post'));
  debug($result);
}

What I was actually expecting that the posted data togo into test DB that i configured in database.php and not in default DB.

1
  • As you set config/database.php DATABASE_CONFIG $default and $test? Commented Jan 28, 2012 at 21:05

1 Answer 1

2

There are a few requirements for tests to occur in CakePHP 2.0 that you may want to double check:

Ensure that your Database Config setting in config/database.php is setup as

public $test = array(
  //Sample Test Settings Here
);

If you running tests from the web interface, debug must be set to at least 1 or else the tests will not run.

You can also validate that PHPUnit and your test database connection is working properly by running CakePHP core tests by navigating to: http://localhost/your_app/test.php and "AllConfigure" test.

All information from the CakePHP Book: http://book.cakephp.org/2.0/en/development/testing.html

Sign up to request clarification or add additional context in comments.

1 Comment

Hi thanks for the reply, Actually my test cases run properly. The only issue is when testing controllers add request, the entries go into default DB. I have setup $test array as that in documentation. My test cases for model add request does not effect the default DB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.