I am using CakePHP 2.4
I have a Model class called Storybook.
There is a method called createDraft and its code looks like this:
public function createDraft($data) {
$data['Storybook']['author'] = AuthComponent::user('id');
When I write a test script using the CakePHP Tests, I have a problem instantiating the user data inside AuthComponent.
My test script looks like this:
<?php
App::uses('Storybook', 'Model');
class StorybookTestCase extends CakeTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(...
);
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Storybook = ClassRegistry::init('Storybook');
...
...
/**
* GIVEN we have only a title
* WHEN we call createDraft
* THEN we have a new draft
*
* @return void
*/
public function testCreateDraftSuccessfully() {
// GIVEN only a title
$data = array('Storybook' => array('title' => 'some title'));
// WHEN we call the createDraft
$actualResult = $this->Storybook->createDraft($data);
....
The test failed at createDraft method.
I cannot fill in the AuthComponent with user data at the setUp method since AuthComponent login method is not static.
Please advise.