php - Symfony2 PHPUnit testing class with services -


i working symfony2 , trying phpunit testing. class trying test has 2 services injected:

validationclass databaserepository 

i have created test file class 'mytemplatetest.php' under test/template directory.

my test file:

<?php  namespace fun\funbundle\tests\dto\template;  use fun\funbundle\dto\template\mytemplate;  class mytemplatetest extends \phpunit_framework_testcase {     public function testbuild()     {         $validation = $this->getmock('validationclass');         $database = $this->getmock('databaserepository');          $confirm = new mytemplate($validation, $database);     } } 

when run phpunit -c app/

i these errors:

argument 1 passed fun\funbundle\dto\template\mytemplate::__construct() must instance of fun\funbundle\validation\validationclass, string given, called in dev/project/src/fun/funbundle/tests/template/mytemplatetest.php

mytemplate

class mytemplate {       /**      * @var validationclass      */     private $validate;      /**      * @var databaserepository      */     private $db;      /**      * @param validationclass $validation      * @param databaserepository $databaserepository      */     public function __construct(         validationclass $validation,         databaserepository $databaserepository     ) {         $this->validate = $validation;         $this->db = $databaserepository;     } } 

i came point have no idea how can test mytemplate class :/ understand errors relating injected services how replicate or in testmytemplate file?

i think you'll need add fqn (fully qualified name) of these classes able mock properly. you'll need prefix validationclass full namespace, some\folder\validation\validationclass


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -