Phpunit测试 - 无法找到实体(Symfony)

时间:2016-12-20 15:26:00

标签: symfony doctrine phpunit

我是symfony和phpunit测试的新手,并且已经收到此错误

不能存根或模拟类或接口" com \ twcl \ agripayrollBundle \ Entity \ Payrollperiod"哪个不存在

这是我在Tests目录中的Selenium Test文件中的测试。

  use com\twcl\agripayrollBundle\Mapping\PayPeriodManager;
  use com\twcl\agripayrollBundle\Entity\Payrollperiod;
  use Doctrine\ORM\EntityRepository;
  use Doctrine\Common\Persistence\ObjectManager;
 class PayrollperiodManagerTest extends PHPUnit_Framework_TestCase  {public function testPayrollPeriodManager()
{
    $payperiod= $this->createMock(Payrollperiod::class);
    $payperiod->expects($this->once())
              ->method('setstartDate')
              ->will($this->setValue(2011-01-01));
    $payperiod->expects($this->once())
              ->method('setendDate')
              ->will($this->setValue(2011-01-18));
    $payperiod->expects($this->once())
              ->method('setState')
              ->will($this->setValue('Active'));

    var_dump($payperiod);
    die();

   }
   }

这是我的phpunit.xml.dist        

   <!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
   <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
     backupGlobals="false"
     colors="true"
     bootstrap="bootstrap.php.cache"
   >
     <testsuites>
      <testsuite name="Project Test Suite">
           <directory>../src/*/*Bundle/Tests</directory>
          <directory>../src/*/Bundle/*Bundle/Tests</directory>
    </testsuite>
</testsuites>

   <!--
   <php>
    <server name="KERNEL_DIR" value="/path/to/your/app/" />
   </php>
    -->

    <filter>
    <whitelist>
        <directory>../src</directory>
        <exclude>
            <directory>../src/*/*Bundle/Resources</directory>
            <directory>../src/*/*Bundle/Tests</directory>
            <directory>../src/*/Bundle/*Bundle/Resources</directory>
            <directory>../src/*/Bundle/*Bundle/Tests</directory>
               </exclude>
          </whitelist>
         </filter>
      </phpunit>

我的自动加载器

  <?php

    use Doctrine\Common\Annotations\AnnotationRegistry;
    use Composer\Autoload\ClassLoader;

     /**
       * @var ClassLoader $loader
       */
    $loader = require __DIR__.'/../vendor/autoload.php';

    AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

   return $loader;

0 个答案:

没有答案