Monday, December 21, 2015

Cakephp Unit testing:using fixtures in components

Hi,
Iam writing test cases for one component ,need to use fixtures in compoment.
my code is
Class SampleComponentTest extends TestCase
{
    public $component = null;
    public $controller = null;
    public $fixtures = ['app.cities','plugin.sampleplugin.states'];
    public function setUp()
    {
        parent::setUp();
        $request = new Request();
        $response = new Response();
        $this->controller = $this->getMock(
            'Cake\Controller\Controller',
            [],
            [$request, $response]
        );
        $registry = new ComponentRegistry($this->controller);
        $this->component = new SampleComponent($registry);
    }
}
And i need to use two fixtures ,one is from app and another is from plugin.
when i run the code i got followign exception
"Exception: Referenced fixture class "SamplePlugin\Test\Fixture\StatesFixture" not found. Fixture "plugin.sampleplugin.states" was referenced in test case "App\Test\TestCase\Controller\Component\SampleComponentTest". in [D:\Projects\xampp\htdocs\testapp\vendor\
cakephp\cakephp\src\TestSuite\Fixture\FixtureManager.php, line 213]".

please provide the solutions to that how to use fixtures in component with sample code/
doubts
1)$this->component is mock object or direct object>
2)what is second parameter of getMock() method(if i provide empty it giving the error,above i replaced with empty)
3)

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at https://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: